fix: MCP servers allowed in settings do not show up in /mcp command (#5324)

This commit is contained in:
laurentsimon 2025-08-07 16:42:17 -07:00 committed by GitHub
parent 494a10e7a7
commit 60362e0329
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 42 additions and 29 deletions

View File

@ -26,6 +26,7 @@ import {
ShellTool, ShellTool,
EditTool, EditTool,
WriteFileTool, WriteFileTool,
MCPServerConfig,
} from '@google/gemini-cli-core'; } from '@google/gemini-cli-core';
import { Settings } from './settings.js'; import { Settings } from './settings.js';
@ -388,12 +389,11 @@ export async function loadCliConfig(
if (!argv.allowedMcpServerNames) { if (!argv.allowedMcpServerNames) {
if (settings.allowMCPServers) { if (settings.allowMCPServers) {
const allowedNames = new Set(settings.allowMCPServers.filter(Boolean)); mcpServers = allowedMcpServers(
if (allowedNames.size > 0) { mcpServers,
mcpServers = Object.fromEntries( settings.allowMCPServers,
Object.entries(mcpServers).filter(([key]) => allowedNames.has(key)), blockedMcpServers,
); );
}
} }
if (settings.excludeMCPServers) { if (settings.excludeMCPServers) {
@ -407,29 +407,11 @@ export async function loadCliConfig(
} }
if (argv.allowedMcpServerNames) { if (argv.allowedMcpServerNames) {
const allowedNames = new Set(argv.allowedMcpServerNames.filter(Boolean)); mcpServers = allowedMcpServers(
if (allowedNames.size > 0) { mcpServers,
mcpServers = Object.fromEntries( argv.allowedMcpServerNames,
Object.entries(mcpServers).filter(([key, server]) => { blockedMcpServers,
const isAllowed = allowedNames.has(key); );
if (!isAllowed) {
blockedMcpServers.push({
name: key,
extensionName: server.extensionName || '',
});
}
return isAllowed;
}),
);
} else {
blockedMcpServers.push(
...Object.entries(mcpServers).map(([key, server]) => ({
name: key,
extensionName: server.extensionName || '',
})),
);
mcpServers = {};
}
} }
const sandboxConfig = await loadSandboxConfig(settings, argv); const sandboxConfig = await loadSandboxConfig(settings, argv);
@ -509,6 +491,37 @@ export async function loadCliConfig(
}); });
} }
function allowedMcpServers(
mcpServers: { [x: string]: MCPServerConfig },
allowMCPServers: string[],
blockedMcpServers: Array<{ name: string; extensionName: string }>,
) {
const allowedNames = new Set(allowMCPServers.filter(Boolean));
if (allowedNames.size > 0) {
mcpServers = Object.fromEntries(
Object.entries(mcpServers).filter(([key, server]) => {
const isAllowed = allowedNames.has(key);
if (!isAllowed) {
blockedMcpServers.push({
name: key,
extensionName: server.extensionName || '',
});
}
return isAllowed;
}),
);
} else {
blockedMcpServers.push(
...Object.entries(mcpServers).map(([key, server]) => ({
name: key,
extensionName: server.extensionName || '',
})),
);
mcpServers = {};
}
return mcpServers;
}
function mergeMcpServers(settings: Settings, extensions: Extension[]) { function mergeMcpServers(settings: Settings, extensions: Extension[]) {
const mcpServers = { ...(settings.mcpServers || {}) }; const mcpServers = { ...(settings.mcpServers || {}) };
for (const extension of extensions) { for (const extension of extensions) {