fix: return 404 for unknown session IDs so clients re-initialize - #20
Merged
Conversation
The MCP Streamable HTTP spec requires 404 for a request carrying an unknown or expired Mcp-Session-Id: it is the client's cue to start a new session with a fresh InitializeRequest. We returned 400, which clients treat as a hard error, leaving them wedged until a human reconnects. Hit this immediately after the dev deploy: the container restarted, and the connected claude.ai client could not recover on its own. It matters more now that idle sessions are swept - every session idle past SESSION_IDLE_TIMEOUT_MS hits this path, so without the correct status code the sweep would strand clients rather than let them reconnect transparently. A missing (rather than unknown) session ID still returns 400, since no re-initialize cue applies. Verified against a locally built server: POST unknown session -> 404 POST no session, non-init -> 400 GET unknown session -> 404 GET no session -> 400
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.
Problem
The MCP Streamable HTTP spec requires 404 for a request carrying an unknown or expired
Mcp-Session-Id— it is the client's cue to start a new session with a freshInitializeRequest. We returned 400, which clients treat as a hard error, so they stay wedged until a human reconnects them.Hit immediately after the dev deploy of #19: the container restarted, and the connected claude.ai client could not recover on its own.
Why it matters more now
#19 added idle session sweeping. Every session idle past
SESSION_IDLE_TIMEOUT_MSnow hits this path — so without the correct status code, the sweep would strand clients rather than let them reconnect transparently. The two changes need to ship together.Change
A missing session ID still returns 400 — no re-initialize cue applies there.
Verification
Against a locally built server:
Also confirmed on the same build that a normal session still initializes and serves
tools/list(144 tools), that idle sessions are swept (activeSessions3 → 0,sweptSessions: 3), and that a session receiving traffic every 2s survives well past a 5s idle timeout.540 tests passing, lint and format clean.