mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-01 08:51:11 -07:00
fix(core): await MCP initialization in non-interactive mode (#17390)
This commit is contained in:
@@ -274,10 +274,11 @@ describe('Server Config (config.ts)', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('should not await MCP initialization', async () => {
|
||||
it('should await MCP initialization in non-interactive mode', async () => {
|
||||
const config = new Config({
|
||||
...baseParams,
|
||||
checkpointing: false,
|
||||
// interactive defaults to false
|
||||
});
|
||||
|
||||
const { McpClientManager } = await import(
|
||||
@@ -295,7 +296,33 @@ describe('Server Config (config.ts)', () => {
|
||||
|
||||
await config.initialize();
|
||||
|
||||
// Should return immediately, before MCP finishes (50ms delay)
|
||||
// Should wait for MCP to finish
|
||||
expect(mcpStarted).toBe(true);
|
||||
});
|
||||
|
||||
it('should not await MCP initialization in interactive mode', async () => {
|
||||
const config = new Config({
|
||||
...baseParams,
|
||||
checkpointing: false,
|
||||
interactive: true,
|
||||
});
|
||||
|
||||
const { McpClientManager } = await import(
|
||||
'../tools/mcp-client-manager.js'
|
||||
);
|
||||
let mcpStarted = false;
|
||||
|
||||
(McpClientManager as unknown as Mock).mockImplementation(() => ({
|
||||
startConfiguredMcpServers: vi.fn().mockImplementation(async () => {
|
||||
await new Promise((resolve) => setTimeout(resolve, 50));
|
||||
mcpStarted = true;
|
||||
}),
|
||||
getMcpInstructions: vi.fn(),
|
||||
}));
|
||||
|
||||
await config.initialize();
|
||||
|
||||
// Should return immediately, before MCP finishes
|
||||
expect(mcpStarted).toBe(false);
|
||||
|
||||
// Wait for it to eventually finish to avoid open handles
|
||||
|
||||
@@ -815,13 +815,21 @@ export class Config {
|
||||
);
|
||||
// We do not await this promise so that the CLI can start up even if
|
||||
// MCP servers are slow to connect.
|
||||
Promise.all([
|
||||
const mcpInitialization = Promise.allSettled([
|
||||
this.mcpClientManager.startConfiguredMcpServers(),
|
||||
this.getExtensionLoader().start(this),
|
||||
]).catch((error) => {
|
||||
debugLogger.error('Error initializing MCP clients:', error);
|
||||
]).then((results) => {
|
||||
for (const result of results) {
|
||||
if (result.status === 'rejected') {
|
||||
debugLogger.error('Error initializing MCP clients:', result.reason);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (!this.interactive) {
|
||||
await mcpInitialization;
|
||||
}
|
||||
|
||||
if (this.skillsSupport) {
|
||||
this.getSkillManager().setAdminSettings(this.adminSkillsEnabled);
|
||||
if (this.adminSkillsEnabled) {
|
||||
|
||||
Reference in New Issue
Block a user