Repository navigation
jsonrpc2: preserve exact request identities - #1253
Closed
andrei-tyk wants to merge 1 commit into
Closed
andrei-tyk wants to merge 1 commit into
andrei-tyk wants to merge 1 commit into
Conversation
andrei-tyk
added a commit
to TykTechnologies/tyk
that referenced
this pull request
Oct 6, 2026
Modern MCP Gateway denials need a namespace that does not collide with JSON-RPC, MCP protocol, or SDK-defined errors. This change allocates Gateway-owned modern errors as `-33000` through `-33006`, selects the final code once from normalized protocol context and structured error classification, and reuses that value for the wire response, request context, logs, and analytics. Legacy HTTP-to-JSON-RPC mappings remain unchanged. The final bounded source also: - shares one private final-code selection/storage helper between the central error handler and direct MCP error writer; - enumerates the pinned v1.6 SDK JSON-RPC and MCP constants in allocation tests, including the documented legacy `HeaderMismatch`/`ResourceNotFound` collisions; - fixes inherited test isolation by capturing the hidden-tool warning through synchronized hooks on the stable logger instead of replacing the package-global logger pointer; - keeps modern synthetic routing disabled. Local validation at `30ded3b457814de5f30cb8b21488291b3277e454` used `GOWORK=off` and task-owned caches: - internal JSON-RPC and MCP package tests passed; - the broader applicable Gateway MCP/error selection passed; - affected Gateway error-path and internal JSON-RPC race tests passed; - the logger/analytics race pair passed 10 consecutive runs; - the exact historical combined Gateway race selection passed with 245 test/subtest pass events and zero failures or skips; - `go vet`, `go mod verify`, `go mod tidy -diff`, formatting, and diff checks passed. An independent source review passed this exact commit with no defects found. This PR remains based on [Gateway #8678](#8678). It intentionally retains `github.com/modelcontextprotocol/go-sdk v1.6.0` and the current Pump dependency. The reviewed exact-ID SDK correction is available as immutable fork commit [`f590438c`](andrei-tyk/go-sdk@f590438) (`v1.6.1-0.20260912063509-f590438c4671`) and is proposed upstream in [modelcontextprotocol/go-sdk #1253](modelcontextprotocol/go-sdk#1253); this Gateway branch does not pin it yet. Pump [#1098](TykTechnologies/tyk-pump#1098) must merge normally before consumer pins are refreshed. The broader Origin-dependent real-middleware exact-ID matrix is deferred until this stack incorporates the separately reviewed Origin/context preservation source. This bounded update does not claim that matrix or TT-18008 as complete. Ticket: https://tyktech.atlassian.net/browse/TT-18008 <!---TykTechnologies/jira-linter starts here--> ### Ticket Details <details> <summary> <a href="https://tyktech.atlassian.net/browse/TT-18008" title="TT-18008" target="_blank">TT-18008</a> </summary> | | | |---------|----| | Status | Ready for Testing | | Summary | Define the modern Tyk error namespace and retire legacy custom codes | Generated at: 2026-09-17 08:38:42 </details> <!---TykTechnologies/jira-linter ends here-->
This was referenced Oct 12, 2026
Contributor
|
@andrei-tyk this issue has been fixed in #1401 with a simpler approach |
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.
JSON-RPC request IDs are currently decoded through
any, which converts numeric values tofloat64beforeMakeIDconstructs an integer ID. As a result, adjacent IDs such as9007199254740992and9007199254740993collide, 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.RawMessageuntil they are parsed into the SDK's existing signed 64-bit ID domain. Requests, responses, andnotifications/cancelleduse 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 ./mcpGOWORK=off go test -race -count=1 ./internal/jsonrpc2 ./mcpgofmtandgit diff --check