mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-20 08:47:44 +00:00
Summarize extensions and MCP servers on startup (#3977)
This commit is contained in:
@@ -17,7 +17,7 @@ describe('extensionsCommand', () => {
|
||||
mockContext = createMockCommandContext({
|
||||
services: {
|
||||
config: {
|
||||
getActiveExtensions: () => [],
|
||||
getExtensions: () => [],
|
||||
},
|
||||
},
|
||||
});
|
||||
@@ -36,13 +36,14 @@ describe('extensionsCommand', () => {
|
||||
|
||||
it('should list active extensions when they are found', async () => {
|
||||
const mockExtensions = [
|
||||
{ name: 'ext-one', version: '1.0.0' },
|
||||
{ name: 'ext-two', version: '2.1.0' },
|
||||
{ name: 'ext-one', version: '1.0.0', isActive: true },
|
||||
{ name: 'ext-two', version: '2.1.0', isActive: true },
|
||||
{ name: 'ext-three', version: '3.0.0', isActive: false },
|
||||
];
|
||||
mockContext = createMockCommandContext({
|
||||
services: {
|
||||
config: {
|
||||
getActiveExtensions: () => mockExtensions,
|
||||
getExtensions: () => mockExtensions,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
@@ -11,7 +11,9 @@ export const extensionsCommand: SlashCommand = {
|
||||
name: 'extensions',
|
||||
description: 'list active extensions',
|
||||
action: async (context: CommandContext): Promise<void> => {
|
||||
const activeExtensions = context.services.config?.getActiveExtensions();
|
||||
const activeExtensions = context.services.config
|
||||
?.getExtensions()
|
||||
.filter((ext) => ext.isActive);
|
||||
if (!activeExtensions || activeExtensions.length === 0) {
|
||||
context.ui.addItem(
|
||||
{
|
||||
|
||||
@@ -63,6 +63,7 @@ describe('mcpCommand', () => {
|
||||
let mockConfig: {
|
||||
getToolRegistry: ReturnType<typeof vi.fn>;
|
||||
getMcpServers: ReturnType<typeof vi.fn>;
|
||||
getBlockedMcpServers: ReturnType<typeof vi.fn>;
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
@@ -83,6 +84,7 @@ describe('mcpCommand', () => {
|
||||
getAllTools: vi.fn().mockReturnValue([]),
|
||||
}),
|
||||
getMcpServers: vi.fn().mockReturnValue({}),
|
||||
getBlockedMcpServers: vi.fn().mockReturnValue([]),
|
||||
};
|
||||
|
||||
mockContext = createMockCommandContext({
|
||||
@@ -419,6 +421,61 @@ describe('mcpCommand', () => {
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
it('should display the extension name for servers from extensions', async () => {
|
||||
const mockMcpServers = {
|
||||
server1: { command: 'cmd1', extensionName: 'my-extension' },
|
||||
};
|
||||
mockConfig.getMcpServers = vi.fn().mockReturnValue(mockMcpServers);
|
||||
|
||||
const result = await mcpCommand.action!(mockContext, '');
|
||||
|
||||
expect(isMessageAction(result)).toBe(true);
|
||||
if (isMessageAction(result)) {
|
||||
const message = result.content;
|
||||
expect(message).toContain('server1 (from my-extension)');
|
||||
}
|
||||
});
|
||||
|
||||
it('should display blocked MCP servers', async () => {
|
||||
mockConfig.getMcpServers = vi.fn().mockReturnValue({});
|
||||
const blockedServers = [
|
||||
{ name: 'blocked-server', extensionName: 'my-extension' },
|
||||
];
|
||||
mockConfig.getBlockedMcpServers = vi.fn().mockReturnValue(blockedServers);
|
||||
|
||||
const result = await mcpCommand.action!(mockContext, '');
|
||||
|
||||
expect(isMessageAction(result)).toBe(true);
|
||||
if (isMessageAction(result)) {
|
||||
const message = result.content;
|
||||
expect(message).toContain(
|
||||
'🔴 \u001b[1mblocked-server (from my-extension)\u001b[0m - Blocked',
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
it('should display both active and blocked servers correctly', async () => {
|
||||
const mockMcpServers = {
|
||||
server1: { command: 'cmd1', extensionName: 'my-extension' },
|
||||
};
|
||||
mockConfig.getMcpServers = vi.fn().mockReturnValue(mockMcpServers);
|
||||
const blockedServers = [
|
||||
{ name: 'blocked-server', extensionName: 'another-extension' },
|
||||
];
|
||||
mockConfig.getBlockedMcpServers = vi.fn().mockReturnValue(blockedServers);
|
||||
|
||||
const result = await mcpCommand.action!(mockContext, '');
|
||||
|
||||
expect(isMessageAction(result)).toBe(true);
|
||||
if (isMessageAction(result)) {
|
||||
const message = result.content;
|
||||
expect(message).toContain('server1 (from my-extension)');
|
||||
expect(message).toContain(
|
||||
'🔴 \u001b[1mblocked-server (from another-extension)\u001b[0m - Blocked',
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('schema functionality', () => {
|
||||
|
||||
@@ -49,8 +49,9 @@ const getMcpStatus = async (
|
||||
|
||||
const mcpServers = config.getMcpServers() || {};
|
||||
const serverNames = Object.keys(mcpServers);
|
||||
const blockedMcpServers = config.getBlockedMcpServers() || [];
|
||||
|
||||
if (serverNames.length === 0) {
|
||||
if (serverNames.length === 0 && blockedMcpServers.length === 0) {
|
||||
const docsUrl = 'https://goo.gle/gemini-cli-docs-mcp';
|
||||
if (process.env.SANDBOX && process.env.SANDBOX !== 'sandbox-exec') {
|
||||
return {
|
||||
@@ -118,9 +119,13 @@ const getMcpStatus = async (
|
||||
|
||||
// Get server description if available
|
||||
const server = mcpServers[serverName];
|
||||
let serverDisplayName = serverName;
|
||||
if (server.extensionName) {
|
||||
serverDisplayName += ` (from ${server.extensionName})`;
|
||||
}
|
||||
|
||||
// Format server header with bold formatting and status
|
||||
message += `${statusIndicator} \u001b[1m${serverName}\u001b[0m - ${statusText}`;
|
||||
message += `${statusIndicator} \u001b[1m${serverDisplayName}\u001b[0m - ${statusText}`;
|
||||
|
||||
// Add tool count with conditional messaging
|
||||
if (status === MCPServerStatus.CONNECTED) {
|
||||
@@ -192,6 +197,14 @@ const getMcpStatus = async (
|
||||
message += '\n';
|
||||
}
|
||||
|
||||
for (const server of blockedMcpServers) {
|
||||
let serverDisplayName = server.name;
|
||||
if (server.extensionName) {
|
||||
serverDisplayName += ` (from ${server.extensionName})`;
|
||||
}
|
||||
message += `🔴 \u001b[1m${serverDisplayName}\u001b[0m - Blocked\n\n`;
|
||||
}
|
||||
|
||||
// Add helpful tips when no arguments are provided
|
||||
if (showTips) {
|
||||
message += '\n';
|
||||
|
||||
Reference in New Issue
Block a user