Skip to content

jsonrpc2: preserve exact request identities - #1253

Open
andrei-tyk wants to merge 1 commit into
modelcontextprotocol:mainfrom
andrei-tyk:tt-18014-main-identity
Open

jsonrpc2: preserve exact request identities#1253
andrei-tyk wants to merge 1 commit into
modelcontextprotocol:mainfrom
andrei-tyk:tt-18014-main-identity

Conversation

@andrei-tyk

Copy link
Copy Markdown

JSON-RPC request IDs are currently decoded through any, which converts numeric values to float64 before MakeID constructs an integer ID. As a result, adjacent IDs such as 9007199254740992 and 9007199254740993 collide, responses can be delivered to the wrong in-flight call, and cancellation can target the wrong request.

This change keeps only JSON-RPC identity fields as json.RawMessage until they are parsed into the SDK's existing signed 64-bit ID domain. Requests, responses, and notifications/cancelled use the same bounded decoder. Numeric and string IDs remain distinct; exact integral decimal and exponent spellings are accepted; fractional and out-of-range values are rejected without aliasing another valid ID. Public APIs and unrelated JSON values are unchanged.

Tests cover request and response round trips, signed boundaries, invalid identities, numeric/string distinction, adjacent large IDs correlated out of order, and cancellation of only one adjacent large-ID request.

Local validation:

  • GOWORK=off go test -count=1 ./internal/jsonrpc2 ./mcp
  • GOWORK=off go test -race -count=1 ./internal/jsonrpc2 ./mcp
  • gofmt and git diff --check

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant