Repository navigation
Add the call-binding argument hash for the vMCP - #7285
Conversation
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]>
Codecov Report❌ Patch coverage is
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. 🚀 New features to boost your workflow:
|
jhrozek
left a comment
There was a problem hiding this comment.
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.
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.
pkg/vmcp/callbindingwithArgumentsSHA256(json.RawMessage) (string, error)andErrNotIJSON.params.arguments. Absent arguments and JSONnullboth hash as{}.encoding/json/jsontext(a strict token decoder for the I-JSON checks, thenValue.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.jsonis the canonical copy of the shared vectors. It holds the hash vectors (includingnull arguments), the refusal cases in a form both sides can read (invalid UTF-8 stored as base64), and agateway_refusesflag on vectors the vMCP refuses before it hashes.Part of "vMCP: accept an access token for the one call its authorization_details names, once" (#7062).
Type of change
Test plan
task test)task lint-fix)Ran
go test -raceon 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'ssha256is also checked against its owncanonicalstring, so a hand edit to the file cannot drift unnoticed. To check that thegateway_refusestest 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
pkg/vmcp/callbinding/argumenthash.gopkg/vmcp/callbinding/argumenthash_test.gogateway_refusescheck against the message decoder, absent forms, the 2^53 literal testpkg/vmcp/callbinding/testdata/argumenthash/vectors.jsonDoes this introduce a user-facing change?
No. The package has no callers.
Special notes for reviewers
toolhive.devtype, and the client already pins the ToolHive module, whose zip includestestdata, 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 thegateway_refusesflag. The client switches to this copy in "Bind each gateway token to its call" (Bind each gateway token to its call mecatl#2727).gateway_refusesis 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 atools/callnever 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 atools/calland runsmcp.DecodeMessage: the flag must be set exactly when the decoder refuses with -32600. That makes this test reach intopkg/mcp, on purpose: the flag describes the vMCP's decoder, and a copy of its rule would drift.bytes.TrimSpaceas absent. That trims Unicode white space too, so a value such as a no-break space followed bynullhashes 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".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.-0against0, 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/jsontextneeds no build flag. Thejsonv2experiment is on by default in Go 1.27; onlyGOEXPERIMENT=nojsonv2would exclude the package.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 throughArgumentsSHA256.Confirmed in the issue discussion
Confirmed in the reply on #7062 (items 8 and 9):
nullhashes as{}, like absent arguments, and is a vector in the shared file (null arguments)."gateway_refuses": true, so both suites know an end-to-endtools/callcannot use them.Still to confirm
bytes.TrimSpaceto trimming JSON whitespace when it adopts this file; otherwise its test fails on the refusals "no-break space before null" and "vertical tab only".1e-400parses as 0 with no error on both sides and hashes as0. 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