Skip to content

feat(identitybroker): limit each agent's gateway calls to its definition's tools - #2937

Open
rdimitrov wants to merge 7 commits into
feat/run-delegationsfrom
feat/agent-tool-limit
Open

rdimitrov wants to merge 7 commits into
feat/run-delegationsfrom
feat/agent-tool-limit

Conversation

@rdimitrov

@rdimitrov rdimitrov commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

Closes #2842. Part of #2851. Stacked on #2930: review only the last commit; this retargets to main once #2930 merges.

With the identity broker on, each gateway call must now be inside the acting agent's tool limit: its definition's, narrowed by the limit of the agent that started it. Before this, the broker accepted any tool. It implements the decision posted on #2842: resolve each definition's limit against the gateway's servers, with no tool lists.

What changes

Identity broker (internal/identitybroker)

  • Ceiling, a new value type: the servers an agent may call, each with the tools on it the agent may not. The zero value allows nothing. DefinitionRecord carries one.
  • The definition loader resolves each definition's ceiling against the servers the gateway routes. It applies the harness's meaning:
    • each server mcpServers references is granted whole, minus the tools disallowedTools names as mcp__<server>__<tool>;
    • tools selects no MCP tools in the harness, so it grants none;
    • an inline server, or a reference to a server the gateway doesn't route, grants nothing;
    • built-in definitions name every routed server.
  • Registration stores each instance's effective ceiling: its definition's, intersected with its parent's effective ceiling. It's computed once, when the instance first registers, and never recomputed or widened.
  • Check 7. AuthorizeCall refuses a call outside the effective ceiling with PERMISSION_DENIED. It runs after the gateway route check (check 6) and before any ID-JAG exchange. Each decision record names the ceiling it checked. A listing is allowed for any server the ceiling grants.
  • Names are unambiguous.
    • A tools/call must name its tool <server>.<tool>; any other name is now INVALID_ARGUMENT, so check 7 always sees a tool of the call's server.
    • Gateway server names are limited to letters, digits, and single underscores, as the MCP configuration already requires. A dot or a double underscore would let one server's name begin another's.

mecak8s

  • Named-definition helpers get gateway tools. A subagent or team member that runs a named definition now gets the session's gateway tools for the servers its definition references, minus excluded tools. This removes Helper agents: their own registered identity and broker MCP tools #2555's shortcut. Helpers that run no named definition still get all of them, narrowed by their parent's authority.
  • File-less team members keep to their definition. Since feat(identitybroker): start the broker from operator configuration and keys #2875 the broker runs without a local workspace, so outside Kubernetes execution its sessions are file-less. A file-less team member that names a definition now gets the file-less core tools its definition doesn't exclude, its definition's own MCP servers instead of the server-global ones and CallMcpWithQuery, and its servers' gateway tools. It also reports the definition, so the broker applies the same limit. Before, it skipped the definition and registered as system/member.

Docs

  • mcp-authorization.md ("Definition-derived ceiling") records the resolution rule.
  • The identityBroker.enabled row in the mecak8s operator docs now describes the named-helper behavior and the limit.

Decisions to review

  1. A server is granted whole, minus excluded tools. This needs no tool list, which only a signed-in user can fetch and which can differ per user. A tool the gateway adds later is inside the limit of every definition that references its server, as it is in the harness today. This is the decision posted on Per-agent tool limit, checked by the broker #2842.
  2. No backfill code. The "Authority work switched on" row asks to backfill live instances. Broker state is in memory, so every instance is registered by this code and none predates the check. An instance with no ceiling would be denied every call, as the row requires.
  3. The ceiling check takes the tool's name on its server. It's a pure set lookup, so [Phase 3] Express the tool limit as generated Cedar policy #2849's Cedar policy replaces only checkCeiling's body. Splitting <server>.<tool> moved into request validation.
  4. The harness resolves the same rule again (defGatewayTools) rather than reading the broker's record, marked as a shortcut removed by Sessions run and register the exact definition revision #2548. A test runs one table of definitions through both and fails if they disagree.

Shortcuts

Found, not in this PR

API compatibility

Assessment: no wire change. No proto, gRPC, or HTTP surface changes. Ceiling, DefinitionRecord.Ceiling, CeilingServer, DecisionRecord.Ceiling, and the stricter AuthorizeCallRequest.Validate are in-process Go API in internal packages. #2559 (broker over gRPC) hasn't landed.

Behavior: with the broker on and a gateway configured, a call outside the agent's limit is refused. Production configures no identity broker gateway yet (#2533), so no deployment sees a difference today.

No major bump, no feature identifier, no approval needed.

Testing

Broker:

  • ceiling_internal_test.go:
    • exact pairs;
    • the empty ceiling;
    • listings;
    • an intersection property test (500 random pairs): the effective ceiling allows exactly what both its definition and its parent allow.
  • ceiling_test.go, through AuthorizeCall:
    • the main agent's built-in ceiling;
    • a read-only reviewer that cannot merge;
    • a deployer under the reviewer that cannot merge whatever its definition allows;
    • a built-in explorer under the deployer that cannot merge, so the exclusion carries down two levels;
    • an agent whose ceiling is empty registers and is refused every call;
    • refusals record the ceiling and make no exchange;
    • check 6 runs before check 7;
    • a tool not named for its server is INVALID_ARGUMENT.
  • loader_test.go: resolution against the routed servers, including an inline server, an unrouted reference, tools naming a routed server's tool, exclusions, built-ins, and no servers.

Harness and broker agree: internal/app TestDefGatewayToolsAgreesWithTheBrokersCeiling runs one table of definitions through both parsers and both rules.

End to end (cmd/mecak8s, real AS-1, AS-2, and the embedded vMCP):

  • A named subagent referencing the server calls its tool under its own identity.
  • A named subagent excluding the tool, and one referencing no server, never reach the gateway.
  • The same for a named team member, both cases, in a file-less session. The named-subagent cases run on the Redis filesystem, the one workspace the broker allows offline since feat(identitybroker): start the broker from operator configuration and keys #2875.
  • internal/app: a named team member with a filesystem, through the real member factory, gets its servers' gateway tools and never runs the excluded one; a file-less named member keeps to its definition's tools and reports the definition, while a generic one keeps the whole file-less surface.

Mutation checks. Each was applied, a test failed, and the code was restored:

Mutation Caught by
Intersecting with the parent's definition ceiling instead of its effective one The three-level test
Dropping the exclusion rule on either side The agreement test
Dropping the member path's gateway tools The team test

Dropping the harness catalog's exclusion alone is not caught. The engine's capability set excludes the tool too, so that mutant behaves the same.

Gates:

  • task lint and task docs pass.
  • Touched packages pass go test -race: internal/identitybroker/..., internal/adapter/mcpbroker, internal/adapter/server, internal/agentcredential/..., cmd/mecak8s, and internal/app.

Real use, local: I rebuilt mecak8s and ran it with the broker on. A subagent and a Team-tool team, whose second member runs a named definition, registered and reported their delegations with no broker warnings. The binary has no flag that turns on a gateway, so the gateway path is proven by the end-to-end tests above.

Panel review (spec, standards, tests, security, architecture, duplication, reuse) found no blockers. I fixed:

  • the stale operator-docs sentence;
  • the missing harness and broker cross-check (two reviewers);
  • the missing three-level, empty-ceiling, tools, and team-exclusion tests;
  • splitting <server>.<tool> inside the policy check;
  • server names that could overlap;
  • small simplifications.

After review

The review's findings and my answers are in the review reply. Two agents also checked each finding against the design independently. Changes from it:

Sign-off on the resolution rule is requested on #2842.

🤖 Generated with Claude Code

…ion's tools

The broker now checks design step (6) check 7: each gateway call's exact
server and tool must be inside the acting agent's effective ceiling.

- The definition loader resolves each definition's ceiling against the
  servers the gateway routes. A server the definition's mcpServers
  references is granted whole, minus the tools its disallowedTools names;
  tools selects no MCP tools, as in the harness. Built-ins name every
  routed server. No tool list is needed, since listing tools needs a
  user's grant.
- Registration stores each instance's effective ceiling: its definition's,
  narrowed by its parent's effective ceiling, computed once and never
  widened.
- Check 7 runs after the gateway route check and refuses with
  PERMISSION_DENIED, recording the ceiling it checked. A call whose tool
  is not named for its server is now an invalid request, and gateway
  server names are limited to letters, digits, and single underscores, so
  "<server>.<tool>" and "mcp__<server>__<tool>" each name one server.
- A helper that runs a named definition, as a subagent or team member,
  now gets the session's gateway tools for the servers its definition
  references, minus excluded tools, removing #2555's shortcut. A test
  checks the harness and the broker resolve each definition the same way.

Records the resolution rule in mcp-authorization.md and updates the
identity broker row in the mecak8s operator docs.

Closes #2842.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

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

Review against the agent identity design and #2842 / #2851. This lists only issues, gaps, and questions. Nothing here blocks the PR, and none of the correctness items is an authorization bypass; they all fail closed. Please address each one or reply with your reasoning.

Design and ticket gaps

  1. The ceiling resolves against the wrong server list (major). The #2842 decision, and this PR's edit to mcp-authorization.md ("Definition-derived ceiling"), say the loader resolves against the operator's MCP configuration (mcp.servers). The code resolves against cfg.IdentityBrokerGatewayServers (internal/app/identitybroker.go:489), which is a test seam that production leaves nil (internal/app/build.go:996). Either change the code, or say in the doc that this list stands in until #2533.
  2. The harness and the broker read different server lists (major). defGatewayTools filters the MCP broker's routed backends (cfg.helperTools); the broker uses the list in point 1. Nothing keeps the two equal. TestDefGatewayToolsAgreesWithTheBrokersCeiling gives both sides the same list, so it can't catch a mismatch.
  3. Resolution inputs aren't kept, so a restart can widen a ceiling (major). The design requires keeping the resolution inputs, and says restoration never recomputes or widens a ceiling (the "Process restart" row in the agent-definitions.md continuity table, and implementation.md "Cedar authorization…" bullet 3). The gateway server set is a hidden input: it isn't in DefinitionRef, the revision, or the provenance. Broker state is in memory, so after a restart the instance registers again and its ceiling is recomputed (agents.go:156). A longer server list then gives more authority under the same definition revision. "Never recomputed or widened" holds only within one process, and no shortcut marker records the gap.
  4. #2842's "Done when" items aren't met (major):
    • The cross-check against the harness's delegated-authority intersection (implementation.md "Cedar authorization…" bullet 3). The new test compares one definition's resolution only. It never compares parent-narrowed effective ceilings with what the harness gives a child. Built-ins aren't compared either: builtinCeiling (loader.go:357) versus readOnlyExplorerCatalog/writableExplorerCatalog.
    • Backfill. The "Authority work switched on" row and #2842 require live instances to be backfilled and marked. The PR argues none exist, but changes neither the row nor the ticket. Please record the exception, e.g. "not applicable while broker state is in memory; revisit with #2559".
  5. The #2842 decision has no sign-off (question). The decision on #2842 is a proposed comment, and the issue asks for review by the design's author. No sign-off is recorded, but the PR treats it as decided.
  6. The decision text and the code disagree (minor):
    • The decision says nothing has to parse mcp__<server>__<tool>, but resolveCeiling parses it (loader.go:383), and the server-name restriction exists because of that.
    • The sentence before the new paragraph in mcp-authorization.md still says "permitted server/tool pairs". So does implementation.md "Work breakdown" (~line 367). Granting a whole server, including tools it adds later, is a widening that the pair wording doesn't allow. Reconcile both places.
  7. Built-ins get every routed server (minor). builtinCeiling ignores its def, but #2842's scope says built-ins get their limit from their built-in fields. If a built-in later sets mcpServers or disallowedTools, the broker ignores them without saying so.
  8. Tool naming is now part of the broker's contract (minor). Validate returns INVALID_ARGUMENT for any tools/call tool not named <server>.<tool> (service.go:474). That ties broker validation to the embedded vMCP's naming. Gateway.Route returns (server, tool) in no fixed format, so an external gateway (#2812) that names tools differently would fail every call. The step (6) failure table in credentials-and-lifecycle.md has no row for this INVALID_ARGUMENT.
  9. Listings aren't limited in practice (minor). Nothing in production reaches the tools/list branch of check 7 (ceiling.go:132): ListTools uses the session's credential (mcpbroker/gateway.go:72) and never calls AuthorizeCall. Excluded tool names and descriptions are still listed. The design's "Tool discovery" paragraph wasn't updated either way.
  10. Ticket accuracy (minor):
    • The shortcut at internal/app/agentdefs.go:604 says it's "removed by #2548", but #2548's "Removes shortcut" list doesn't include it. Add it there.
    • "Cedar replaces only checkCeiling's body" understates #2849. Cedar also needs per-definition policy generation and a policy-based intersection, so the exported Ceiling type, intersect, and DefinitionRecord.Ceiling change too.
  11. Branch hygiene (minor):
    • #2939 is now merged. This branch still has the defDisallowsTool loop that #2939 removed, next to the new registerHelperTools call, so a rebase will conflict or duplicate it. The PR body still describes #2939 as pending.
    • "Closes #2842" doesn't link while the base is feat/run-delegations (closingIssuesReferences is empty). Check that the link appears after retargeting to main.
  12. Operator docs (minor). In user-docs/operating/mecak8s/identity-and-client-access.md, the identityBroker.enabled row has two problems:
    • "the tools of each server its mcpServers lists" is inaccurate. Only a server named by reference and routed by the gateway counts; inline entries grant nothing. The doc doesn't give the excluded-tool form mcp__<server>__<tool>, or say that tools selects no MCP tools (tools: [Read] plus mcpServers: [github] still gets every GitHub tool).
    • It describes a refusal that production can't reach yet, because no gateway is configured (#2533). Add a qualifier or link.

Correctness

  1. The harness and the broker name servers differently (minor). GatewayServer() returns route.backend (internal/adapter/mcpbroker/runtime.go:660), while check 7 uses the server name Gateway.Route() returns. These agree only because embeddedGateway.Route passes the backend name through unchanged. An external gateway that maps names differently would split the harness from the broker without any error. The doc comment on GatewayServer() is wrong as written.
  2. Check 7 depends on the reported DefinitionRef (minor). Because of the #2551 shortcut, a root can register as system/main and get every server. A child that registers as a built-in gets its parent's whole ceiling instead of its own narrower one. Please note this in the check 7 shortcut comment.
  3. Whitespace in excluded tool names (minor). NewCeiling trims whitespace around excluded tool names (ceiling.go:36), but defDisallowsTool matches exactly. For mcp__github__ merge, the broker excludes the tool and the harness doesn't. The broker is the stricter side, but the agreement test doesn't cover it.
  4. The ceiling string is ambiguous (minor). Ceiling.String (ceiling.go:109) escapes nothing. Exclusions come from definition files, so a ,, a ;, or " except " makes the canonical form recorded in DecisionRecord.Ceiling ambiguous.
  5. Nits:
    • isGatewayServerName's doc says the rule rules out prefix clashes, but leading and trailing underscores still allow them: git and git_ both produce mcp__git___x.
    • The full ceiling string goes into every decision record and every refusal sent to the caller. It has no size limit, and it shows the child its parent's exclusion list.
    • effectiveCeilingLocked runs on every re-registration, and the result is discarded (agents.go:148).

Missing tests

  • No end-to-end test reaches a check 7 refusal. The harness drops the tool first, so #2851's "refused before any token is issued" is proven only by core unit tests.
  • The agreement test (internal/app/defgatewaytools_test.go:83-91) re-implements the broker's allow logic instead of calling Ceiling.allows/checkCeiling. Both sides also go through agentdef.Parse, despite the comment about "their own parsers".
  • No cases for:
    • tools containing . or __, through Validate, the ceiling, and the loader;
    • mixed-case names;
    • an integration case where the child's definition grants a server its parent lacks (only the property test covers this).

- A gateway call is refused unless the gateway routes it to the tool's own
  backend, so the harness and the broker always mean the same server.
- Ceilings match tool names exactly, as the harness does; records quote
  names holding a separator; a refusal no longer shows the ceiling.
- A built-in definition that sets tool fields fails to load instead of
  having them ignored.
- An effective ceiling is computed only for a new instance.
- Shortcut markers for restart recomputation (#2563) and reported
  definitions (#2551).
- The agreement test uses the broker's own check and covers built-ins and
  the main agent as parent; new cases for dotted, mixed-case, and
  ambiguous names, and a child under an empty ceiling.
- Docs: the server list the limit resolves against until #2533, whole-server
  entries, no backfill while state is in memory, the tool-naming refusal,
  unlimited listings until #2729, and the operator row's accuracy.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
rdimitrov and others added 3 commits November 21, 2026 20:08
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Brings in main, whose identity broker refuses a workspace on the process's
filesystem (#2875). Named definitions run only in sessions with a
workspace, so the named-subagent end-to-end test runs on the Redis
filesystem, and the named team member, which needs teams and so Kubernetes
execution, is tested through the member factory instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A team member without a filesystem skipped its agent definition entirely,
so it got every server-global MCP tool and every gateway tool, including
ones its definition excludes, and registered with the identity broker as
the built-in member, so the broker allowed them too. With the broker on,
file-less is the only setup outside Kubernetes execution (#2875).

A file-less member that names a definition now gets the file-less core
tools its definition does not exclude, its definition's own MCP servers
instead of the server-global ones and CallMcpWithQuery, and its servers'
gateway tools, and reports the definition, so the broker checks the same
limit. The rest of the definition stays file-oriented and is not applied.

The named team member end-to-end test runs again, file-less.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@rdimitrov

Copy link
Copy Markdown
Member Author

Thanks, this was thorough. Point by point; fixes are in 29b94ce, plus aa312f5 for a related gap described at the end.

Design and ticket gaps

  1. Server list. Agreed the doc overstated it. The code stays as is, and mcp-authorization.md now says that until Configure the embedded gateway's authorization server as AS-2 #2533 builds the gateway from the MCP configuration, the broker resolves against its gateway entry's servers, which production leaves empty, so every gateway call is refused at check 6 first.
  2. Two server lists. There is one list. ib.gatewayServers feeds both the identity broker's loader and the MCP broker's GatewayCalls.Servers (internal/app/build.go), and a session tool is a helper gateway tool only if its backend is in that list (gatewayRoute). So defGatewayTools can only pick tools of servers the broker resolved against. I added a comment where the list is wired. The remaining gap was the name each side uses for a server, which is point 13, now enforced.
  3. Restart widening. Agreed, and it had no marker. Added a shortcut on effectiveCeilingLocked, removed by Durable broker state and recovery #2563, since durable state is what keeps each effective ceiling and its resolution inputs. While state is in memory, a restart also drops every registration, so the widening needs both a restart and a longer server list in the new process.
  4. Done-when items.
  5. Sign-off. Fair. The decision on Per-agent tool limit, checked by the broker #2842 is a proposal, and I've asked for the author's sign-off there before this merges.
  6. Decision text vs code.
    • The loader parses each mcp__<server>__<tool> exclusion once, at resolution. Calls are never parsed. The doc now says so; "nothing has to parse" in the decision referred to calls.
    • Reworded mcp-authorization.md and the implementation.md work breakdown. A server-wide entry permits the server's tools as they are when each call is checked, so a tool added later is allowed unless excluded by name, as the harness behaves.
  7. Built-ins. A built-in that sets tools, disallowedTools, or mcpServers now fails to load, with a test, instead of having them ignored.
  8. Tool naming. It is now stated as the gateway's contract: Gateway.Route's doc says the server must be the backend and the tool must be <server>.<tool>. An external gateway (External gateway: Gateway implementation, operator setup, and end-to-end test #2812) maps its names to that form. Added the INVALID_ARGUMENT row to the step (6) failure table, and a sentence on the request form.
  9. Listings. Right. Until List gateway tools with a broker-issued token #2729, listings use the MCP broker's own sign-in and never reach AuthorizeCall. The "Tool discovery" paragraph now says so, and that the harness gives a helper only its definition's gateway tools from that listing. The only agent that sees the full listing is the main agent, whose built-in ceiling grants every server.
  10. Tickets.
  11. Branch hygiene. Resolved: main is now merged into feat/run-delegations and that into this branch, so fix(app): keep a team member's MCP tools within its definition's exclusions #2939's change is in, with the member path appending the gateway tools to registered. I merged rather than rebased, so nothing was force-pushed. I'll check that "Closes Per-agent tool limit, checked by the broker #2842" links after this retargets to main.
  12. Operator docs. The row now:
    • says a server counts only when named by reference;
    • gives the mcp__<server>__<tool> form;
    • says inline entries and tools add no gateway tools;
    • says the chart doesn't configure a gateway yet, so helpers get no gateway tools for now.

Correctness

  1. Server names. The MCP broker now refuses a gateway call if Route names a server other than the tool's backend, before anything is authorized, with a test. GatewayServer()'s doc says it's the backend, and why that is the server the broker checks.
  2. Reported definition. Added a Full definition loader and registration rules #2551 shortcut on check 7: a root reporting system/main gets every server, and a child reporting a built-in gets its parent's whole ceiling.
  3. Whitespace. NewCeiling now keeps tool names exactly, as the harness does. In practice agentdef drops an entry like mcp__github__ merge before either side sees it. The agreement test has that case, alongside mixed case and dotted names.
  4. Record string. A tool name with anything other than letters, digits, _, -, or . is now quoted as a Go string, with a test.
  5. Nits.
    • Underscores: corrected isGatewayServerName's doc. The MCP configuration allows a trailing underscore, so the broker accepts it too. mcp__git___x is then ambiguous, and the loader excludes it from both servers, so it only narrows. A loader test covers it.
    • Ceiling in refusals: the refusal no longer shows the ceiling. Only the decision record names it, so a child no longer sees its parent's exclusions. The record's size is bounded by the definition file.
    • Recomputing on re-registration: the effective ceiling is now computed only for a new instance.

Missing tests

  • End-to-end check 7 refusal: not reachable through the harness by design, because the harness drops the tool first. Check 7 refusals are covered at AuthorizeCall with the real broker, counting that no exchange or redemption happens. The new route-mismatch test covers the MCP broker side.
  • Re-implemented allow logic: the agreement test now calls Ceiling.Allows, and its comment no longer claims separate parsers.
  • New cases:
    • tools with . and __ through Validate and the ceiling (TestAuthorizeCallSplitsOnlyTheServerPrefix), and through the loader;
    • mixed-case server prefixes, refused, and tool names, matched exactly;
    • a child whose definition grants github under a parent with an empty ceiling, refused (TestAuthorizeCallChildCannotGainAServerItsParentLacks).

Also changed since

  • File-less team members kept to their definition. feat(identitybroker): start the broker from operator configuration and keys #2875 on main refuses the broker with a workspace on the process's filesystem, so without Kubernetes execution its sessions are file-less. A file-less team member used to skip its agent definition entirely: it got every server-global MCP tool and every gateway tool, and it registered as system/member, so the broker allowed a tool its definition excludes. Now it gets the file-less core tools its definition doesn't exclude, its definition's own MCP servers in place of the server-global ones and CallMcpWithQuery, and its servers' gateway tools. It also reports the definition, so check 7 applies the same limit. The rest of the definition (prompt, model, hooks) still isn't applied without a filesystem. A file-less subagent already refuses a named definition.
  • End-to-end tests after feat(identitybroker): start the broker from operator configuration and keys #2875. The named-subagent test runs on the Redis filesystem, the one workspace the broker allows offline. The named team-member test runs file-less and now covers the case above. The member path with a filesystem, which needs Kubernetes execution, is covered by an app-level test on the real member factory.

This branch was successfully deployed

1 active (outdated) deployment
Preview — aa312f57 Deployed Nov 21, 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.

2 participants