Repository navigation
Conversation
Signed-off-by: bbdu3 <ergouyang854@gmail.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.
Summary
Both HTTP server transports currently return JSON-RPC error code
-32700when a POST body cannot be classified as a request, notification, or response. This conflates malformed JSON with valid JSON that does not represent a JSON-RPC message.Fixes #321.
For example, within an initialized stateful session:
{"not_a_valid_request": true}-32700-32600{"jsonrpc":"2.0","id":7}-32700-32600not valid json{-32700-32700JSON-RPC 2.0 §5.1 reserves
-32700for invalid JSON and defines-32600for an invalid Request object. MCP’s Streamable HTTP specification requires each POST body to contain a single JSON-RPC request, notification, or response.HTTP responses remain
400 Bad Request, withid: nulland the existing session headers.Changes
JSONRPCMessageKindthat distinguishes JSON parsing failures from message classification failures:MCPError.parseErrorwhen the body is malformed JSON.MCPError.invalidRequestwhen the body is valid JSON but cannot be classified..fragmentsAllowedduring JSON parsing so valid JSON scalars are rejected as invalid messages rather than reported as syntax errors.StatefulHTTPServerTransportandStatelessHTTPServerTransportto return the specific classification error.Validation
Validated in an isolated WSL Ubuntu 22.04 environment using Swift 6.1.
-32700to-32600; malformed JSON continued to return-32700.swift build— passed.swift test— all 497 tests passed, including the parameterized regression cases.modelcontextprotocol/conformance@v0.1.15— 40 passed, 0 failed.git diff --check— passed.macOS validation was not performed locally.