Skip to content

vMCP: accept an access token for the one call its authorization_details names, once #7062

Done

Description

@ChrisJBurns

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/call only 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 of params.arguments as received, or of {} when absent or null, 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_tool and code mode's execute_tool_script dispatch 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 jti starts at most one call. Record each jti with the call it started until exp plus 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 same jti on 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/call again, 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.
  • 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/cancelled for 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's exp limits 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/auth stays strict by default: an opt-in validator option (for example WithExpiredTokenAdmission(maxAge, admit)) re-validates an expired JWT with every check except exp, requires exp to be present and less than maxAge in 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 jti has an open call on this replica, Mcp-Session-Id matches 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_mismatch otherwise), and initialize is refused. After exp they are refused. A stream opened before exp keeps running.
  • tools/list: a tool-call token may list tools without using up the jti, 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 with WWW-Authenticate: Bearer error="invalid_token", carrying the same realm and resource_metadata as 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 no WWW-Authenticate, like the vMCP's other authorization refusals. insufficient_scope is 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's client_id, or its azp when client_id is absent. A listed client's token without an mcp_tool_call entry is refused with 403, audit reason entry_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/call matching 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/call with 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/call with 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 null arguments), 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_call entry unchanged;
  • composite tools, call_tool and execute_tool_script are 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 unknown jti, or a call older than the maximum duration is refused. Without the pkg/auth option, 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

  1. added
    needs-triage
    on Nov 5, 2026
  2. rdimitrov commented on Nov 24, 2026

    @rdimitrov
    Member

    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.

    1. Listed client, token without an entry. The issue says "tokens without the entry behave exactly as today"; the Mecatl design says the vMCP refuses a listed client's token that names no call. Proposed: refuse it (403, fail closed); "as today" applies to clients not on the list. Safe, because Mecatl sets the list in the same release in which it starts sending entries.
    2. Unlisted client, token with an entry. As written, the entry would be ignored and the token accepted for any call. Proposed: enforce the entry whenever it is present; the client list only decides whether an entry is required. No issuer emits these entries today, so nothing existing changes.
    3. Messages after the token expires. Accepting cancellations and elicitation replies for the open call after exp needs an exception in pkg/auth token 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.
    4. GET and DELETE. They carry no body, so the "exactly one parsed operation" rule does not cover them. Proposed: allow GET (the SSE stream, which may carry the elicitation request) and DELETE on the token's own session while the token is valid, without using up its jti.
    5. Tools without a single server. Composite tools, the optimizer's call_tool and code mode's execute_tool_script dispatch further calls. Proposed: refuse them for call-bound tokens.
    6. Refusal shape. HTTP 403 with 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.
    7. Clock skew. Proposed: reuse the token validator's leeway instead of a new setting.
    8. null arguments. Hash as {}, like absent arguments (Mecatl already does this).
    9. Shared test vectors. Proposed: ToolHive holds the canonical copy, including the refusal cases; Mecatl's test compares its copy with the pinned module's.
    10. Progress. Clients do not normally send progress for a call. Proposed: drop "progress" from the accept list unless a client case is found.

    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.

  3. jhrozek commented on Nov 24, 2026

    @jhrozek
    Contributor

    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:

    • "Entry" means an entry of type https://toolhive.dev/mcp_tool_call. Entries of other types are ignored by this check.
    • A token with two or more mcp_tool_call entries is refused (403, reason single_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.
    • In the same spirit, an mcp_tool_call entry 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_call entry (unchanged, as today).

    3. Messages after the token expires. Agree on its own PR in the same release, but let's keep pkg/auth strict 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, in ValidateToken); validateClaims also checks exp but in practice only matters for introspected tokens. An expired opaque token comes back from introspection as active=false with no claims. TokenValidator.Middleware turns any validation error into 401 invalid_token. The vMCP only gets the middleware (GetAuthenticationMiddleware in pkg/auth/utils.go, built in newOIDCAuthMiddleware in pkg/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:

    type ExpiredToken struct {
        Claims    jwt.MapClaims
        ExpiredAt time.Time
    }
    type ExpiredTokenAdmitter func(r *http.Request, t ExpiredToken) bool
    func WithExpiredTokenAdmission(maxAge time.Duration, admit ExpiredTokenAdmitter) TokenValidatorOption
    • NewTokenValidator refuses maxAge <= 0 or a nil callback.
    • ValidateToken is unchanged. Without the option, Middleware is byte-for-byte today's path.
    • With the option, and only when the error is the expiry: re-validate with every check except exp (signature, iss, aud, nbf, iat), require exp to be present and less than maxAge in the past, then call the callback. JWTs only: an expired opaque token never qualifies.
    • Callback says no: the same 401 invalid_token, same body, as today. Callback says yes: the identity goes into the context as normal, marked with a new Identity.AdmittedAfterExpiry time.Time.
    • No extra leeway. The grace window is anchored to when the call started, on the vMCP's clock; maxAge is only a ceiling so old tokens are never re-verified.
    • Why not the alternatives: a typed error carrying the claims would put verified claims on an error value that gets wrapped and logged, and any errors.As could use them; a separate validate method needs a validator handle the vMCP doesn't have and would duplicate the identity and upstream-token logic in Middleware; 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:

    • the token carries an mcp_tool_call entry;
    • its jti has an open call recorded on this replica;
    • Mcp-Session-Id equals the session recorded with that call;
    • less than the maximum call duration has passed since the call started;
    • the parsed message is notifications/cancelled whose requestId equals 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 with AdmittedAfterExpiry set, and session ownership (session_ownership.go) still checks the same iss and sub. 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=true and 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 the jti together with sub.

    Three things to check in that PR:

    • The parser has to run before auth so the callback can see the method and IDs. That means parsing unauthenticated bodies; the body size is already capped, but say so in the PR.
    • Upstream tokens are loaded after admission in Middleware. These messages need no new backend credential, so skip the load for AdmittedAfterExpiry identities, after confirming that cancellation reaches the backend through the open call's context and not through a new backend call.
    • "Any response" relies on go-sdk dropping responses whose IDs it is not waiting for. Verify that with a test before shipping.

    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, wrong iss, wrong aud, future nbf, missing exp, or exp older than maxAge each get a 401 without calling the callback; callback false gives today's 401 body; callback true gives an identity with AdmittedAfterExpiry set; a valid token never calls the callback; an expired opaque token never qualifies.
    • pkg/vmcp: after exp, 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 unknown jti, a call older than the maximum duration, and a token without the entry; the call gate refuses an AdmittedAfterExpiry identity.

    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. After exp they are refused (see 3); a stream opened before exp keeps running.

    5. Tools without a single server. Agree: refuse composite tools, the optimizer's call_tool and code mode's execute_tool_script for 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 a scope= parameter in the challenge. MCP clients read insufficient_scope plus 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. null arguments. Agree: hash null as {}, 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:

    • the hash function must still pass that vector;
    • an end-to-end tools/call test can't use it, because the request is refused first (fail closed, which is correct);
    • mark such vectors in the file, e.g. "gateway_refuses": true, so both test suites know;
    • Mecatl's client should know about the case-fold rule, or it will debug a request error as a hash mismatch.

    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.

  4. removed
    needs-triage
    on Nov 24, 2026
  5. self-assigned this
    on Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions