Skip to content

feat(assistant): request approval for external MCP writes - #973

Open
crispinhu27 wants to merge 3 commits into
mainfrom
feature/external-mcp-approval
Open

crispinhu27 wants to merge 3 commits into
mainfrom
feature/external-mcp-approval

Conversation

@crispinhu27

Copy link
Copy Markdown
Collaborator

What changed

In Request approval mode, the session gateway immediately rejected external MCP writes. It now uses the external-write approval panel introduced in #947. The current speaker sees the MCP server, tool, and redacted arguments. Approval releases the original call once and returns its result to the CLI.

The gateway expires the pending request on refusal, timeout, turn stop, or mode handoff. Runner connections carry cancellation per MCP request so a disconnected call loses its approval without affecting parallel calls.

Scope

  • Platform core / API / runner
  • Shared behavior contract

Compatibility

Approvals use the existing generation payload. For remote execution, update the Runner alongside the API to enable per-request cancellation for manual MCP approvals.

Validation

  • Passed the Docker regression tests for approval, refusal, request timeout, turn stop, mode handoff, argument redaction, and remote cancellation alongside a parallel approved call.
  • Passed TestMySQLNativeApprovalsShareGenerationControlState against isolated MySQL 8.4.
  • Passed bash scripts/build-chatbot.sh (371 tests) and python3 scripts/check-public.py.
  • Validation used a mock upstream MCP and real Runner WebSocket connections. The full Go suite and individual CLI timeout limits were not exercised in this run.
go test -p=2 -count=1 -timeout=3m ./internal/httpapi ./internal/runner ./internal/mcpclient ./internal/repo -run 'Test(ExternalMCPWrite|RunnerWebsocket|ForwardConversationTool|ConversationMCPFollows|MCPCallMayWrite|WorkspaceExternalWrites|NativeApproval|CallTool|ListTools)'

Safety

  • The commit contains public repository source, tests, and documentation.

crispinhu27 and others added 3 commits November 17, 2026 01:06
The resumed-turn context now says 待确认的平台写入 because external MCP
writes wait for approval instead of going into drafts. Keep asserting that
the turn names the qualified submission tool, using the new wording.

Co-Authored-By: Claude Code <noreply@anthropic.com>
@crispinhu27

Copy link
Copy Markdown
Collaborator Author

修复 core CI 失败(head c173243)

原因

core 失败在 TestAssistantPromptsNameCallableMCPSubmissionTool(agent_tool_native_terminal_test.go:147),platform-required 只是汇总了 core 的结果。本 PR 把续接轮次的提示从「待确认写入仍须通过 …」改成「待确认的平台写入仍须通过 …」(外部 MCP 写入不再走 drafts),测试还在断言旧句子。属于测试期望没跟着文案更新,不是基础设施问题,也不是功能缺陷。

改动

本地验证(合并 main 之后)

  • bash scripts/build-chatbot.sh:374/374 通过。
  • go test -p=2 ./... -skip "$REAL_BROWSER_TESTS"(与 CI core 相同):全部通过。internal/engine 里有两条 git 身份测试受容器里的 GIT_AUTHOR_* 环境变量影响,清掉这些变量后通过,与本 PR 无关。
  • go vet ./... 和 python3 scripts/check-public.py 通过。TestExternalMCPWriteWaitsForSpeaker 和修复的这条测试在 -race 下也通过。

本地部署(Chrome CDP 操作 chatbot)

环境:MySQL 8.4.7 官方二进制包(容器不支持 Docker 挂载),本分支构建的 agentflow(role all),已执行 migrations/001。CodeBuddy CLI 用替身:它从 --mcp-config 连到真实的平台会话网关,先 tools/list,再调用外部 MCP 的写工具,不调用模型。外部 MCP 是本地的 mock HTTP MCP,项目 Demo 安装后命名为 Mock Tickets。会话审批模式为「请求批准」。

场景 结果
调用 mock_tickets__create_ticket 出现「批准外部写入:Mock Tickets · create_ticket」卡片,参数里的 token 显示为 [redacted];等待期间上游调用数不变
批准 上游只执行 1 次,CLI 收到 mock upstream executed create_ticket
拒绝 上游调用数不变,CLI 收到「用户拒绝了本次外部 MCP 写入 create_ticket,操作未执行。不要换一种方式重试。」
等待审批时停止回复 CLI 退出(context canceled),native-approvals 变为 [],上游调用数不变

/api/health 返回 200,日志里没有 panic。停止回复这一项是在合并 main 之前的构建上验证的,批准和拒绝在合并后重新跑过。

审批卡片 批准后
panel allow
拒绝后 等待时停止回复
deny stop

没有验证的部分:远端 Runner 的逐请求取消(本地没起远端 Runner)、真实模型下 CLI 的行为。

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.

1 participant