mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-24 03:54:43 -07:00
feat(plan): implement support for MCP servers in Plan mode (#18229)
This commit is contained in:
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user