feat(plan): implement support for MCP servers in Plan mode (#18229)

This commit is contained in:
Adib234
2026-02-05 16:37:28 -05:00
committed by GitHub
parent 00a739e84c
commit fe975da91e
8 changed files with 256 additions and 9 deletions
+16
View File
@@ -32,6 +32,7 @@ import {
PromptListChangedNotificationSchema,
type Tool as McpTool,
} from '@modelcontextprotocol/sdk/types.js';
import { ApprovalMode, PolicyDecision } from '../policy/types.js';
import { parse } from 'shell-quote';
import type {
Config,
@@ -1028,6 +1029,9 @@ export async function discoverTools(
mcpServerConfig.timeout ?? MCP_DEFAULT_TIMEOUT_MSEC,
);
// Extract readOnlyHint from annotations
const isReadOnly = toolDef.annotations?.readOnlyHint === true;
const tool = new DiscoveredMCPTool(
mcpCallableTool,
mcpServerName,
@@ -1036,12 +1040,24 @@ export async function discoverTools(
toolDef.inputSchema ?? { type: 'object', properties: {} },
messageBus,
mcpServerConfig.trust,
isReadOnly,
undefined,
cliConfig,
mcpServerConfig.extension?.name,
mcpServerConfig.extension?.id,
);
// If the tool is read-only, allow it in Plan mode
if (isReadOnly) {
cliConfig.getPolicyEngine().addRule({
toolName: tool.getFullyQualifiedName(),
decision: PolicyDecision.ASK_USER,
priority: 50, // Match priority of built-in plan tools
modes: [ApprovalMode.PLAN],
source: `MCP Annotation (readOnlyHint) - ${mcpServerName}`,
});
}
discoveredTools.push(tool);
} catch (error) {
coreEvents.emitFeedback(