Skip to main content
TanStack Start is a server-mode Commerce Engine SEO integration in the production starters: use one request middleware for discovery surfaces, build route head data from loader results, and register WebMCP from one root client initializer.

1. Share site and route configuration

Keep public site identity and routes in a storefront-free module so both server SEO code and browser agent registration can import it safely.
src/lib/commerce-seo.config.ts

2. Create the SEO instance

src/lib/seo.ts
Browser code should import site and routes from commerce-seo.config.ts, not from the module exporting seo. The SEO instance holds the storefront and is used by loaders, head generation, and request middleware.

3. Mount one request middleware

TanStack file-route params must be valid JavaScript identifiers, so .md mirror paths are a poor fit for route files. Mount the Commerce Engine request middleware once instead:
src/start.ts
The request adapter always handles:
  • product/category/search Markdown negotiation
  • explicit .md mirrors
  • /llms.txt
  • /sitemap.md
robots.txt and the XML sitemap are deliberately opt-in in server mode; the example enables both.

4. Build route head data from loader data

head itself is synchronous, so resolve catalog data and asynchronous SEO routes in the loader and return the completed head model through loaderData.
src/routes/product/$slug.tsx
Only a confirmed missing product should become a not-found state. Treat transport/5xx catalog failures as recoverable failures rather than permanent 404s.
Breadcrumb URLs come from seo.productUrl() and seo.categoryUrl(). Do not rebuild /product/... or /category/... strings independently; custom route bases and CMS-owned slugs must remain consistent across canonicals, sitemaps, Markdown, breadcrumbs, and agent navigation.

5. Register WebMCP independently of session bootstrap

Tool registration only declares capabilities. Public catalog tools should not wait for anonymous-session or Hosted Checkout initialization, and session/cart tools already return a retryable not-ready result until the session is usable.
src/components/StorefrontInitializer.tsx
Mount this initializer once near the router root. Registration and checkout bootstrap run in parallel, and teardown cannot leave a late WebMCP registration alive after unmount.

Production checklist

  • src/start.ts mounts createTanStackStartSeoMiddleware() once
  • server mode enables robots: true and sitemap: true when Commerce Engine owns those routes
  • loaders use publicStorefront() for public catalog reads
  • asynchronous SEO head data is resolved in the loader and returned through loaderData
  • breadcrumb URLs use SEO route resolvers
  • WebMCP registration starts without waiting for session bootstrap
  • late registration is aborted if the root initializer unmounts
  • development diagnostics prove registration actually ran
  • site and routes come from the pure shared config in browser code

Reference starter

Full TanStack Start storefront using request middleware, route head data, and independent WebMCP registration.