Repository navigation
fix(streamable-http-server): answer a session-less non-initialize POST with 400 - #1377
Open
jensholdgaard wants to merge 1 commit into
Open
jensholdgaard wants to merge 1 commit into
jensholdgaard wants to merge 1 commit into
Conversation
…T with 400 In legacy session mode a POST without an Mcp-Session-Id header whose message is not initialize got 422 Unprocessable Entity. The Streamable HTTP transport's Session Management section says servers that require a session ID SHOULD respond to requests without one (other than initialization) with 400 Bad Request, which GET and DELETE already do. Return the same 400 "Bad Request: Session ID is required" response from both session-less POST branches, through one helper shared with GET and DELETE. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Jens Holdgaard Pedersen <Jens@holdgaard.org>
Contributor
|
@connor4312 is on triage rotation this week and is the reviewer for this one. Labels come from the PR labeler. Please review the change. Automated triage. Labels are a first pass and the assigned maintainer has the final say. |
This branch has not been deployed
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.
Fixes #1376.
Problem
In legacy session mode,
StreamableHttpServiceanswers a POST that has noMcp-Session-Idheader and is notinitializewith 422 Unprocessable Entity (Unexpected message, expect initialize request). GET and DELETE without a session id already return 400 Bad Request (Bad Request: Session ID is required), so POST was the odd one out, and the spec asks for 400 here.The Session Management section of the Streamable HTTP transport says, in 2025-11-25 (and in the same words in 2025-06-18):
What changed
server_side_http.rs:unexpected_message_response(422) is replaced bysession_id_required_response(400,Bad Request: Session ID is required). The two POST call sites were its only callers.tower.rs: both session-less POST branches (a non-initializerequest, and a notification or response) now return that response. The GET and DELETE handlers use the same helper in place of their inline copies, with no change in behaviour.Stateless mode and the session-less
server/discoverpath are untouched. They never reached these branches.Tests
stateful_rejected_initial_posts_do_not_create_sessions: the expected status for a session-lesstools/listchanges from 422 to 400. The old value encoded the spec deviation.stateful_post_without_session_id_is_bad_request: a session-less request and a session-less notification each get 400 with the same body as GET and DELETE, and no session is created.test_discover_http_client_startup.rsstill uses a mock legacy server that returns 422. It stands for already-deployed servers, and the client's discover fallback accepts any non-auth 4xx, so it is left as is.How it was found
An MCP client was reconnecting after the server had reaped an idle session. Its request with the stale session id got 404 Not Found, as the spec requires. Its next session-less request then got 422 instead of 400, before the client re-initialized.