Skip to content

Per-call grant and gateway token #2535

Closed

Description

@ChrisJBurns

Depends on: #2534 and #2738 (PR #2744: the embedded AS-2 and its startup values). For the real servers: #2533, #2654, stacklok/toolhive#6898, and stacklok/toolhive#6887. Built and tested against the offline harness's AS-1 and ToolHive's authorization server (the version Mecatl pins) as AS-2.

Problem

The gateway needs a token for each call that names both the user and the acting agent. Today it receives the MCP broker's per-session OAuth token, which names no agent, and the identity broker cannot authorize anything (Broker.AuthorizeCall in internal/identitybroker/sessions.go denies every call).

Design

Until PR #2779 merges, the request's method, server, and tool, the rejected-token retry, the revoked rule with no recorded reason, the gateway token's jti, and the record order are in that PR rather than on main.

Shortcuts

Shortcut Removed by
Production configures no gateway entry for the identity broker, so authorized gateway calls work only in tests #2533, once AS-2 trusts AS-1
The rejected-token retry state and the call records are kept in memory #2563
AS-2 refusals carry no reason code, so every invalid_grant is retried once with a new ID-JAG #2533, after stacklok/toolhive#7030
AS-1's upstream_revoked and owner_action_required fail the call but are not recorded against the session, and the session stays open #2568
The gateway token is not bound to its call, and its lifetime is AS-2's server-wide access-token lifetime capped at the ID-JAG's #2538 (lifetime), #2727 (binding)
No authorization_details on redemption #2727
The AS-2 port is bound in process after startup, so a call to the configured gateway before it is bound or while it is being unbound fails as UNAVAILABLE #2560 (AS-2 over the network)
Step (6) checks 4 and 5 (run and owner) and 7 (ceiling) accept their inputs without checking them #2557, the authority work
A gateway token that is not a JWT has no reference in the decision record #2541 (references AS-2's redemption event)
The broker holds one gateway, the embedded one, with one AS-2 binding #2538 (operator-declared gateway entries, each with its own AS-2)
The embedded AS-2 trusts the harness's AS-1 only through a test seam (ToolHiveConfig.AS2Trust, set by mcpbrokertest) #2533

Requirements

"Authorize an MCP call" in the real identity broker, as steps (6) to (8) specify:

How it fits

Steps (6) to (8) of the flow: the gateway receives a token naming the user and the agent, and the user's provider credential never leaves the gateway.

Done when

Against the offline harness's AS-1 and the real ToolHive AS-2:

  • every call obtains its own gateway token from a new ID-JAG, nothing is cached, and each call makes exactly one exchange and one redemption (two of each with the rejected-token retry);
  • the gateway token's expiry is no later than the ID-JAG's exp;
  • decisions and ID-JAG records are written in the audit chapter's order, with its failure behaviour;
  • the rejected-token retry, the revoked and parent_revoked rules, a lost redemption response, and a session closed during an exchange behave as step (8) and "Error reasons" specify;
  • AS-2 refuses a reused ID-JAG, and the gateway token carries act and client_id mecatl;
  • a list request needs no tool or argument hash, and a tools/call does;
  • every failure in the failure matrix that this ticket can reach maps as specified;
  • a leak test shows the ID-JAG and gateway token appear in no model or tool content, transcript, log, environment variable, error, diagnostic, recorder record, or client assertion;
  • tokens are never shared across users or sessions, and none is issued after the session closes;
  • the authorization contract tests (internal/identitybroker/conformance) gain cases for the new request fields, no_grant, and the retry flag's refusals, and the real implementation passes them.

Activity

  1. 3 remaining items

  2. ChrisJBurns commented on Nov 6, 2026

    @ChrisJBurns
    ContributorAuthor

    Decide when starting this ticket: what server and tool mean

    This ticket fixes the AuthorizeCall request shape. #2560 turns it into gRPC, #2541 records the same names, and #2727 and stacklok/toolhive#7061/#7062 bind and check them. Settle this before writing the request.

    • tool: step (8) says it is "the name the vMCP routes by, as sent in params.name". The embedded vMCP prefixes tools with {workload}. (toolHiveAggregationConfig in internal/adapter/mcpbroker/toolhive_process.go), so the routed name is github.pull_request_read. The step (8) examples, and audit.md, use the unprefixed pull_request_read.
    • server: not defined anywhere. Candidates: the vMCP backend workload the route resolves to, the MCP server name registered in Mecatl, or the gateway entry.
    • Today's code: the merged request has Target ("the gateway or backend"), not server (internal/identitybroker/service.go).
    • Listing: a tools/list request needs its own rule for what it names.

    Suggested: server is the vMCP backend workload, and tool is exactly params.name as sent. Then fix the step (8) examples and audit.md.

    Who decides: Chris, with jhrozek and the owner of stacklok/toolhive#7061.

  3. ChrisJBurns commented on Nov 13, 2026

    @ChrisJBurns
    ContributorAuthor

    Answered on 2026-11-13: tool is the routed name exactly as sent in params.name (e.g. github.pull_request_read), server is the gateway's backend name, and a Method field distinguishes calls from listings. Recorded in the design, step (6), by docs PR #2779.

  4. self-assigned this
    on Nov 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions