Repository navigation
Return JSON-RPC error for non-string routing name in Streamable HTTP body - #1932
Open
pournasserian wants to merge 1 commit into
Open
pournasserian wants to merge 1 commit into
pournasserian wants to merge 1 commit into
Conversation
…body A tools/call, prompts/get or resources/read request whose params.name or params.uri was a number, bool, object or array made ValidateMcpHeaders throw InvalidOperationException, so the client got an HTTP 500 without a JSON-RPC envelope. Reject it as a header mismatch carrying the request id instead. Fixes modelcontextprotocol#1919
This branch has not been deployed
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.
Fixes #1919
Problem
On the Streamable HTTP POST path, a
tools/call,prompts/getorresources/readrequest (protocol version2026-07-28) whose routing field (params.name/params.uri) is valid JSON but not a string madeGetJsonNodeStringPropertycallGetValue<string>()on a number, bool, object or array. That threwInvalidOperationExceptionout ofValidateMcpHeaders, so the client received an HTTP 500 with no JSON-RPC envelope and the server logged an unhandled exception.Fix
GetJsonNodeStringPropertynow usesJsonValue.TryGetValue<string>and returnsnullfor non-string values instead of throwing.ValidateMcpHeadersrejects a routing field that is present but not a string, so the request is answered with HTTP 400 and a JSON-RPC error carrying the request id. It uses the sameHeaderMismatch(-32020) code as the otherValidateMcpHeadersfailures.Tests
Added
HttpHeaderConformanceTests.Server_RejectsNonStringRoutingNameInBody_WithJsonRpcError, covering numeric, boolean, object and array values fortools/call,prompts/getandresources/read. It asserts a 400 response whose JSON-RPC error has the original request id and theHeaderMismatchcode. All 6 cases fail without the fix and pass with it; the rest ofHttpHeaderConformanceTestspasses on net9.0 and net10.0.