fix: return HTTP 404 for unknown session IDs instead of 400#1808
Merged
maxisbey merged 4 commits intomodelcontextprotocol:mainfrom Dec 31, 2025
Merged
fix: return HTTP 404 for unknown session IDs instead of 400#1808maxisbey merged 4 commits intomodelcontextprotocol:mainfrom
maxisbey merged 4 commits intomodelcontextprotocol:mainfrom
Conversation
f413274 to
fed7971
Compare
Per the MCP Streamable HTTP transport spec, servers MUST respond with HTTP 404 when the session ID is not found. This aligns behavior with the TypeScript SDK implementation. Github-Issue: modelcontextprotocol#1727
fed7971 to
4aaf4ad
Compare
- Replace raw dict with JSONRPCError and ErrorData types for consistency with the rest of the codebase - Use INVALID_REQUEST (-32600) error code instead of -32001, which is in the reserved JSON-RPC implementation range (see spec issue modelcontextprotocol#509) - Remove pragma: no cover and add unit test for unknown session ID - Test verifies HTTP 404 status and proper JSON-RPC error format Github-Issue:modelcontextprotocol#1727
maxisbey
previously approved these changes
Dec 24, 2025
Contributor
maxisbey
left a comment
There was a problem hiding this comment.
Thanks for the fix! I've gone ahead and used the existing type objects and added a unit test so we can get this merged
Link to tracking issue for JSON-RPC error code clarification.
maxisbey
approved these changes
Dec 31, 2025
LucaButBoring
pushed a commit
to LucaButBoring/mcp-python-sdk
that referenced
this pull request
Jan 23, 2026
…textprotocol#1808) Co-authored-by: Max Isbey <224885523+maxisbey@users.noreply.github.com>
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
Fixes incorrect HTTP status code returned by
StreamableHTTPSessionManagerwhen receiving requests with unknown or expired session IDs.Per the MCP Streamable HTTP transport specification, servers MUST respond with HTTP 404 (Not Found) when the session ID is not recognized. The previous implementation returned HTTP 400 (Bad Request), which incorrectly signals a malformed request rather than a missing resource.
This change aligns the Python SDK behavior with:
Changes
Fixes #1727