Repository navigation
Conversation
Fixes modelcontextprotocol#1918 In StreamableHttpHandler.HandlePostRequestAsync, parse the POST body into a JsonElement first using the existing source-generated JsonTypeInfo<JsonElement> contract, and deserialize JsonRpcMessage from that element in a second step. - Invalid JSON syntax (truncated payloads, malformed tokens, exceeded max depth) now returns HTTP 400 with McpErrorCode.ParseError (-32700) and a null id per JSON-RPC 2.0 section 5.1, while keeping the parser diagnostic message from modelcontextprotocol#1844. - Valid JSON that is not a valid JSON-RPC 2.0 message (e.g., null, [], {}, invalid jsonrpc version, or explicit id: null) continues to return HTTP 400 with McpErrorCode.InvalidRequest (-32600).
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 #1918
Previously,
StreamableHttpHandler.HandlePostRequestAsynccaught allJsonExceptions fromReadJsonRpcMessageAsyncand returnedMcpErrorCode.InvalidRequest(-32600), whether the failure was invalid JSON syntax or a valid JSON document that failed JSON-RPC envelope validation.Changes
JsonElementfirst (reusing the existing source-generatedJsonTypeInfo<JsonElement>inMcpJsonUtilities.ProtocolOptions), returning HTTP 400 withMcpErrorCode.ParseError(-32700) andid: nullwhen JSON parsing fails while preserving the parser error detail from Surface JSON parse detail in streamable-HTTP 400 responses #1844.JsonRpcMessagefrom the parsedJsonElementin a second step so invalid JSON-RPC envelopes (such asnull,[],{}, wrongjsonrpcversion, or explicitid: null) continue returningMcpErrorCode.InvalidRequest(-32600).-32700, and add tests confirming invalid JSON-RPC envelopes still return-32600.