Skip to content

Enforce list-call tokens at the vMCP - #7325

Merged
rdimitrov merged 10 commits into
mainfrom
vmcp-call-binding-3-list-calls
Nov 26, 2026
Merged

rdimitrov merged 10 commits into
mainfrom
vmcp-call-binding-3-list-calls

Conversation

@rdimitrov

@rdimitrov rdimitrov commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

Summary

An access token can be narrowed to one MCP call with an RFC 9396 authorization_details entry of type https://toolhive.dev/mcp_tool_call. An entry names either a tool call or a list call: a backend (server) and a list method. Until now the vMCP enforced only tool-call entries. It refused list-call entries with list_call_unsupported, and AS-1 refused to sign a list-call entry into an ID-JAG, so it never issued a token the vMCP would reject. This PR adds list-call enforcement to the vMCP and lifts the AS-1 refusal in the same change, so the two ship together.

  • vMCP: a list-call token may send the list method its entry names (tools/list, prompts/list, resources/list or resources/templates/list), once: like a tool call, the list call uses up the token. A list request carries no server, so the binding narrows the answer: the vMCP returns only the items whose backend is the entry's server. The items come from one admission-filtered core list, each attributed by its own BackendID, so another backend's item that shares a name or URI is never returned. Composite tools, execute_tool_script and optimizer meta-tools have no single backend, so they are never listed. The server must be a backend in the caller's view, or the request is refused before the token is used.
  • One response, no cursor: the usual handler still answers the list call, after every later check, but its items are replaced by the backend's items, rendered as a Modern list renders them, and its nextCursor is dropped. Both revisions cut pages whose cursor carries the last unfiltered key, which can name another backend's item, so neither the handler's items nor its cursor reach the client. A Legacy session the SDK rehydrated (from another replica, or after the idle timeout) answers in text/event-stream; the list call is answered in JSON all the same. A list call that carries its own cursor is refused with invalid_params.
  • Refusals: before the list call, a tools/call or a different list method gets method_mismatch, and anything else gets method_not_allowed. Both use the same 403, JSON-RPC body and audit record as tool-call mismatches. A server that is unknown, hidden from the caller by authorization, offers the caller nothing (no tool, resource, resource template or prompt), or fails discovery gets the same 403 server_not_found, as an unknown tool gets tool_not_found: AS-1 signs any server name, so the answer must not tell whether a backend the caller can't see exists. A backend in the caller's view that the core's lists leave out for its health status (unhealthy, unknown or unauthenticated, even while it still answers) gets 503; a degraded one stays in the lists and is listed. Once a token has started its call, a tools/call or a list method other than a tool-call token's tools/list gets 401 token_reused before the request is checked, for list-call and tool-call tokens alike, so the client knows it needs a new token. A tool-call token keeps its existing access to tools/list, unfiltered, after its call as before. JSON-RPC responses are not admitted on an open list call's session, since a list call asks the client nothing.
  • AS-1: toolcalldetails no longer refuses list-call entries on an ID-JAG token exchange. The list_call_unsupported reason is removed from toolcalldetails and callbinding. Neither constant was ever in a release. toolcalldetails.IsListMethod is now exported as the single list of list methods.
  • Docs: docs/arch/10, docs/arch/17, docs/arch/vmcp-library.md and docs/authz.md are corrected where they said list calls were refused.

Part of #7062. Accepting messages for a call after its token's exp is still open under that issue.

Type of change

  • New feature

Test plan

  • Unit tests (task test): race runs of pkg/vmcp/callbinding, pkg/mcp/toolcalldetails, pkg/vmcp/server, pkg/vmcp/core and pkg/authserver/...
  • Linting (task lint-fix): task lint reports 0 issues; task docs produces no changes
  • Manual testing (described below)

What the new tests cover:

  • pkg/vmcp/callbinding/list_test.go: reading the handler's response and writing the answer, including member order and bytes preserved, refusal of duplicate or case-folded members (result, error, items, nextCursor, cacheScope, ttlMs) and of a response with both result and error, a missing items member, cache hints, the client-cursor check, and reading the response out of an event stream.
  • pkg/vmcp/server/call_binding_list_test.go:
    • all four list methods on Legacy and Modern;
    • refusals and their audit record;
    • a list call made after a refusal;
    • lists longer than one page on Legacy and Modern, including a first page with none of the server's items: one response, no nextCursor, and no other backend's key anywhere in the body; a client-sent cursor is refused with invalid_params and leaves the token unused;
    • two backends exposing the same resource URI, on Legacy and Modern: only the bound backend's item is returned;
    • the same 403 server_not_found, byte for byte, for a server that is unknown, offers the caller nothing, or fails discovery (the token stays unused); a backend that offers only resource templates is in the view;
    • a bound backend marked unhealthy, unknown or unauthenticated gets 503 with the token unused, and the same token gets the list once the backend is healthy; a degraded backend is listed; the health monitor's status decides over the registry's;
    • single use: a second list call with the token gets token_reused on Legacy and Modern, a list call and a tool call under the same issuer and jti use up each other, and after either kind of call a tools/call or a list method other than a tool-call token's tools/list gets 401 token_reused rather than a 403 about the request, while that tools/list still gets 200;
    • a list call answered without a list (a session the server doesn't know, a JSON-RPC error, any status other than 2xx, a client that goes away) is not recorded, so the token stays unused; of two concurrent duplicates, both run the handler and exactly one is answered;
    • a Modern client that cancels while dispatch runs keeps its token, though dispatch then writes its whole answer: a retry with the same token gets the list, and the cancelled call is audited as error, not success;
    • a list call on a Legacy session rehydrated on another replica, which answers in an event stream, is answered in JSON with only the bound server's items;
    • a notifications/cancelled or a JSON-RPC response sent while a list call runs gets no_open_call; a list request without an id gets method_not_allowed and leaves the token unused;
    • a first tools/call needs no record read (it runs while record reads fail), and a spent list-call token's resources/read keeps its 403 method_not_allowed;
    • a failed list lookup (503), and response bodies that pass through or fail closed, with the handler's headers sent only with its own response.
  • TestCallBindingReal_ListCallKeepsAdmission: Cedar still hides a tool on the bound backend from a list-call token. TestCallBindingReal_ListCallServerInView, against the real core: a backend that offers only resource templates gets its resources/templates/list, and one whose items Cedar hides gets the same 403 server_not_found as a server that doesn't exist.
  • pkg/vmcp/server/call_binding_idjag_integration_test.go: real AS-1 and AS-2 (pkg/authserver/runner), with the call type registered on both, in front of a vMCP with two backends. The vMCP validates tokens with the production OIDC validator. For each list method, a list-call entry is signed by AS-1 and copied by AS-2, and the vMCP returns only the bound backend's item. Another list method and a tools/call are refused, with method_mismatch before the list call and token_reused after it. A tool-call token still runs its call and is refused prompts/list.

Manual run (made before list calls became single use and before the review fixes; Mecatl's tokens carry no call details, so it would not exercise them): I built Mecatl's cmd/mecak8s against this branch through a temporary go.work replace and ran its identity-broker harness tests. Those tests drive the real AS-1 and the bundled ToolHive AS-2 and vMCP, and all pass. Mecatl does not yet send authorization_details on gateway calls, so its tokens carry no entry. That means the run checks that tokens without an entry behave as before (a gateway listing still returns every backend's tools). It does not exercise a list-call token end to end; the Go chain test above covers that.

Changes

File Change
pkg/vmcp/server/call_binding.go Admit the entry's list method for a list-call token and answer it from one backend-attributed view, recording the call once the answer is ready; refuse a spent token with token_reused first
pkg/vmcp/callbinding/list.go ReadListResponse, ListResponse.Encode, ListParamsCarryCursor, SSEResponse: read the handler's response and write the answer
pkg/vmcp/callbinding/binding.go ReasonMethodMismatch, ReasonServerNotFound; drop ReasonListCallUnsupported
pkg/vmcp/server/serve.go Wire the list lookup into call binding
pkg/mcp/toolcalldetails/toolcalldetails.go Stop refusing list calls on ID-JAG exchange; export IsListMethod
docs/... Correct the four pages that said list calls are refused
*_test.go Unit, server, Cedar and AS-1 → AS-2 → vMCP tests

Does this introduce a user-facing change?

Yes, for deployments that issue call-bound tokens.

  • List-call tokens at the vMCP. Before: a list-call token got HTTP 403 list_call_unsupported for every list method. After: its own list method returns 200 with all of its server's items in one response, without nextCursor, once; after that, a list method or tools/call with the same token gets HTTP 401 token_reused, as a reused tool-call token does. Before the list call, a tools/call or a different list method gets 403 method_mismatch, a request carrying a cursor gets 403 invalid_params, a server that is unknown, hidden from the caller, offers it nothing, or fails discovery gets 403 server_not_found, and one in the caller's view that isn't served for its health status gets 503.
  • Tool-call tokens after their call. Before: a tools/call naming another tool, or a list method other than tools/list, got 403 (tool_mismatch, arguments_mismatch, method_not_allowed and so on). After: it gets 401 token_reused. Before their call, nothing changes.
  • AS-1. Before: a token exchange for an ID-JAG with a list-call entry got 400 invalid_authorization_details / list_call_unsupported. After: AS-1 signs the entry into the ID-JAG.
  • Tokens without an entry behave as before.

Special notes for reviewers

  • List calls are single use, like tool calls, following vMCP: accept an access token for the one call its authorization_details names, once #7062's "a token's jti starts at most one call". The list call is recorded only once its answer is ready, and ended at once; any later list method, tools/call or initialize gets token_reused. Of concurrent duplicates, each runs the handler, but only the first to record is answered, and the others get token_reused. So a list call that gives the client no list leaves the token unused: a refusal (method_mismatch, invalid_params, server_not_found), a 503, a JSON-RPC error, a later refusal such as the session 404, an unreadable response, a handler that panics, or a client that went away before the answer reached it, on Legacy and Modern, even when the handler had answered. A call cancelled that way is answered with a 503 the client never reads, so the audit log records it as error. A client that goes away after the answer was written still spends the token; the vMCP can't tell that apart from a delivered answer. Because a list call is never open, a notifications/cancelled or response sent while it runs gets no_open_call.
  • Which backends are in the view. The server check uses the caller's view only: LookupBackend, which keeps a backend the caller is admitted to at least one tool, resource or prompt of, plus the resource templates list, which LookupBackend doesn't count. A backend outside that view gets server_not_found whatever the reason. For one inside it, the check applies the rule the core's lists use: health.ShouldAdvertise on the health monitor's status, or else the registry's, which admits healthy, degraded and unmonitored backends.
  • Why the answer is rendered from the core view rather than filtered from the handler's pages. Matching the handler's items by name or URI against a separate lookup could return another backend's item with the same key when the view changed between the two, on Modern as well as Legacy. Rendering from one core list keeps each item's backend, needs no page walk and no cursor, and fixes the earlier Legacy stale-snapshot limit. The items are rendered with the same functions Modern lists use (modernToolFromDomain and its siblings), which build items the same way Legacy sessions do.
  • Exceptions to .claude/rules/vmcp-anti-patterns.md:
    • Implement secret store #4, middleware that wraps the ResponseWriter: the call-binding middleware buffers the handler's list response to replace its items. Legacy lists are served by the SDK from the session's own store, and toolhive-core's mcpcompat exposes no hook that can change a list result: AddBeforeListTools cannot, and receiving middleware exists only as a test seam. Modern dispatch calls the core directly. Replacing the items in the call-binding middleware covers both revisions with one mechanism and keeps call binding able only to refuse or narrow. Legacy always answers in application/json; any response that is not a readable list gets a 500 rather than going out. Once Legacy is retired, this can move into Modern dispatch.
    • Bump golangci/golangci-lint-action from 2f856675483cb8b9378ee77ee0beb67955aca9d7 to 4696ba8babb6127d732c3c6dde519db15edab9ea #3, the Server struct: Server gains the list lookup (callBindingListItems, callBindingListServer). It is wired into callBinding the same way the existing route lookup is, as a function, and holds no new state.
    • The page walk of the previous revision, which rebuilt request bodies (Do we want the container monitor? #2) and rewrote the parsed request in the context (Create proxy subcommand #7), is gone.
  • Known limits, not fixed here:
    • Single use is enforced per replica until a shared record lands (vMCP: one single-use record shared by all replicas for call-bound access tokens #7261). This is the same gap tool calls already have: a token spent on one replica is accepted once more on another.
    • With the optimizer enabled, a list-call tools/list is always empty, because the optimizer's meta-tools have no backend. This is tracked on the Mecatl side.
    • The server check and the items come from separate aggregations, so a backend that drops out of the view between the two is answered with an empty list and the token is used. Likewise, Modern discovery turns a transient failure of one list method into an empty list. A follow-up will add a core method that returns one backend's discovery outcome and admitted items from a single aggregation; arch/10 notes the race until then.
  • Release order: the AS-1 change and the vMCP change must ship together. With version skew, both directions fail closed:
    • A new AS-1 in front of an old vMCP: the vMCP refuses list-call tokens with 403.
    • An old AS-1 in front of a new vMCP: AS-1 issues no list-call tokens.
  • Every real-backend vMCP test, the new chain tests included, spends about 30 seconds in teardown, because backend streams outlive the vMCP server. This predates the PR. The tests run in parallel.

🤖 Generated with Claude Code

rdimitrov and others added 5 commits November 26, 2026 12:13
A call-bound access token whose mcp_tool_call entry names a list call
(server and list method) was refused at the vMCP, and AS-1 refused to
sign such an entry into an ID-JAG so it never issued a token the vMCP
would reject.

The vMCP now accepts the entry's list method and answers it with only
the items whose backend is the entry's server: a list request names no
server, so the binding narrows the answer. A tools/call or another list
method is refused with method_mismatch. A list call starts no call and
does not use the token up, so a client can follow nextCursor.

AS-1 stops refusing list-call entries in the same change.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Write nothing for a list call whose client went away before the
handler answered, rather than logging a filter failure at ERROR, and
narrow the server-without-items test to what its name says.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Filter list results with the pkg/mcp member helpers, which keep the
handler's bytes and member order and refuse duplicate or case-folded
members, and name the cause of an unreadable result. Filter every
response body whatever its status, refuse a result without its items
member, and mark the result's cache hints private and stale. Export
toolcalldetails.IsListMethod as the one list of list methods.

Add tests for Cedar filtering under a list-call token, following
nextCursor across filtered pages, the audit of a list refusal and a
list after a refusal, and share the MCP request helpers between the
integration tests. Document the matching rule and its known limits.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Both revisions cut list pages before the call-binding filter runs, and
their cursors carry the last key of the unfiltered page, so a filtered
page's nextCursor could name another backend's item. For a list-call
token the vMCP now follows the pages itself, each through every later
check on the same session, and answers with all of the bound server's
items in one response without nextCursor. The walk is bounded and
refuses a repeated cursor.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A token's jti starts at most one call (#7062), and a list call is now
that call for a list-call token: it is recorded before the list is
served, so a second request with the token gets token_reused, as a
reused tool-call token does. The pages the vMCP follows belong to the
one call, a refusal before it is recorded leaves the token unused, and
a cancellation for the open list call is admitted like a tool call's.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added the size/XL Extra large PR: 1000+ lines changed label Nov 26, 2026
@codecov

codecov Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.41577% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.38%. Comparing base (ac27d5e) to head (bde2ce7).
⚠️ Report is 12 commits behind head on main.

Files with missing lines Patch % Lines
pkg/vmcp/server/call_binding.go 96.04% 7 Missing ⚠️
pkg/vmcp/callbinding/list.go 96.93% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7325      +/-   ##
==========================================
+ Coverage   82.18%   82.38%   +0.20%     
==========================================
  Files         932      937       +5     
  Lines       94564    95748    +1184     
==========================================
+ Hits        77715    78881    +1166     
- Misses      16844    16862      +18     
  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.

rdimitrov and others added 2 commits November 26, 2026 14:22
Add Record.Release, which forgets a recorded call so its token can
start a call again. The vMCP needs it to give a list-call token back
when the list call reached the client with no answer. The callbinding
package has not been released, so the interface can still grow.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Address review of list-call enforcement:

- Answer a list-call token with the items one admission-filtered core
  list attributes to the entry's server by their own BackendID,
  rendered as a Modern list renders them, in place of the handler's
  items. Matching the handler's items by name or URI against a
  separate lookup could answer another backend's item that shares a
  key, on Modern too. The handler still runs for its checks and
  envelope; the vMCP no longer follows its pages.
- Refuse a list call on a server that is not a backend
  (server_not_found) and answer 503 for one missing from the current
  view, before the call is recorded, rather than an empty list that
  uses the token up.
- Release the token when the list call gave the client no list: a
  JSON-RPC error, a later refusal, an unreadable response, or a
  client that went away. A duplicate sent while the call runs is
  still refused.
- Once a token has started its call, refuse a tools/call or a list
  method with token_reused before checking the request, for list-call
  and tool-call tokens alike, so the client learns it needs a new
  token.
- Refuse a list call that carries a cursor (invalid_params), and any
  JSON-RPC response on an open list call's session (no_open_call).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added size/XL Extra large PR: 1000+ lines changed and removed size/XL Extra large PR: 1000+ lines changed labels Nov 26, 2026
Address the second real-environment run of list-call enforcement:

- Check the list call's server against the health rule the core's
  lists apply (health.ShouldAdvertise on the monitor's status, else
  the registry's), so a backend marked unhealthy, unknown or
  unauthenticated, though it still answers, gets 503 with the token
  unused rather than an empty list that spends it. LookupBackend does
  not filter on health. A degraded backend stays in the lists and is
  listed.
- Release a list call whose client went away before the answer
  reached it, whatever the handler wrote: Modern dispatch writes its
  whole answer after a cancellation, so the empty-body test missed
  it. The cancelled call is answered with a 503 the client cannot
  read, so the audit log records it as an error, not a success.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added size/XL Extra large PR: 1000+ lines changed and removed size/XL Extra large PR: 1000+ lines changed labels Nov 26, 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.

The core of this looks right to me. I couldn't find a way for a list-call token to get another backend's items or to be used twice, and keeping the AS-1 side to a shape check is the right call. There are a few problems around the edges, though. Two of them stop list calls from working in ordinary setups, so I've left inline comments.

The two that matter most:

  • The check that the server is in the view uses LookupBackend, and with the real core that gives a 503 that never goes away for some perfectly valid requests. It also tells apart "no such backend" (403) and "backend you can't see" (503). I'd answer 403 server_not_found for all of unknown, hidden and nothing-admitted, which is what checkToolCall does with tool_not_found.
  • Rehydrated Legacy sessions answer list calls in SSE, not JSON, so the rewrite fails with a 500 on them. That covers sessions from another replica, and also a session coming back after the idle timeout on a single replica.

The check and the items also come from two separate aggregations, so a backend that drops out between them gets 200 [] and the token is spent. Fixing that properly needs a core method that returns one backend's discovery outcome and its admitted items together. I'm fine leaving that for a follow-up PR if you note the race in the docs for now. Same for the per-method case: a transient prompts/list failure during Modern discovery currently turns into an empty list.

A few smaller things are inline: the missing defer, a spent list-call token getting 401 for every method, the buffer sharing the real writer's headers, and some test timeouts.

Docs and comments that need a touch:

  • arch/10 still says every list is capped at 1000 items per page; bound lists are an exception now.
  • arch/10 says the middleware refuses with 401 or 403, but it can also answer 503 and 500.
  • docs/authz.md doesn't mention the list-call statuses: server_not_found, method_mismatch, invalid_params for a cursor, the 503, and no nextCursor.
  • The godoc for ServerConfig.CallBinding and Config.CallBinding only talks about tool calls.
  • Call.RequestID and callSessionID still say "tools/call".
  • The Encode comment says the cache hints are set, but they're only replaced when the response already has them.

In the PR body, degraded backends are listed, not refused with 503 (health.ShouldAdvertise lets them through). And a spent tool-call token can still send tools/list, which the summary bullet contradicts.

Comment thread pkg/vmcp/server/call_binding.go Resolved
Comment thread pkg/vmcp/server/call_binding.go Resolved
Comment thread pkg/vmcp/server/call_binding.go Resolved
Comment thread pkg/vmcp/server/call_binding.go Resolved
Comment thread pkg/vmcp/server/call_binding.go Resolved
Comment thread pkg/vmcp/server/call_binding.go Resolved
Comment thread pkg/vmcp/callbinding/list.go Resolved
Comment thread pkg/vmcp/callbinding/record.go Resolved
Comment thread pkg/vmcp/server/serve_session_test.go Resolved
rdimitrov and others added 2 commits November 26, 2026 16:05
- Answer 403 server_not_found for a list call on a server that is
  unknown, hidden from the caller, offers it nothing, or fails
  discovery, as checkToolCall answers tool_not_found, so the answer
  does not tell which backends exist; count resource templates, and
  keep 503 for a backend in the caller's view that is not served for
  its health. Stop reading the admin backend list.
- Record a list call only once its answer is ready and end it at
  once: a call that gives the client no list, a panic included,
  leaves the token unused, and of concurrent duplicates only the first
  to record is answered.
- Answer a list call on a rehydrated Legacy session, which the SDK
  answers in text/event-stream, by reading the response out of the
  event stream.
- Give the response buffer its own headers, pass any non-2xx response
  through, and drop an unreachable branch.
- Refuse a method no list-call token may send before checking reuse,
  and read the record for a tools/call only when refusing it.
- Refuse an ambiguous result, error, nextCursor, cacheScope or ttlMs
  member, and an envelope with both a result and an error.
- Document the race between the server check and the items, and the
  list-call statuses.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A list call is now recorded only once its answer is ready, so no
recorded call has to be given back. Removing Release keeps the record
to Start, End and Lookup for the shared record that #7261 will add.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added size/XL Extra large PR: 1000+ lines changed and removed size/XL Extra large PR: 1000+ lines changed labels Nov 26, 2026
@rdimitrov
rdimitrov merged commit 829427b into main Nov 26, 2026
61 checks passed
@rdimitrov
rdimitrov deleted the vmcp-call-binding-3-list-calls branch November 26, 2026 14:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/XL Extra large PR: 1000+ lines changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants