@@ -26,6 +26,7 @@ import open from "open"
2626
2727export namespace MCP {
2828 const log = Log . create ( { service : "mcp" } )
29+ const DEFAULT_TIMEOUT = 5000
2930
3031 export const ToolsChanged = BusEvent . define (
3132 "mcp.tools.changed" ,
@@ -294,13 +295,14 @@ export namespace MCP {
294295 ]
295296
296297 let lastError : Error | undefined
298+ const connectTimeout = mcp . timeout ?? DEFAULT_TIMEOUT
297299 for ( const { name, transport } of transports ) {
298300 try {
299301 const client = new Client ( {
300302 name : "opencode" ,
301303 version : Installation . VERSION ,
302304 } )
303- await client . connect ( transport )
305+ await withTimeout ( client . connect ( transport ) , connectTimeout )
304306 registerNotificationHandlers ( client , key )
305307 mcpClient = client
306308 log . info ( "connected" , { key, transport : name } )
@@ -370,12 +372,13 @@ export namespace MCP {
370372 } ,
371373 } )
372374
375+ const connectTimeout = mcp . timeout ?? DEFAULT_TIMEOUT
373376 try {
374377 const client = new Client ( {
375378 name : "opencode" ,
376379 version : Installation . VERSION ,
377380 } )
378- await client . connect ( transport )
381+ await withTimeout ( client . connect ( transport ) , connectTimeout )
379382 registerNotificationHandlers ( client , key )
380383 mcpClient = client
381384 status = {
@@ -409,7 +412,7 @@ export namespace MCP {
409412 }
410413 }
411414
412- const result = await withTimeout ( mcpClient . listTools ( ) , mcp . timeout ?? 5000 ) . catch ( ( err ) => {
415+ const result = await withTimeout ( mcpClient . listTools ( ) , mcp . timeout ?? DEFAULT_TIMEOUT ) . catch ( ( err ) => {
413416 log . error ( "failed to get tools from client" , { key, error : err } )
414417 return undefined
415418 } )
0 commit comments