Use yargs array type for the allowedMcpServerNames flag instead of processing the list directly ourselves. (#3600)
This commit is contained in:
parent
017a0a6c86
commit
6c12f9e0d9
|
@ -527,7 +527,9 @@ describe('loadCliConfig with allowed-mcp-server-names', () => {
|
||||||
'node',
|
'node',
|
||||||
'script.js',
|
'script.js',
|
||||||
'--allowed-mcp-server-names',
|
'--allowed-mcp-server-names',
|
||||||
'server1,server3',
|
'server1',
|
||||||
|
'--allowed-mcp-server-names',
|
||||||
|
'server3',
|
||||||
];
|
];
|
||||||
const config = await loadCliConfig(baseSettings, [], 'test-session');
|
const config = await loadCliConfig(baseSettings, [], 'test-session');
|
||||||
expect(config.getMcpServers()).toEqual({
|
expect(config.getMcpServers()).toEqual({
|
||||||
|
@ -541,7 +543,9 @@ describe('loadCliConfig with allowed-mcp-server-names', () => {
|
||||||
'node',
|
'node',
|
||||||
'script.js',
|
'script.js',
|
||||||
'--allowed-mcp-server-names',
|
'--allowed-mcp-server-names',
|
||||||
'server1,server4',
|
'server1',
|
||||||
|
'--allowed-mcp-server-names',
|
||||||
|
'server4',
|
||||||
];
|
];
|
||||||
const config = await loadCliConfig(baseSettings, [], 'test-session');
|
const config = await loadCliConfig(baseSettings, [], 'test-session');
|
||||||
expect(config.getMcpServers()).toEqual({
|
expect(config.getMcpServers()).toEqual({
|
||||||
|
@ -549,10 +553,10 @@ describe('loadCliConfig with allowed-mcp-server-names', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should allow all MCP servers if the flag is an empty string', async () => {
|
it('should allow no MCP servers if the flag is provided but empty', async () => {
|
||||||
process.argv = ['node', 'script.js', '--allowed-mcp-server-names', ''];
|
process.argv = ['node', 'script.js', '--allowed-mcp-server-names', ''];
|
||||||
const config = await loadCliConfig(baseSettings, [], 'test-session');
|
const config = await loadCliConfig(baseSettings, [], 'test-session');
|
||||||
expect(config.getMcpServers()).toEqual(baseSettings.mcpServers);
|
expect(config.getMcpServers()).toEqual({});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -50,7 +50,7 @@ interface CliArgs {
|
||||||
telemetryTarget: string | undefined;
|
telemetryTarget: string | undefined;
|
||||||
telemetryOtlpEndpoint: string | undefined;
|
telemetryOtlpEndpoint: string | undefined;
|
||||||
telemetryLogPrompts: boolean | undefined;
|
telemetryLogPrompts: boolean | undefined;
|
||||||
allowedMcpServerNames: string | undefined;
|
allowedMcpServerNames: string[] | undefined;
|
||||||
extensions: string[] | undefined;
|
extensions: string[] | undefined;
|
||||||
listExtensions: boolean | undefined;
|
listExtensions: boolean | undefined;
|
||||||
}
|
}
|
||||||
|
@ -152,7 +152,8 @@ async function parseArguments(): Promise<CliArgs> {
|
||||||
default: false,
|
default: false,
|
||||||
})
|
})
|
||||||
.option('allowed-mcp-server-names', {
|
.option('allowed-mcp-server-names', {
|
||||||
type: 'string',
|
type: 'array',
|
||||||
|
string: true,
|
||||||
description: 'Allowed MCP server names',
|
description: 'Allowed MCP server names',
|
||||||
})
|
})
|
||||||
.option('extensions', {
|
.option('extensions', {
|
||||||
|
@ -247,9 +248,7 @@ export async function loadCliConfig(
|
||||||
const excludeTools = mergeExcludeTools(settings, activeExtensions);
|
const excludeTools = mergeExcludeTools(settings, activeExtensions);
|
||||||
|
|
||||||
if (argv.allowedMcpServerNames) {
|
if (argv.allowedMcpServerNames) {
|
||||||
const allowedNames = new Set(
|
const allowedNames = new Set(argv.allowedMcpServerNames.filter(Boolean));
|
||||||
argv.allowedMcpServerNames.split(',').filter(Boolean),
|
|
||||||
);
|
|
||||||
if (allowedNames.size > 0) {
|
if (allowedNames.size > 0) {
|
||||||
mcpServers = Object.fromEntries(
|
mcpServers = Object.fromEntries(
|
||||||
Object.entries(mcpServers).filter(([key]) => allowedNames.has(key)),
|
Object.entries(mcpServers).filter(([key]) => allowedNames.has(key)),
|
||||||
|
|
Loading…
Reference in New Issue