From 794de1b197211397f611ffc853424771e560afbe Mon Sep 17 00:00:00 2001 From: "continue[bot]" <230936708+continue[bot]@users.noreply.github.com> Date: Mon, 3 Nov 2025 14:46:03 -0800 Subject: [PATCH] Throw error and exit on MCP failure in headless mode (#8559) In headless/CLI mode, when an MCP server fails to load, the process now throws an error and exits rather than silently continuing. This provides clear feedback to users about configuration issues. Changes: - Track headless mode flag in MCPService - Throw errors on MCP connection failures in headless mode - Throw errors when MCP tools/prompts fail to load in headless mode - Aggregate and report all MCP failures after connection attempts Fixes CON-4568 Generated with [Continue](https://continue.dev) Co-authored-by: continue[bot] Co-authored-by: Continue --- extensions/cli/src/services/MCPService.ts | 40 +++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/extensions/cli/src/services/MCPService.ts b/extensions/cli/src/services/MCPService.ts index 15e30e50c..62f9e37dd 100644 --- a/extensions/cli/src/services/MCPService.ts +++ b/extensions/cli/src/services/MCPService.ts @@ -50,6 +50,7 @@ export class MCPService private connections: Map = new Map(); private assistant: AssistantConfig | null = null; private isShuttingDown = false; + private isHeadless = false; getDependencies(): string[] { return [SERVICE_NAMES.CONFIG]; @@ -77,6 +78,9 @@ export class MCPService serverCount: assistant.mcpServers?.length || 0, }); + // Store headless mode flag + this.isHeadless = waitForConnections; + await this.shutdownConnections(); this.assistant = assistant; @@ -103,6 +107,19 @@ export class MCPService ); if (waitForConnections) { await connectionInit; + + // In headless mode, throw error if any MCP server failed to connect + const failedConnections = Array.from(this.connections.values()).filter( + (c) => c.status === "error", + ); + if (failedConnections.length > 0) { + const errorMessages = failedConnections.map( + (c) => `${c.config?.name}: ${c.error}`, + ); + throw new Error( + `MCP server(s) failed to load in headless mode:\n${errorMessages.join("\n")}`, + ); + } } else { this.updateState(); } @@ -259,6 +276,13 @@ export class MCPService name: serverName, error: errorMessage, }); + + // In headless mode, throw error on capability failures + if (this.isHeadless) { + throw new Error( + `Failed to load prompts from MCP server ${serverName}: ${errorMessage}`, + ); + } } } @@ -276,18 +300,30 @@ export class MCPService name: serverName, error: errorMessage, }); + + // In headless mode, throw error on capability failures + if (this.isHeadless) { + throw new Error( + `Failed to load tools from MCP server ${serverName}: ${errorMessage}`, + ); + } } } - logger.debug("MCP server restarted successfully", { name: serverName }); + logger.debug("MCP server connected successfully", { name: serverName }); } catch (error) { const errorMessage = getErrorString(error); connection.status = "error"; connection.error = errorMessage; - logger.error("Failed to restart MCP server", { + logger.error("Failed to connect to MCP server", { name: serverName, error: errorMessage, }); + + // In headless mode, re-throw the error to fail fast + if (this.isHeadless) { + throw error; + } } this.updateState();