Reject mismatched initialize protocol versions#1724
Merged
Conversation
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR addresses #1580 by enforcing consistency between the Streamable HTTP MCP-Protocol-Version header and the initialize.params.protocolVersion value in the JSON-RPC body. When the two disagree, the server now rejects the request with HTTP 400 using the HeaderMismatch error code while echoing the parsed JSON-RPC request ID, and adds regression coverage for both mismatch directions in both stateful and stateless profiles.
Changes:
- Add an
initialize-specific protocol version consistency check (header vs.params.protocolVersion) in the Streamable HTTP handler. - Preserve JSON-RPC request ID when returning
HeaderMismatchfor this new validation failure. - Add integration tests covering both mismatch directions across stateful/stateless modes.
Show a summary per file
| File | Description |
|---|---|
| tests/ModelContextProtocol.AspNetCore.Tests/StreamableHttpServerConformanceTests.cs | Adds regression tests asserting HTTP 400 + HeaderMismatch and that the JSON-RPC id is preserved when header/body versions disagree on initialize. |
| src/ModelContextProtocol.AspNetCore/StreamableHttpHandler.cs | Implements header/body protocol version mismatch rejection for initialize requests via ValidateProtocolVersionEnvelope. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 0
- Review effort level: Low
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 #1580.
Rejects Streamable HTTP
initializerequests whenMCP-Protocol-Versiondisagrees withparams.protocolVersion. The handler returns HTTP 400 withHeaderMismatchand preserves the parsed JSON-RPC request ID.Adds coverage for both mismatch directions in stateful and stateless modes.