Reject POST requests without session ID in stateful mode#274
Merged
koic merged 1 commit intomodelcontextprotocol:mainfrom Mar 29, 2026
Merged
Reject POST requests without session ID in stateful mode#274koic merged 1 commit intomodelcontextprotocol:mainfrom
koic merged 1 commit intomodelcontextprotocol:mainfrom
Conversation
Per the MCP specification (Streamable HTTP > Session Management): > Servers that require a session ID SHOULD respond to requests without an `Mcp-Session-Id` header > (other than initialization) with HTTP 400 Bad Request. https://modelcontextprotocol.io/specification/2025-11-25/basic/transports#session-management Previously, non-initialize POST requests without `Mcp-Session-Id` in stateful mode were processed with HTTP 200 (for regular requests) or HTTP 202 (for notifications/responses). This change adds an explicit check in `handle_post` to return HTTP 400 Bad Request when the session ID is missing in stateful mode for all non-initialize requests, aligning with the specification.
atesgoral
approved these changes
Mar 29, 2026
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.
Motivation and Context
Per the MCP specification (Streamable HTTP > Session Management):
https://modelcontextprotocol.io/specification/2025-11-25/basic/transports#session-management
Previously, non-initialize POST requests without
Mcp-Session-Idin stateful mode were processed with HTTP 200 (for regular requests) or HTTP 202 (for notifications/responses).This change adds an explicit check in
handle_postto return HTTP 400 Bad Request when the session ID is missing in stateful mode for all non-initialize requests, aligning with the specification.How Has This Been Tested?
Added a regression test and passed.
Breaking Changes
This is not a breaking change, as it is a bug fix to align with the MCP specification.
Types of changes
Checklist