Repository navigation
Give call-binding refusals a machine-readable reason - #7369
Merged
Merged
Conversation
A client that must act on why the vMCP refused a call-bound token had to match the human-readable text. On token_reused that decides whether a call is retried, so a rewording could make a client run a call twice. A 401 refusal now carries the reason as a reason auth-param on the WWW-Authenticate challenge and a reason member of the RFC 6750 body; error stays invalid_token. A 403 refusal carries it as error.data.reason. The description and message text are unchanged. docs/authz.md lists the reason values. Closes #7362 Co-Authored-By: Claude Opus 5.5 <[email protected]>
ChrisJBurns
approved these changes
Nov 28, 2026
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #7369 +/- ##
==========================================
- Coverage 82.71% 82.69% -0.03%
==========================================
Files 947 947
Lines 97369 97384 +15
==========================================
- Hits 80543 80532 -11
- Misses 16821 16847 +26
Partials 5 5 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This was referenced Nov 28, 2026
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
When the vMCP refuses a call-bound access token, the reason (
token_reused,method_mismatch, ...) is given only inside human-readable text: theerror_descriptionof the 401 challenge, or the JSON-RPC error message of the 403. A client that must act on a specific reason has to match that text. Fortoken_reusedthe stakes are high: the first call may already have run with a stolen token, so the client must not retry. A rewording of the text would silently turn that into a retry.This PR adds the reason as a stable, documented field next to the existing text:
token_expired,token_reused,malformed_entry,single_entry_required,claims_required): areasonauth-param on theWWW-Authenticatechallenge, aftererror_description, and areasonmember of the RFC 6750 JSON body.errorstaysinvalid_token. RFC 6750 §3 allows extra auth-params.error.data.reasonon the JSON-RPC error.error_descriptionand the JSON-RPC message are unchanged byte for byte, so clients that match on the text keep working.pkg/authgainsBearerChallenge.WriteInvalidTokenReasonand anomitemptyReasonmember onRFC6750Error.WriteInvalidTokenandHeaderwrite exactly what they wrote before.docs/authz.mddocuments both fields and lists every reason value with its status and meaning.Closes #7362
Type of change
Test plan
Unit tests (
task test)E2E tests (
task test-e2e)Linting (
task lint-fix)Scoped unit tests: the Taskfile's
go testcommand and flags (-race, same ldflags) on./pkg/auth/...and./pkg/vmcp/...requireRefused, the helper every call-binding refusal test goes through, now checks the field and pins the full description or message. So the field is checked for every reason those tests cover, includingtoken_reused,token_expired,no_open_callandmethod_mismatch.TestCallBinding_RefusalWireFormatpins the exact bytes of a 403 body and of a 401 challenge and body.TestBearerChallengeWriteInvalidTokencovers the challenge and body with and without a reason, and quote escaping.Does this introduce a user-facing change?
Yes, additive. A client of a vMCP with call binding sees:
WWW-Authenticate: Bearer error="invalid_token", error_description="the access token is not accepted (token_reused)"and body{"error":"invalid_token","error_description":"the access token is not accepted (token_reused)"}., reason="token_reused"at the end of the challenge and"reason":"token_reused"in the body.{"jsonrpc":"2.0","id":2,"error":{"code":403,"message":"Forbidden: the access token does not permit this request (arguments_mismatch)"}}."data":{"reason":"arguments_mismatch"}inerror.A 401 from the token validator itself (for example an expired token outside any admission grace) carries no
reason. The docs say so, so a client can tell the two apart.Special notes for reviewers
reason, matchingdata.reasonon the 403 and thecallbinding.Reason*constants.writeCallBindingErrorencodes a small tagged struct rather than ajsonrpc2.Responsethroughpkg/mcp.WriteJSONRPCError, becausejsonrpc2.NewErrorcannot carrydata. The struct keeps members in the orderjsonrpc2.EncodeMessagewrites them and the ID omitted when absent, never null. So the 503 and 500 bodies it also writes are unchanged.expis unchanged: a spent token replayed afterexpstill getstoken_expired, nottoken_reused.🤖 Generated with Claude Code