Return HTTP 404 for stale Streamable HTTP sessions - #8
Merged
Conversation
Return the HTTP status required by Streamable HTTP when a client sends an unknown MCP session ID. Keep the JSON-RPC -32001 body so clients can log the protocol error while using HTTP 404 to start a new session.
Replace fixed 200 ms sleeps with bounded condition waits. This matches the deterministic listener test change already present in PR #4 and prevents unrelated platform timing failures from masking the stale-session regression.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
404 Not Foundwhen a legacy Streamable HTTP request carries an unknownMCP-Session-Id-32001error body for protocol diagnosticsresources/readflow with a transport regression testRoot cause
The server classified an unknown session correctly as JSON-RPC
-32001, butjsonrpc_erroralways forced HTTP200. The MCP 2025-11-25 Streamable HTTP session contract requires HTTP404after a session terminates. That status tells the client to initialize a new session. A client that relies on the required HTTP recovery signal can otherwise keep reusing the stale session and fail the request.The GET event-stream path already returns HTTP
404for an unknown session. This change makes the POST JSON-RPC path consistent.Specification: https://modelcontextprotocol.io/specification/2025-11-25/basic/transports#session-management
Scope
The runtime change is transport-only. It does not alter session storage, session lifetime, JSON-RPC error codes, tools, resources, or application behavior. Other JSON-RPC errors keep HTTP
200.The branch also reuses the test-only deterministic listener waits already present in PR #4. Main used fixed 200 ms sleeps, which failed before this regression on Linux and Windows. This adds no runtime change.
Validation
200 == 404-32001and theUnknown MCP sessionmessageCo-authored by Codex