fix: MCP servers allowed in settings do not show up in /mcp command (#5324)
This commit is contained in:
parent
494a10e7a7
commit
60362e0329
|
@ -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) {
|
||||||
|
|
Loading…
Reference in New Issue