summaryrefslogtreecommitdiff
path: root/packages/cli/src/commands/mcp.test.ts
diff options
context:
space:
mode:
authorJack Wotherspoon <[email protected]>2025-08-06 11:52:29 -0400
committerGitHub <[email protected]>2025-08-06 15:52:29 +0000
commitca4c745e3b620e3ac4eca24b610cc7b936c0a50d (patch)
treeeb1b9cfb46bd4fa2e7f9631828b0704df1050eb7 /packages/cli/src/commands/mcp.test.ts
parentb38f377c9a2672e88dd15119b38d908c0f00b54a (diff)
feat(mcp): add `gemini mcp` commands for `add`, `remove` and `list` (#5481)
Diffstat (limited to 'packages/cli/src/commands/mcp.test.ts')
-rw-r--r--packages/cli/src/commands/mcp.test.ts55
1 files changed, 55 insertions, 0 deletions
diff --git a/packages/cli/src/commands/mcp.test.ts b/packages/cli/src/commands/mcp.test.ts
new file mode 100644
index 00000000..b4e9980c
--- /dev/null
+++ b/packages/cli/src/commands/mcp.test.ts
@@ -0,0 +1,55 @@
+/**
+ * @license
+ * Copyright 2025 Google LLC
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+import { describe, it, expect, vi } from 'vitest';
+import { mcpCommand } from './mcp.js';
+import { type Argv } from 'yargs';
+import yargs from 'yargs';
+
+describe('mcp command', () => {
+ it('should have correct command definition', () => {
+ expect(mcpCommand.command).toBe('mcp');
+ expect(mcpCommand.describe).toBe('Manage MCP servers');
+ expect(typeof mcpCommand.builder).toBe('function');
+ expect(typeof mcpCommand.handler).toBe('function');
+ });
+
+ it('should have exactly one option (help flag)', () => {
+ // Test to ensure that the global 'gemini' flags are not added to the mcp command
+ const yargsInstance = yargs();
+ const builtYargs = mcpCommand.builder(yargsInstance);
+ const options = builtYargs.getOptions();
+
+ // Should have exactly 1 option (help flag)
+ expect(Object.keys(options.key).length).toBe(1);
+ expect(options.key).toHaveProperty('help');
+ });
+
+ it('should register add, remove, and list subcommands', () => {
+ const mockYargs = {
+ command: vi.fn().mockReturnThis(),
+ demandCommand: vi.fn().mockReturnThis(),
+ version: vi.fn().mockReturnThis(),
+ };
+
+ mcpCommand.builder(mockYargs as unknown as Argv);
+
+ expect(mockYargs.command).toHaveBeenCalledTimes(3);
+
+ // Verify that the specific subcommands are registered
+ const commandCalls = mockYargs.command.mock.calls;
+ const commandNames = commandCalls.map((call) => call[0].command);
+
+ expect(commandNames).toContain('add <name> <commandOrUrl> [args...]');
+ expect(commandNames).toContain('remove <name>');
+ expect(commandNames).toContain('list');
+
+ expect(mockYargs.demandCommand).toHaveBeenCalledWith(
+ 1,
+ 'You need at least one command before continuing.',
+ );
+ });
+});