Skip to content

Reject mismatched initialize protocol versions#1724

Merged
halter73 merged 1 commit into
mainfrom
halter73-validate-protocol-versions
Jul 23, 2026
Merged

Reject mismatched initialize protocol versions#1724
halter73 merged 1 commit into
mainfrom
halter73-validate-protocol-versions

Conversation

@halter73

Copy link
Copy Markdown
Contributor

Fixes #1580.

Rejects Streamable HTTP initialize requests when MCP-Protocol-Version disagrees with params.protocolVersion. The handler returns HTTP 400 with HeaderMismatch and preserves the parsed JSON-RPC request ID.

Adds coverage for both mismatch directions in stateful and stateless modes.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 HeaderMismatch for 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

@tarekgh tarekgh left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@halter73
halter73 merged commit 9df7640 into main Jul 23, 2026
17 of 18 checks passed
@halter73
halter73 deleted the halter73-validate-protocol-versions branch July 23, 2026 18:45
@jeffhandley jeffhandley mentioned this pull request Jul 25, 2026
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.

Streamable HTTP server accepts mismatched header/body protocol versions on initialize

3 participants