You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Streamable HTTP examples use incorrect status code for invalid session IDs #389
Currently, the streamable HTTP examples give a 400 status code when presented with an invalid session ID. While this is not explicitly written out in the spec, it does say:
When a client receives HTTP 404 in response to a request containing an Mcp-Session-Id, it MUST start a new session by sending a new InitializeRequest without a session ID attached.
To me this implies that a server that receives a request with an invalid Mcp-Session-Id, it should respond with a 404 status code to signal the client should start a new session. However, the examples give a 400 here, e.g.
Indeed, they should respond to requests without a session ID with a 400, but they should respond to requests with an invalid session ID with a 404 (in order for clients to precisely implement refresh logic).
(though in microsoft/vscode#247258 I decided to blindly will retry on an 4xx in case servers don't implement this 'correctly'_
Ah I see what you’re saying. This is ambiguous. On one hand if the client is sending arbitrary session-ids which they consider to be valid for some reason, then I feel like that 400 is appropriate. But for client recovery (in the event of accidental session-id state management discrepancies), issuing a 404 would help.
Feels like the former would be better in terms of ensuring clients are managing sessions appropriately
The streamable HTTP example has two big issues imo that make it unusable in the wild:
Responding with a 400 is against the spec and causes clients to not work as expected. Take claude code for example, if you return a 400 error from the server (because say you're debugging it locally and restarting it and it loses all sessions on restart), it'll show the following message:
mcp-server - toolCall (MCP)()
⎿ Error: Error POSTing to endpoint (HTTP 400): {"jsonrpc":"2.0","error":{"code":-32000,"message":"Bad Request: No valid session ID provided"}}
which isn't much help to you as an end-user, whereas if you return a 404, it gives back:
The mcp-server system is disconnected again. You'll need to reconnect it before I can call the tool.
where this gives actionable feedback (ideally it'd just call /mcp reconnect mcp-server for me, but 🤷)
The call to isInitializeRequest call will fail if the client does application/json, event/stream as it's message format, where req.body will be undefined until you read to the end of the stream (which is what the SDK does internally.
Activity
flippinjoe commentedon Apr 23, 2025
@connor4312
This is actually to spec in the Session Management 2a. https://modelcontextprotocol.io/specification/2025-03-26/basic/transports
connor4312 commentedon Apr 23, 2025
Indeed, they should respond to requests without a session ID with a 400, but they should respond to requests with an invalid session ID with a 404 (in order for clients to precisely implement refresh logic).
(though in microsoft/vscode#247258 I decided to blindly will retry on an 4xx in case servers don't implement this 'correctly'_
flippinjoe commentedon Apr 23, 2025
Ah I see what you’re saying. This is ambiguous. On one hand if the client is sending arbitrary session-ids which they consider to be valid for some reason, then I feel like that 400 is appropriate. But for client recovery (in the event of accidental session-id state management discrepancies), issuing a 404 would help.
Feels like the former would be better in terms of ensuring clients are managing sessions appropriately
MasterOdin commentedon Sep 11, 2025
The streamable HTTP example has two big issues imo that make it unusable in the wild:
isInitializeRequestcall will fail if the client doesapplication/json, event/streamas it's message format, wherereq.bodywill beundefineduntil you read to the end of the stream (which is what the SDK does internally.fix(examples): use 404 status for invalid session IDs
fix(examples): return 404 for unknown session IDs, 400 for missing