fix(mcp): require trust for read-only auto-approval - #6924
Conversation
|
Thanks for the PR! Template looks good ✓ Problem: Observed bug with clear reproduction. Issue #6917 describes a concrete scenario — MCP tool with Direction: Clearly aligned. MCP annotations are server-supplied hints; granting automatic permission based on a server's self-description, bypassing the user's trust configuration, is a genuine security concern. The MCP annotation spec itself says clients should treat annotations as untrusted from untrusted servers. This fix is the right call. Size: 1 production line added, 6 deleted (in Approach: Minimal and correct. Removes the 4-line block that auto-grants Moving on to code review. 🔍 中文说明感谢贡献! 模板完整 ✓ 问题:已观测到的 bug,有明确复现。Issue #6917 描述了具体场景—— 方向:完全对齐。MCP 注解是服务器提供的提示;基于服务器自我描述授予自动许可、绕过用户信任配置,是真实的安全隐患。MCP 注解规范本身也要求客户端将不可信服务器的注解视为不可信。 规模:1 行生产代码新增,6 行删除( 方案:最小且正确。移除了仅凭 进入代码审查 🔍 — Qwen Code · qwen3.7-max Reviewed at |
|
Code review: the change is correct and minimal. The 4-line Before (installed build — main branch)After (this PR)Unit tests: 61/61 passed ✓ 中文说明代码审查:变更正确且最小。4 行 变更前后对比显示:修复前,不可信服务器和不可信文件夹中的 单元测试:61/61 通过 ✓ — Qwen Code · qwen3.7-max Reviewed at |
|
Confidence: 5/5 — Clean security fix, confirmed bug, minimal change, comprehensive tests. This is exactly the kind of PR the gate should pass without hesitation. The bug is real — I confirmed it on main: untrusted MCP servers with The PR is focused — no scope creep, no drive-by changes, no over-engineering. The PR description is clear, bilingual, and the reviewer test plan with before/after evidence is thorough. The linked issue (#6917) has proper labels and a concrete reproduction. Shipping this. ✅ 中文说明置信度:5/5 — 干净的安全修复,已确认的 bug,最小变更,全面的测试。 这正是 gate 应该毫不犹豫地通过的 PR 类型。bug 是真实的——我在 main 分支上确认了:带有 PR 聚焦——无范围蔓延、无顺手改动、无过度工程化。PR 描述清晰、双语,审阅者测试计划包含变更前后证据。关联的 issue (#6917) 有正确的标签和具体复现。 批准合并 ✅ — Qwen Code · qwen3.7-max Reviewed at |
qwen-code-ci-bot
left a comment
There was a problem hiding this comment.
LGTM, looks ready to ship. ✅
qwen-code-ci-bot
left a comment
There was a problem hiding this comment.
Reviewed. Not reviewed: chunk 1 — no agent reported covering these; nobody read them.
— qwen3.7-max via Qwen Code /review
✅ Local verification — built & ran real tests (merge reference)I verified this PR locally in an isolated worktree at the PR head ( What the fix does
1 · After the fix — all green (real build & run)The PR's own suite ( 2 · Load-bearing proof (controlled experiment)I reverted only the source fix (restored the deleted
Restoring the fix returns all 68 tests to green. Nothing else moves — the deleted block is the sole cause, and the fix closes exactly that path. Scope / mergeability notes
EnvironmentmacOS (Darwin 24.6.0), Node 22, isolated git worktree at PR head, 🇨🇳 中文说明(点击展开)✅ 本地验证 —— 构建并运行了真实测试(合并参考)我在独立 worktree(检出 PR HEAD 修复做了什么
1 · 修复后 —— 全绿(真实构建与运行)PR 自带测试( 2 · 可证明必要性(受控实验)我只回退了源码修复(恢复被删除的
恢复修复后,全部 68 项测试重新变绿。其他一切不变——被删除的代码块是唯一根因,修复恰好只封堵了该路径。 范围 / 可合并性说明
Verified locally on macOS; screenshots render real terminal output from the runs above. |



What this PR does
Requires user-controlled MCP server trust before a tool can receive automatic default permission. A server-provided
readOnlyHintcontinues to classify the tool as read-only for plan mode, but no longer grants permission by itself.Adds regression coverage for annotated tools across untrusted servers, untrusted workspaces, trusted servers in trusted workspaces, and disabled annotations.
Why it's needed
MCP tool annotations come from the server's discovery response. Previously,
readOnlyHint: truechanged the default permission fromasktoalloweven when the server was not configured as trusted, bypassing the normal confirmation prompt. Automatic permission should depend on the user's trust configuration, not the server's self-description.Reviewer Test Plan
How to verify
Build an MCP tool invocation with
readOnlyHint: trueunder each trust combination. Confirm that an untrusted server asks, a trusted server in an untrusted workspace asks, and a trusted server in a trusted workspace remains allowed. Confirm that an absent or false annotation retains the existing behavior and that annotated tools remain classified as read-only.Evidence (Before & After)
readOnlyHint: trueallowaskreadOnlyHint: trueallowaskreadOnlyHint: trueallowallowThe focused regression failed in the first two scenarios before the fix and passes after it. The complete MCP tool test file passes 61 tests.
Tested on
Environment (optional)
Node.js 24; focused and complete MCP tool unit tests, repository build, typecheck, lint, Prettier, and targeted ESLint.
Risk & Scope
Linked Issues
Fixes #6917
中文说明
此 PR 的作用
只有在用户明确将 MCP 服务器设为可信时,工具才能获得自动默认许可。服务器提供的
readOnlyHint仍用于在计划模式中将工具分类为只读,但不再单独授予执行许可。新增回归测试,覆盖不可信服务器、不可信工作区、可信工作区中的可信服务器,以及禁用注解的情况。
为什么需要此变更
MCP 工具注解来自服务器的发现响应。此前,即使服务器未配置为可信,
readOnlyHint: true也会将默认许可从ask改为allow,从而跳过正常的确认提示。自动许可应由用户的信任配置决定,而不是由服务器的自我描述决定。审阅者测试计划
如何验证
在每种信任组合下构建带有
readOnlyHint: true的 MCP 工具调用。确认不可信服务器会询问,位于不可信工作区中的可信服务器会询问,而位于可信工作区中的可信服务器仍会被允许。确认缺少注解或注解为 false 时保留现有行为,并且带注解的工具仍被分类为只读。证据(变更前后)
readOnlyHint: true的不可信服务器allowaskreadOnlyHint: true的可信服务器allowaskreadOnlyHint: true的可信服务器allowallow修复前,聚焦回归测试在前两个场景中失败;修复后通过。完整的 MCP 工具测试文件通过 61 项测试。
测试平台
环境(可选)
Node.js 24;已运行聚焦及完整的 MCP 工具单元测试、仓库构建、类型检查、lint、Prettier 和针对性 ESLint。
风险与范围
关联问题
修复 #6917