MCP TypeScript SDK StreamableHttp without sticky sessions in multi-replica deployments?
I run an MCP server built with the TypeScript SDK's StreamableHttp and SSE transports on multiple Kubernetes replicas behind a load balancer. The transport is cached in memory on the pod that created the session, so requests routed to another pod fail. How can I avoid sticky sessions in a multi-node setup?
Originally asked on GitHub: https://github.com/modelcontextprotocol/typescript-sdk/issues/330
4 answers
Status: fixed in @modelcontextprotocol/typescript-sdk 1.10.1. The release includes a stateless mode for StreamableHttp, and the repo has a multi-node example at src/examples/server/simpleStatelessStreamableHttp.ts, with notes in the README under "Multi-node deployment".
The issue is that the server keeps transports in an in-memory map keyed by session ID, so only the pod holding that map entry can serve the session. A maintainer confirmed the trade-off: stateless mode gives up server-sent events, because SSE requires a session ID. Plan for that if your clients depend on streaming.
The README says you can use a database to persist session data while still allowing any node to handle requests. The thread does not show a concrete serialization format for that state. A transport object itself cannot be stored in Redis, so any shared state must be plain data that you serialize yourself.
General advice: review the example file and the README before adapting it, and test it with the MCP clients you use, since the thread did not report client compatibility results.
Did this work for you?What @dglozic tried on GitHub (Didn't work)
Ran the MCP server with multiple replicas behind a load balancer without sticky sessions. Requests reaching a pod without the in-memory transport returned an error.
Source: https://github.com/modelcontextprotocol/typescript-sdk/issues/330 (opens external site)
Did this work for you?What @asprouse tried on GitHub (Outcome unclear)
Pointed to the stateless-mode comments in streamableHttp.ts (lines 68-89) and asked whether major clients support stateless mode. No one in the thread reported testing this.
Did this work for you?What @ihrpr tried on GitHub (Outcome unclear)
A contributor pointed to 1.10.1 and the multi-node README and the stateless example, simpleStatelessStreamableHttp.ts, as the official approach.
Did this work for you?
Related questions
- MCP stdio server: SyntaxError Unexpected token in deserializeMessage when using console.log
- MCP typescript-sdk: tool inputSchema/outputSchema reject JSON Schema type 'array'?
- Use Zod union/intersection as MCP tool paramsSchema in typescript-sdk?
- MCP Inspector: "Invalid transport type: undefined" when connecting to an SSE server
- MCP TypeScript SDK with Zod v4 fails: `w._parse is not a function` — how to fix?