fix(mcp): add timeout to client.connect() calls (#6760)

pull/6773/head
Rhys Sullivan 2026-01-03 09:54:24 -08:00 committed by GitHub
parent 69d4ef038b
commit 586e7347bd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 6 additions and 3 deletions

View File

@ -26,6 +26,7 @@ import open from "open"
export namespace MCP {
const log = Log.create({ service: "mcp" })
const DEFAULT_TIMEOUT = 5000
export const ToolsChanged = BusEvent.define(
"mcp.tools.changed",
@ -294,13 +295,14 @@ export namespace MCP {
]
let lastError: Error | undefined
const connectTimeout = mcp.timeout ?? DEFAULT_TIMEOUT
for (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 = client
log.info("connected", { key, transport: name })
@ -370,12 +372,13 @@ export namespace MCP {
},
})
const connectTimeout = mcp.timeout ?? DEFAULT_TIMEOUT
try {
const client = new Client({
name: "opencode",
version: Installation.VERSION,
})
await client.connect(transport)
await withTimeout(client.connect(transport), connectTimeout)
registerNotificationHandlers(client, key)
mcpClient = client
status = {
@ -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
})