fix: map HeaderMismatch to HTTP 400 - #1226
Draft
lucarlig wants to merge 1 commit into
Draft
Conversation
Signed-off-by: lucarlig <luca.carlig@ibm.com>
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.
Map handler-generated JSON-RPC
HeaderMismatcherrors (-32020) to HTTP 400 on the modern per-request Streamable HTTP path. Add an integration test that exercises a valid2026-07-28request reaching a handler and verifies both the HTTP status and JSON-RPC error code.Fixes #1225.
Motivation and Context
The MCP 2026-07-28 Streamable HTTP server-validation rules require header-validation failures to return HTTP 400 with JSON-RPC error code
-32020.RMCP already returns that combination when its transport detects a mismatch before dispatch. However, when application validation returns
ErrorData::header_mismatch(...)from aServerHandler, the response flows throughjsonrpc_http_status, whereHEADER_MISMATCHpreviously fell through to HTTP 200.This change adds
HEADER_MISMATCHto the modern bad-request mapping. Legacy requests continue to bypass this mapper and retain their existing HTTP 200 JSON-RPC behavior.Specification:
https://modelcontextprotocol.io/specification/2026-07-28/basic/transports/streamable-http#server-validation
How Has This Been Tested?
The new regression test failed against unmodified
mainwith HTTP 200 instead of 400, then passed after the mapper change.Ran:
Results: 7 tests passed; Clippy, formatting, and whitespace checks passed. Stable rustfmt emitted the repository's existing warnings for nightly-only configuration options.
Breaking Changes
None. This corrects the HTTP status for an existing modern JSON-RPC error response. The JSON-RPC error code and legacy response behavior are unchanged.
Types of changes
Checklist
Additional context
Related transport-level validation paths already construct HTTP 400 responses directly. The new test specifically covers a
HeaderMismatchreturned after handler dispatch.