-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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!