diff --git a/core/config/load.ts b/core/config/load.ts index 3636b4bf8..5abb3fd5e 100644 --- a/core/config/load.ts +++ b/core/config/load.ts @@ -539,18 +539,21 @@ async function intermediateToFinalConfig( // Apply MCP if specified const mcpManager = MCPManagerSingleton.getInstance(); if (config.experimental?.modelContextProtocolServers) { - await Promise.all( + const abortController = new AbortController(); + const mcpConnectionTimeout = setTimeout( + () => abortController.abort(), + 4000, + ); + + await Promise.allSettled( config.experimental.modelContextProtocolServers?.map( async (server, index) => { - const mcpId = index.toString(); - const mcpConnection = mcpManager.createConnection(mcpId, server); - if (!mcpConnection) { - return; - } - - const abortController = new AbortController(); - try { + const mcpId = index.toString(); + const mcpConnection = mcpManager.createConnection(mcpId, server); + if (!mcpConnection) { + return; + } const mcpError = await mcpConnection.modifyConfig( continueConfig, mcpId, @@ -561,14 +564,21 @@ async function intermediateToFinalConfig( if (mcpError) { errors.push(mcpError); } - } catch (e: any) { + } catch (e) { + let errorMessage = "Failed to load MCP server"; + if (e instanceof Error) { + if (e.name === "AbortError") { + errorMessage += ": connection timed out"; + } else { + errorMessage += ": " + e.message; + } + } errors.push({ fatal: false, - message: `Failed to load MCP server: ${e.message}`, + message: errorMessage, }); - if (e.name !== "AbortError") { - throw e; - } + } finally { + clearTimeout(mcpConnectionTimeout); } }, ) || [], diff --git a/core/config/yaml/loadYaml.ts b/core/config/yaml/loadYaml.ts index 352f2349f..b0cabac3b 100644 --- a/core/config/yaml/loadYaml.ts +++ b/core/config/yaml/loadYaml.ts @@ -331,27 +331,27 @@ async function configYamlToContinueConfig( // Apply MCP if specified const mcpManager = MCPManagerSingleton.getInstance(); - await Promise.all( + await Promise.allSettled( config.mcpServers?.map(async (server) => { - const mcpId = server.name; - const mcpConnection = mcpManager.createConnection(mcpId, { - transport: { - type: "stdio", - args: [], - ...server, - }, - }); - if (!mcpConnection) { - return; - } - const abortController = new AbortController(); const mcpConnectionTimeout = setTimeout( () => abortController.abort(), - 5000, + 4000, ); try { + const mcpId = server.name; + const mcpConnection = mcpManager.createConnection(mcpId, { + transport: { + type: "stdio", + args: [], + ...server, + }, + }); + if (!mcpConnection) { + return; + } + const mcpError = await mcpConnection.modifyConfig( continueConfig, mcpId, @@ -362,16 +362,22 @@ async function configYamlToContinueConfig( if (mcpError) { errors.push(mcpError); } - } catch (e: any) { + } catch (e) { + let errorMessage = `Failed to load MCP server ${server.name}`; + if (e instanceof Error) { + if (e.name === "AbortError") { + errorMessage += ": connection timed out"; + } else { + errorMessage += ": " + e.message; + } + } errors.push({ fatal: false, - message: `Failed to load MCP server: ${e.message}`, + message: errorMessage, }); - if (e.name !== "AbortError") { - throw e; - } + } finally { + clearTimeout(mcpConnectionTimeout); } - clearTimeout(mcpConnectionTimeout); }) ?? [], );