fix: return 404 for unknown session id so clients recover after restart (2.2.2) - #50
Merged
Conversation
…rt (2.2.2) HTTP sessions are in-memory, so a redeploy wipes them. A client still holding an Mcp-Session-Id got a generic 400 (GET/DELETE) or had its stale-id POST grafted onto a fresh transport, and never re-initialized — an apparent connector outage for that user while the server served everyone else fine. Route requests spec-correctly: an unknown session id returns HTTP 404 (code -32001) so a compliant client starts a new session, and a session is created only for a POST carrying an initialize request (SDK isInitializeRequest). Decision logic extracted into a pure, unit-tested classifySessionRequest(). Closes #49.
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.
Closes #49.
Problem
HTTP sessions are in-memory; a redeploy wipes them. A client still holding an
Mcp-Session-Idgot a generic400(GET/DELETE) or had its stale-id POST grafted onto a fresh transport, and never re-initialized — presenting as a total connector outage for that one user while the server served everyone else at ~92% success. Seen in production right after the 2.2.1 redeploy.Fix
Spec-correct session routing via a pure, unit-tested
classifySessionRequest():code -32001) so a compliant client re-initializes (the recovery path; applies to POST/GET/DELETE)isInitializeRequest(body)→ create sessionStops creating orphan sessions for stale-id POSTs. New
src/session-routing.test.tscovers every branch incl. the regression (stale-id POST →expired, nevercreate). Full suite 43/43,tscclean. Patch 2.2.2.