For agentic workers: REQUIRED SUB-SKILL: Use
superpowers:executing-plansto implement this plan task-by-task. Steps use checkbox (- [ ]) syntax for tracking.
Goal: 让 Plan mode 下的 MCP 工具跳过普通 readonly 判定,但仍保留 MCP 身份识别、显式 destructive 拦截、项目 deny/ask 规则和现有非 MCP 写保护。
Architecture: 不改 MCP registry、metadata、protocol 或 UI。MCP 工具继续由 apps/zcode-cli/packages/core/src/mcp/index.ts 注册,权限层通过 permission.permission === "mcp" 形成的 capability.permissionName 识别 MCP;Plan mode 只新增一个 MCP 专用 permission 分支,避免把普通 unknown tool 或伪 mcp__ 名称一起放过。
Tech Stack: TypeScript, Vitest, @zcode/core permission service, MCP bridge, ZCode runtime tool loop.
packages/shared/src/zcode-protocol/index.ts,因为本次不新增协议字段。packages/ui 和 DESIGN.md。toolName.startsWith("mcp__") 作为主判断;MCP 身份以 permission.permission === "mcp" 为准。destructiveHint: true 的 MCP 仍拒绝。permission.permission === "mcp" 且 destructive !== true 的 MCP 允许执行,即使 readOnlyHint 缺失或为 false。ExitPlanMode / EnterPlanMode 现有专用规则不变。计划改动文件:
docs/plan-mode-approval-boundary.md
apps/zcode-cli/packages/core/src/permission/service.ts
PermissionService.checkPlanMode() 中增加 MCP 专用分支。capability.permissionName === "mcp"。apps/zcode-cli/packages/core/tests/permission-service.test.ts
apps/zcode-cli/packages/core/tests/mcp-runtime.test.ts
不改文件:
apps/zcode-cli/packages/core/src/mcp/index.ts
readOnly / destructive。apps/zcode-cli/packages/core/src/tool/executor/permission-flow.ts
entry.permission.permission 合并为 PermissionToolCapability.permission.permission。packages/shared/src/zcode-protocol/index.ts
packages/ui/**
Files:
docs/plan-mode-approval-boundary.mdInterfaces:
ExitPlanMode 审批语义。Produces: 后续实现与测试共同遵守的 MCP 例外语义。
[ ] Step 1: 在文档 “语义” 段落后加入 MCP 例外说明
在 docs/plan-mode-approval-boundary.md 的 ## 语义 列表后追加:
## MCP 工具例外
Plan mode 默认只允许只读、非 destructive 的工具执行。MCP 工具是外部 server 动态暴露的能力,部分工具不会声明 `readOnlyHint`,但仍需要在计划阶段用于读取外部上下文、设备状态或远端资料。
因此 Plan mode 对 MCP 工具使用独立权限边界:
- MCP 身份由工具权限声明 `permission.permission === "mcp"` 识别,不靠 `mcp__` 名称前缀推断。
- 项目级 `deny` / `ask` 规则仍优先生效,不能被 MCP 例外绕过。
- 显式声明 `destructiveHint: true` 的 MCP 工具仍在 Plan mode 下拒绝执行。
- 未显式 destructive 的 MCP 工具允许在 Plan mode 下执行,即使该工具没有声明 `readOnlyHint: true`。
- 该例外只跳过 Plan mode 的 readonly 判定,不改变 MCP 工具注册、模型可见 schema、输出预算、timeout、取消、日志或 UI 权限展示协议。
检查文档中同时说明了:
Run:
rg -n "MCP 工具例外|permission.permission|destructiveHint|项目级" docs/plan-mode-approval-boundary.md
Expected:
docs/plan-mode-approval-boundary.md:<line>:## MCP 工具例外
docs/plan-mode-approval-boundary.md:<line>:- MCP 身份由工具权限声明 `permission.permission === "mcp"` 识别,不靠 `mcp__` 名称前缀推断。
docs/plan-mode-approval-boundary.md:<line>:- 项目级 `deny` / `ask` 规则仍优先生效,不能被 MCP 例外绕过。
docs/plan-mode-approval-boundary.md:<line>:- 显式声明 `destructiveHint: true` 的 MCP 工具仍在 Plan mode 下拒绝执行。
Files:
apps/zcode-cli/packages/core/tests/permission-service.test.tsInterfaces:
PermissionService.checkPermission(context, capability, projectRules?)Produces: 新的 expected behavior,供实现 checkPlanMode() 时驱动。
[ ] Step 1: 增加 MCP capability fixtures
在 permission-service.test.ts 顶部现有 fixture 后加入:
const mcpCapability: PermissionToolCapability = {
destructive: false,
needsApproval: true,
permission: {
denyPriority: "beforeAsk",
needsApproval: true,
permission: "mcp",
reason: "MCP tool executes through an external server",
riskLevel: "medium",
sideEffectScope: "network",
},
readOnly: false,
riskLevel: "medium",
sideEffectScope: "network",
};
const destructiveMcpCapability: PermissionToolCapability = {
...mcpCapability,
destructive: true,
permission: {
...mcpCapability.permission!,
riskLevel: "high",
},
riskLevel: "high",
};
const fakeMcpNameCapability: PermissionToolCapability = {
destructive: false,
needsApproval: true,
readOnly: false,
riskLevel: "medium",
sideEffectScope: "network",
};
在 describe("PermissionService mode policy", () => { 内、Plan mode 相关测试附近加入:
it("allows non-destructive MCP tools in plan mode without requiring readOnly metadata", () => {
const service = new PermissionService();
const decision = service.checkPermission(
{
input: { query: "current simulator state" },
mode: "plan",
riskLevel: "medium",
toolName: "mcp__ios_simulator__status",
},
mcpCapability,
);
expect(decision).toMatchObject({
allowed: true,
decision: "allow",
ruleId: "mode.plan.mcp",
sideEffectScope: "network",
});
});
同一 describe 内继续加入:
it("denies destructive MCP tools in plan mode", () => {
const service = new PermissionService();
const decision = service.checkPermission(
{
input: { target: "device" },
mode: "plan",
riskLevel: "high",
toolName: "mcp__device__reset",
},
destructiveMcpCapability,
);
expect(decision).toMatchObject({
allowed: false,
decision: "deny",
ruleId: "mode.plan.nonReadOnly",
});
});
同一 describe 内继续加入:
it("does not treat an mcp-prefixed tool name as MCP without the mcp permission declaration", () => {
const service = new PermissionService();
const decision = service.checkPermission(
{
input: {},
mode: "plan",
riskLevel: "medium",
toolName: "mcp__fake__write",
},
fakeMcpNameCapability,
);
expect(decision).toMatchObject({
allowed: false,
decision: "deny",
ruleId: "mode.plan.nonReadOnly",
});
});
同一 describe 内继续加入:
it("lets project deny rules override the plan-mode MCP exception", () => {
const service = new PermissionService();
const decision = service.checkPermission(
{
input: { query: "secret" },
mode: "plan",
riskLevel: "medium",
toolName: "mcp__external__search",
},
mcpCapability,
{
version: 1,
deny: [{ toolName: "mcp__external__search" }],
},
);
expect(decision).toMatchObject({
allowed: false,
decision: "deny",
ruleId: "rule.project.deny",
});
});
it("lets project ask rules override the plan-mode MCP exception", () => {
const service = new PermissionService();
const decision = service.checkPermission(
{
input: { query: "maybe external" },
mode: "plan",
riskLevel: "medium",
toolName: "mcp__external__search",
},
mcpCapability,
{
version: 1,
ask: [{ toolName: "mcp__external__search" }],
},
);
expect(decision).toMatchObject({
allowed: false,
decision: "ask",
ruleId: "rule.project.ask",
});
});
Run:
pnpm --filter @zcode/core exec vitest run tests/permission-service.test.ts
Expected before implementation:
FAIL tests/permission-service.test.ts
...
expected ... ruleId ... "mode.plan.mcp"
Files:
apps/zcode-cli/packages/core/src/permission/service.tsInterfaces:
ResolvedPermissionCapability.permissionName?: stringResolvedPermissionCapability.destructive: booleanProduces:
mode.plan.mcp allow rule[ ] Step 1: 修改 checkPlanMode()
把当前 checkPlanMode() 替换为:
private checkPlanMode(
context: PermissionContext,
capability: ResolvedPermissionCapability,
): PermissionDecisionResult {
if (capability.readOnly && !capability.destructive) {
return this.allow(
context,
capability,
"mode.plan.readOnly",
"Plan mode allows read-only tool execution",
);
}
if (this.isMcpToolCapability(capability) && !capability.destructive) {
return this.allow(
context,
capability,
"mode.plan.mcp",
"Plan mode allows non-destructive MCP tool execution",
);
}
return this.deny(
context,
capability,
"mode.plan.nonReadOnly",
"Plan mode only allows read-only, non-destructive tools",
);
}
在 checkPlanMode() 附近加入私有方法:
private isMcpToolCapability(capability: ResolvedPermissionCapability): boolean {
return capability.permissionName === "mcp";
}
resolveCapability() 不变确认 resolveCapability() 仍保留:
permissionName: toolCapability?.permission?.permission,
不要新增 toolName.startsWith("mcp__") 判断。
Run:
pnpm --filter @zcode/core exec vitest run tests/permission-service.test.ts
Expected:
Test Files 1 passed (1)
Files:
apps/zcode-cli/packages/core/tests/mcp-tool-bridge.test.tsInterfaces:
registerMcpTools(registry, mcpPort, descriptors)Produces: 测试证明 destructiveHint: true 会变成 entry.metadata.destructive === true 和 high risk。
[ ] Step 1: 增加 destructiveHint 映射测试
在 describe("MCP tool bridge", () => { 内加入:
it("maps destructive MCP annotations into tool metadata", () => {
const registry = createToolRegistry();
const mcpPort = createMockMcpPort();
registerMcpTools(registry, mcpPort, [
{
serverName: "device",
toolName: "reset",
description: "Reset a device",
inputSchema: { type: "object" },
annotations: {
destructiveHint: true,
},
},
]);
const entry = registry.get("mcp__device__reset");
expect(entry?.metadata).toMatchObject({
destructive: true,
readOnly: false,
riskLevel: "high",
sideEffectScope: "network",
});
expect(entry?.permission).toMatchObject({
permission: "mcp",
riskLevel: "high",
sideEffectScope: "network",
});
});
Run:
pnpm --filter @zcode/core exec vitest run tests/mcp-tool-bridge.test.ts
Expected:
Test Files 1 passed (1)
Files:
apps/zcode-cli/packages/core/tests/mcp-runtime.test.tsInterfaces:
AgentRuntimecreateMockMcpPort(...)Produces: 真实 runtime 回归:Plan mode 下没有 readOnlyHint 的 MCP tool 不被 mode.plan.nonReadOnly 拦截。
[ ] Step 1: 在 import 中加入 type PermissionBrokerPort
把当前 imports 调整为包含:
type PermissionBrokerPort,
即:
import {
SessionEventType,
createSessionId,
type McpConnectionSnapshot,
type McpPort,
type PermissionBrokerPort,
type SessionEventStorePort,
type SessionId,
} from "@zcode/contracts";
在 describe("AgentRuntime MCP integration", () => { 内加入:
it("executes non-destructive MCP tools in plan mode without readOnlyHint", async () => {
const sessionId = createSessionId("runtime-mcp-plan-mode");
const eventStore = createTestSessionEventStore();
let modelCallCount = 0;
let mcpCallCount = 0;
let permissionRequestCount = 0;
const permissionBroker: PermissionBrokerPort = {
async requestPermission() {
permissionRequestCount++;
return {
decision: "deny",
reason: "permission broker should not be called for plan-mode MCP allow",
};
},
};
const mcpPort = createMockMcpPort({
connectConfiguredServers: async () => ({
statuses: {
local: {
status: "connected",
transport: "stdio",
toolCount: 1,
updatedAt: "now",
},
},
tools: [
{
serverName: "local",
toolName: "lookup",
inputSchema: {
type: "object",
properties: {
query: { type: "string" },
},
},
},
],
}),
callTool: async (request) => {
mcpCallCount++;
return {
content: [{ type: "text", text: `lookup:${request.arguments?.query}` }],
};
},
});
const runtime = new AgentRuntime(
sessionId,
{
mode: "plan",
mcp: {
enabled: true,
servers: {
local: {
type: "stdio",
command: "node",
args: ["server.js"],
},
},
},
},
{
eventStore,
mcpPort,
permissionBroker,
modelAdapter: {
async generateText(request: any) {
modelCallCount++;
if (modelCallCount === 1) {
expect(request.tools.map((tool: { name: string }) => tool.name)).toContain(
"mcp__local__lookup",
);
return {
finishReason: "tool-calls",
model: request.model,
providerMetadata: undefined,
text: "I will look this up.",
toolCalls: [
{
id: "mcp-lookup",
name: "mcp__local__lookup",
input: { query: "plan context" },
},
],
usage: {
inputTokens: 1,
outputTokens: 1,
totalTokens: 2,
},
};
}
expect(request.messages.some((message: any) => {
return message.role === "tool" && String(message.content).includes("lookup:plan context");
})).toBe(true);
return {
finishReason: "stop",
model: request.model,
providerMetadata: undefined,
text: "done",
usage: {
inputTokens: 1,
outputTokens: 1,
totalTokens: 2,
},
};
},
} as never,
},
);
const result = await runtime.executeTurn("use mcp while planning");
expect(result.response).toBe("done");
expect(mcpCallCount).toBe(1);
expect(permissionRequestCount).toBe(0);
});
同一 describe 内加入:
it("denies destructive MCP tools in plan mode before calling the MCP server", async () => {
const sessionId = createSessionId("runtime-mcp-plan-destructive");
const eventStore = createTestSessionEventStore();
let modelCallCount = 0;
let mcpCallCount = 0;
let secondRequest: any;
const mcpPort = createMockMcpPort({
connectConfiguredServers: async () => ({
statuses: {
device: {
status: "connected",
transport: "stdio",
toolCount: 1,
updatedAt: "now",
},
},
tools: [
{
serverName: "device",
toolName: "reset",
inputSchema: {
type: "object",
properties: {},
},
annotations: {
destructiveHint: true,
},
},
],
}),
callTool: async () => {
mcpCallCount++;
return { content: [{ type: "text", text: "should-not-run" }] };
},
});
const runtime = new AgentRuntime(
sessionId,
{
mode: "plan",
mcp: {
enabled: true,
servers: {
device: {
type: "stdio",
command: "node",
args: ["server.js"],
},
},
},
},
{
eventStore,
mcpPort,
modelAdapter: {
async generateText(request: any) {
modelCallCount++;
if (modelCallCount === 1) {
return {
finishReason: "tool-calls",
model: request.model,
providerMetadata: undefined,
text: "I will reset the device.",
toolCalls: [
{
id: "mcp-reset",
name: "mcp__device__reset",
input: {},
},
],
usage: {
inputTokens: 1,
outputTokens: 1,
totalTokens: 2,
},
};
}
secondRequest = request;
return {
finishReason: "stop",
model: request.model,
providerMetadata: undefined,
text: "done",
usage: {
inputTokens: 1,
outputTokens: 1,
totalTokens: 2,
},
};
},
} as never,
},
);
const result = await runtime.executeTurn("do not mutate while planning");
const toolMessage = secondRequest.messages.find((message: any) => message.role === "tool");
expect(result.response).toBe("done");
expect(mcpCallCount).toBe(0);
expect(toolMessage?.content).toContain("Plan mode only allows read-only, non-destructive tools");
});
Run:
pnpm --filter @zcode/core exec vitest run tests/mcp-runtime.test.ts
Expected:
Test Files 1 passed (1)
Files:
Interfaces:
Produces: 可交付验证结论。
[ ] Step 1: 跑 permission + MCP focused tests
Run:
pnpm --filter @zcode/core exec vitest run \
tests/permission-service.test.ts \
tests/mcp-tool-bridge.test.ts \
tests/mcp-runtime.test.ts
Expected:
Test Files 3 passed (3)
Run:
pnpm --filter @zcode/core exec vitest run tests/runtime-tool-loop.test.ts -t "continues later tool calls after a blocking permission denial"
Expected:
Test Files 1 passed (1)
Purpose:
确认拦截后后续只读工具仍能继续执行。
[ ] Step 3: 跑 core typecheck
Run:
pnpm --filter @zcode/core typecheck
Expected:
No TypeScript errors from @zcode/core
Run:
pnpm lint
Expected:
Lint passes, or only reports pre-existing unrelated warnings/errors.
If root lint reports unrelated existing failures, record exact file and message in final report. Do not fix unrelated files in this task.
Run:
pnpm typecheck
Expected:
Typecheck passes, or only reports pre-existing unrelated failures.
If root typecheck still fails on known unrelated desktop e2e Istanbul declarations, record the exact failure and keep this task scoped.
Files:
docs/plan-mode-approval-boundary.mdapps/zcode-cli/packages/core/src/permission/service.tsapps/zcode-cli/packages/core/tests/permission-service.test.tsapps/zcode-cli/packages/core/tests/mcp-tool-bridge.test.tsapps/zcode-cli/packages/core/tests/mcp-runtime.test.tsInterfaces:
Produces: 用户可 review 的最终说明。
[ ] Step 1: 检查没有误改 UI/protocol/registry
Run:
git diff --name-only
Expected files only:
docs/plan-mode-approval-boundary.md
apps/zcode-cli/packages/core/src/permission/service.ts
apps/zcode-cli/packages/core/tests/permission-service.test.ts
apps/zcode-cli/packages/core/tests/mcp-tool-bridge.test.ts
apps/zcode-cli/packages/core/tests/mcp-runtime.test.ts
docs/superpowers/plans/2026-07-07-plan-mode-mcp-permission.md
Run:
rg -n "startsWith\\(\\\"mcp__\\\"\\)|mode\\.plan\\.mcp|permissionName === \\\"mcp\\\"" apps/zcode-cli/packages/core/src/permission apps/zcode-cli/packages/core/tests
Expected:
permissionName === "mcp" 只出现在 helper 或测试断言相关语义里。mode.plan.mcp 出现在实现和测试中。不新增以 startsWith("mcp__") 作为 permission 主判断的代码。
[ ] Step 3: 检查 destructive 语义没有被覆盖
Run:
rg -n "destructive MCP|destructiveHint|mode.plan.nonReadOnly|mode.plan.mcp" apps/zcode-cli/packages/core/tests docs/plan-mode-approval-boundary.md
Expected:
permission-service.test.ts 包含 destructive MCP 拒绝。mcp-runtime.test.ts 包含 destructive MCP 不调用 server。
[ ] Step 4: 准备最终说明
最终说明必须包含:
仅当用户明确说“帮我提交吧”时提交。
建议 commit message:
fix(zcode-cli): allow non-destructive mcp tools in plan mode
提交前必须重新运行:
pnpm --filter @zcode/core exec vitest run \
tests/permission-service.test.ts \
tests/mcp-tool-bridge.test.ts \
tests/mcp-runtime.test.ts
pnpm --filter @zcode/core typecheck
pnpm lint
提交命令:
git add \
docs/plan-mode-approval-boundary.md \
apps/zcode-cli/packages/core/src/permission/service.ts \
apps/zcode-cli/packages/core/tests/permission-service.test.ts \
apps/zcode-cli/packages/core/tests/mcp-tool-bridge.test.ts \
apps/zcode-cli/packages/core/tests/mcp-runtime.test.ts \
docs/superpowers/plans/2026-07-07-plan-mode-mcp-permission.md
git commit -m "fix(zcode-cli): allow non-destructive mcp tools in plan mode"
PermissionToolCapability、ResolvedPermissionCapability.permissionName、PermissionService.checkPermission()、registerMcpTools()、AgentRuntime。destructiveHint 来自 MCP server annotation,当前实现只能识别显式 destructiveHint: true;缺失 annotation 的 MCP 会按非 destructive 处理,这是本计划明确接受的产品边界。