Repository navigation
Description
Part of #2851 (Phase 2, Slice 4: Limited access). Depends on: #7061 (the authorization server puts the mcp_tool_call entry in the token). Related: #6779 (session binding for list methods), #6888 (session bound to act), #6979 (reported operation IDs).
Problem: with the token narrowed to one call by its authorization server, the vMCP must enforce it: a token issued for one tool call with given arguments must not start another call, and must not start the same call twice.
Change: when an access token carries an authorization_details entry of type https://toolhive.dev/mcp_tool_call, the vMCP enforces it, whichever client the token belongs to. Entries of other types are ignored by this check. A token with two or more mcp_tool_call entries is refused (single_entry_required), and a malformed entry or one with unknown fields is refused (malformed_entry), not skipped.
- Tool call: accept a
tools/callonly if its server,params.name, and argument hash match the entry. Compute the hash as the lowercase hex SHA-256 of the RFC 8785 (JCS) serialization ofparams.argumentsas received, or of{}when absent ornull, before any routing, prefix stripping, or rewriting. Refuse arguments that are not I-JSON (RFC 7493). - Tools without a single server: composite tools, the optimizer's
call_tooland code mode'sexecute_tool_scriptdispatch further calls, so a call-bound token is refused for them even if the entry names them (tool_not_bindable). Decide this from what the name resolves to in the router, not from a list of names, so a new fan-out tool type is refused by default. - List call: a token whose entry names a list method accepts only that list call on that server, and cannot start a
tools/call. - Single use: a token's
jtistarts at most one call. Record eachjtiwith the call it started untilexpplus the clock skew (the token validator's existing leeway, no new setting) or the end of that call, whichever is later; refuse a second call with the samejtion the same replica. The first release keeps the record per replica, a named shortcut removed by vMCP: one single-use record shared by all replicas for call-bound access tokens (vMCP: one single-use record shared by all replicas for call-bound access tokens #7261).- A retry is a second call. When a client sends the same
tools/callagain, for example after URL-mode elicitation (the server asks the user to finish a step in a browser, then the client retries), the retry needs a new call-bound token; the vMCP refuses the used one.
- A retry is a second call. When a client sends the same
- Messages for the open call: accept the session handshake during the token's lifetime, and messages that belong to the call it started (a
notifications/cancelledfor the call's JSON-RPC ID, or a JSON-RPC response such as an elicitation reply, on the recorded session) for as long as that call is open, even after the token expires, up to a configured maximum call duration. The token'sexplimits only when a call can start. Accepting "any response on the recorded session" is a named shortcut until "vMCP: bind the session to act" (vMCP: bind sessions to the client, acting agent, and delegated-access marker, not just the user #6888).pkg/authstays strict by default: an opt-in validator option (for exampleWithExpiredTokenAdmission(maxAge, admit)) re-validates an expired JWT with every check exceptexp, requiresexpto be present and less thanmaxAgein the past, and asks a callback the vMCP implements. Without the option, the middleware behaves exactly as today. Opaque tokens never qualify. An admitted identity is marked, and the call gate refuses marked identities as a backstop.- The vMCP admits only when the token carries the entry, its
jtihas an open call on this replica,Mcp-Session-Idmatches the recorded session, the maximum call duration has not passed, and the message is one of the two above. Everything else gets today's 401. - This ships as its own PR with a security review, in the same release. If it cannot make the release, the release slips; Mecatl does not stretch tokens to the longest call duration instead.
- GET and DELETE: allowed while the token is valid, on a session the token's identity owns, without using up the
jti; neither can start a call. Once the token has started its call, they are allowed only on that call's session (session_mismatchotherwise), andinitializeis refused. Afterexpthey are refused. A stream opened beforeexpkeeps running. tools/list: a tool-call token may list tools without using up thejti, filtered by admission as usual. Some SDK clients list tools right after a call to read its output schema.- Refusal: a refusal that describes the token itself (a reused
jti, a malformed or repeated entry, missing claims, an expired token) is HTTP 401 withWWW-Authenticate: Bearer error="invalid_token", carrying the samerealmandresource_metadataas the vMCP's other 401s; the client's only fix is a new token. A refusal about the request (a different server, tool or argument set, a tool without a single server, a listed client without an entry, a message for no open call) is HTTP 403 with a JSON-RPC error body and noWWW-Authenticate, like the vMCP's other authorization refusals.insufficient_scopeis not used: no scope fixes these refusals, and MCP clients read it as a step-up hint. Each refusal is audited like a Cedar denial, with its reason. The token and the arguments are never logged. - Clients that must send the entry: an embedder lists clients whose tokens must carry an entry (Mecatl lists
mecatl). The client is the token'sclient_id, or itsazpwhenclient_idis absent. A listed client's token without anmcp_tool_callentry is refused with 403, audit reasonentry_required. The list is empty by default. Tokens from unlisted clients without the entry behave exactly as today.- Rollout: an embedder must not list a client before the ToolHive release that signs entries into ID-JAGs (AS-1) and copies them into the access token (AS-2) is deployed in front of that vMCP; otherwise every call from that client is refused. Mecatl ships the list in the same release in which it starts sending entries, with the pin bump already in place.
- A JSON-RPC batch carrying a call-bound token is refused, and so is any POST body that does not hold exactly one parsed operation for that token. Batches with other tokens are unchanged.
Where it runs: a Go check in the vMCP's existing admission seam, next to its open tracking items, before the Cedar check, as a required condition that can only deny more. Cedar can't express the exact-argument check (it has no hash, and arrays are sets), and cedar-go has no extension hook. It runs whether or not Cedar authorization is configured, and Cedar does not decide it.
Acceptance:
- a
tools/callmatching the entry runs; a different server, tool, or argument set is refused, including arguments that differ only after the vMCP rewrites the request; - a second
tools/callwith the same token is refused on the same replica; a replay to another replica is accepted in the first release (the shared-record issue removes this); - a retry of the same
tools/callwith the same token, as after URL-mode elicitation, is refused; with a new token for the same entry it runs; - a cancellation or elicitation reply for the open call is accepted after the token expires, and refused once the call has ended or passed the maximum call duration;
- a list-call token cannot start a
tools/call; - the hash matches a shared set of test vectors (number formatting, large and negative numbers, Unicode escapes, key order, nesting, absent and
nullarguments), the same vectors Mecatl's client uses. ToolHive holds the canonical copy, including the refusal cases (numbers beyond 2^53,1e400, lone surrogates, duplicate keys, non-object top level, trailing data). Vectors the gateway refuses before hashing, such as keys that collide after case folding, are marked (for example"gateway_refuses": true) so end-to-end tests skip them; - a listed client's token without an entry is refused with
entry_required; an unlisted client's token with a matching entry is accepted, with a mismatching entry or two entries refused, and with only a non-mcp_tool_callentry unchanged; - composite tools,
call_toolandexecute_tool_scriptare refused for a call-bound token; - after
exp, a cancellation for the call's ID is admitted; a cancellation for another ID, any request,tools/call,tools/list,initialize, the wrong session, a closed call, an unknownjti, or a call older than the maximum duration is refused. Without thepkg/authoption, an expired JWT gets exactly today's 401; - tokens from unlisted clients without the entry are unaffected.
Context: Mecatl agent identity design, credentials-and-lifecycle.md steps (8) and (9) and implementation.md "ToolHive work list". Tracked in Phase 2, Slice 4: Limited access (stacklok/mecatl#2851).
Activity
rdimitrov commentedon Nov 24, 2026
Work on the vMCP side has started too, beginning with the argument hash. Some behaviour is not settled by the issue text, or disagrees with the Mecatl design. Proposed answers below; a reply per number is enough.
expneeds an exception inpkg/authtoken validation, which MCPServer proxies share. Proposed: ship it in its own PR in the same release. If it cannot make the release, Mecatl would have to make the token live as long as the maximum call duration, which is a design change. For elicitation replies, the first version accepts any JSON-RPC response on the recorded session while the call is open, since the vMCP does not see the SDK's pending request IDs.jti.call_tooland code mode'sexecute_tool_scriptdispatch further calls. Proposed: refuse them for call-bound tokens.WWW-Authenticate: Bearer error="insufficient_scope"and a JSON-RPC error body, audited like a Cedar denial. The token and the arguments are never logged.nullarguments. Hash as{}, like absent arguments (Mecatl already does this).Also for "vMCP: one single-use record shared by all replicas for call-bound access tokens" (#7261): it has no "blocked by" link to this issue, and its GitHub parent differs from the issue its body names. Proposed: blocked by this issue; parent stays the multi-replica phase 3 issue.
jhrozek commentedon Nov 24, 2026
Agree with the direction on all ten. Details per number below, written so each can go into the issue body or a PR. File paths are on current
main.1. Listed client, token without an entry. Agree: refuse with 403, fail closed. A listed client's token that arrives without its entry means something upstream dropped it, and "as today" would turn it into a token good for any call. One caveat for the rollout, worth adding to the issue: the embedder must not list a client before the ToolHive release that signs entries into ID-JAGs (AS-1) and copies them into the access token (AS-2) is deployed in front of that vMCP. Otherwise every call from that client is refused. For Mecatl that means shipping the list in the same release in which it starts sending entries, as you say, with the pin bump already in place. Give the refusal its own reason (e.g.
entry_required) in the audit record, so this misconfiguration is easy to tell apart from a mismatch.2. Unlisted client, token with an entry. Agree: enforce the entry whenever it is present; the list only decides whether an entry is required. Two things to pin down in the issue:
https://toolhive.dev/mcp_tool_call. Entries of other types are ignored by this check.mcp_tool_callentries is refused (403, reasonsingle_entry_required, the same name the authorization server uses). The issue says "the entry", and refusing is simpler and safer than defining what "one call" means with two entries. The authorization server already refuses more than one, so this only fires if something else minted the token.mcp_tool_callentry that is malformed or has unknown fields is refused (malformed_entry), not skipped.Tests: unlisted client with a matching entry (accepted), with a mismatching entry (refused), with two entries (refused), with only a non-
mcp_tool_callentry (unchanged, as today).3. Messages after the token expires. Agree on its own PR in the same release, but let's keep
pkg/authstrict by default and put the decision in the vMCP. It relaxes token validation, so it should get a security review. Suggested shape:Today: for JWTs the expiry is enforced inside
jwt.Parse(pkg/auth/token.go, inValidateToken);validateClaimsalso checksexpbut in practice only matters for introspected tokens. An expired opaque token comes back from introspection asactive=falsewith no claims.TokenValidator.Middlewareturns any validation error into 401invalid_token. The vMCP only gets the middleware (GetAuthenticationMiddlewareinpkg/auth/utils.go, built innewOIDCAuthMiddlewareinpkg/vmcp/auth/factory/incoming.go), and the body parser runs inside auth (incoming.go,mcp.ParsingMiddleware), so on a 401 nobody has parsed the body yet.pkg/auth: an opt-in validator option with a typed callback:NewTokenValidatorrefusesmaxAge <= 0or a nil callback.ValidateTokenis unchanged. Without the option,Middlewareis byte-for-byte today's path.exp(signature,iss,aud,nbf,iat), requireexpto be present and less thanmaxAgein the past, then call the callback. JWTs only: an expired opaque token never qualifies.invalid_token, same body, as today. Callback says yes: the identity goes into the context as normal, marked with a newIdentity.AdmittedAfterExpiry time.Time.maxAgeis only a ceiling so old tokens are never re-verified.errors.Ascould use them; a separate validate method needs a validator handle the vMCP doesn't have and would duplicate the identity and upstream-token logic inMiddleware; a context flag is easy to set by accident.vMCP: the call-binding component implements the callback. It admits only when all of these hold:
mcp_tool_callentry;jtihas an open call recorded on this replica;Mcp-Session-Idequals the session recorded with that call;notifications/cancelledwhoserequestIdequals the call's JSON-RPC ID, or a JSON-RPC response (elicitation reply).Everything else gets a no: any request,
tools/call, list calls,initialize, GET, DELETE, batches. As a backstop, the call gate (pkg/vmcp/server/call_gate.go) refuses any identity withAdmittedAfterExpiryset, and session ownership (session_ownership.go) still checks the sameissandsub. Accepting any response on the session is a named shortcut: the session ID is the only binding until "vMCP: bind the session to act" (vMCP: bind sessions to the client, acting agent, and delegated-access marker, not just the user #6888). Say so in a comment at the site.Audit and logs: refusals of the exception are the same 401 as today and are audited as today. Admitted messages are audited as normal plus
admitted_after_expiry=trueand the call's operation ID. Log why the callback said no at DEBUG (no_open_call,session_mismatch,call_too_old,method): a caller can trigger it at request rate, so not WARN. Never log thejtitogether withsub.Three things to check in that PR:
Middleware. These messages need no new backend credential, so skip the load forAdmittedAfterExpiryidentities, after confirming that cancellation reaches the backend through the open call's context and not through a new backend call.Tests:
pkg/auth: without the option, an expired JWT gets exactly today's 401 and the callback is never called; with the option, a bad signature, wrongiss, wrongaud, futurenbf, missingexp, orexpolder thanmaxAgeeach get a 401 without calling the callback; callback false gives today's 401 body; callback true gives an identity withAdmittedAfterExpiryset; a valid token never calls the callback; an expired opaque token never qualifies.pkg/vmcp: afterexp, a cancellation for the call's ID is admitted; refused are a cancellation for another ID, any request,tools/call,tools/list,initialize, the wrong session, a closed call, an unknownjti, a call older than the maximum duration, and a token without the entry; the call gate refuses anAdmittedAfterExpiryidentity.If this can't make the release, I'd rather slip the release than have Mecatl stretch the token to the longest call duration: that widens every token to cover the rare long call.
4. GET and DELETE. Agree: allow both while the token is valid, on a session the token's identity owns (the existing session-ownership check), without using up the
jti. Neither can start a call. Afterexpthey are refused (see 3); a stream opened beforeexpkeeps running.5. Tools without a single server. Agree: refuse composite tools, the optimizer's
call_tooland code mode'sexecute_tool_scriptfor call-bound tokens, even if the entry names them, with its own reason (e.g.tool_not_bindable). Decide it from what the name resolves to in the router, not from a list of names, so a new fan-out tool type is refused by default. Binding those would need a new entry shape, which is a separate issue if a client ever needs it.6. Refusal shape. Agree: 403,
WWW-Authenticate: Bearer error="insufficient_scope", JSON-RPC error body, audited like a Cedar denial with the reason, never logging the token or the arguments. One addition: leave out ascope=parameter in the challenge. MCP clients readinsufficient_scopeplus a scope as a step-up hint, and no scope fixes this.7. Clock skew. Agree: reuse the token validator's leeway, no new setting.
8.
nullarguments. Agree: hashnullas{}, like absent arguments. Add it to the shared vectors so both sides are pinned to it.9. Shared test vectors. Agree: ToolHive holds the canonical copy, and the refusal cases currently inline in
argumenthash_test.go(numbers beyond 2^53,1e400, lone surrogates, duplicate keys, non-object top level, trailing data) move into the file. One wrinkle: the vector "ASCII key order" has both"A"and"a". The vMCP refuses keys that collide after case folding, at any depth, with -32600 before the hash runs (pkg/mcp/json_ambiguity.go). So:tools/calltest can't use it, because the request is refused first (fail closed, which is correct);"gateway_refuses": true, so both test suites know;10. Progress. Agree: drop "progress" from the accept list.
"vMCP: one single-use record shared by all replicas for call-bound access tokens" (#7261). Agree: mark it blocked by this issue, keep the multi-replica phase 3 issue as its parent, and fix the body so it names the same parent.
Add the call-binding argument hash for the vMCP (#7285)
Accept call messages only while the call is open
Enforce call-bound access tokens at the vMCP (#7302)
Enforce list-call tokens at the vMCP (#7325)