ConstFactory invoked once per new client session to build the McpServer.
OptionalsessionOptions: McpSessionOptionsOptional per-session lifecycle controls (idle timeout, max age, cap).
Declarative McpServerConfig bundle. A fresh McpServer is built per
session by passing this config to create_mcp_server.
OptionalsessionOptions: McpSessionOptionsOptional per-session lifecycle controls.
Creates a mountable Router that hosts an MCP server over the Streamable HTTP transport. Each client session gets its own
McpServerinstance and its own transport, keyed by themcp-session-idheader. POST without a session ID initializes a new session; POST with a known session ID dispatches to the existing transport; GET streams server-to-client notifications for an existing session; DELETE terminates a session.The returned router is a
ProtectedRouter, so callers can install anAuthenticationProviderto gate every MCP request.Two ways to specify the per-session server:
() => McpServerfactory when the server needs per-session state captured in a closure (DB connections, session-scoped caches, etc.).McpServerConfigbundle (the same shapecreate_mcp_serveraccepts) when the server is fully described by its declarative primitive list.