fix(jsonrpc2): decode requests when method key is present#1000
Open
piyushbag wants to merge 1 commit into
Open
fix(jsonrpc2): decode requests when method key is present#1000piyushbag wants to merge 1 commit into
piyushbag wants to merge 1 commit into
Conversation
Use json.RawMessage for the method field so DecodeMessage can distinguish a missing method key from an explicitly empty method string. Fixes the silent stdio drop in modelcontextprotocol#976 with a single JSON parse. Fixes modelcontextprotocol#976
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
Fixes #976.
DecodeMessageusedmsg.Method != ""to classify messages. A wire payload with"method":""was decoded as a response, so stdio servers dropped it without a correlated JSON-RPC error.Approach
Decode into a
wireDecodestruct whosemethodfield isjson.RawMessage. Treat the message as a request when themethodkey is present on the wire (including""), which matches JSON-RPC semantics.This revision:
json.RawMessageis used formethodmethodkey stay on the response pathTest plan
go test ./internal/jsonrpc2/... -vgo test ./mcp/... -run TestIOConnRead_EmptyMethod -vgo test ./... -count=1go test -race ./internal/jsonrpc2/... -count=1npx @modelcontextprotocol/conformance server --url http://127.0.0.1:3000/mcp) — 40 passed, 0 failed./scripts/client-conformance.sh) — 217 passed, 0 failedScope note
This PR addresses the primary repro in #976 (empty
methodwith validid). Other cases listed in the issue (id: null, structurally invalid envelopes) are unchanged.