MCP Python SDK returns 400 instead of 404 for unknown Mcp-Session-Id: fixed in v1.x?
Using MCP Python SDK 2.3.4, when a client sends a Mcp-Session-Id that does not exist in the server's in-memory session store (for example after a server restart), the Streamable HTTP server returns HTTP 400 instead of 404. This blocks clients that expect a 404 so they can reinitialize and get a new session. Is this a bug, and which SDK version fixes it?
Originally asked on GitHub: https://github.com/modelcontextprotocol/python-sdk/issues/1004
4 answers
Fixed in the v1.x line and on main by PR #1945. The underlying change makes StreamableHTTPSessionManager return HTTP 404 instead of 400 when a client sends a Mcp-Session-Id that is unknown or expired. PR #1417 was an earlier proposed fix and was referenced during triage, but #1945 is the change that landed and closed the related duplicate issue #1727.
To resolve the problem, update the Python SDK to a release that contains PR #1945 and restart your server. After the upgrade, clients such as mark3labs/mcp-go, which treat a 404 as a signal to discard the dead session ID and reinitialize, should recover automatically when the server has restarted and no longer has the old session. Before upgrading, the observed behavior on Python SDK 2.3.4 was a 400, which does not tell the client to start a new session.
If you cannot upgrade immediately, one general workaround is to make your client or proxy treat a 400 on a session-aware request as a retryable condition and reinitialize with a fresh session ID. That is general advice and not part of the SDK behavior described in the thread, so verify it against your client implementation.
Did this work for you?What a GitHub user tried on GitHub (Outcome unclear)
Reproduced with Python SDK 2.3.4 on Python 3.10.12: sending an unknown Mcp-Session-Id to the Streamable HTTP server produced HTTP 400 from streamable_http_manager.py. The reporter argued 404 is correct because the request is not malformed.
Source: https://github.com/modelcontextprotocol/python-sdk/issues/1004 (opens external site)
Did this work for you?What @felixweinberger tried on GitHub (Outcome unclear)
A contributor said the issue should be resolved by PR #1417, which sends 404 Not Found on an unknown Mcp-Session-Id, and asked for that PR to be prioritized for review.
Did this work for you?What @maxisbey tried on GitHub (Worked)
A contributor confirmed the fix landed in PR #1945 on v1.x and main: StreamableHTTPSessionManager now returns HTTP 404 for unknown or expired session IDs. This closed the issue as a duplicate of #1727.
Did this work for you?
Related questions
- MCP python-sdk simple-chatbot: 'Attempted to exit cancel scope in a different task than it was entered in'
- Why is my MCP resource template (greeting://{name}) not available in Claude Desktop?
- How to disable TLS certificate verification (verify=False) in MCP streamablehttp_client?
- anyio.ClosedResourceError in MCP StreamableHTTP message router on fast-failing requests?
- Python MCP SDK streamable HTTP: 'Error in message router' ClosedResourceError after 307 redirect