Repository navigation
refactor(mcpbroker): move authorization orchestration behind the broker contract - #2685
Merged
Merged
Conversation
…er contract The server now calls explicit MCP broker contract operations instead of orchestrating MCP authorization itself or type-asserting on broker attachments. Present, settle (cancel + reconcile), expiry, and granted continuation (catalogue refresh, query tool, parked-argument check) live in internal/mcpbroker and internal/adapter/mcpbroker. The server keeps locks, leases, persistence, engine rebuilds, events, error mapping, and the identity broker session open, in the same order as before. Behavior and the wire API are unchanged. Refs #2530, #2422 Co-authored-by: Mecatl <[email protected]>
rdimitrov
approved these changes
Nov 5, 2026
rdimitrov
left a comment
Member
There was a problem hiding this comment.
LGTM. I checked that each authorization path behaves exactly as it did before:
- Cancel: only a failed cancel on lost state resolves as interrupted, as before. A failed status read after
CancelAlreadyResolvedstill surfaces.CancelFailedErrorunwraps, sobrokerStateLostand theerrors.Ismapping still match. - Recheck / expiry timer: the status-read/cancel/reconcile order is unchanged, and an expiry-timer status-read error on lost state still resolves as interrupted. The
ErrFailedPreconditionmessages are the same afterauthorizationOutcomeError. - Granted continuation: refresh, add query tool, rebuild, then reject on bad args: same order and same tool set. Validation now runs under the broker lock, but it is cheap.
- Workspace enrollment: the removed "not configured" branch was unreachable.
*mcpbroker.Attachmentis the only productionAttachment, and it already implemented enrollment.
CI is green.
Merged
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #2530. Part of #2422.
Summary
The server now calls explicit MCP broker contract operations for MCP authorization. It no longer type-asserts on broker attachments or orchestrates broker state itself. Slice 4 of agent identity (#2536) can then add the identity-broker call check, per-call gateway tokens and resumed-call checks inside the MCP broker, without spreading into the server.
Contract (
internal/mcpbroker)AttachmentembedsWorkspaceEnrollmentAttachmentserver/workspace_enrollment.goAttachment.CallMcpWithQueryTool()server/mcp_broker.goPresentPendingAuthorization(ctx, tx, auth)ErrAuthorizationNotPending)SettleAuthorization(ctx, tx, auth, settled)reconcileAuthorizationCancellationin the server). A failed cancel is reported as*CancelFailedErrorExpireAuthorization(ctx, tx, auth)Attachment.PrepareGrantedAuthorization(ctx, pending)ArgumentsErrmeans the host must not run the callThe settle/present/expire operations are package functions over the small
AuthorizationTransactionsinterface, whichAttachmentsatisfies. They are not attachment methods, because every implementation would just forward to the same logic.What stays in the server, and why
These are server-owned:
openIdentityBrokerSessionstays in the server and runs at the same point as before: before any settle, save or append, so a refused access token leaves the authorization pending and the session unchanged. Recheck therefore still reads status and settles in two steps, so the identity-broker open can sit between them.The connector inventory is unchanged and stays behind
ConnectorInspector, which #1699 can reuse.API compatibility
Assessment: no change. No proto, route, event or stored-data changes. Error codes and messages match the previous behaviour, including the two failed-precondition messages for invalid cancellation outcomes and the not-pending error. Persisted
PendingAuthorization/ExternalAuthorizationand restart interruption (ErrStateUnavailable→ interrupted) are unchanged. Only the internal Go contract ininternal/mcpbrokerchanged. No major bump or feature identifier. No upgrade implications.Tests
PrepareGrantedAuthorizationreturns the catalogue plus the query tool, accepts a valid parkedCallMcpWithQuerycall and refuses a forged one. With no query tool it returns only the catalogue and refuses the parked query call.ErrFailedPreconditionwith the exact message on cancel, recheck and the expiry timer;Commands run, all passing:
The full
task test:racewas not run to completion on macOS. Failures it showed on the earlier working tree, e.g. the ACP placement tests andmicrovm/gitexec, reproduce on a cleanmaincheckout; one failing package (microvmmanager) was not re-checked onmain. CI covers the full suite.Follow-ups
tool.Tool,session.PendingAuthorization,session.AuthorizationStatus).AuthorizationStatus/CancelAuthorizationdirectly. They could become one settle-on-close operation.PrepareGrantedAuthorizationor the broker's tool wrappers. The server will still be involved in two places: