fix(core): await MCP initialization in non-interactive mode (#17390)

This commit is contained in:
Ratish P
2026-01-23 22:51:47 +05:30
committed by GitHub
parent 488d5fc439
commit 4fc3ebb930
2 changed files with 40 additions and 5 deletions

View File

@@ -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

View File

@@ -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) {