Skip to content

fix(mcp): authorize client-registered MCP tools in session capability set - #1627

Merged
kantord merged 4 commits into
mainfrom
tool-call-fix
Sep 16, 2026
Merged

kantord merged 4 commits into
mainfrom
tool-call-fix

Conversation

@kantord

@kantord kantord commented Sep 16, 2026

Copy link
Copy Markdown
Member

Summary

client.tool() (SDK) correctly mounts a per-session client-provided MCP server and dispatches calls to it, but every call was denied by the authority evaluator:

tool "mcp__sdk__get_diagnostics" denied by authority: tool is absent from the capability set

Root authority is minted once per session kind, from the static build-time catalog plus the operator-global MCP manager (mintRootAuthority) — it has no visibility into a session's own client-mounted MCP servers, which don't exist until that session is created. Only --authority-evaluator noop (test/demo only) happened to skip the check, which is why the SDK's own callback-tool.ts example "worked."

  • Add SessionEngineResult.MountedClientMCPTools (populated by the new mountedClientMCPToolNames, mirroring the existing per-server mountedClientMCPNames) and fold it into the minted authority in setPerSessionLabels, the same way DebugMCPTools already is for debug sessions.
  • Add a regression test (client_mcp_authority_test.go) using a fixture that binds a real root authority and wires the real localauthority.Evaluator — every existing client-MCP test leaves Config.RootAuthority unset, so authority is never bound and enforcement never engages, meaning none of them could have caught this. Verified the new test fails with production's exact error message when the fix is reverted, and passes with it restored.

Test plan

  • go build ./...
  • go test ./internal/adapter/server/... ./internal/app/... — all pass
  • New test verified to fail (with the exact real-world error message) when the fix is disabled, and pass when restored
  • Verified live against a real spawned mecated (not just Go tests): unmodified binary denies a real client.tool() call; binary built from this branch executes it and returns the real tool result

🤖 Generated with Claude Code

kantord and others added 2 commits September 16, 2026 13:38
…aluator

Every existing client-MCP test (client_mcp_scenario_test.go) leaves
Config.RootAuthority unset, so session.Authority is never bound
(Provenance is empty) and authorizeExecution's first check skips
enforcement entirely. Those tests pass identically whether or not a
mounted tool is in the capability set - they cannot see the bug the
previous commit fixed.

Add a fixture that binds a real root authority and wires the real
localauthority.Evaluator (mecated's default), then a test asserting a
client-mounted tool call actually succeeds under it. Verified this
test fails with exactly production's "denied by authority: tool is
absent from the capability set" when the capability-set widening is
disabled, and passes with it restored.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@kantord
kantord marked this pull request as ready for review September 16, 2026 12:09

@samuv samuv 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.

Thanks for tracking this down. The authority change is headed in the right direction. I found one CI-blocking stale SDK expectation and one catalog-to-authority snapshot consistency issue, both noted inline.

Comment thread internal/app/build.go Resolved
Comment thread internal/app/build.go Resolved
kantord and others added 2 commits September 16, 2026 14:18
sdk/typescript/e2e/tool.e2e.test.ts had a test deliberately asserting
the OLD (buggy) denial as correct, with a comment explicitly saying
"so the eventual RootAuthority widening has a failing test to flip"
(introduced in #1111/#1122, M3 close-out). The previous two commits
are exactly that widening, so CI's offline SDK e2e caught it: this
test still expected the call denied.

Updated it to assert the tool is now actually invoked and its real
result reaches the model, using the same fixture/assertions as the
file's existing happy-path test, still under the real "local"
evaluator (not noop) so it keeps exercising the authorization path,
not just mount+dispatch. Verified locally against a same-checkout
mecated build.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
… second manager read

Addresses review feedback from @samuv on #1627: mountedClientMCPToolNames
called mgr.Servers()[].Tools() independently, AFTER assembleCatalog had
already registered those same tools into the session's Catalog via a
separate mcp.Register(cat, s.clientMgr.Tools()) call. Server.Tools()
lazily refreshes on a tools/list_changed notification, so those two
reads of the client MCP manager could disagree for a server whose tool
list changes between catalog assembly and authority minting: the
catalog would still advertise tool A (the earlier snapshot) while the
authority list named tool B (a later one), and a call to A -- the only
tool the model can actually see -- would be denied. That reproduces
this fix's original bug for any dynamic client MCP server.

assembleCatalog already snapshots the catalog's name set before and
after mounting client MCP (classifyAdded, for classification purposes);
reuse that same before/after diff to name the authorized tools instead,
so the set is authoritative by construction -- it cannot drift from
what the model was actually offered, because it comes from the exact
same registration pass. assembleCatalog now returns this list as a
third value (nil on the build-time/shared call, which never sets
clientMgr); mountedClientMCPToolNames is removed, and its call site
now threads the catalog-derived list straight into
SessionEngineResult.MountedClientMCPTools.

Verified: go build/vet clean, internal/app + internal/adapter/server
suites pass, and the SDK e2e test added in the previous commit still
passes against a rebuilt same-checkout mecated.

Co-Authored-By: Claude Sonnet 5 <[email protected]>

@samuv samuv 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.

Thanks for addressing both comments. I rechecked the catalog-derived tool snapshot and the updated SDK E2E, and both fixes look good. Focused authority and catalog tests pass.

@kantord
kantord merged commit 2f33adf into main Sep 16, 2026
36 checks passed
@kantord
kantord deleted the tool-call-fix branch September 16, 2026 14:13
This was referenced Sep 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants