Skip to content

fix: provide MCP permission prompt metadata for ACP v2 - #758

Open
ruixingshi wants to merge 3 commits into
agentclientprotocol:mainfrom
ruixingshi:codex/fix-mcp-v2-permission-title
Open

ruixingshi wants to merge 3 commits into
agentclientprotocol:mainfrom
ruixingshi:codex/fix-mcp-v2-permission-title

Conversation

@ruixingshi

Copy link
Copy Markdown

Closes #757.

Correlated MCP approvals reuse an existing tool call without a title. On ACP v2, the permission converter consequently has no prompt title and throws before the client can approve the request; the elicitation handler then cancels the call.

Use the existing requestPermissionMeta mechanism in buildMcpPermissionRequest to supply a separate prompt title and the MCP message as its description. Merge that metadata with is_mcp_tool_approval, preserving the correlated tool ID and all approval options. The existing capability handling controls v2 prompt fields and AIR metadata; ordinary ACP v1 clients keep their existing request shape.

Validation:

  • npm run typecheck
  • npm run build
  • git diff --check
  • Isolated real Codex smoke over ACP v2 in read-only mode: the client received Run MCP tool?, selected allow_once, the Herd HTTP MCP list_agents tool completed, and the turn ended with end_turn. No missing-title conversion error.

The smoke explicitly approved this one MCP request. The separate tool-identity problem described in #553 remains outside this change. No new test suite or dependency changes; validation was limited to static checks and the real smoke flow.

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

I tested 40d7fd7 and base 9b2a785 with the bundled Codex 0.166.0, the ACP SDK client, and a disposable HTTP MCP echo server. The parent and a spawned child both discovered the MCP server supplied through session/new.

  • On the base, both ACP v2 approvals stopped at the missing-title error before reaching the client. The MCP server received zero tool calls.
  • On the PR, both prompts arrived with Run MCP tool? and the respective echo-parent and echo-child tool IDs. Approving both yielded both server calls and returned both markers.
  • In a separate run, I approved the parent and rejected the child. Only the parent call reached the server.
  • ACP v1 still completed both calls with separate approvals. The existing permission and approval suites passed all 51 tests.

The child-session case also exercises the MCP inheritance path described in #761. On current v2.9.0 with Codex 0.171.0, both threads discovered the tool under ACP v1 and v2, including when it was supplied only through session/new. ACP v2 stopped at the approval stage on that release.

Assisted by AI.

Comment thread src/permissions/mcp.ts Outdated
? "Open MCP server URL?"
: context.isToolApproval ? "Run MCP tool?" : "Respond to MCP server?";
const meta = {
...requestPermissionMeta(renderer.capabilities, title, params.message)._meta,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Problem: npm test fails on this PR, and the bug it fixes has no regression test.

  • The AIR golden snapshot AIR golden snapshots > mcp-tool-approval (src/__tests__/scenarios/client-profiles.test.ts) now fails. AIR now gets _meta.jetbrains.air.permission with title: "Run MCP tool?" and the MCP message on MCP approvals, and src/__tests__/scenarios/data/air/mcp-tool-approval.jsonl was not updated. I checked the merge base 9b2a785: that snapshot passes there, so this failure comes from this PR. The other failures I saw locally fail on the base too.
  • No test covers the fixed case: an ACP v2 client getting a tool approval that reuses a started MCP tool call. The v2 tests in src/__tests__/CodexACPAgent/elicitation-v2.test.ts only cover the URL fallback and check that a permissionRequest exists, not its shape. None of them fails on the base, so they would not have caught ACP v2: correlated MCP tool approvals are cancelled because the permission prompt title is missing #757.

Fix: update the AIR snapshot (npx vitest run -u src/__tests__/scenarios) and check the new record is what AIR should get. Add one v2 test to elicitation-v2.test.ts: emit item/started for an mcpToolCall, then send a form elicitation with _meta.codex_approval_kind: "mcp_tool_call" for the same server. Snapshot the permissionRequest with toMatchFileSnapshot(). It should have title: "Run MCP tool?", the message as description, and the started call's toolCallId. I ran a temporary test like this: it passes on this PR and fails on the base with the missing-title error.

Comment thread src/permissions/mcp.ts Outdated
? "Open MCP server URL?"
: context.isToolApproval ? "Run MCP tool?" : "Respond to MCP server?";
const meta = {
...requestPermissionMeta(renderer.capabilities, title, params.message)._meta,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

For standalone and URL elicitations, the message is already in the tool call's content (and in rawInput.description). Using it as the prompt description too means v2 and AIR clients now show the same question twice. For example, a v2 "Question from MCP server" request now has description: "Proceed?" and also content: [{text: "Proceed?"}]. docs/air-extensions.md promises "one copy of the question in content" for these requests.

Only the correlated tool approval needs the message, because its tool call has no content. Pass it only in that case:

...requestPermissionMeta(renderer.capabilities, title, correlatedCallId !== undefined ? params.message : null)._meta,

I checked this change: the correlated v2 prompt still gets the description, standalone and URL prompts get only the title, and the elicitation, permission, and tool-call tests pass.

Comment thread src/permissions/mcp.ts
nextStandaloneToolCallId,
));
const toolApprovalMeta = context.isToolApproval && params.mode !== "url" ? {_meta: {is_mcp_tool_approval: true}} : {};
const title = params.mode === "url"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

These are new request titles that AIR now receives too, but docs/air-extensions.md ("Presentation record") still says the request titles are only Run command?, Allow network access?, Make edits?, and Grant permissions?. Please add the three MCP titles there. Also consider moving them into src/permissions/metadata.ts next to the other CODEX_*_TITLE constants, so all permission titles live in one place.

@ruixingshi

Copy link
Copy Markdown
Author

Thanks for the detailed review, @EugeneTheDev. I pushed e73183c to address all three threads.

  • Only approvals that reuse a started MCP tool call now get the message as the prompt description. Standalone form and URL prompts keep the message in the tool call.
  • I updated the AIR snapshot and added ACP v2 snapshots for the correlated approval and the two standalone fallbacks. The correlated test reproduced the missing-title error on 9b2a785 and passes on this branch.
  • The three MCP titles now live in permissions/metadata.ts and are documented in the AIR extension reference.

Typecheck and build passed. The full npm test run had the same four failures on the merge base and this branch, in the session-index and live-subagent tests.

Align the ACP v2 approval snapshot with live tool status and add environmentId to the MCP test fixtures.

This branch has not been deployed

No deployments
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.

ACP v2: correlated MCP tool approvals are cancelled because the permission prompt title is missing

3 participants