server with registered tools; see the complete examples for runnable applications and lifecycle handling. Mount combined handlers at the application root so auth metadata is reachable.
Express
next before reading the body. Close both the application listener and Toolgrain server on shutdown.
Hono
server.close().
Elysia
Next.js App Router
For an unprotected endpoint, define the server once in a route module and export its Web handler:app/mcp/route.ts
lib/server.ts is your module exporting a composed server. Use explicit metadata factories in a matching well-known route when protecting a filesystem-routed endpoint; exporting /mcp alone does not make the public metadata path routable. Apply the same production host settings to both handlers. See authorization integration.
The examples independently test plain Node, Express, Hono, Elysia, and Next.js. Fastify and NestJS are not separately verified; do not infer a tested integration from shared Request/Response types.