fix: improve robustness of `gemini mcp add` command (#6332)
This commit is contained in:
parent
f5a5cdd973
commit
31b4c76a6b
|
@ -85,4 +85,38 @@ describe('mcp add command', () => {
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should handle MCP server args with -- separator', async () => {
|
||||||
|
await parser.parseAsync(
|
||||||
|
'add my-server npx -- -y http://example.com/some-package',
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(mockSetValue).toHaveBeenCalledWith(
|
||||||
|
SettingScope.Workspace,
|
||||||
|
'mcpServers',
|
||||||
|
{
|
||||||
|
'my-server': {
|
||||||
|
command: 'npx',
|
||||||
|
args: ['-y', 'http://example.com/some-package'],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should handle unknown options as MCP server args', async () => {
|
||||||
|
await parser.parseAsync(
|
||||||
|
'add test-server npx -y http://example.com/some-package',
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(mockSetValue).toHaveBeenCalledWith(
|
||||||
|
SettingScope.Workspace,
|
||||||
|
'mcpServers',
|
||||||
|
{
|
||||||
|
'test-server': {
|
||||||
|
command: 'npx',
|
||||||
|
args: ['-y', 'http://example.com/some-package'],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -130,6 +130,10 @@ export const addCommand: CommandModule = {
|
||||||
builder: (yargs) =>
|
builder: (yargs) =>
|
||||||
yargs
|
yargs
|
||||||
.usage('Usage: gemini mcp add [options] <name> <commandOrUrl> [args...]')
|
.usage('Usage: gemini mcp add [options] <name> <commandOrUrl> [args...]')
|
||||||
|
.parserConfiguration({
|
||||||
|
'unknown-options-as-args': true, // Pass unknown options as server args
|
||||||
|
'populate--': true, // Populate server args after -- separator
|
||||||
|
})
|
||||||
.positional('name', {
|
.positional('name', {
|
||||||
describe: 'Name of the server',
|
describe: 'Name of the server',
|
||||||
type: 'string',
|
type: 'string',
|
||||||
|
@ -189,6 +193,13 @@ export const addCommand: CommandModule = {
|
||||||
describe: 'A comma-separated list of tools to exclude',
|
describe: 'A comma-separated list of tools to exclude',
|
||||||
type: 'array',
|
type: 'array',
|
||||||
string: true,
|
string: true,
|
||||||
|
})
|
||||||
|
.middleware((argv) => {
|
||||||
|
// Handle -- separator args as server args if present
|
||||||
|
if (argv['--']) {
|
||||||
|
const existingArgs = (argv.args as Array<string | number>) || [];
|
||||||
|
argv.args = [...existingArgs, ...(argv['--'] as string[])];
|
||||||
|
}
|
||||||
}),
|
}),
|
||||||
handler: async (argv) => {
|
handler: async (argv) => {
|
||||||
await addMcpServer(
|
await addMcpServer(
|
||||||
|
|
Loading…
Reference in New Issue