mcp load fails won't crash config

This commit is contained in:
Dallin Romney 2025-03-12 17:47:05 -07:00
parent 7c9c6b0806
commit 283f7b4865
2 changed files with 50 additions and 34 deletions

View file

@ -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);
}
},
) || [],

View file

@ -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);
}) ?? [],
);