Skip to content

🔌 feat: Let an Owner Grant an API Key Its MCP Access From Settings - #18281

Merged
danny-avila merged 0 commit into
danny-avila/key-integration-grantsfrom
danny-avila/key-grant-dialog
Nov 18, 2026
Merged

danny-avila merged 0 commit into
danny-avila/key-integration-grantsfrom
danny-avila/key-grant-dialog

Conversation

@danny-avila

@danny-avila danny-avila commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

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

GET /api/api-keys                         { keys, grants?: true }      # new flag: grants are in use

client/src/components/MCP/GrantDialog.tsx                              # the dialog, moved out of Schedules
  GrantDialog({ source, copy, name, subjectKey, children })
  └── Grant (keyed by subjectKey)                                      # the owner's choices for one subject
client/src/components/SidePanel/Schedules/Consent.tsx                  # now a wrapper: schedule hooks + schedule copy
client/src/components/Nav/SettingsTabs/ApiKeys/KeyGrant.tsx            # new: agent picker + key hooks + key copy
client/src/data-provider/ApiKeys/consent.ts                            # new: useApiKeyMCPConsent(keyId, agentId)

GrantDialog takes 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

  • Feature
  • Refactor

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 carries grants: true only 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 --noEmit is clean in client, packages/api and packages/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):

Before After
row before row after

The dialog: before an agent is picked, the picker open, and an agent picked.

Nothing picked Picker Agent picked, light Agent picked, dark
idle picker picked, light picked, dark

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: false and 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.

@danny-avila

Copy link
Copy Markdown
Collaborator Author

@codex review f84e03f

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-18T11:12:16.404880Z f84e03f Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread api/server/routes/apiKeys.js Outdated
Comment on lines +26 to +28
usesGrants: async (req) =>
resolveRemoteIntegrations(await getAppConfig(getAppConfigOptionsFromUser(req.user))).mode ===
'delegated',

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +36 to +39
const { data: agents } = useListAgentsQuery(
{ requiredPermission: PermissionBits.VIEW },
{ select: (res) => res.data },
);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@danny-avila
danny-avila marked this pull request as ready for review November 18, 2026 16:57
@danny-avila
danny-avila force-pushed the danny-avila/key-grant-dialog branch from f84e03f to 7214869 Compare November 18, 2026 17:27
@danny-avila
danny-avila merged commit 7214869 into dev Nov 18, 2026
1 check passed
@danny-avila
danny-avila deleted the danny-avila/key-grant-dialog branch November 18, 2026 17:27
@danny-avila

Copy link
Copy Markdown
Collaborator Author

Folded into #18280 at 7214869, as its review asked: the backend capability and its entry point now ship in one PR. This PR's branch points at the same commit, which is why it shows as merged into danny-avila/key-integration-grants. Its two review threads are answered here and addressed in #18280.

An error occurred while trying to automatically change base from danny-avila/key-integration-grants to dev November 18, 2026 18:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant