diff --git a/packages/cli/src/ui/hooks/slashCommandProcessor.test.ts b/packages/cli/src/ui/hooks/slashCommandProcessor.test.ts index 31105509..d411a2da 100644 --- a/packages/cli/src/ui/hooks/slashCommandProcessor.test.ts +++ b/packages/cli/src/ui/hooks/slashCommandProcessor.test.ts @@ -754,7 +754,8 @@ Add any other context about the problem here. expect(commandResult).toBe(true); }); - it('should display a message when no MCP servers are configured', async () => { + it('should display a message with a URL when no MCP servers are configured in a sandbox', async () => { + process.env.SANDBOX = 'sandbox'; mockConfig = { ...mockConfig, getToolRegistry: vi.fn().mockResolvedValue({ @@ -773,11 +774,39 @@ Add any other context about the problem here. 2, expect.objectContaining({ type: MessageType.INFO, - text: 'No MCP servers configured.', + text: `No MCP servers configured. Please open the following URL in your browser to view documentation:\nhttps://goo.gle/gemini-cli-docs-mcp`, }), expect.any(Number), ); expect(commandResult).toBe(true); + delete process.env.SANDBOX; + }); + + it('should display a message and open a URL when no MCP servers are configured outside a sandbox', async () => { + mockConfig = { + ...mockConfig, + getToolRegistry: vi.fn().mockResolvedValue({ + getToolsByServer: vi.fn().mockReturnValue([]), + }), + getMcpServers: vi.fn().mockReturnValue({}), + } as unknown as Config; + + const { handleSlashCommand } = getProcessor(); + let commandResult: SlashCommandActionReturn | boolean = false; + await act(async () => { + commandResult = await handleSlashCommand('/mcp'); + }); + + expect(mockAddItem).toHaveBeenNthCalledWith( + 2, + expect.objectContaining({ + type: MessageType.INFO, + text: 'No MCP servers configured. Opening documentation in your browser: https://goo.gle/gemini-cli-docs-mcp', + }), + expect.any(Number), + ); + expect(open).toHaveBeenCalledWith('https://goo.gle/gemini-cli-docs-mcp'); + expect(commandResult).toBe(true); }); it('should display configured MCP servers with status indicators and their tools', async () => { diff --git a/packages/cli/src/ui/hooks/slashCommandProcessor.ts b/packages/cli/src/ui/hooks/slashCommandProcessor.ts index 2bc84a10..397c6e3c 100644 --- a/packages/cli/src/ui/hooks/slashCommandProcessor.ts +++ b/packages/cli/src/ui/hooks/slashCommandProcessor.ts @@ -291,11 +291,21 @@ export const useSlashCommandProcessor = ( const serverNames = Object.keys(mcpServers); if (serverNames.length === 0) { - addMessage({ - type: MessageType.INFO, - content: 'No MCP servers configured.', - timestamp: new Date(), - }); + const docsUrl = 'https://goo.gle/gemini-cli-docs-mcp'; + if (process.env.SANDBOX && process.env.SANDBOX !== 'sandbox-exec') { + addMessage({ + type: MessageType.INFO, + content: `No MCP servers configured. Please open the following URL in your browser to view documentation:\n${docsUrl}`, + timestamp: new Date(), + }); + } else { + addMessage({ + type: MessageType.INFO, + content: `No MCP servers configured. Opening documentation in your browser: ${docsUrl}`, + timestamp: new Date(), + }); + await open(docsUrl); + } return; }