Skip to content

Give call-binding refusals a machine-readable reason - #7369

Merged
rdimitrov merged 1 commit into
mainfrom
claude/7362-refusal-reason-field-78869f
Nov 28, 2026
Merged

rdimitrov merged 1 commit into
mainfrom
claude/7362-refusal-reason-field-78869f

Conversation

@rdimitrov

Copy link
Copy Markdown
Member

Summary

When the vMCP refuses a call-bound access token, the reason (token_reused, method_mismatch, ...) is given only inside human-readable text: the error_description of 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. For token_reused the 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:

  • 401 refusals (token_expired, token_reused, malformed_entry, single_entry_required, claims_required): a reason auth-param on the WWW-Authenticate challenge, after error_description, and a reason member of the RFC 6750 JSON body. error stays invalid_token. RFC 6750 §3 allows extra auth-params.
  • 403 refusals (every other reason): error.data.reason on the JSON-RPC error.
  • error_description and the JSON-RPC message are unchanged byte for byte, so clients that match on the text keep working.
  • pkg/auth gains BearerChallenge.WriteInvalidTokenReason and an omitempty Reason member on RFC6750Error. WriteInvalidToken and Header write exactly what they wrote before.
  • docs/authz.md documents both fields and lists every reason value with its status and meaning.

Closes #7362

Type of change

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

Test plan

  • Unit tests (task test)

  • E2E tests (task test-e2e)

  • Linting (task lint-fix)

  • Scoped unit tests: the Taskfile's go test command 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, including token_reused, token_expired, no_open_call and method_mismatch.

  • TestCallBinding_RefusalWireFormat pins the exact bytes of a 403 body and of a 401 challenge and body.

  • TestBearerChallengeWriteInvalidToken covers 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:

  • Before: 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)"}.
  • After: the same, plus , reason="token_reused" at the end of the challenge and "reason":"token_reused" in the body.
  • Before: {"jsonrpc":"2.0","id":2,"error":{"code":403,"message":"Forbidden: the access token does not permit this request (arguments_mismatch)"}}.
  • After: the same, plus "data":{"reason":"arguments_mismatch"} in error.

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

  • Param name. The auth-param and the body member are both called reason, matching data.reason on the 403 and the callbinding.Reason* constants.
  • Deviation from the JSON-RPC encoding rule. writeCallBindingError encodes a small tagged struct rather than a jsonrpc2.Response through pkg/mcp.WriteJSONRPCError, because jsonrpc2.NewError cannot carry data. The struct keeps members in the order jsonrpc2.EncodeMessage writes them and the ID omitted when absent, never null. So the 503 and 500 bodies it also writes are unchanged.
  • Out of scope. Which reason a request gets after exp is unchanged: a spent token replayed after exp still gets token_expired, not token_reused.

🤖 Generated with Claude Code

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]>
@github-actions github-actions Bot added the size/S Small PR: 100-299 lines changed label Nov 28, 2026
@codecov

codecov Bot commented Nov 28, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.30769% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.69%. Comparing base (4eda109) to head (2179eb9).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
pkg/vmcp/server/call_binding.go 88.88% 2 Missing ⚠️
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.
📢 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.

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

Labels

size/S Small PR: 100-299 lines changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

vMCP: give call-binding refusals a machine-readable reason

2 participants