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
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
- product/category/search Markdown negotiation
- explicit
.mdmirrors /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
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
Production checklist
src/start.tsmountscreateTanStackStartSeoMiddleware()once- server mode enables
robots: trueandsitemap: truewhen 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
siteandroutescome from the pure shared config in browser code
Reference starter
Full TanStack Start storefront using request middleware, route head data, and independent WebMCP registration.