Skip to content

Add the call-binding argument hash for the vMCP - #7285

Merged
rdimitrov merged 2 commits into
mainfrom
vmcp-call-binding-1-argument-hash
Nov 24, 2026
Merged

rdimitrov merged 2 commits into
mainfrom
vmcp-call-binding-1-argument-hash

Conversation

@rdimitrov

@rdimitrov rdimitrov commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

Summary

A call-bound access token names one MCP tool call, including a hash of its arguments ("Authorization server: narrow a JWT-bearer access token to one MCP call with authorization_details" (#7061)). The client that asks for the token computes that hash before sending, and the vMCP recomputes it over the arguments it receives ("vMCP: accept an access token for the one call its authorization_details names, once" (#7062)). The two sides compute it independently, so any difference between them fails every call. This PR adds the vMCP's half of that contract as a leaf package, together with the canonical copy of the shared test vectors, so the enforcement work that follows can build on a hash already pinned to them.

  • New package pkg/vmcp/callbinding with ArgumentsSHA256(json.RawMessage) (string, error) and ErrNotIJSON.
  • The hash is the lowercase hex SHA-256 of the RFC 8785 (JCS) serialization of params.arguments. Absent arguments and JSON null both hash as {}.
  • Anything that is not exactly one I-JSON (RFC 7493) object is refused, not hashed: invalid UTF-8, lone or reversed surrogate escapes, duplicate member names (including duplicates only after escape decoding), non-finite numbers, integer-valued numbers above 2^53 in magnitude, and trailing data.
  • It is a port of the client's implementation, on the same standard-library encoding/json/jsontext (a strict token decoder for the I-JSON checks, then Value.Canonicalize), with its own number-range check including the exact test for literals that round to ±2^53. No JCS dependency is added.
  • testdata/argumenthash/vectors.json is the canonical copy of the shared vectors. It holds the hash vectors (including null arguments), the refusal cases in a form both sides can read (invalid UTF-8 stored as base64), and a gateway_refuses flag on vectors the vMCP refuses before it hashes.
  • Nothing calls the package yet.

Part of "vMCP: accept an access token for the one call its authorization_details names, once" (#7062).

Type of change

  • New feature

Test plan

  • Unit tests (task test)
  • Linting (task lint-fix)
  • Manual testing (describe below)

Ran go test -race on the package: 16 vectors, 38 refusals, 97.8% statement coverage. The only line not covered is a fail-closed check that the earlier decoder makes unreachable. Each vector's sha256 is also checked against its own canonical string, so a hand edit to the file cannot drift unnoticed. To check that the gateway_refuses test bites, I set the flag on a vector the decoder accepts and confirmed the test fails; removing it from "ASCII key order" fails a pinned check.

Changes

File Change
pkg/vmcp/callbinding/argumenthash.go The hash and the I-JSON refusals
pkg/vmcp/callbinding/argumenthash_test.go Shared vectors and refusals, the gateway_refuses check against the message decoder, absent forms, the 2^53 literal test
pkg/vmcp/callbinding/testdata/argumenthash/vectors.json Canonical shared vectors and refusal cases (origin and changes are in the test)

Does this introduce a user-facing change?

No. The package has no callers.

Special notes for reviewers

  • The canonical vectors live here. The entry type is a toolhive.dev type, and the client already pins the ToolHive module, whose zip includes testdata, so the client's test compares its copy with the pinned module's copy rather than ToolHive's tests depending on the client. The file started as a verbatim copy of the client's at a recorded commit; it now also carries the refusal cases (previously inline in the client's Go test) and the gateway_refuses flag. The client switches to this copy in "Bind each gateway token to its call" (Bind each gateway token to its call mecatl#2727).
  • gateway_refuses is checked against the real decoder. The vector "ASCII key order" has both "A" and "a". The vMCP's message decoder refuses member names that collide after case folding, at any depth, with -32600 (pkg/mcp/json_ambiguity.go), so such a tools/call never reaches the hash and an end-to-end test cannot use the vector; the client gets a request error, not a hash mismatch. The hash still has to match on it, and does. Rather than restate the case-fold rule, the test wraps each vector's arguments in a tools/call and runs mcp.DecodeMessage: the flag must be set exactly when the decoder refuses with -32600. That makes this test reach into pkg/mcp, on purpose: the flag describes the vMCP's decoder, and a copy of its rule would drift.
  • One deliberate difference from the client's code. The client treats arguments that are empty after bytes.TrimSpace as absent. That trims Unicode white space too, so a value such as a no-break space followed by null hashes as {} there. Here only JSON whitespace (RFC 8259 section 2) counts as absent, and anything else is left to the decoder, which refuses it. This only refuses more, and the client never sends such a value (it sends {} for absent arguments), so it cannot fail a real call. The refusal cases include two such values, which the client's current code would fail; see "Still to confirm".
  • Errors name the cause without quoting arguments. jsontext's syntax errors quote parts of the input, so the package returns fixed messages that wrap ErrNotIJSON ("duplicate member name", "number beyond 2^53", "not a JSON object", and so on). A caller can log the refusal reason without logging arguments, and a test checks that no refusal's message contains a quote.
  • One token covers every RFC 8785 spelling of its arguments. Member order, whitespace, string escapes and number spelling (including -0 against 0, and digits beyond double precision) all hash the same. The doc comment says so. The caller in the next branch decides whether to forward a value derived from the canonical form or accept this; it does not change the hash.
  • encoding/json/jsontext needs no build flag. The jsonv2 experiment is on by default in Go 1.27; only GOEXPERIMENT=nojsonv2 would exclude the package.
  • The client's test of jsontext's number formatting against RFC 8785 Appendix B is not ported, because it tests the dependency rather than this package. The Appendix B numbers within the I-JSON range are in the shared vectors and go through ArgumentsSHA256.

Confirmed in the issue discussion

Confirmed in the reply on #7062 (items 8 and 9):

  1. null hashes as {}, like absent arguments, and is a vector in the shared file (null arguments).
  2. ToolHive holds the canonical copy of the vectors, and the refusal cases live in the file rather than only in Go tests.
  3. Vectors the gateway refuses before hashing are marked with "gateway_refuses": true, so both suites know an end-to-end tools/call cannot use them.

Still to confirm

  1. Only JSON whitespace counts as absent. The client should switch from bytes.TrimSpace to trimming JSON whitespace when it adopts this file; otherwise its test fails on the refusals "no-break space before null" and "vertical tab only".
  2. Numbers that underflow. A literal such as 1e-400 parses as 0 with no error on both sides and hashes as 0. RFC 7493 says only SHOULD NOT for excess precision. Decide whether to accept or refuse it, then add the case to the shared file so a third implementation cannot differ unnoticed.

🤖 Generated with Claude Code

rdimitrov and others added 2 commits November 24, 2026 21:15
A call-bound access token names one MCP tool call, including a hash of
its arguments. The client that asks for the token and the vMCP that
checks it compute that hash independently, so any difference between
them fails every call. This adds the vMCP's side as a leaf package with
no callers yet.

The hash is the lowercase hex SHA-256 of the RFC 8785 serialization of
params.arguments, with {} for absent or null arguments. It is a port of
the client's implementation on the standard library's jsontext: a
strict token decoder for the I-JSON checks, Canonicalize for RFC 8785,
and its own check for integers beyond 2^53. Anything that is not
exactly one I-JSON object is refused rather than hashed. Unlike the
client's copy, only JSON whitespace counts as absent.

The client's test vectors are mirrored verbatim. The refusal cases are
added as a separate file both sides can read, with invalid UTF-8 stored
as base64.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The shared argument hash vectors now live in ToolHive, as agreed on
"vMCP: accept an access token for the one call its authorization_details
names, once" (#7062). The client will compare its copy with this one.

The refusal cases move from a separate file into vectors.json, so one
file pins both what hashes and what is refused. A gateway_refuses flag
marks vectors the vMCP refuses with -32600 before hashing because member
names collide after case folding ("ASCII key order"). A test wraps each
vector in a tools/call and runs it through the real message decoder, so
the flag cannot drift from the decoder's rule.

The test records the client commit the file started from and how it
has diverged since.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added the size/M Medium PR: 300-599 lines changed label Nov 24, 2026
@codecov

codecov Bot commented Nov 24, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.82609% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 81.86%. Comparing base (65cc86f) to head (c9b91fe).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
pkg/vmcp/callbinding/argumenthash.go 97.82% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #7285   +/-   ##
=======================================
  Coverage   81.85%   81.86%           
=======================================
  Files         915      916    +1     
  Lines       92853    92914   +61     
=======================================
+ Hits        76001    76060   +59     
- Misses      16847    16849    +2     
  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.

@jhrozek jhrozek left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I ran a few AI reviewers over this and they came back with a handful of nitpicks (number edge cases around 2^53 and underflow not being pinned in vectors.json, noncharacters slipping past the I-JSON check, the error-leak test only checking for double quotes), but none of them matter in practice. Everything either fails closed or is about test quality, so nothing here needs to block. Agreed on only JSON whitespace counting as absent.

@rdimitrov
rdimitrov merged commit 3be89fa into main Nov 24, 2026
47 of 48 checks passed
@rdimitrov
rdimitrov deleted the vmcp-call-binding-1-argument-hash branch November 24, 2026 22:20
@github-actions github-actions Bot mentioned this pull request Nov 24, 2026
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/M Medium PR: 300-599 lines changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants