Skip to content

Authorization server: narrow a JWT-bearer access token to one MCP call with authorization_details #7061

Done

Description

@ChrisJBurns

Part of #2851 (Phase 2, Slice 4: Limited access). Related: Delegated access: subject mapping at ID-JAG redemption (#6887), which no longer returns the granted entries; they belong to this issue. #6909, #6910, #6912.

Problem: a client that redeems an ID-JAG at the gateway's authorization server (RFC 7523 JWT-bearer grant) gets an access token good for any call to the resource until it expires. A client that sends tool calls on behalf of a separate, more trusted authorizer (Mecatl: the harness sends the call, its identity broker authorizes it and redeems the ID-JAG) should hold a token that serves only the call the authorizer approved. Today the token cannot be narrowed to one call.

Today: only token exchange reads authorization_details (the parameter). Neither redemption handler reads the parameter or the ID-JAG's claim, so a redeemed token never carries details.

Change: AS-2 processes the authorization_details claim of the ID-JAG that AS-1 signed, as ID-JAG §4.4.1 and RFC 9396 require. It copies the granted entries into the access token and grants an mcp_tool_call entry unchanged. In the first release a type's hook may drop whole signed entries but not change or add one; narrowing inside an entry is "Narrow authorization_details on token exchange and refresh" (#6912). A redemption that still carries an authorization_details parameter is refused with invalid_authorization_details and reason parameter_not_allowed.

  • Entry type https://toolhive.dev/mcp_tool_call, one of:
    • a tool call: server, tool (the name the vMCP routes by, as in params.name), arguments_sha256 (lowercase hex SHA-256 of the RFC 8785 serialization of params.arguments, or of {} when absent), operation_id;
    • a list call: server, method (tools/list or another list method).
  • Narrowing only: the entry can only restrict the token, never widen what the grant, client, or resource would otherwise allow. Exactly one entry; a malformed entry, an unknown field, or more than one entry is refused with invalid_authorization_details (RFC 9396 §5).
  • Whole entries only: the hook's result must be a subset of the signed entries, compared by exact JSON value. A result that changes or adds an entry is a hook bug, not a client error: answer server_error, log it, and issue nothing. Dropping every entry is refused as empty_grant, never treated as unrestricted.
  • Claim checks at redemption (before the assertion is consumed; a refused assertion stays unconsumed):
    • a plain RFC 7523 assertion (not an ID-JAG) that carries authorization_details keeps being refused with invalid_grant / invalid_assertion;
    • an ID-JAG claim that is present but null, [], a string, an object, or an array holding any non-object is refused with invalid_grant / invalid_assertion. Presence is checked in both the standard and the extra claims;
    • an ID-JAG carrying the claim at an AS-2 with no registry (or without the type registered for JWT-bearer) is refused with invalid_authorization_details / unknown_type, since ID-JAG §4.4.1 requires AS-2 to process the claim. The refusal is logged at WARN with the ID-JAG issuer and the entry types, never the entries.
  • Hook subject: authorizationdetails.Subject.Subject is the assertion's sub on every path. An optional ResolvedUser field is set only when this redemption resolved the subject (subject_mode: resolve), and is empty for namespaced issuers and on token exchange. On the ID-JAG path the claim is processed after subject resolution, so the field is filled when the hook runs.
  • Terminal tokens: a token that carries authorization_details (any value, from this server or an external IdP) cannot be exchanged. On RFC 8693 exchange such a subject or actor token is refused with the code the handler already uses for a refused subject or actor token plus its own reason, before any hook runs or anything is consumed. This stops a narrowed token from being exchanged for an unrestricted one.
  • In the token: the entry is copied unchanged into the access token's authorization_details claim. The token response returns the granted entries in authorization_details, required by ID-JAG §4.4.1 whether or not the redemption asked. Any external authorization server used for tool calls must support this as a profile requirement.
  • Lifetime per client: a configurable access-token lifetime for a client (here, Mecatl's mecatl client), so these tokens can live seconds while other clients keep the default.
  • Reason codes: refusals under invalid_authorization_details carry one of malformed_entry, unknown_type, single_entry_required, empty_grant, parameter_not_allowed, or a reason from the type's hook, in error_description. The redemption reasons shipped in v0.67.0 (reason codes for ID-JAG redemption refusals (Authorization server: reason codes in error_description for ID-JAG redemption refusals #7030), closed).

AS-1 signing (token exchange): AS-1 accepts an authorization_details entry of the same type on the ID-JAG request, checks its shape and the registered types, and signs the granted entries into the ID-JAG's authorization_details claim. An empty grant or an unknown type is refused with invalid_authorization_details. The type's hook checks the fields. ToolHive owns the call type's validator; an authorization server refuses any type it has no registered validator for. On token exchange the mcp_tool_call hook accepts the entry only when requested_token_type is the ID-JAG type; any other requested type (an access or refresh token) is refused with reason id_jag_required, so a plain exchange never echoes an entry its token does not carry.

Release order: AS-2 processing of the signed claim ships in the same release as AS-1 signing, or an earlier one. An AS-2 that predates it ignores the claim, and the token comes out unrestricted. If they are separate PRs, the AS-1 PR says "Depends on" the AS-2 one and stays in draft until it merges. Mecatl's side (stacklok/mecatl#2727) merges only with the ToolHive pin bump that contains both. The release notes of that release call this out, together with the new refusal of an ID-JAG that carries the claim at a server without a registry.

Lifetime: the per-client lifetime is an upper bound, not a guarantee. The token AS-2 issues lives for the shortest of:

  1. the per-client lifetime this issue adds (or the server's access-token lifespan when none is set);
  2. the time left on the ID-JAG when it is redeemed (assertionBoundedLifetime in pkg/authserver/server/tokenexchange/redeemer.go). This is the ID-JAG's own lifetime minus however long the broker took to redeem it;
  3. for a marked token, the marker cap from "Delegated access: subject mapping at ID-JAG redemption" (Delegated access: subject mapping at ID-JAG redemption #6887), a few minutes.

The ID-JAG's own lifetime is set at the issuing authorization server (AS-1). On a ToolHive AS-1:

  • It is the ID-JAG target's lifetime: 60 seconds when the target sets none, and at most 300 seconds (defaultIDJAGLifetime, maxIDJAGLifetime in pkg/authserver/config.go).
  • It is also capped by the actor credential's expiry, and by the grant's expiry and id_jag_max_lifetime.

So a client lifetime longer than the ID-JAG's is silently shortened, with no error. Examples, assuming the broker redeems 2 seconds after issuance:

ID-JAG target lifetime at AS-1 Per-client lifetime at AS-2 Issued token lives
60 s (default) 30 s 30 s
60 s (default) 2 min about 58 s
300 s (the maximum) 2 min 2 min
300 s (the maximum) 5 min about 298 s

Configuration note for operators: to get the per-client lifetime you configure, set the AS-1 target's ID-JAG lifetime to at least that lifetime plus the expected redemption delay. A per-client lifetime above 300 seconds can never be reached with a ToolHive AS-1. Mecatl's design uses tokens that live for seconds (expires_in: 30 in credentials-and-lifecycle.md step (8)), which the default 60-second ID-JAG covers.

Validation: a per-client lifetime must be at least 2s and at most 24h (a Go zero value must not mean "unlimited"), checked when the configuration is loaded so a bad value fails at startup, not on the first request. The 2s floor exists because exp is signed in whole seconds, rounded down, and expires_in is truncated: a shorter lifetime could issue a token that is already expired after its single-use ID-JAG is consumed. A client that sets a lifetime needs a trusted issuer that accepts ID-JAG assertions; otherwise startup fails, since the lifetime could never apply. Don't compare it with AS-1's settings: AS-2 cannot see them.

Acceptance:

  • an ID-JAG whose signed claim holds a valid tool-call or list-call entry yields a token whose authorization_details equals that entry, and a redemption that still carries the parameter is refused with parameter_not_allowed;
  • a malformed entry, two entries, or an unknown type is refused with invalid_authorization_details and one of the reasons below;
  • the entry never adds a resource, scope, or audience the redemption would not otherwise grant;
  • a client with a configured lifetime gets tokens with that lifetime; other clients are unaffected;
  • a redemption without authorization_details behaves exactly as today.
  • each refused claim shape (null, [], string, object, array with a non-object) is refused and leaves the assertion unconsumed; a plain RFC 7523 assertion carrying the claim is still refused, while the same claim in an ID-JAG is processed;
  • a hook result that changes or adds an entry yields server_error and no token;
  • a subject or actor token carrying authorization_details, including an external IdP's, is refused on RFC 8693 exchange; a token without details still exchanges as today;
  • on token exchange the mcp_tool_call entry is accepted for an ID-JAG request and refused with id_jag_required when an access or refresh token is requested;
  • a per-client lifetime of 0, a negative value, anything under 2s, or more than 24h fails at startup; exactly 2s and exactly 24h are accepted; unset falls back to the server lifespan; a lifetime with no trusted issuer accepting ID-JAG assertions fails at startup.
  • The issued token's exp is the earliest of the per-client lifetime, the ID-JAG's exp, and (for a marked token) the marker cap. expires_in in the response matches. Tested with an ID-JAG whose remaining lifetime is shorter than the client's lifetime.

Context: Mecatl agent identity design, credentials-and-lifecycle.md step (8) ("The argument hash") 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 this issue has started from the handover notes. A few rules the code needs are not in the issue text yet. Below is the proposed answer for each; a reply of "agree" or a number with a correction is enough, and the issue body can be updated to match.

    1. Release order. AS-2 processing of the signed claim ships in a release before, or with, AS-1 signing. An older AS-2 ignores the claim, so the access token would come out unrestricted. Proposed: add to the issue; the PRs enforce it by merge order.
    2. Plain RFC 7523 assertions. A plain JWT-bearer assertion (not an ID-JAG) that carries authorization_details keeps being refused with invalid_grant, invalid_assertion.
    3. Claim shape. An ID-JAG authorization_details claim that is not a JSON array of objects is refused with invalid_grant, invalid_assertion (the Mecatl design says the same).
    4. Terminal tokens. A token carrying authorization_details cannot be exchanged, as subject or actor token, including an external IdP's token on RFC 8693 exchange. Today the details are dropped silently. Proposed: refuse (fail closed), so a narrowed token cannot be widened through another exchange.
    5. Token exchange for mcp_tool_call. On token exchange, the type's hook accepts the entry only when requested_token_type is the ID-JAG type; otherwise plain exchange would echo an entry the issued token does not carry. Proposed reason: id_jag_required.
    6. Whole entries only. In the first release a hook may drop whole signed entries, but not narrow inside an entry or add to it. Per-type narrowing stays with "Narrow authorization_details on token exchange and refresh" (Narrow authorization_details on token exchange and refresh #6912).
    7. Per-client lifetime cap. A per-client access-token lifetime must be greater than 0 and at most 24h.
    8. Hook subject on a resolved redemption. With subject mapping, the token's sub is the local user. Proposed: the details hook sees the assertion's subject, not the mapped one.
    9. ID-JAG with the claim at an AS-2 without a registry. Proposed: refused with invalid_authorization_details, unknown_type, instead of issuing an unrestricted token. Risk: an IdP that puts authorization_details into its ID-JAGs would start failing at such a server. We have not checked whether any IdP does.

    Two text fixes for the body: the "Today" line says the server already parses the entry, but on main only token exchange reads it (neither redemption handler does); and assertionBoundedLifetime now lives in redeemer.go, not jwt_bearer_handler.go.

  3. jhrozek commented on Nov 24, 2026

    @jhrozek
    Contributor

    Thanks, this is a good list. Agree with all nine; details below, written so each one can go straight into the issue body or a PR. File paths are on current main.

    1. Release order. Agree, and let's make the dependency explicit rather than relying on merge order alone:

    • Add a "Release order" paragraph to the issue: AS-2 processing of the signed claim ships in the same release as AS-1 signing, or an earlier one. An AS-2 that predates it ignores the claim, and the token comes out unrestricted.
    • If AS-2 claim processing and AS-1 signing are separate PRs, the AS-1 PR says "Depends on" the AS-2 one in its body and stays in draft until that one merges.
    • Mecatl's side (Bind each gateway token to its call mecatl#2727) must not merge before the ToolHive pin bump that contains both.
    • Call it out in the release notes of that release.

    2. Plain RFC 7523 assertions. Agree, no change: keep refusing authorization_details on a plain JWT-bearer assertion with invalid_grant / invalid_assertion. Keep the existing test, and add one that sends the same claim in an ID-JAG to make sure the two paths stay separate after the AS-2 change.

    3. Claim shape. Agree. To be precise about what counts as "not an array of objects": a claim that is present but null, [], a string, an object, or an array holding any non-object is refused with invalid_grant / invalid_assertion. Presence is checked in both the standard and extra claims, like the existing presence checks. [] matters most: in this deployment a token without details is unrestricted, so an empty signed grant must not turn into an unrestricted token. Tests: one row per shape above, and each must leave the assertion unconsumed.

    4. Terminal tokens. Agree, fail closed. On RFC 8693 exchange, a subject or actor token that carries authorization_details (any value, including an external IdP's token) is refused with the error code the handler already uses for a subject or actor token it rejects, plus a new reason, e.g. details_bearing_token. Refuse before any hook runs or anything is consumed. Tests: subject token with details, actor token with details, external IdP token with details, and a token without details still exchanging as today.

    5. Token exchange for mcp_tool_call. Agree, reason id_jag_required. The mcp_tool_call hook refuses the entry unless requested_token_type is the ID-JAG type. If the hook's Request doesn't carry the requested token type yet, add it there rather than special-casing the type in the handler. Tests: ID-JAG requested (accepted), access token requested (refused, id_jag_required), refresh token requested (refused).

    6. Whole entries only. Agree. Concretely, for the first release:

    • the hook's result must be a subset of the signed entries, compared by exact JSON value;
    • a result that modifies an entry or adds one is a hook bug, not a client error: answer server_error and log it, rather than issuing anything;
    • dropping every entry is not "unrestricted": it is refused as empty_grant.
      Per-type narrowing stays with "Narrow authorization_details on token exchange and refresh" (Narrow authorization_details on token exchange and refresh #6912).

    7. Per-client lifetime cap. Agree: greater than 0 and at most 24h, checked when the configuration is loaded so a bad value fails at startup, not on the first request. Tests: 0, negative, exactly 24h (accepted), 24h + 1s (refused), unset (falls back to the server lifespan).

    8. Hook subject on a resolved redemption. Agree that Subject should be the assertion's subject, with one meaning on every path. But an embedder running subject_mode: resolve writes its policies against the resolved local user, not the IdP subject, and shouldn't have to resolve again inside the hook. So:

    • keep authorizationdetails.Subject.Subject as the assertion's sub;
    • add an optional field, e.g. ResolvedUser string, set only when this redemption resolved the subject, and empty for namespaced issuers and on token exchange;
    • in the ID-JAG path, process the claim after subject resolution, so the field is filled in when the hook runs. That's the same order the actor check already uses: the act.iss pre-check, then resolution, then the policy on the resolved user. detailsSubject in pkg/authserver/server/tokenexchange/authdetails.go takes the resolved user as an argument instead of reading it from the claims.
    • Tests: namespaced issuer (field empty, Subject = assertion sub), resolve issuer (field = local user, Subject still the assertion sub), and resolution failing before the hook runs (hook never called).
      subject_mode stays per issuer; we don't see a need for per-client or per-actor subject handling.

    9. ID-JAG with the claim at an AS-2 without a registry. Agree: refuse with invalid_authorization_details / unknown_type. ID-JAG §4.4.1 says the redeeming server must process the claim, and an AS-2 without a registry can't, so refusing is the only conformant answer. For the IdP risk, log the refusal at WARN with the ID-JAG issuer and the entry types (never the entries themselves), so an operator whose IdP starts sending details can see why redemptions fail. Mention it in the release notes.

    Text fixes. Agree with both. Suggested replacements:

    • "Today": "Only token exchange reads authorization_details (the parameter). Neither redemption handler reads the parameter or the ID-JAG's claim, so a redeemed token never carries details."
    • Lifetime item 2: "assertionBoundedLifetime in pkg/authserver/server/tokenexchange/redeemer.go".
      Also worth adding a "Release order" paragraph (item 1) and the shape rules from items 3, 6 and 7 to the body.
  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