Skip to content

Add the MCP tool-call details type - #7283

Merged
rdimitrov merged 3 commits into
mainfrom
as2-call-binding-5-mcp-tool-call-type
Nov 25, 2026
Merged

rdimitrov merged 3 commits into
mainfrom
as2-call-binding-5-mcp-tool-call-type

Conversation

@rdimitrov

Copy link
Copy Markdown
Member

Summary

  • Why: a client that redeems an ID-JAG at the gateway's authorization server gets an access token that is good for any call until it expires. To narrow that token to the one MCP call an authorizer approved ("Authorization server: narrow a JWT-bearer access token to one MCP call with authorization_details" (Authorization server: narrow a JWT-bearer access token to one MCP call with authorization_details #7061)), the authorization server and the vMCP need a shared authorization_details type that describes the call. This PR adds that type, and nothing else, so the vMCP enforcement work can import it without waiting on the authorization-server changes.
  • What: new package pkg/mcp/toolcalldetails, which depends only on pkg/authserver/authorizationdetails and pkg/oauthproto.
    • Type is https://toolhive.dev/mcp_tool_call. An entry is a tool call (server, tool, arguments_sha256 as 64 lowercase hex characters, operation_id, all non-empty strings) or a list call (server, method in tools/list, prompts/list, resources/list, resources/templates/list). No other members, and the two shapes are never mixed.
    • Register adds the type for RFC 8693 token exchange and RFC 7523 JWT-bearer. The hook accepts exactly one entry of its type and grants it unchanged.
    • Refusals are invalid_authorization_details with one of single_entry_required, malformed_entry, invalid_arguments_hash, invalid_method. On a token exchange that reaches the hook without requesting an ID-JAG, the refusal is invalid_request with id_jag_required.
    • Entry and ParseEntry expose the same shape check, so the vMCP enforcement in "vMCP: accept an access token for the one call its authorization_details names, once" (vMCP: accept an access token for the one call its authorization_details names, once #7062) can parse the token claim with this one definition. ParseEntry scans the object itself and refuses repeated members, non-string values, trailing data, invalid UTF-8 and any value containing U+FFFD. It does not rely on the caller having run Registry.Parse first.
    • The package doc defines arguments_sha256 (RFC 8785 serialization of params.arguments, or of {} when absent), states the intended AS-1 / AS-2 use, and states that the authorization-server handlers do not read the entry yet.
    • A short paragraph in "Authorization details" in docs/arch/17-token-exchange-delegation.md.

Part of #7061.

Safe to merge and release on its own. Nothing registers the type by default, and even when an embedder registers it, no token is narrowed or appears narrowed:

  • a token-exchange request for an ID-JAG still refuses the authorization_details parameter (checkIDJAGExtraParameters), before the registry is consulted;
  • JWT-bearer redemption never consults the registry (the only Registry.Parse callers use the token-exchange grant), so the JWT-bearer registration is inert;
  • an access-token exchange (or one with no requested_token_type) that sends the entry is refused by the hook with id_jag_required;
  • refresh-token exchange parses with its own registry, so it refuses the entry as an unknown type (invalid_authorization_details) before any hook runs.

The AS-1 signing and AS-2 claim changes build on this package later; each updates the package doc's "do not read it yet" paragraph when it lands.

Type of change

  • New feature

Test plan

  • Unit tests (task test): pass
  • Linting (task lint-fix): 0 issues
  • Scoped: go test -race ./pkg/mcp/toolcalldetails/... ./pkg/authserver/... and golangci-lint run ./pkg/mcp/toolcalldetails/...: pass, 0 issues.

New tests:

  • the hook table through a real authorizationdetails.Registry: tool and list calls on JWT-bearer (empty RequestedTokenType) and on ID-JAG token exchange; id_jag_required for an access-token, a refresh-token and an empty requested_token_type (the refresh-token row pins the hook's rule; on main the refresh-token handler refuses the entry earlier); single_entry_required on both grants; unknown, missing, empty, non-string and mixed members; bad hashes; a method outside the set;
  • the registered grant-type list (exactly token exchange and JWT-bearer);
  • ParseEntry on its own: all four list methods and near misses; non-hex and wrong-length hashes; a missing server in either shape; other or missing type; repeated members, including an escaped repeat; a member in a different letter case; number, null and object values; trailing data; a non-object; invalid JSON; invalid UTF-8; an unpaired surrogate escape and a literal U+FFFD; empty input; and accepted escapes and whitespace.

Changes

File Change
pkg/mcp/toolcalldetails/toolcalldetails.go New: Type, reasons, Entry, ParseEntry, Register and its hook
pkg/mcp/toolcalldetails/toolcalldetails_test.go New: tests above
docs/arch/17-token-exchange-delegation.md "MCP call type" paragraph under "Authorization details"

Does this introduce a user-facing change?

No. Nothing registers the type by default. An embedder that registers it sees one difference: a non-ID-JAG token exchange that sends the entry was refused as an unregistered type (invalid_authorization_details) and is now refused with invalid_request / id_jag_required. ID-JAG requests and JWT-bearer redemption behave as before.

Special notes for reviewers

Confirmed in the issue discussion (#7061 comment, #7062 comment):

  • On token exchange the hook accepts the entry only when requested_token_type is urn:ietf:params:oauth:token-type:id-jag, and otherwise refuses with id_jag_required (code invalid_request, since requested_token_type is the related parameter at fault). Without this rule a plain RFC 8693 exchange would accept and echo the entry while the token it issues carries nothing, so the client would believe it holds a narrowed token.
  • single_entry_required and malformed_entry apply per mcp_tool_call type. The hook sees only entries of its own type (Pending.Grant groups by type); entries of other registered types are left to their own hooks.

Other notes:

  • The JWT-bearer registration has no guard of its own: the hook cannot tell a signed claim from a client's form parameter. Refusing the redemption parameter before the registry is consulted belongs to the AS-2 claim change. On main, JWT-bearer redemption never consults the registry, so the registration is inert.
  • ParseEntry refuses any value containing U+FFFD. encoding/json decodes an unpaired surrogate escape such as \ud800 to U+FFFD, so without the check two different signed values could compare equal after decoding.
  • Entry has no JSON tags on purpose. Decoding with json.Unmarshal would skip the shape check (and keep the last of two repeated members), so the only way in is ParseEntry.
  • The authorization server only checks the entry's shape. It never computes arguments_sha256 or compares it with real arguments; the vMCP enforces the call (vMCP: accept an access token for the one call its authorization_details names, once #7062).
  • ParseEntry has its own small token scanner rather than using pkg/mcp's DecodeJSONObjectMembers, to keep the package's dependencies to authorizationdetails and oauthproto.

🤖 Generated with Claude Code

An access token redeemed from an ID-JAG should be able to serve only the
one MCP call an authorizer approved ("Authorization server: narrow a
JWT-bearer access token to one MCP call with authorization_details"
(#7061)). That needs an authorization_details type that describes the
call, shared by the authorization server and the vMCP that enforces it.

pkg/mcp/toolcalldetails defines https://toolhive.dev/mcp_tool_call: a
tool call (server, tool, arguments_sha256 as 64 lowercase hex,
operation_id) or a list call (server and one of tools/list,
prompts/list, resources/list, resources/templates/list). Register adds
it for token exchange, where AS-1 is meant to sign it into an ID-JAG,
and for JWT-bearer, where AS-2 is meant to read it from the signed
claim. The hook accepts
exactly one entry of its type and grants it unchanged; refusals are
invalid_authorization_details with single_entry_required,
malformed_entry, invalid_arguments_hash or invalid_method. On token
exchange it also refuses unless requested_token_type is the ID-JAG type
(invalid_request, id_jag_required), because a plain exchange would echo
the entry while the issued token carries nothing.

ParseEntry exposes the same shape check as an Entry value, so the vMCP
can parse a token's claim with one definition. It scans the object
itself and refuses repeated members, non-string values, trailing data,
invalid UTF-8 and any value holding U+FFFD, so the decoded value stays
one-to-one with the signed bytes instead of relying on the caller
having run Registry.Parse first.

It is safe to release on its own. Nothing registers the type by
default, and when an embedder does, no token is narrowed: the ID-JAG
token-exchange request still refuses the authorization_details
parameter, JWT-bearer redemption never consults the registry, an
access-token exchange is refused with id_jag_required, and refresh-token
exchange refuses the entry as an unknown type. The package depends only on authorizationdetails and
oauthproto, so the vMCP can import it without waiting on the
authorization-server changes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added the size/M Medium PR: 300-599 lines changed label Nov 24, 2026
@codecov

codecov Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.87%. Comparing base (8d64314) to head (a4790cb).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #7283   +/-   ##
=======================================
  Coverage   81.86%   81.87%           
=======================================
  Files         915      916    +1     
  Lines       92868    92935   +67     
=======================================
+ Hits        76029    76092   +63     
- Misses      16834    16838    +4     
  Partials        5        5           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

jhrozek
jhrozek previously approved these changes Nov 24, 2026

@jhrozek jhrozek left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, the type and the hook look right to me and I agree this is safe to land on its own. I left three small doc comments inline. None of them block this, they're fine as follow-ups, but it would be good to sort out the first two before the vMCP enforcement work ("vMCP: accept an access token for the one call its authorization_details names, once") starts coding against this doc.

Codespell read the JSON escape in "server" as the word "ser".
Escape the first letter instead; the test still checks that an escaped
member name decodes to the same name.

Add rows for a member name that is not a string, an object without its
closing brace, and an object closed by a bracket, which cover the two
decoder error returns that had no test.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added size/M Medium PR: 300-599 lines changed and removed size/M Medium PR: 300-599 lines changed labels Nov 24, 2026
Say what each member means so the vMCP and its clients implement the same
match: server is the ID of the backend the call is routed to, and tool is
params.name exactly as sent, including any backend prefix. A list call
lists only that backend's items. Fix the example to use the routed name.

The argument hash uses {} when arguments are absent or null, as agreed
for the vMCP check. Reword the token-exchange comment and the Register
doc so they don't suggest the ID-JAG path reads the entry today.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added size/M Medium PR: 300-599 lines changed and removed size/M Medium PR: 300-599 lines changed labels Nov 24, 2026
@rdimitrov
rdimitrov merged commit faa0076 into main Nov 25, 2026
53 checks passed
@rdimitrov
rdimitrov deleted the as2-call-binding-5-mcp-tool-call-type branch November 25, 2026 08:39
@github-actions github-actions Bot mentioned this pull request Nov 25, 2026
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/M Medium PR: 300-599 lines changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants