Add support for running available commands prior to MCP servers loading (#15596)

This commit is contained in:
Adib234
2026-01-15 15:33:16 -05:00
committed by GitHub
parent 8a627d6c9a
commit 1e8f87fbdf
7 changed files with 230 additions and 8 deletions

View File

@@ -28,6 +28,9 @@ import {
ToolConfirmationOutcome,
Storage,
IdeClient,
addMCPStatusChangeListener,
removeMCPStatusChangeListener,
MCPDiscoveryState,
} from '@google/gemini-cli-core';
import { useSessionStats } from '../contexts/SessionContext.js';
import type {
@@ -269,6 +272,10 @@ export const useSlashCommandProcessor = (
ideClient.addStatusChangeListener(listener);
})();
// Listen for MCP server status changes (e.g. connection, discovery completion)
// to reload slash commands (since they may include MCP prompts).
addMCPStatusChangeListener(listener);
// TODO: Ideally this would happen more directly inside the ExtensionLoader,
// but the CommandService today is not conducive to that since it isn't a
// long lived service but instead gets fully re-created based on reload
@@ -289,6 +296,7 @@ export const useSlashCommandProcessor = (
const ideClient = await IdeClient.getInstance();
ideClient.removeStatusChangeListener(listener);
})();
removeMCPStatusChangeListener(listener);
appEvents.off('extensionsStarting', extensionEventListener);
appEvents.off('extensionsStopping', extensionEventListener);
};
@@ -572,9 +580,16 @@ export const useSlashCommandProcessor = (
}
}
const isMcpLoading =
config?.getMcpClientManager()?.getDiscoveryState() ===
MCPDiscoveryState.IN_PROGRESS;
const errorMessage = isMcpLoading
? `Unknown command: ${trimmed}. Command might have been from an MCP server but MCP servers are not done loading.`
: `Unknown command: ${trimmed}`;
addMessage({
type: MessageType.ERROR,
content: `Unknown command: ${trimmed}`,
content: errorMessage,
timestamp: new Date(),
});