summaryrefslogtreecommitdiff
path: root/packages/cli/src
diff options
context:
space:
mode:
authorlaurentsimon <[email protected]>2025-08-07 16:42:17 -0700
committerGitHub <[email protected]>2025-08-07 23:42:17 +0000
commit60362e0329febb8811f37d7f68f00843dd51e1ed (patch)
tree5761edd9d1ff5364b196d3fb2a385f4d1329fb2d /packages/cli/src
parent494a10e7a7d31233f5d8cb0db1235bd432421d87 (diff)
fix: MCP servers allowed in settings do not show up in /mcp command (#5324)
Diffstat (limited to 'packages/cli/src')
-rw-r--r--packages/cli/src/config/config.ts71
1 files changed, 42 insertions, 29 deletions
diff --git a/packages/cli/src/config/config.ts b/packages/cli/src/config/config.ts
index d142bd12..400d7432 100644
--- a/packages/cli/src/config/config.ts
+++ b/packages/cli/src/config/config.ts
@@ -26,6 +26,7 @@ import {
ShellTool,
EditTool,
WriteFileTool,
+ MCPServerConfig,
} from '@google/gemini-cli-core';
import { Settings } from './settings.js';
@@ -388,12 +389,11 @@ export async function loadCliConfig(
if (!argv.allowedMcpServerNames) {
if (settings.allowMCPServers) {
- const allowedNames = new Set(settings.allowMCPServers.filter(Boolean));
- if (allowedNames.size > 0) {
- mcpServers = Object.fromEntries(
- Object.entries(mcpServers).filter(([key]) => allowedNames.has(key)),
- );
- }
+ mcpServers = allowedMcpServers(
+ mcpServers,
+ settings.allowMCPServers,
+ blockedMcpServers,
+ );
}
if (settings.excludeMCPServers) {
@@ -407,29 +407,11 @@ export async function loadCliConfig(
}
if (argv.allowedMcpServerNames) {
- const allowedNames = new Set(argv.allowedMcpServerNames.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 = {};
- }
+ mcpServers = allowedMcpServers(
+ mcpServers,
+ argv.allowedMcpServerNames,
+ blockedMcpServers,
+ );
}
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[]) {
const mcpServers = { ...(settings.mcpServers || {}) };
for (const extension of extensions) {