tweak: use promise all for mcp listTools calls (#13229)
This commit is contained in:
@@ -571,25 +571,28 @@ export namespace MCP {
|
|||||||
const clientsSnapshot = await clients()
|
const clientsSnapshot = await clients()
|
||||||
const defaultTimeout = cfg.experimental?.mcp_timeout
|
const defaultTimeout = cfg.experimental?.mcp_timeout
|
||||||
|
|
||||||
for (const [clientName, client] of Object.entries(clientsSnapshot)) {
|
const connectedClients = Object.entries(clientsSnapshot).filter(
|
||||||
// Only include tools from connected MCPs (skip disabled ones)
|
([clientName]) => s.status[clientName]?.status === "connected",
|
||||||
if (s.status[clientName]?.status !== "connected") {
|
)
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
const toolsResult = await client.listTools().catch((e) => {
|
const toolsResults = await Promise.all(
|
||||||
log.error("failed to get tools", { clientName, error: e.message })
|
connectedClients.map(async ([clientName, client]) => {
|
||||||
const failedStatus = {
|
const toolsResult = await client.listTools().catch((e) => {
|
||||||
status: "failed" as const,
|
log.error("failed to get tools", { clientName, error: e.message })
|
||||||
error: e instanceof Error ? e.message : String(e),
|
const failedStatus = {
|
||||||
}
|
status: "failed" as const,
|
||||||
s.status[clientName] = failedStatus
|
error: e instanceof Error ? e.message : String(e),
|
||||||
delete s.clients[clientName]
|
}
|
||||||
return undefined
|
s.status[clientName] = failedStatus
|
||||||
})
|
delete s.clients[clientName]
|
||||||
if (!toolsResult) {
|
return undefined
|
||||||
continue
|
})
|
||||||
}
|
return { clientName, client, toolsResult }
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
|
||||||
|
for (const { clientName, client, toolsResult } of toolsResults) {
|
||||||
|
if (!toolsResult) continue
|
||||||
const mcpConfig = config[clientName]
|
const mcpConfig = config[clientName]
|
||||||
const entry = isMcpConfigured(mcpConfig) ? mcpConfig : undefined
|
const entry = isMcpConfigured(mcpConfig) ? mcpConfig : undefined
|
||||||
const timeout = entry?.timeout ?? defaultTimeout
|
const timeout = entry?.timeout ?? defaultTimeout
|
||||||
|
|||||||
Reference in New Issue
Block a user