Repository navigation
feat(identity): give named-definition sessions their servers' gateway tools - #2965
Conversation
… tools A session created with agent_definition_name now attaches to the MCP broker when the identity broker is on, and its main agent gets the gateway tools of the servers its definition references, minus the tools it excludes, as a named helper does. The tools are in the catalog before the session's authority is minted from it, so the authority stays within the definition. No other broker route reaches the session. Fork and Clear successors and rebuilds of a live session get the same tools, limited to the session's fixed authority. The broker-OAuth grant refusal stays, as only non-gateway routes park for it. Connector listings stay unavailable for these sessions, and API teams rooted in one give their members no gateway tools. Closes #2938 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Session tools are ordinary arguments, never recovered from context values, so AgentDefSessionEngineFactory takes the gateway tools as a parameter and the SessionContextEngine path passes them in its tools slot. One attachesBroker rule now decides when a session attaches to the MCP broker. Tests now plant a tool the inherited authority does not allow on Fork and Clear, cover an aborted attachment when the build fails, and check at the broker that a root registered under a named definition is held to that definition's ceiling. User docs describe the gateway tools named sessions get. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The factory test claimed the agent-definition factory drops a broker route that acts as the session. Real broker routes all name their server, so only the server's HelperGatewayTools filter drops them; the comment now says so. The gRPC reference also states that a bound session gets only a server's statically declared tools, since it cannot use workspace enrollment to discover the rest. Co-Authored-By: Claude Opus 5.5 <[email protected]>
jhrozek
left a comment
There was a problem hiding this comment.
The design holds up. Gateway tools are filtered against the definition before the session's authority is minted, and every case I checked (create, fork, clear, live rebuild, team members) keeps out tools from outside the definition, non-gateway broker routes, and tools published later. The attachment is also released on every error path I could find. Comments are inline; two more are here because their lines are outside the diff:
RefreshMcpSources sends users to something that refuses them. On a named session it now fails at mcp_refresh.go:181-182 with "broker-bound sessions use workspace enrollment", and workspace enrollment then refuses the session (workspace_enrollment.go:225). Could this get its own check before line 181 with a message that fits, or a reworded message? Also, no test calls RefreshMcpSources on a named session. The refusal works only because these sessions now carry an ExternalBinding, so a short test would keep it from disappearing silently.
Follow-up filed: #2972. On create, a failed broker commit leaves the saved session and its engine behind. This is already on main, but this PR sends named sessions through that path too. Not blocking here.
Nits (take or leave)
service.go:340: the factory doc comment still says the context approach means "no per-feature parameter growth", right above the paragraph that adds a parameter.service.go:7366: the rebuild filters all broker tools by authority, then keeps the gateway ones.teamHelperToolsdoes it the other way round. The result is the same; matching them would help.docs/architecture/extensibility.md:65says a session gets its tool list "one of two ways" (lazy authorization or enrollment). Named sessions now have a third: statically declared gateway routes, with no parking and no enrollment.grpc-api.md: use the full keymcp.servers[].auth.oauth.tools, say the MCP broker must also be on (mecak8s), and say inline server entries andtools:add no gateway tools. The operator pageidentity-and-client-access.mddoesn't mention the static-tools limit.- Tests: the connector-listing test has no positive control (it never checks that the session has a binding). The failed-build test's comment says "never persisted" but checks only the broker counters. The same
code/outcome == completedcheck is copied across the gateway tests. - PR description: "Stale rule comments" names
agentdef_root.go. The fixed comment is inagentdefs.go:1164. defGatewayToolsis called in two places (agentdef_root.go:81andagentdefs.go:1132). Calling it where gateway tools are registered would give roots and helpers one rule.
- MCP refresh on an agent-bound session with a broker binding now says its MCP tools come from its definition, instead of pointing to workspace enrollment, which refuses it too; a test pins the refusal. - The gRPC reference says a bound root gets gateway tools only once mecak8s can route servers through the gateway, links the operator page, and names mcp.servers[].auth.oauth.tools; the operator page states the declared-tools limit. - The mecak8s test compares the ID-JAG's actor with the agent registered as the named session's main agent under its definition. - The architecture chapter lists the third way a session gets its catalogue, and test comments and controls are tightened. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Thanks for the review. Pushed in 1cdf415:
🤖 Addressed by Claude Code |
jhrozek
left a comment
There was a problem hiding this comment.
All five points from my review are addressed in 1cdf415: the gRPC reference and release note no longer promise gateway tools operators can't enable yet, the e2e test checks that the ID-JAG's act.sub is this session's agent, RefreshMcpSources has its own refusal message with a test, the rollback note is in the "Stored data" bullet, and the architecture and operator docs match.
Approving on the code as it stands. CI was still running when I approved (no failures so far), so please wait for it to finish before merging. The remaining nits (rebuild filter order, repeated completed assertion, defGatewayTools called in two places) and the failed-commit cleanup in #2972 can follow.
Closes #2938
What changed
A session created with
agent_definition_namenow gets MCP gateway tools when the identity broker is on. Its main agent gets the gateway tools of each server its definition'smcpServersnames by reference, minus each tool itsdisallowedToolsnames: the same rule a named helper follows (defGatewayTools, #2842).HelperGatewayTools). The factory keeps the definition's servers and drops its exclusions before the session's authority is minted from the catalog, so the authority and ceiling stay within the definition.CallMcpWithQueryact as the session with its shared grant, so they never reach the session.global/<name>), notsystem/main, so the broker's check 7 applies the definition's ceiling. A new broker test pins it.AgentDefSessionEngineFactorygains a trailinggatewayTools []tool.Toolparameter, and theSessionContextEnginepath passes them in its existing tools slot, following the package rule that session tools are ordinary arguments, never context values.setPerSessionLabels,rebuildGrantedAuthorizationEngine,placement_successor.go,resolvedAgentDefCatalog(agentdefs.go),docs/architecture/extensibility.mdand the agreement test now describe the new rule.Decisions
SubagentorTeam, and a team created over the API in an agent-bound session gives its members no gateway tools.rebuildGrantedAuthorizationEngineguard to narrow. A gateway call never parks for the MCP broker's OAuth (the identity broker authorizes it when it runs), and the session's gateway tools are the bare routes, so only a non-gateway route could reach that guard. Refusing and narrowing behave the same; the comment now says why.Known limit: listing
Until #2729, a gateway server's tools are listed through the MCP broker's own sign-in (workspace enrollment), and agent-bound sessions cannot enroll. So a named session gets only the tools a server declares statically in
auth.oauth.tools; a server that declares none gives it no tools. Checked offline in the mecak8s harness: with the calendar server's declared tools removed, the named session was offered no calendar tools. This is not verified against a real gateway, which arrives with #2533. #2729 removes the limit.Known issue: failed broker commit (#2972)
A failed broker commit on create leaves the saved session and its engine behind. This is already the case on
mainfor ordinary sessions; named sessions now take the same path when the identity broker is on. Tracked in #2972, not fixed here.API compatibility
Assessment: compatible; no major bump; no new feature identifier.
agent_definition_nameis offered, and can call, the gateway tools of its definition's referenced servers. Clients see these as ordinarymcp__<server>__<tool>tool calls and results in events and transcripts, a shape every conforming client already handles. Clients never opt in, and the session's tool catalog is not on the wire, so there is nothing new to discover.resolved_agent_definition_name,ListSessionMcpConnectors(still unavailable for these sessions), workspace enrollment andSetModerefusals.RefreshMcpSourceson such a session now returnsFailedPrecondition("an agent-bound session gets its MCP tools from its agent definition"), where before it went on to its later checks. Only sessions with a broker binding take this path, so deployments without the identity broker are unchanged.AgentDefSessionEngineFactoryininternal/adapter/servergains a parameter; internal only.ListSessionMcpConnectorson a named session created by this version returns the broker's connector inventory instead ofFailedPrecondition, because the older check looks only for a binding; the impact is limited to that listing.Release note: Once
mecak8sroutes servers through the identity broker's gateway (it refuses to until the gateway's authorization server accepts AS-1's tokens), a session created with a named agent definition (agent_definition_name) gets the MCP gateway tools of the servers its definition'smcpServersreferences, minus the tools itsdisallowedToolsnames. Until then, these sessions get no MCP broker tools, as before.Shortcuts
defGatewayTools. Updated wording for Sessions run and register the exact definition revision #2548, Phase 1: Signed-in users' agents call gateway tools with their own access #2451 and Phase 2, Slice 6: End to end — An unattended scheduled review runs under its own identities and leaves a trail #2817 is proposed and awaits a maintainer's approval.Testing
internal/app/agentdef_root_gateway_test.go): a root gets exactly its referenced servers' gateway tools minus exclusions, in the catalog, authority, ceiling and the tools the model is offered; an unreferenced server, a definition with no servers, atools:-only reference and a non-gateway route grant nothing; an excluded call never runs. Inline servers stay covered by the broker agreement test (defgatewaytools_test.go).internal/adapter/server/agent_bound_gateway_tools_internal_test.go): only gateway routes reach the factory on create, live rebuild, fork and clear; a later-published gateway tool is dropped; without the identity broker nothing attaches; a failed build aborts the attachment; connector listing stays unavailable. Team members of an agent-bound root get no gateway tools.internal/identitybroker/ceiling_named_root_test.go): a root registered under a named definition is checked against that definition's ceiling, not the built-in main agent's.cmd/mecak8s/identity_broker_named_session_test.go): through mecak8s's startup, the real AS-1 and AS-2, and the embedded vMCP, a named session's main agent is offered and calls its gateway tool under its own identity (one ID-JAG, completed at the vMCP); sessions whose definition excludes the tool or references no server are never offered it and never reach the gateway; the non-gatewaynotesroute is never offered.global/calendar-readerreturns the same agent, and undersystem/mainis refused.TestAgentBoundSessionRefusesMCPRefreshcallsRefreshMcpSourceson a named session with a binding and checks the refusal and that nothing is reconciled.lookupandecho, and a definition excludingecho. The session was offered onlymcp__calendar__lookup; its call went through the identity broker (ID-JAG naming the main agent) and completed at the vMCP with HTTP 200;echoandnotescalls were refused as unknown tools and never reached the gateway.-race(internal/adapter/server,internal/app,cmd/mecak8s,internal/identitybroker/...,internal/adapter/mcpbroker);task lint(0 issues);task docs;task test(all packages pass except two unrelated load flakes,internal/adapter/microvmmanagerandcmd/mecatui/agenthook, which pass when rerun alone)./code-review(2 findings, both fixed) and a four-axis panel review (1 important, fixed: tools are now an explicit factory argument; advisories fixed or declined with reasons).Docs
user-docs/operating/mecak8s/identity-and-client-access.md: the identity broker row says which agents get which gateway tools, now including named sessions.user-docs/reference/grpc-api.md: agent-bound creation says gateway tools arrive oncemecak8scan route servers through the gateway, links the operator page, and describes the broker's check and the declared-tools limit.user-docs/operating/mecak8s/identity-and-client-access.mdalso states the declared-tools limit.🤖 Generated with Claude Code