Repository navigation
Description
When using the MCP TypeScript SDK as a client in browser environments (e.g., React or Hugging Face), the mcp-session-id header returned by the server is not reused in subsequent requests. This results in errors such as Missing session ID, since the server expects the client to maintain session continuity.
Although the header is correctly received in the initial response, the client does not persist or forward the sessionId in the next request. The issue appears to originate in the client.connect method, which fails to update the sessionId within the StreamableHTTPClientTransport object—even though the value is stored internally.
This behavior differs from Node.js environments, where session management works correctly via cookies. In browsers, however, the SDK lacks the necessary logic to maintain session state using the mcp-session-id.
Issue is also reported here but this approach presents the target to solve it: #764
Relevant context:
I know I can set my own session id
Regardless of this, my client it's not sending the header in the request
As its not saving or doing anything with that session id, on the exact next request, it sends another post, but without a session id.
Making it impossible for the server to respond back, as it doesn't send a session id...
I know the issue is inside client.connect when sending my transport as in the first image. The method is not sending the sessions Id. But, it saves the sessionId inside the StreamableHTTPClientTransport object
This is a console.log with the following data directTransport.sessionId
And just for you to track which client I'm talking about its a Client Object from @modelcontextprotocol/sdk/client/index.js
This issue affects browser-based clients and breaks session continuity, which is now required by the protocol in the new update .
https://modelcontextprotocol.io/specification/2025-06-18/basic/transports
Fixing this would align the TypeScript SDK’s behavior with its Node.js counterpart and improve compatibility across environments.
Happy to provide additional logs or test cases if needed!
Activity
SlaterVanS commentedon Aug 8, 2025
Same here—the browser client never reuses the mcp-session-id, so the server rejects every follow-up request. Looking forward to an official fix!!!
DW8Reaper commentedon Aug 14, 2025
Are you perhaps getting this due to your CORS setup? I had the same issue because I only had
mcp-session-idin theAccess-Control-Allow-Headersheaders on my server and had forgotten to add it toAccess-Control-Expose-Headers.If you don't have it in
Expose-Headersyou will see your first POST initialize jsonrpc calls works and returnsmcp-session-idbut subsequent POST calls will not include the header. WithoutExpose-Headersthemcp-session-idheader is not accessible in javascript so the MCP client library cannot access it.SlaterVanS commentedon Aug 15, 2025
However, this issue is hard to avoid in browser-based applications, and we should address it.
dandrykevych commentedon Sep 5, 2025
for anyone facing the same issue: it's not a SDK related issue, your BE CORS doesn't allow browser javascript to get the session-id value from response header. Expose these 2 headers and you are ok.
expose_headers=[ "mcp-session-id", "mcp-protocol-version", ]SlaterVanS commentedon Sep 7, 2025
Hi, in a B/S architecture users can add MCP tools by themselves, but these tools come from different providers; I have no way to control whether they will expose the headers "mcp-session-id" and "mcp-protocol-version". How should I solve this problem? Thanks for your helpful reply!
DW8Reaper commentedon Sep 7, 2025
Hey @SlaterVanS your users must expose those headers there is nothing this library could change to work around the cors requirements the browser will always remove those headers if the cors config on the server does not allow them. This is standard behavior so you always need to configure permitted headers and origins on the server side, if the tools your users are adding are intended to be used anywhere they should already allow ‘origin: *’ and allow javascript access to those headers ( or perhaps have a way to customize the cors config)
The only way to avoid that is to start the browser in insecure mode which would not be a great idea except maybe for some local testing.
felixweinberger commentedon Sep 29, 2025
Potentially related: #764
sstklen commentedon Feb 24, 2026
Hey! I ran into a similar pattern in our bug knowledge base and thought this might help.
What's happening: Server CORS missing
Access-Control-Expose-Headers: mcp-session-id. Browser CORS policy hides response headers not explicitly exposed — SDK receives the header butfetch()strips it before JS can read it. Node.js unaffected because it has no CORS enforcement.What worked for us:
Add
mcp-session-idtoAccess-Control-Expose-Headerson the MCP server. This is a server-side CORS config fix, not an SDK bug.Hope this helps! Let me know if it doesn't match your case — happy to dig deeper. 🦞
🦞 Confucius Debug — community knowledge base for AI agent bugs. Free to search via MCP.
felixweinberger commentedon Oct 7, 2026
This is the browser's CORS rule, not the client: a page can read
Mcp-Session-Idonly if the server lists it inAccess-Control-Expose-Headers(with thecorspackage:exposedHeaders: ['Mcp-Session-Id']). For servers you do not control there is no client-side way around it. Closing.