The open source coding agent.
TypeScript
fix(mcp): add timeout to client.connect() calls (#6760)
Rhys Sullivan586e7347bd48
diff --git a/packages/opencode/src/mcp/index.ts b/packages/opencode/src/mcp/index.tsindex 322761c551e..4aa981727ee 100644--- a/packages/opencode/src/mcp/index.ts+++ b/packages/opencode/src/mcp/index.ts@@ -26,6 +26,7 @@ import open from "open"export namespace MCP {const log = Log.create({ service: "mcp" })+ const DEFAULT_TIMEOUT = 5000export const ToolsChanged = BusEvent.define("mcp.tools.changed",@@ -294,13 +295,14 @@ export namespace MCP {]let lastError: Error | undefined+ const connectTimeout = mcp.timeout ?? DEFAULT_TIMEOUTfor (const { name, transport } of transports) {try {const client = new Client({name: "opencode",version: Installation.VERSION,})- await client.connect(transport)+ await withTimeout(client.connect(transport), connectTimeout)registerNotificationHandlers(client, key)mcpClient = clientlog.info("connected", { key, transport: name })@@ -370,12 +372,13 @@ export namespace MCP {},})+ const connectTimeout = mcp.timeout ?? DEFAULT_TIMEOUTtry {const client = new Client({name: "opencode",version: Installation.VERSION,})- await client.connect(transport)+ await withTimeout(client.connect(transport), connectTimeout)registerNotificationHandlers(client, key)mcpClient = clientstatus = {@@ -409,7 +412,7 @@ export namespace MCP {}}- const result = await withTimeout(mcpClient.listTools(), mcp.timeout ?? 5000).catch((err) => {+ const result = await withTimeout(mcpClient.listTools(), mcp.timeout ?? DEFAULT_TIMEOUT).catch((err) => {log.error("failed to get tools from client", { key, error: err })return undefined})