Repository navigation
fix: provide MCP permission prompt metadata for ACP v2 - #758
ruixingshi wants to merge 3 commits into
Conversation
ychampion
left a comment
There was a problem hiding this comment.
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 respectiveecho-parentandecho-childtool 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.
| ? "Open MCP server URL?" | ||
| : context.isToolApproval ? "Run MCP tool?" : "Respond to MCP server?"; | ||
| const meta = { | ||
| ...requestPermissionMeta(renderer.capabilities, title, params.message)._meta, |
There was a problem hiding this comment.
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.permissionwithtitle: "Run MCP tool?"and the MCP message on MCP approvals, andsrc/__tests__/scenarios/data/air/mcp-tool-approval.jsonlwas not updated. I checked the merge base9b2a785: 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.tsonly cover the URL fallback and check that apermissionRequestexists, 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.
| ? "Open MCP server URL?" | ||
| : context.isToolApproval ? "Run MCP tool?" : "Respond to MCP server?"; | ||
| const meta = { | ||
| ...requestPermissionMeta(renderer.capabilities, title, params.message)._meta, |
There was a problem hiding this comment.
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.
| nextStandaloneToolCallId, | ||
| )); | ||
| const toolApprovalMeta = context.isToolApproval && params.mode !== "url" ? {_meta: {is_mcp_tool_approval: true}} : {}; | ||
| const title = params.mode === "url" |
There was a problem hiding this comment.
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.
|
Thanks for the detailed review, @EugeneTheDev. I pushed e73183c to address all three threads.
Typecheck and build passed. The full |
Align the ACP v2 approval snapshot with live tool status and add environmentId to the MCP test fixtures.
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
requestPermissionMetamechanism inbuildMcpPermissionRequestto supply a separate prompt title and the MCP message as its description. Merge that metadata withis_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 typechecknpm run buildgit diff --checkread-onlymode: the client receivedRun MCP tool?, selectedallow_once, the Herd HTTP MCPlist_agentstool completed, and the turn ended withend_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.