mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-22 19:14:33 -07:00
feat(core): add tool name validation in TOML policy files (#19281)
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
This commit is contained in:
@@ -69,6 +69,7 @@ import { debugLogger } from '../utils/debugLogger.js';
|
||||
import { type MessageBus } from '../confirmation-bus/message-bus.js';
|
||||
import { coreEvents } from '../utils/events.js';
|
||||
import type { ResourceRegistry } from '../resources/resource-registry.js';
|
||||
import { validateMcpPolicyToolNames } from '../policy/toml-loader.js';
|
||||
import {
|
||||
sanitizeEnvironment,
|
||||
type EnvironmentSanitizationConfig,
|
||||
@@ -221,6 +222,23 @@ export class McpClient implements McpProgressReporter {
|
||||
this.toolRegistry.registerTool(tool);
|
||||
}
|
||||
this.toolRegistry.sortTools();
|
||||
|
||||
// Validate MCP tool names in policy rules against discovered tools
|
||||
try {
|
||||
const discoveredToolNames = tools.map((t) => t.serverToolName);
|
||||
const policyRules = cliConfig.getPolicyEngine?.()?.getRules() ?? [];
|
||||
const warnings = validateMcpPolicyToolNames(
|
||||
this.serverName,
|
||||
discoveredToolNames,
|
||||
policyRules,
|
||||
);
|
||||
for (const warning of warnings) {
|
||||
coreEvents.emitFeedback('warning', warning);
|
||||
}
|
||||
} catch {
|
||||
// Policy engine may not be available in all contexts (e.g. tests).
|
||||
// Validation is best-effort; skip silently if unavailable.
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1577,6 +1595,9 @@ export interface McpContext {
|
||||
): void;
|
||||
setUserInteractedWithMcp?(): void;
|
||||
isTrustedFolder(): boolean;
|
||||
getPolicyEngine?(): {
|
||||
getRules(): ReadonlyArray<{ toolName?: string; source?: string }>;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user