Repository navigation
Description
Summary
CallMcpWithQuery (the model-facing {server, tool, args?, jq_filter} meta-tool
that runs a tool call and returns only a bounded jq projection instead of the
full result) never went through the session's MCP broker attachment. For any
backend reached via the broker (ToolHive-fronted, OAuth-protected MCP servers —
internal/adapter/mcpbroker), this tool was either unusable or, if reachable,
bypassed the attachment's authorization/audit lifecycle entirely.
Where this was found
While investigating tool-result size overflow behavior for broker-routed tools,
we traced CallMcpWithQuery's actual call path and found:
internal/app/catalog.go(mountGlobalMCP) only registersCallMcpWithQuery
when a non-nil direct/global MCP manager (globalMgr) exists. A broker-only
session (no direct MCP configured, only broker-routed backends) never got the
tool registered at all — the model had no way to ask for a filtered/bounded
result from a broker-routed tool, only the full, unbounded one.internal/adapter/mcp/callmcpwithquery.goinvokedprovider.CallTool(server, tool, args)against the direct MCPProvider, never the session's broker
Attachment. Even in a mixed session (direct MCP present alongside broker
tools), a broker-routed target's query would not route through the
attachment's frozen route/authorization — it would either fail to resolve, or
(worse) reach the backend outside the attachment's authorization/audit path,
which is the ONE thing every other broker-routed call is required to go
through (internal/adapter/mcpbroker/runtime.go'ssessionTool.Execute
acquires an attachment operation and revalidates its route on every call).
Why this matters
- A real functionality gap. Broker-only deployments (increasingly the
normal case — see ADR 0310/0311, the lazy per-tool and bundle-enrollment
authorization work) had no way to get a bounded/filtered tool result at all.
The model was stuck getting the full raw result on every call to a
broker-routed tool, which is exactly the failure modeCallMcpWithQuery
exists to avoid (see ADR 0063,
docs/adr/0063-mcp-structured-failclosed-callmcpwithquery.md). - A latent authorization/audit-path bypass, not yet proven exploitable but
worth closing on principle: any query path that can reach a broker-routed
backend WITHOUT going through the attachment's authorization gate breaks the
invariant every other broker call relies on (frozen route revalidation per
call, ADR 0310's authorization-continuation guarantees, ADR 0311's
OAuth-chain ownership).CallMcpWithQueryreaching the backend through a
second, parallel path — even read-only — is the kind of thing that quietly
drifts into a real bypass the next time either side changes independently.
Proposed fix (already implemented locally, not yet submitted)
Route CallMcpWithQuery through the session's existing broker attachment for
broker-backed targets, reusing the SAME frozen route + authorization path every
other broker tool call uses — no second connection, no raw result crossing the
attachment boundary (only the bounded jq projection). Direct MCP targets keep
their existing path unchanged.
This exists as a local, fully-tested branch (plan/callmcpwithquery-broker-support,
commit d641f3646) with acceptance plan
docs/acceptance/callmcpwithquery-broker-support.md and full offline coverage
(attachment-bound projection, authorization continuation across restart,
isolation/foreign-session rejection, broker-only registration, direct-manager
compatibility, and an ADR-0234 authority-unchanged proof). It has not been
pushed, reviewed, or merged — filing this issue to give the fix a tracking
reference and record why it's needed before it goes through review.
Scope notes / deliberately NOT addressed here
- Whether
CallMcpWithQuery.ReadOnly()'s unconditionaltrueis itself a
permission-bypass concern for mutating targets is a separate, still-open
question (flagged during the investigation, not proven exploitable, and out
of scope for this fix — the fix does not widen or narrow that semantic, only
corrects the connection path). - Redesigning target-aware engine dispatch, permission migration, or pending-
authorization/snapshot representations is explicitly out of scope.
Activity
docs(acceptance): record live end-to-end verification and PR authoriz…
feat(mcp): support attachment-backed broker queries
docs(acceptance): record live end-to-end verification and PR authoriz…
feat(mcp): support attachment-backed broker queries
docs(acceptance): record live end-to-end verification and PR authoriz…