Extensions MCP refactor (#12413)

This commit is contained in:
Jacob MacDonald
2025-11-04 07:51:18 -08:00
committed by GitHub
parent 2b77c1ded4
commit da4fa5ad75
28 changed files with 877 additions and 478 deletions

View File

@@ -295,6 +295,7 @@ describe('AppContainer State Management', () => {
getExtensions: vi.fn().mockReturnValue([]),
setRequestConsent: vi.fn(),
setRequestSetting: vi.fn(),
start: vi.fn(),
} as unknown as ExtensionManager);
vi.spyOn(mockConfig, 'getExtensionLoader').mockReturnValue(
mockExtensionManager,

View File

@@ -62,6 +62,7 @@ describe('mcpCommand', () => {
getBlockedMcpServers: ReturnType<typeof vi.fn>;
getPromptRegistry: ReturnType<typeof vi.fn>;
getGeminiClient: ReturnType<typeof vi.fn>;
getMcpClientManager: ReturnType<typeof vi.fn>;
};
beforeEach(() => {
@@ -88,6 +89,10 @@ describe('mcpCommand', () => {
getPromptsByServer: vi.fn().mockReturnValue([]),
}),
getGeminiClient: vi.fn(),
getMcpClientManager: vi.fn().mockImplementation(() => ({
getBlockedMcpServers: vi.fn(),
getMcpServers: vi.fn(),
})),
};
mockContext = createMockCommandContext({

View File

@@ -43,7 +43,7 @@ const authCommand: SlashCommand = {
};
}
const mcpServers = config.getMcpServers() || {};
const mcpServers = config.getMcpClientManager()?.getMcpServers() ?? {};
if (!serverName) {
// List servers that support OAuth
@@ -119,20 +119,20 @@ const authCommand: SlashCommand = {
);
// Trigger tool re-discovery to pick up authenticated server
const toolRegistry = config.getToolRegistry();
if (toolRegistry) {
const mcpClientManager = config.getMcpClientManager();
if (mcpClientManager) {
context.ui.addItem(
{
type: 'info',
text: `Re-discovering tools from '${serverName}'...`,
text: `Restarting MCP server '${serverName}'...`,
},
Date.now(),
);
await toolRegistry.discoverToolsForServer(serverName);
await mcpClientManager.restartServer(serverName);
}
// Update the client with the new tools
const geminiClient = config.getGeminiClient();
if (geminiClient) {
if (geminiClient?.isInitialized()) {
await geminiClient.setTools();
}
@@ -158,7 +158,7 @@ const authCommand: SlashCommand = {
const { config } = context.services;
if (!config) return [];
const mcpServers = config.getMcpServers() || {};
const mcpServers = config.getMcpClientManager()?.getMcpServers() || {};
return Object.keys(mcpServers).filter((name) =>
name.startsWith(partialArg),
);
@@ -188,9 +188,10 @@ const listAction = async (
};
}
const mcpServers = config.getMcpServers() || {};
const mcpServers = config.getMcpClientManager()?.getMcpServers() || {};
const serverNames = Object.keys(mcpServers);
const blockedMcpServers = config.getBlockedMcpServers() || [];
const blockedMcpServers =
config.getMcpClientManager()?.getBlockedMcpServers() || [];
const connectingServers = serverNames.filter(
(name) => getMCPServerStatus(name) === MCPServerStatus.CONNECTING,
@@ -299,12 +300,12 @@ const refreshCommand: SlashCommand = {
};
}
const toolRegistry = config.getToolRegistry();
if (!toolRegistry) {
const mcpClientManager = config.getMcpClientManager();
if (!mcpClientManager) {
return {
type: 'message',
messageType: 'error',
content: 'Could not retrieve tool registry.',
content: 'Could not retrieve mcp client manager.',
};
}
@@ -316,11 +317,11 @@ const refreshCommand: SlashCommand = {
Date.now(),
);
await toolRegistry.restartMcpServers();
await mcpClientManager.restart();
// Update the client with the new tools
const geminiClient = config.getGeminiClient();
if (geminiClient) {
if (geminiClient?.isInitialized()) {
await geminiClient.setTools();
}

View File

@@ -144,7 +144,10 @@ const createMockConfig = (overrides = {}) => ({
getDebugMode: vi.fn(() => false),
getAccessibility: vi.fn(() => ({})),
getMcpServers: vi.fn(() => ({})),
getBlockedMcpServers: vi.fn(() => []),
getMcpClientManager: vi.fn().mockImplementation(() => ({
getBlockedMcpServers: vi.fn(),
getMcpServers: vi.fn(),
})),
...overrides,
});

View File

@@ -101,8 +101,10 @@ export const Composer = () => {
ideContext={uiState.ideContextState}
geminiMdFileCount={uiState.geminiMdFileCount}
contextFileNames={contextFileNames}
mcpServers={config.getMcpServers()}
blockedMcpServers={config.getBlockedMcpServers()}
mcpServers={config.getMcpClientManager()?.getMcpServers() ?? {}}
blockedMcpServers={
config.getMcpClientManager()?.getBlockedMcpServers() ?? []
}
/>
)
)}

View File

@@ -5,15 +5,13 @@
*/
import { useEffect, useState } from 'react';
import { appEvents } from './../../utils/events.js';
import { AppEvent, appEvents } from './../../utils/events.js';
import { Box, Text } from 'ink';
import { useConfig } from '../contexts/ConfigContext.js';
import { type McpClient, MCPServerStatus } from '@google/gemini-cli-core';
import { GeminiSpinner } from './GeminiRespondingSpinner.js';
import { theme } from '../semantic-colors.js';
export const ConfigInitDisplay = () => {
const config = useConfig();
const [message, setMessage] = useState('Initializing...');
useEffect(() => {
@@ -31,11 +29,11 @@ export const ConfigInitDisplay = () => {
setMessage(`Connecting to MCP servers... (${connected}/${clients.size})`);
};
appEvents.on('mcp-client-update', onChange);
appEvents.on(AppEvent.McpClientUpdate, onChange);
return () => {
appEvents.off('mcp-client-update', onChange);
appEvents.off(AppEvent.McpClientUpdate, onChange);
};
}, [config]);
}, []);
return (
<Box marginTop={1}>