Skip to main content
Next.js is the lowest-wiring server deployment: one pure public config, one server-bound SEO instance, one proxy/middleware for the discovery surfaces, and one Client Component for agent tools.

1. Create the shared public config

src/lib/commerce-seo.config.ts

2. Create the server-bound SEO instance

src/lib/seo.ts
Client Components must not import @/lib/seo. Import site and routes from commerce-seo.config.ts. The SEO instance holds the storefront and belongs on the server/build side of the bundle boundary.

3. Serve every discovery surface from one proxy

Next.js 16 uses proxy.ts. On Next.js 15, export the same handler from middleware.ts.
src/proxy.ts
This one handler owns:
  • product/category Markdown mirrors
  • same-URL Markdown negotiation
  • /llms.txt
  • /sitemap.md
  • robots.txt
  • sitemap.xml and shards beyond the URL limit
You do not need eleven separate App Router route files.

Static/prerendered Next output

If the deployment has no Next server at request time, use the same prebuild strategy as a React/Vite app and write assets into public/ with @commercengine/seo/build.

4. Generate native Next metadata

Use the public storefront inside generateMetadata:
app/product/[slug]/page.tsx
If public/CMS slugs differ from CE slugs, resolve the route first:
Category pages use createCategoryMetadata().

5. Render product JSON-LD and breadcrumbs

Next Metadata covers normal head metadata. Render JSON-LD in the page body:
You can use your own safe JSON-LD serializer or the package serializer. Do not emit a second hand-written Product schema for the same item.

Product-specific Open Graph properties

productOpenGraphTags() from @commercengine/seo/nextjs exposes product Open Graph fields that do not map cleanly into the generic Next Metadata shape:

6. Register WebMCP in a root Client Component

src/components/AgentTools.tsx
Mount <AgentTools /> once in the root layout. It returns no UI.
Do not wait for storefront.bootstrap() before registering the tools. Registration only declares them; session-dependent tools already report a retryable failure until the browser session is ready.

7. Hosted Checkout remains human-controlled

If you already use Hosted Checkout, keep its normal root bootstrap. The AI bridge only exposes open_cart, open_checkout, and optionally open_login; cart mutations themselves use the authenticated Storefront SDK. See Hosted Checkout + Next.js for the session synchronization pattern.

Production checklist

  • proxy.ts matcher includes the .md, robots, sitemap, and discovery paths you enable
  • generateMetadata uses publicStorefront() rather than a live session accessor
  • PDP has exactly one product schema plus its breadcrumb schema
  • Client AgentTools imports commerce-seo.config, not the server SEO module
  • registration?.abort() runs on unmount
  • development console contains the Commerce AI registration diagnostic
  • direct requests to /product/example.md, /llms.txt, and /sitemap.xml return successfully

Reference starter

Full Next.js production storefront with both packages wired.