fix: map HeaderMismatch to HTTP 400 - #1226
Open
lucarlig wants to merge 2 commits into
Open
Conversation
lucarlig
marked this pull request as ready for review
September 11, 2026 09:18
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Signed-off-by: lucarlig <luca.carlig@ibm.com>
Signed-off-by: lucarlig <luca.carlig@ibm.com>
lucarlig
force-pushed
the
user/luca/header-mismatch-http-400
branch
from
September 11, 2026 09:46
0d59e0a to
c2b31b7
Compare
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 integration coverage for valid2026-07-28requests reaching a handler, with JSON responses and legacy session support each enabled and disabled. Verify HTTP status, JSON content type, request ID, error code, and the handler-generated message.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?
Rebased onto main at
e27c5d1. All four regression configurations fail with HTTP 200 instead of 400 when the mapping is removed, and pass with the fix restored.Ran:
Results: 49 focused tests passed. The 10-test JSON response suite also passed again after restoring the mapping. 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.