Skip to content

Reallocate rate-limit error code to 429 - #6120

Merged
JAORMX merged 1 commit into
mainfrom
reallocate-rate-limit-error-code
Jul 28, 2026
Merged

JAORMX merged 1 commit into
mainfrom
reallocate-rate-limit-error-code

Conversation

@JAORMX

@JAORMX JAORMX commented Jul 28, 2026

Copy link
Copy Markdown
Collaborator

Summary

The MCP 2026-07-28 revision published today and partitions the JSON-RPC implementation-defined server-error range (Error Codes, verified live): -32020..-32099 is reserved exclusively for spec-defined codes (only -32020 HeaderMismatch, -32021 MissingRequiredClientCapability, -32022 UnsupportedProtocolVersion are defined), and implementations MUST NOT emit undefined codes from that band. ToolHive's CodeRateLimited = -32029 is therefore non-conformant; it was chosen (RFC THV-0057) when -32000..-32099 was uniformly implementation-defined.

The reallocation keeps ToolHive conformant with both eras with a single code and no version branching:

  • 2026-07-28: new application codes SHOULD be allocated outside the JSON-RPC reserved range (-32768..-32000) — 429 complies.
  • 2025-11-25 and earlier: these revisions inherit plain JSON-RPC 2.0, which leaves everything outside -32768..-32000 application-defined — 429 is equally legal, and no earlier revision ever defined a rate-limit code, so old-era clients have no spec-based expectation of -32029. (Version branching would also be impossible in the HTTP middleware, which runs before protocol parsing.)

What changed:

  • CodeRateLimited is now 429, mirroring HTTP Too Many Requests — the same pattern as the existing JSONRPCCodeDenied = 403 (pkg/mcp/errors.go), which is positive-code precedent already shipped in production. data.retryAfterSeconds is unchanged (error data "MAY include a data member with additional information of any type" in every revision).
  • Updated the hardcoded fallback body in the ratelimit middleware, comments on the vMCP Modern dispatch/envelope path, the pinned wire values in unit/e2e tests, and the vMCP architecture doc's rate-limit gate section.

Also audited every other custom code ToolHive emits against the new partition: -32001 (SessionNotFound) and the streamable proxy's -32000 fallback sit in -32000..-32019, which 2026-07-28 explicitly grandfathers as legacy — and both are legacy-transport-only paths (the new revision removes sessions entirely), so they are conformant as-is. -32020/-32021/-32022 are used with their spec meanings.

Closes #6101

Type of change

  • Bug fix
  • New feature
  • Refactoring (no behavior change)
  • Dependency update
  • Documentation
  • Other (describe):

Test plan

  • Unit tests (task test) — pkg/ratelimit and pkg/vmcp/server pass; the only failures are two pre-existing pkg/api tests requiring a container runtime unavailable in the sandbox
  • E2E tests (task test-e2e)
  • Linting (task lint-fix) — 0 issues

Does this introduce a user-facing change?

Yes. The JSON-RPC error code for rate-limited requests changes from -32029 to 429 on every surface that carries it: the HTTP 429 response body from the ratelimit middleware, the vMCP Modern dispatch path's JSON-RPC error object, and the Legacy path's IsError tool-result structuredContent. Clients pattern-matching -32029 must switch to 429; data.retryAfterSeconds and the Retry-After header are unchanged.

Special notes for reviewers

  • RFC THV-0057 cites the now-invalidated "implementation-defined code in the -32000 to -32099 range" premise; it lives outside this repo, so it needs a follow-up edit there to record the 429 allocation.
  • Follow-up (cosmetic, separate PR): pkg/mcp/revision.go comments still say "draft MCP spec" throughout — the revision shipped today as 2026-07-28, and the wording could be updated.

Generated with Claude Code

🤖 Generated with Claude Code

https://claude.ai/code/session_01W1kKpsGZTfSgKBi8GdTZXR

The MCP 2026-07-28 revision, published today, partitions the JSON-RPC
implementation-defined range: -32020..-32099 is now reserved exclusively
for spec-defined codes, making ToolHive's CodeRateLimited (-32029)
non-conformant. The same revision directs application codes outside the
JSON-RPC reserved range (-32768..-32000), where they are equally legal
under 2025-11-25 and earlier (plain JSON-RPC 2.0), so one code stays
conformant across every revision without version branching.

429 mirrors HTTP Too Many Requests, matching the existing precedent of
JSONRPCCodeDenied (403). Wire-visible change: clients pattern-matching
-32029 must switch to 429; data.retryAfterSeconds is unchanged.

Closes #6101

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01W1kKpsGZTfSgKBi8GdTZXR
@github-actions github-actions Bot added the size/XS Extra small PR: < 100 lines changed label Jul 28, 2026
@codecov

codecov Bot commented Jul 28, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 72.42%. Comparing base (333d71d) to head (c913274).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6120      +/-   ##
==========================================
- Coverage   72.48%   72.42%   -0.06%     
==========================================
  Files         733      733              
  Lines       75842    75856      +14     
==========================================
- Hits        54971    54939      -32     
- Misses      16960    17027      +67     
+ Partials     3911     3890      -21     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@JAORMX
JAORMX merged commit 1ae976c into main Jul 28, 2026
48 checks passed
@JAORMX
JAORMX deleted the reallocate-rate-limit-error-code branch July 28, 2026 16:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/XS Extra small PR: < 100 lines changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Rate-limit error code -32029 sits in the MCP-spec-reserved band

2 participants