summaryrefslogtreecommitdiff
path: root/packages/cli/src/ui/commands/mcpCommand.test.ts
diff options
context:
space:
mode:
authorRamón Medrano Llamas <[email protected]>2025-07-25 03:14:45 +0200
committerGitHub <[email protected]>2025-07-25 01:14:45 +0000
commit273e74c09da89492d16fc076cfbff4d043eafa4c (patch)
treed68076b1139ac909b43eb9ba402e62238044d8d2 /packages/cli/src/ui/commands/mcpCommand.test.ts
parente9ee686ab6c5c99d895d80951336613f248f6560 (diff)
feat: add /mcp refresh command (#4566)
Diffstat (limited to 'packages/cli/src/ui/commands/mcpCommand.test.ts')
-rw-r--r--packages/cli/src/ui/commands/mcpCommand.test.ts80
1 files changed, 80 insertions, 0 deletions
diff --git a/packages/cli/src/ui/commands/mcpCommand.test.ts b/packages/cli/src/ui/commands/mcpCommand.test.ts
index e52cb9df..2b8753a0 100644
--- a/packages/cli/src/ui/commands/mcpCommand.test.ts
+++ b/packages/cli/src/ui/commands/mcpCommand.test.ts
@@ -976,4 +976,84 @@ describe('mcpCommand', () => {
}
});
});
+
+ describe('refresh subcommand', () => {
+ it('should refresh the list of tools and display the status', async () => {
+ const mockToolRegistry = {
+ discoverMcpTools: vi.fn(),
+ getAllTools: vi.fn().mockReturnValue([]),
+ };
+ const mockGeminiClient = {
+ setTools: vi.fn(),
+ };
+
+ const context = createMockCommandContext({
+ services: {
+ config: {
+ getMcpServers: vi.fn().mockReturnValue({ server1: {} }),
+ getBlockedMcpServers: vi.fn().mockReturnValue([]),
+ getToolRegistry: vi.fn().mockResolvedValue(mockToolRegistry),
+ getGeminiClient: vi.fn().mockReturnValue(mockGeminiClient),
+ },
+ },
+ });
+
+ const refreshCommand = mcpCommand.subCommands?.find(
+ (cmd) => cmd.name === 'refresh',
+ );
+ expect(refreshCommand).toBeDefined();
+
+ const result = await refreshCommand!.action!(context, '');
+
+ expect(context.ui.addItem).toHaveBeenCalledWith(
+ {
+ type: 'info',
+ text: 'Refreshing MCP servers and tools...',
+ },
+ expect.any(Number),
+ );
+ expect(mockToolRegistry.discoverMcpTools).toHaveBeenCalled();
+ expect(mockGeminiClient.setTools).toHaveBeenCalled();
+
+ expect(isMessageAction(result)).toBe(true);
+ if (isMessageAction(result)) {
+ expect(result.messageType).toBe('info');
+ expect(result.content).toContain('Configured MCP servers:');
+ }
+ });
+
+ it('should show an error if config is not available', async () => {
+ const contextWithoutConfig = createMockCommandContext({
+ services: {
+ config: null,
+ },
+ });
+
+ const refreshCommand = mcpCommand.subCommands?.find(
+ (cmd) => cmd.name === 'refresh',
+ );
+ const result = await refreshCommand!.action!(contextWithoutConfig, '');
+
+ expect(result).toEqual({
+ type: 'message',
+ messageType: 'error',
+ content: 'Config not loaded.',
+ });
+ });
+
+ it('should show an error if tool registry is not available', async () => {
+ mockConfig.getToolRegistry = vi.fn().mockResolvedValue(undefined);
+
+ const refreshCommand = mcpCommand.subCommands?.find(
+ (cmd) => cmd.name === 'refresh',
+ );
+ const result = await refreshCommand!.action!(mockContext, '');
+
+ expect(result).toEqual({
+ type: 'message',
+ messageType: 'error',
+ content: 'Could not retrieve tool registry.',
+ });
+ });
+ });
});