Skip to content

fix: return header mismatch for missing protocol header - #1083

Merged
DaleSeo merged 1 commit into
modelcontextprotocol:mainfrom
mrcs64:fix/missing-protocol-version-header-code
Jul 29, 2026
Merged

fix: return header mismatch for missing protocol header#1083
DaleSeo merged 1 commit into
modelcontextprotocol:mainfrom
mrcs64:fix/missing-protocol-version-header-code

Conversation

@mrcs64

@mrcs64 mrcs64 commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Return HeaderMismatch (-32020) when request _meta declares a protocol version but the required MCP-Protocol-Version header is absent. Add a stateless HTTP regression test covering the complete JSON-RPC error response.

Motivation and Context

The 2026-07-28 per-request protocol mirrors request metadata into HTTP headers. Required headers that are missing, malformed, or disagree with the request body are header-validation failures.

The missing MCP-Protocol-Version branch previously returned Invalid Request (-32600), unlike the adjacent header/body mismatch branch, which correctly returns HeaderMismatch (-32020).

This change is intentionally limited to that modern per-request validation branch:

  • a missing required field in server/discover remains Invalid Params (-32602)
  • legacy initialize header/body validation remains Invalid Request (-32600)

References:

How Has This Been Tested?

Added a stateless HTTP regression test that verifies:

  • HTTP 400
  • JSON-RPC version and request ID
  • error code -32020
  • a branch-specific missing-header diagnostic

Ran:

cargo test -p rmcp \
  --test test_streamable_http_protocol_version \
  --test test_server_discover_http \
  --test test_streamable_http_standard_headers \
  --features 'server client transport-streamable-http-server reqwest'

Result: 28 passed, 0 failed.

cargo fmt --all -- --check also passes with the installed stable formatter. It reports the repository's existing warnings for nightly-only rustfmt settings.

Breaking Changes

None. This corrects the error classification for an already-invalid request.

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

The regression request includes the required Mcp-Method header so the only missing modern routing header is MCP-Protocol-Version. The assertion matches a stable message fragment rather than the full diagnostic text.

@github-actions github-actions Bot added T-test Testing related changes T-core Core library changes T-transport Transport layer changes labels Jul 29, 2026
@mrcs64
mrcs64 marked this pull request as ready for review July 29, 2026 19:31
@mrcs64
mrcs64 requested a review from a team as a code owner July 29, 2026 19:31

@DaleSeo DaleSeo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the fix, @mrcs64!

@DaleSeo
DaleSeo merged commit f3c7867 into modelcontextprotocol:main Jul 29, 2026
22 checks passed
@github-actions github-actions Bot mentioned this pull request Jul 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

T-core Core library changes T-test Testing related changes T-transport Transport layer changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants