mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-20 16:57:46 +00:00
feat(cli): Prevent redundant opening of browser tabs when zero MCP servers are configured (#5367)
Co-authored-by: Allen Hutchison <adh@google.com>
This commit is contained in:
@@ -14,15 +14,10 @@ import {
|
|||||||
getMCPDiscoveryState,
|
getMCPDiscoveryState,
|
||||||
DiscoveredMCPTool,
|
DiscoveredMCPTool,
|
||||||
} from '@google/gemini-cli-core';
|
} from '@google/gemini-cli-core';
|
||||||
import open from 'open';
|
|
||||||
import { MessageActionReturn } from './types.js';
|
import { MessageActionReturn } from './types.js';
|
||||||
import { Type, CallableTool } from '@google/genai';
|
import { Type, CallableTool } from '@google/genai';
|
||||||
|
|
||||||
// Mock external dependencies
|
|
||||||
vi.mock('open', () => ({
|
|
||||||
default: vi.fn(),
|
|
||||||
}));
|
|
||||||
|
|
||||||
vi.mock('@google/gemini-cli-core', async (importOriginal) => {
|
vi.mock('@google/gemini-cli-core', async (importOriginal) => {
|
||||||
const actual =
|
const actual =
|
||||||
await importOriginal<typeof import('@google/gemini-cli-core')>();
|
await importOriginal<typeof import('@google/gemini-cli-core')>();
|
||||||
@@ -144,30 +139,15 @@ describe('mcpCommand', () => {
|
|||||||
mockConfig.getMcpServers = vi.fn().mockReturnValue({});
|
mockConfig.getMcpServers = vi.fn().mockReturnValue({});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should display a message with a URL when no MCP servers are configured in a sandbox', async () => {
|
it('should display a message with a URL when no MCP servers are configured', async () => {
|
||||||
process.env.SANDBOX = 'sandbox';
|
|
||||||
|
|
||||||
const result = await mcpCommand.action!(mockContext, '');
|
const result = await mcpCommand.action!(mockContext, '');
|
||||||
|
|
||||||
expect(result).toEqual({
|
expect(result).toEqual({
|
||||||
type: 'message',
|
type: 'message',
|
||||||
messageType: 'info',
|
messageType: 'info',
|
||||||
content:
|
content:
|
||||||
'No MCP servers configured. Please open the following URL in your browser to view documentation:\nhttps://goo.gle/gemini-cli-docs-mcp',
|
'No MCP servers configured. Please view MCP documentation in your browser: https://goo.gle/gemini-cli-docs-mcp or use the cli /docs command',
|
||||||
});
|
});
|
||||||
expect(open).not.toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should display a message and open a URL when no MCP servers are configured outside a sandbox', async () => {
|
|
||||||
const result = await mcpCommand.action!(mockContext, '');
|
|
||||||
|
|
||||||
expect(result).toEqual({
|
|
||||||
type: 'message',
|
|
||||||
messageType: 'info',
|
|
||||||
content:
|
|
||||||
'No MCP servers configured. Opening documentation in your browser: https://goo.gle/gemini-cli-docs-mcp',
|
|
||||||
});
|
|
||||||
expect(open).toHaveBeenCalledWith('https://goo.gle/gemini-cli-docs-mcp');
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ import {
|
|||||||
mcpServerRequiresOAuth,
|
mcpServerRequiresOAuth,
|
||||||
getErrorMessage,
|
getErrorMessage,
|
||||||
} from '@google/gemini-cli-core';
|
} from '@google/gemini-cli-core';
|
||||||
import open from 'open';
|
|
||||||
|
|
||||||
const COLOR_GREEN = '\u001b[32m';
|
const COLOR_GREEN = '\u001b[32m';
|
||||||
const COLOR_YELLOW = '\u001b[33m';
|
const COLOR_YELLOW = '\u001b[33m';
|
||||||
@@ -60,21 +59,11 @@ const getMcpStatus = async (
|
|||||||
|
|
||||||
if (serverNames.length === 0 && blockedMcpServers.length === 0) {
|
if (serverNames.length === 0 && blockedMcpServers.length === 0) {
|
||||||
const docsUrl = 'https://goo.gle/gemini-cli-docs-mcp';
|
const docsUrl = 'https://goo.gle/gemini-cli-docs-mcp';
|
||||||
if (process.env.SANDBOX && process.env.SANDBOX !== 'sandbox-exec') {
|
return {
|
||||||
return {
|
type: 'message',
|
||||||
type: 'message',
|
messageType: 'info',
|
||||||
messageType: 'info',
|
content: `No MCP servers configured. Please view MCP documentation in your browser: ${docsUrl} or use the cli /docs command`,
|
||||||
content: `No MCP servers configured. Please open the following URL in your browser to view documentation:\n${docsUrl}`,
|
};
|
||||||
};
|
|
||||||
} else {
|
|
||||||
// Open the URL in the browser
|
|
||||||
await open(docsUrl);
|
|
||||||
return {
|
|
||||||
type: 'message',
|
|
||||||
messageType: 'info',
|
|
||||||
content: `No MCP servers configured. Opening documentation in your browser: ${docsUrl}`,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if any servers are still connecting
|
// Check if any servers are still connecting
|
||||||
|
|||||||
Reference in New Issue
Block a user