Skip to content

fix: reject init header/body version mismatch#853

Open
DaleSeo wants to merge 1 commit into
mainfrom
fix-header-body-mismatch
Open

fix: reject init header/body version mismatch#853
DaleSeo wants to merge 1 commit into
mainfrom
fix-header-body-mismatch

Conversation

@DaleSeo
Copy link
Copy Markdown
Member

@DaleSeo DaleSeo commented May 17, 2026

Fixes #852

Motivation and Context

When a client sends an initialize request and the MCP-Protocol-Version HTTP header doesn't match the params.protocolVersion value in the JSON-RPC body, the Streamable HTTP server accepts the request without any notification. According to the MCP 2025-11-25 spec's Protocol Version Header section, an invalid or unsupported MCP-Protocol-Version should return a 400 Bad Request. A header that contradicts the body shows a clear inconsistency on the client side and should be rejected before the session is established.

How Has This Been Tested?

Added intergration tests.

Breaking Changes

None

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling- [ ] I have added or updated documentation as needed

Additional context

This change aligns with the fix in the TypeScript SDK modelcontextprotocol/typescript-sdk#2111 and the spec PR modelcontextprotocol/modelcontextprotocol#2721. When the header is missing, which is expected during the first initialize round-trip before any version has been negotiated, the request will still go through as usual.

@DaleSeo DaleSeo self-assigned this May 17, 2026
@github-actions github-actions Bot added T-dependencies Dependencies related changes T-test Testing related changes T-config Configuration file changes T-core Core library changes T-transport Transport layer changes labels May 17, 2026
@DaleSeo DaleSeo marked this pull request as ready for review May 17, 2026 19:56
@DaleSeo DaleSeo requested a review from a team as a code owner May 17, 2026 19:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

T-config Configuration file changes T-core Core library changes T-dependencies Dependencies related changes T-test Testing related changes T-transport Transport layer changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Streamable HTTP server accepts mismatched header/body protocol versions and negotiates 2024-11-05 on initialize

1 participant