Skip to content

feat(identity): give named-definition sessions their servers' gateway tools - #2965

Merged
rdimitrov merged 4 commits into
mainfrom
claude/named-session-gateway-tools-421478
Nov 24, 2026
Merged

rdimitrov merged 4 commits into
mainfrom
claude/named-session-gateway-tools-421478

Conversation

@rdimitrov

@rdimitrov rdimitrov commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

Closes #2938

What changed

A session created with agent_definition_name now gets MCP gateway tools when the identity broker is on. Its main agent gets the gateway tools of each server its definition's mcpServers names by reference, minus each tool its disallowedTools names: the same rule a named helper follows (defGatewayTools, #2842).

  • Create. The session attaches to the MCP broker like an ordinary session, and the server passes the agent-definition factory only the attachment's gateway routes (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.
  • No other broker routes. Non-gateway routes and CallMcpWithQuery act as the session with its shared grant, so they never reach the session.
  • Fork, Clear and rebuilds. A successor gets a fresh attachment's gateway tools; a rebuild of a live session reopens its own attachment. Both keep only the gateway tools the session's fixed authority allows, so a tool published after the authority was minted is not offered.
  • Registration. No change needed: the root already registers under its own definition (global/<name>), not system/main, so the broker's check 7 applies the definition's ceiling. A new broker test pins it.
  • Factory signature. AgentDefSessionEngineFactory gains a trailing gatewayTools []tool.Tool parameter, and the SessionContextEngine path passes them in its existing tools slot, following the package rule that session tools are ordinary arguments, never context values.
  • Stale rule comments in setPerSessionLabels, rebuildGrantedAuthorizationEngine, placement_successor.go, resolvedAgentDefCatalog (agentdefs.go), docs/architecture/extensibility.md and the agreement test now describe the new rule.
  • MCP refresh on an agent-bound session with a broker binding is refused with a message that fits it (its MCP tools come from its definition), instead of pointing to workspace enrollment, which refuses it too.

Decisions

  • Identity broker only (the issue's first question). Gateway routes exist only when the identity broker installs a gateway, and it checks every call against the definition's ceiling, so there is no harness-only case. Without it, an agent-bound session still attaches to nothing.
  • Helpers from an agent-bound root stay separate (the second question). The root's catalog still has no Subagent or Team, and a team created over the API in an agent-bound session gives its members no gateway tools.
  • Re-grant: the refusal is kept, not narrowed. The proposal asked the rebuildGrantedAuthorizationEngine guard 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.
  • Restart: unchanged. Rehydration of an agent-bound session is still refused (Session-scoped agent identity: persist and enforce authority across all engine-rebuild paths #1796), so a restarted session never resumes with other tools. When Session-scoped agent identity: persist and enforce authority across all engine-rebuild paths #1796 lifts that, the rebuild branch here already reopens the session's attachment and filters by its persisted authority.
  • Connector listing stays unavailable for agent-bound sessions: their attachment carries only gateway tools, so the broker's connector inventory would not describe them.

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 main for 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.

  • Remote-observable change: with the identity broker and the MCP broker on, the model in a session created with agent_definition_name is offered, and can call, the gateway tools of its definition's referenced servers. Clients see these as ordinary mcp__<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.
  • Unchanged on the wire: the create request and response, resolved_agent_definition_name, ListSessionMcpConnectors (still unavailable for these sessions), workspace enrollment and SetMode refusals.
  • One error path changes: RefreshMcpSources on such a session now returns FailedPrecondition ("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.
  • Go source: AgentDefSessionEngineFactory in internal/adapter/server gains a parameter; internal only.
  • Stored data: agent-bound sessions now persist an MCP broker binding. Agent-bound sessions are not rehydrated after a restart either way. After a rollback, though, ListSessionMcpConnectors on a named session created by this version returns the broker's connector inventory instead of FailedPrecondition, because the older check looks only for a binding; the impact is limited to that listing.
  • No break, so no approval needed.

Release note: Once mecak8s routes 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's mcpServers references, minus the tools its disallowedTools names. Until then, these sessions get no MCP broker tools, as before.

Shortcuts

Testing

  • Unit and composition, through the real factory (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, a tools:-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).
  • Service (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.
  • Broker (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.
  • End to end (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-gateway notes route is never offered.
  • Identity: the e2e test compares the ID-JAG's actor with the agent registered as the named session's main agent: registering that instance again under global/calendar-reader returns the same agent, and under system/main is refused.
  • Refresh: TestAgentBoundSessionRefusesMCPRefresh calls RefreshMcpSources on a named session with a binding and checks the refusal and that nothing is reconciled.
  • Local run: the same harness with a calendar server declaring lookup and echo, and a definition excluding echo. The session was offered only mcp__calendar__lookup; its call went through the identity broker (ID-JAG naming the main agent) and completed at the vMCP with HTTP 200; echo and notes calls were refused as unknown tools and never reached the gateway.
  • Local checks: focused tests with -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/microvmmanager and cmd/mecatui/agenthook, which pass when rerun alone).
  • Reviews: /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 once mecak8s can 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.md also states the declared-tools limit.

🤖 Generated with Claude Code

rdimitrov and others added 2 commits November 24, 2026 11:27
… 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 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 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. teamHelperTools does it the other way round. The result is the same; matching them would help.
  • docs/architecture/extensibility.md:65 says 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 key mcp.servers[].auth.oauth.tools, say the MCP broker must also be on (mecak8s), and say inline server entries and tools: add no gateway tools. The operator page identity-and-client-access.md doesn'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 == completed check is copied across the gateway tests.
  • PR description: "Stale rule comments" names agentdef_root.go. The fixed comment is in agentdefs.go:1164.
  • defGatewayTools is called in two places (agentdef_root.go:81 and agentdefs.go:1132). Calling it where gateway tools are registered would give roots and helpers one rule.

Comment thread user-docs/reference/grpc-api.md Resolved
- 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]>
@rdimitrov

Copy link
Copy Markdown
Member Author

Thanks for the review. Pushed in 1cdf415:

  • RefreshMcpSources: an agent-bound session with a broker binding is now refused with "an agent-bound session gets its MCP tools from its agent definition", checked before the broker-bound message. TestAgentBoundSessionRefusesMCPRefresh calls it on a named session, asserts the session has a binding, and checks nothing is reconciled.
  • Session create leaves a saved session and its engine behind when the broker commit fails #2972: noted in the PR body as a known issue that named sessions now share.
  • Nits taken: the factory doc no longer claims "no per-feature parameter growth"; docs/architecture/extensibility.md lists named sessions as a third way to get a catalogue; grpc-api.md uses mcp.servers[].auth.oauth.tools, says the MCP broker must be on, and that inline servers and tools: add no gateway tools; the operator page states the declared-tools limit; the connector-listing test now checks the session has a binding; the failed-build test's comment matches what it checks; the PR description names agentdefs.go.
  • Nits left: the rebuild's filter order (same result as teamHelperTools), the repeated completed check across gateway tests, and calling defGatewayTools in one place (a shared refactor of the helper path, better on its own).

🤖 Addressed by Claude Code

@rdimitrov
rdimitrov requested a review from jhrozek November 24, 2026 11:46

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

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.

@rdimitrov
rdimitrov merged commit f50079c into main Nov 24, 2026
52 of 53 checks passed
@rdimitrov
rdimitrov deleted the claude/named-session-gateway-tools-421478 branch November 24, 2026 13:04

This branch was successfully deployed

1 active deployment
Preview — 1cdf4153 Deployed Nov 24, 2026 by vercel[bot]
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.

Sessions started with a named agent definition get their servers' gateway tools

2 participants