Repository navigation
Description
Part of #6886 (the gateway side is in the scope of #6406). Related: #3919 (audit logging in the authorization server).
Problem: a client that mediates tool calls, such as an agent harness's broker, records each call as an operation with one or more attempts. The vMCP's mcp_tool_call audit events cannot be joined exactly to the client's records. A join by user, tool, and time picks the wrong record when one agent calls the same tool twice in parallel.
Since "Authorization server: narrow a JWT-bearer access token to one MCP call with authorization_details" (#7061) and "vMCP: accept an access token for the one call its authorization_details names, once" (#7062), the vMCP holds two verified identifiers for each call:
- the
operation_idin the token'shttps://toolhive.dev/mcp_tool_callentry. The authorization server signed it, and the vMCP validates the token before it admits the call; - the token's
jti. A call-bound token starts one call, so itsjtinames that attempt.
The audit already reads the first one, but only for a request admitted after its token expired (stampAdmittedAfterExpiry in pkg/audit/auditor.go, key operation_id). No event records the jti.
Change:
- Verified values. For every request whose validated token carries a call entry, record the entry's
operation_idinMetadata.Extra["operation_id"](the existing key), and the token'sjtiin a newMetadata.Extrakey, for exampletoken_jti. Record the token'sisstoo if it is not already on the event. Do this for allowed calls, denials, and binding refusals. A listing token has nooperation_id, so record only thejti. - Reported values. Read the operation and attempt identifiers from the MCP request's
_meta, under configurable keys, and the run identifier from trace headers. Record them under separate keys marked as reported, for examplereported_operation_idandreported_attempt_id. Never write a reported value into a verified key. Limit their length and character set, and drop a malformed value with a log line. - Record none of these as subjects. Subjects say who acted; these say which call.
- Never use any of these values for an authorization or policy decision in this change. The call binding already checks the token's entry.
Acceptance:
- a call with a call-bound token yields an event with the entry's
operation_idand the token'sjti, also when the call is denied or refused by the binding; - with two parallel calls to the same tool by the same client, each event carries its own
jtiandoperation_id; - a
_metavalue that differs from the token'soperation_idis recorded under the reported key, and the verified key keeps the token's value; - a malformed or oversized
_metavalue is dropped and does not fail the request; - no token value and no other claim reach the event.
What Mecatl removes when this lands: Mecatl embeds the vMCP and, as a stopgap (stacklok/mecatl#3023), sets AuditSubjectEnricher to add gateway_token_jti and operation_id as subjects on each event, read from the validated token. When this lands, Mecatl removes that enricher and joins on the new fields instead.
Activity
[-]Record the operation and attempt IDs a client reports, at the authorization server and the vMCP[/-][+]Record the operation and attempt IDs a client reports, at the vMCP[/+][-]Record the operation and attempt IDs a client reports, at the vMCP[/-][+]vMCP: record the call-bound token's operation ID and jti, and the IDs a client reports[/+]