Skip to content

Conversation

@max-rousseau
Copy link

Summary

Fixes incorrect HTTP status code returned by StreamableHTTPSessionManager when 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:

  • The MCP specification requirements
  • The TypeScript SDK implementation

Changes

  • Return HTTP 404 instead of 400 for unknown session IDs
  • Use JSON-RPC error format in the response body, matching TypeScript SDK behavior

Fixes #1727

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
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.

StreamableHTTPSessionManager returns 400 instead of 404 for unknown session ID

1 participant