Skip to content

Return HTTP 404 for stale Streamable HTTP sessions - #8

Merged
quinnj merged 2 commits into
mainfrom
codex/invalid-session-404
Jul 31, 2026
Merged

Return HTTP 404 for stale Streamable HTTP sessions#8
quinnj merged 2 commits into
mainfrom
codex/invalid-session-404

Conversation

@quinnj

@quinnj quinnj commented Jul 30, 2026

Copy link
Copy Markdown
Member

Summary

  • return HTTP 404 Not Found when a legacy Streamable HTTP request carries an unknown MCP-Session-Id
  • preserve the existing JSON-RPC -32001 error body for protocol diagnostics
  • cover the exact stale-session resources/read flow with a transport regression test

Root cause

The server classified an unknown session correctly as JSON-RPC -32001, but jsonrpc_error always forced HTTP 200. The MCP 2025-11-25 Streamable HTTP session contract requires HTTP 404 after 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 404 for 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

Co-authored by Codex

quinnj added 2 commits July 29, 2026 21:09
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.
@quinnj
quinnj merged commit 8867466 into main Jul 31, 2026
11 checks passed
@quinnj
quinnj deleted the codex/invalid-session-404 branch July 31, 2026 11:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant