Repository navigation
🔌 feat: Let an Owner Grant an API Key Its MCP Access From Settings - #18281
Conversation
94a7e98 to
f84e03f
Compare
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f84e03fd65
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| usesGrants: async (req) => | ||
| resolveRemoteIntegrations(await getAppConfig(getAppConfigOptionsFromUser(req.user))).mode === | ||
| 'delegated', |
There was a problem hiding this comment.
Move grant-mode resolution into the TypeScript backend
The new usesGrants callback adds configuration loading and grant-mode policy logic directly to the legacy CJS route. AGENTS.md explicitly prohibits adding helpers, service calls, or other behavior under /api, including edits to existing files. Move this resolution into packages/api and inject getAppConfig as a dependency, leaving this route responsible only for wiring the handler.
AGENTS.md reference: AGENTS.md:L80-L84
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in d3bc5d8 (now in #18280). The route passes getAppConfig to createApiKeyHandlers, and the handlers resolve the mode in packages/api/src/apiKeys/handlers.ts (usesGrants).
Evidence: handlers.spec.ts › listApiKeys, and api/server/routes/__tests__/apiKeys.spec.js, which loads the real route and checks the flag comes from the configuration resolved for the caller. Dropping getAppConfig from the route fails it.
| const { data: agents } = useListAgentsQuery( | ||
| { requiredPermission: PermissionBits.VIEW }, | ||
| { select: (res) => res.data }, | ||
| ); |
There was a problem hiding this comment.
Surface agent-list failures in the grant dialog
If the agent-list request fails with no cached data, discarding its error state and converting undefined to an empty list leaves the owner looking at an empty picker and an instruction to choose an agent, with no error explanation or retry action. The shared dialog cannot handle this failure because its consent query remains disabled until an agent is selected. Handle the catalog query's loading and error states here, provide a retry action, and cover the failed-list scenario in the component tests.
AGENTS.md reference: AGENTS.md:L218-L221
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 745b152 (now in #18280). KeyGrant.tsx shows a spinner while the agent list loads, an alert with a Retry button when it could not be read and nothing is cached, and a plain statement when the owner has no agent; the picker and its instruction appear only once there are agents. A cached list stays usable when a refresh fails.
Evidence: KeyGrant.spec.tsx › the loading, failed-with-retry, stale-but-usable and empty cases; three of them fail against the previous component.
f84e03f to
7214869
Compare
Summary
#18280 lets the owner of an agent API key limit what a run started with that key may do: which MCP servers and tools, per agent. It added the record, the check and three routes, but no way to use them short of calling the routes by hand.
This PR adds that way. Where the operator has turned grants on (
endpoints.agents.remoteApi.integrations.mode: delegated), each key in Settings → API Keys gets an "MCP access" button. It opens a dialog where the owner picks an agent and ticks the servers and tools that key may use with it. It is the dialog scheduled chats already use, given a second data source.The default mode is still
owner, so nothing appears on a deployment that has not opted in. Changing that default is a separate, one-line PR.Stacked on #18280. Related to #13824.
How it works
GrantDialogtakes where the grant is read and written (source: one query and two mutations) and the words that depend on what holds it (copy: title, opening paragraph, and the status lines that otherwise speak of schedules). Everything else, including the tool boxes, the changed-tool note and the lifetime field, is shared.The key dialog has one thing a schedule's does not: the owner has to pick the agent first. Until then nothing is requested and nothing is shown below the picker. The owner's ticks live in a part of the dialog keyed by the agent, so switching agent starts over instead of carrying one agent's ticks to the next.
The schedule dialog's behaviour is unchanged; its existing tests run against the shared component through the wrapper.
Type of change
Testing
Tested environments/configuration: WSL2, Node.js 24. No external services.
Automated tests:
client/src/components/Nav/SettingsTabs/ApiKeys/__tests__/KeyGrant.spec.tsx(new): nothing is requested, listed or spinning until an agent is picked; picking one requests that key and agent's grant, and confirming sends it for that key and agent; picking another agent starts over with that agent's tools and nothing ticked; a state with nothing to grant uses the key's wording, not the schedule's; revoking goes to that key and agent.client/src/components/Nav/SettingsTabs/ApiKeys/__tests__/Item.spec.tsx,List.spec.tsx: the button is absent unless the list says grants are in use; it is labelled with the key's name, announces a dialog, and opens it for that key.client/src/components/SidePanel/Schedules/__tests__/Consent.spec.tsx(existing, 19 tests): unchanged and passing against the shared dialog.packages/api/src/apiKeys/handlers.spec.ts(new): the list carriesgrants: trueonly when told so, and does not list keys when the mode cannot be established.Each new behaviour was broken in turn (six mutations) and a test confirmed to fail.
npx tsc --noEmitis clean inclient,packages/apiandpackages/data-provider.Not verified: the dialog against a running server. The captures below use fixed data in place of the API.
Screenshots / recordings
The real components under the app's stylesheet in Chromium, fed fixed data in place of the API. The Cancel button shows its key because the capture does not initialise the shared package's i18n; the app does.
A key row, before and after (the button only appears where grants are in use):
The dialog: before an agent is picked, the picker open, and an agent picked.
Risk / compatibility
The agent picker lists the agents the owner can view, the same list the schedule dialog uses. An agent the owner cannot run remotely can be picked; the server then answers that there is nothing to grant or refuses. I did not add a remote-access filter to the list.
The key dialog has no "ask me first". A remote run cannot pause for its owner, so the server reports
approval: falseand the control is not rendered.Wording. A state with no grant still reads "Authorization required", shared with schedules. The lifetime field and Confirm and Revoke labels are shared too.
No stored-data or config change. The list response gains an optional field that older clients ignore.