fix: MCP connection - Added explicit connectAll() method with timeout - Updated mcp-connect endpoint to use connectAll - Enhanced UI feedback for connection errors
This commit is contained in:
@@ -465,6 +465,33 @@ export class McpManager {
|
||||
return texts.join("\n") || (result.isError ? "Tool execution failed" : "Tool executed successfully")
|
||||
}
|
||||
|
||||
/**
|
||||
* Connect all configured servers
|
||||
*/
|
||||
async connectAll(): Promise<Record<string, { connected: boolean; error?: string }>> {
|
||||
const results: Record<string, { connected: boolean; error?: string }> = {}
|
||||
|
||||
for (const [name, client] of this.clients) {
|
||||
try {
|
||||
// Add timeout for connection
|
||||
const connectPromise = client.connect()
|
||||
const timeoutPromise = new Promise<never>((_, reject) =>
|
||||
setTimeout(() => reject(new Error("Connection timeout")), 15000)
|
||||
)
|
||||
|
||||
await Promise.race([connectPromise, timeoutPromise])
|
||||
results[name] = { connected: true }
|
||||
log.info({ server: name }, "MCP server connected successfully")
|
||||
} catch (error) {
|
||||
const errorMsg = error instanceof Error ? error.message : String(error)
|
||||
log.warn({ server: name, error: errorMsg }, "Failed to connect MCP server")
|
||||
results[name] = { connected: false, error: errorMsg }
|
||||
}
|
||||
}
|
||||
|
||||
return results
|
||||
}
|
||||
|
||||
/**
|
||||
* Disconnect all servers
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user