Repository navigation
Surface JSON parse detail in streamable-HTTP 400 responses - #1844
Conversation
|
Additional verification context: the change is limited to preserving the existing 400 GitHub currently shows no completed check jobs or reviews for this commit, so the evidence above refers to the recorded local verification only.
|
0923355 to
30aa219
Compare
|
Rebased onto current
The rebase was clean, and the two changes do not overlap: #1837 edited Force-pushed to the PR branch ( Reproduction note: build/test locally with
|
When the POST body cannot be parsed as a JSON-RPC message, the 400 InvalidRequest response was a fixed one-liner that discarded the JsonException's reason and position. A body truncated by an intermediary (proxy, gateway, or transport) is therefore indistinguishable from any other malformed body without server-side logs (modelcontextprotocol#1842). The catch now includes the parser message and line/byte position in the error message, so the failure is diagnosable from the response alone. The message prefix and the conformant id=null envelope are unchanged.
30aa219 to
911a4dc
Compare
System.Text.Json already includes the line and byte position in its syntax-error messages, so surface JsonException.Message as-is. The tests now compare against the JsonException produced by deserializing the same body instead of looking for a hard-coded position string.
Summary
Surface JSON parse detail in streamable-HTTP 400 responses: when the POST body is not a valid JSON-RPC message, the JSON-RPC error message now includes
JsonException.Message(which already carries System.Text.Json's line/byte position), so a truncated or corrupted body is diagnosable from the response alone.Verification
dotnet test tests/ModelContextProtocol.AspNetCore.Tests -f net10.0 --filter 'FullyQualifiedName~StreamableHttpServerConformanceTests'(56 passed at 9dc2eb4).PostMalformedJson_Returns400_InvalidRequest_WithNullIdand the newPostTruncatedJson_Returns400_WithParserDetailtheory assert the response contains theJsonException.Messageproduced by deserializing the same body asJsonRpcMessage.Related to #1842