How to run the MCP TypeScript SDK client for multiple concurrent users?
I'm building a web chat application where multiple users connect concurrently, and I need to know how to use the MCP TypeScript SDK client in this scenario. Reusing one transport/client looks impossible because the SDK auth function appears to support only one user, but creating a client and transport per active user seems expensive because of the initialization handshake. What is the recommended architecture for running an MCP client for multiple users?
Originally asked on GitHub: https://github.com/modelcontextprotocol/typescript-sdk/issues/243
6 answers
Status: explained. A contributor closed the issue saying multi-user support is possible today with StreamableHTTP and pointed to the SDK's examples folder. The thread itself does not prescribe one official architecture; commenters offered patterns that work today.
For HTTP with SSE, comment 1 says you need a new MCPServer instance per user connecting and cites FastMCP's FastMCPSession as the same approach. The setup that received a positive confirmation in comment 5 was FastMCP with streamable-http: start the server with mcp.run(transport='streamable-http', host='0.0.0.0', port=3000), connect from the client using StreamableHttpTransport, and pass user context in request headers such as X-User-ID and Authorization. A tool can then read the HTTP request from the MCP context to identify which user is calling. Comment 5 confirmed this helped and called it the best current way to handle multi-user MCP.
Two alternatives appear in the thread: a community package called nchan-mcp-transport, which uses Nchan as a transport and gateway so each JSON-RPC request becomes an HTTP request and the web server manages user sessions; and Spring AI's enterprise MCP OAuth2 design, which uses two OAuth clients, one for the handshake and another for user authentication. The thread also notes that per-user tool authorization/permissions are still not fully solved.
Did this work for you?What a GitHub user tried on GitHub (Outcome unclear)
Asked whether a single transport/client could be reused for all users, noting that the SDK auth function appears to support only one user. No shared-client implementation or test result is reported in the thread.
Source: https://github.com/modelcontextprotocol/typescript-sdk/issues/243 (opens external site)
Did this work for you?What @csmoakpax8 tried on GitHub (Outcome unclear)
Recommended creating a new MCPServer instance per connected user and pointed to FastMCP's FastMCPSession as an example, adding that the SDK docs on HTTP with SSE are misleading. No working result is reported.
Did this work for you?What @xblaauw tried on GitHub (Worked)
Provided a FastMCP example using streamable-http on port 3000, a client with StreamableHttpTransport, and user identity passed via X-User-ID and Authorization headers. A later commenter said this helped and called it the best current approach.
Did this work for you?What @lloydzhou tried on GitHub (Outcome unclear)
Shared a package, nchan-mcp-transport, that uses Nchan as a transport and gateway so every JSON-RPC request becomes an HTTP request and user sessions are managed by the web server. No success report appears in the thread.
Did this work for you?What @andruhon tried on GitHub (Outcome unclear)
Mentioned Spring AI's enterprise MCP OAuth2 approach, which uses two OAuth clients: one for the handshake and one for user authentication. The thread notes per-user tool access is still not solved.
Did this work for you?
Related questions
- MCP TypeScript SDK StreamableHttp without sticky sessions in multi-replica deployments?
- 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