Repository navigation
Enforce list-call tokens at the vMCP - #7325
Conversation
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]>
Codecov Report❌ Patch coverage is
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. 🚀 New features to boost your workflow:
|
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]>
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]>
jhrozek
left a comment
There was a problem hiding this comment.
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 403server_not_foundfor all of unknown, hidden and nothing-admitted, which is whatcheckToolCalldoes withtool_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.mddoesn't mention the list-call statuses:server_not_found,method_mismatch,invalid_paramsfor a cursor, the 503, and nonextCursor.- The godoc for
ServerConfig.CallBindingandConfig.CallBindingonly talks about tool calls. Call.RequestIDandcallSessionIDstill say "tools/call".- The
Encodecomment 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.
- 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]>
Summary
An access token can be narrowed to one MCP call with an RFC 9396
authorization_detailsentry of typehttps://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 withlist_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.tools/list,prompts/list,resources/listorresources/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'sserver. The items come from one admission-filtered core list, each attributed by its ownBackendID, so another backend's item that shares a name or URI is never returned. Composite tools,execute_tool_scriptand optimizer meta-tools have no single backend, so they are never listed. Theservermust be a backend in the caller's view, or the request is refused before the token is used.nextCursoris 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 intext/event-stream; the list call is answered in JSON all the same. A list call that carries its owncursoris refused withinvalid_params.tools/callor a different list method getsmethod_mismatch, and anything else getsmethod_not_allowed. Both use the same 403, JSON-RPC body and audit record as tool-call mismatches. Aserverthat 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 403server_not_found, as an unknown tool getstool_not_found: AS-1 signs anyservername, 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, atools/callor a list method other than a tool-call token'stools/listgets 401token_reusedbefore 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 totools/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.toolcalldetailsno longer refuses list-call entries on an ID-JAG token exchange. Thelist_call_unsupportedreason is removed fromtoolcalldetailsandcallbinding. Neither constant was ever in a release.toolcalldetails.IsListMethodis now exported as the single list of list methods.docs/arch/10,docs/arch/17,docs/arch/vmcp-library.mdanddocs/authz.mdare corrected where they said list calls were refused.Part of #7062. Accepting messages for a call after its token's
expis still open under that issue.Type of change
Test plan
task test): race runs ofpkg/vmcp/callbinding,pkg/mcp/toolcalldetails,pkg/vmcp/server,pkg/vmcp/coreandpkg/authserver/...task lint-fix):task lintreports 0 issues;task docsproduces no changesWhat 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 bothresultanderror, 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:nextCursor, and no other backend's key anywhere in the body; a client-sent cursor is refused withinvalid_paramsand leaves the token unused;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;token_reusedon Legacy and Modern, a list call and a tool call under the same issuer andjtiuse up each other, and after either kind of call atools/callor a list method other than a tool-call token'stools/listgets 401token_reusedrather than a 403 about the request, while thattools/liststill gets 200;error, notsuccess;notifications/cancelledor a JSON-RPC response sent while a list call runs getsno_open_call; a list request without anidgetsmethod_not_allowedand leaves the token unused;tools/callneeds no record read (it runs while record reads fail), and a spent list-call token'sresources/readkeeps its 403method_not_allowed;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 itsresources/templates/list, and one whose items Cedar hides gets the same 403server_not_foundas 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 atools/callare refused, withmethod_mismatchbefore the list call andtoken_reusedafter it. A tool-call token still runs its call and is refusedprompts/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/mecak8sagainst this branch through a temporarygo.workreplace 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 sendauthorization_detailson 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
pkg/vmcp/server/call_binding.gotoken_reusedfirstpkg/vmcp/callbinding/list.goReadListResponse,ListResponse.Encode,ListParamsCarryCursor,SSEResponse: read the handler's response and write the answerpkg/vmcp/callbinding/binding.goReasonMethodMismatch,ReasonServerNotFound; dropReasonListCallUnsupportedpkg/vmcp/server/serve.gopkg/mcp/toolcalldetails/toolcalldetails.goIsListMethoddocs/...*_test.goDoes this introduce a user-facing change?
Yes, for deployments that issue call-bound tokens.
list_call_unsupportedfor every list method. After: its own list method returns 200 with all of its server's items in one response, withoutnextCursor, once; after that, a list method ortools/callwith the same token gets HTTP 401token_reused, as a reused tool-call token does. Before the list call, atools/callor a different list method gets 403method_mismatch, a request carrying acursorgets 403invalid_params, aserverthat is unknown, hidden from the caller, offers it nothing, or fails discovery gets 403server_not_found, and one in the caller's view that isn't served for its health status gets 503.tools/callnaming another tool, or a list method other thantools/list, got 403 (tool_mismatch,arguments_mismatch,method_not_allowedand so on). After: it gets 401token_reused. Before their call, nothing changes.invalid_authorization_details/list_call_unsupported. After: AS-1 signs the entry into the ID-JAG.Special notes for reviewers
jtistarts at most one call". The list call is recorded only once its answer is ready, and ended at once; any later list method,tools/callorinitializegetstoken_reused. Of concurrent duplicates, each runs the handler, but only the first to record is answered, and the others gettoken_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 aserror. 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, anotifications/cancelledor response sent while it runs getsno_open_call.LookupBackend, which keeps a backend the caller is admitted to at least one tool, resource or prompt of, plus the resource templates list, whichLookupBackenddoesn't count. A backend outside that view getsserver_not_foundwhatever the reason. For one inside it, the check applies the rule the core's lists use:health.ShouldAdvertiseon the health monitor's status, or else the registry's, which admits healthy, degraded and unmonitored backends.modernToolFromDomainand its siblings), which build items the same way Legacy sessions do..claude/rules/vmcp-anti-patterns.md: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'smcpcompatexposes no hook that can change a list result:AddBeforeListToolscannot, 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 inapplication/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.Servergains the list lookup (callBindingListItems,callBindingListServer). It is wired intocallBindingthe same way the existing route lookup is, as a function, and holds no new state.proxysubcommand #7), is gone.tools/listis always empty, because the optimizer's meta-tools have no backend. This is tracked on the Mecatl side.🤖 Generated with Claude Code