summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--packages/opencode/src/mcp/index.ts39
1 files changed, 21 insertions, 18 deletions
diff --git a/packages/opencode/src/mcp/index.ts b/packages/opencode/src/mcp/index.ts
index 29e958fe3..3c29fe03d 100644
--- a/packages/opencode/src/mcp/index.ts
+++ b/packages/opencode/src/mcp/index.ts
@@ -571,25 +571,28 @@ export namespace MCP {
const clientsSnapshot = await clients()
const defaultTimeout = cfg.experimental?.mcp_timeout
- for (const [clientName, client] of Object.entries(clientsSnapshot)) {
- // Only include tools from connected MCPs (skip disabled ones)
- if (s.status[clientName]?.status !== "connected") {
- continue
- }
+ const connectedClients = Object.entries(clientsSnapshot).filter(
+ ([clientName]) => s.status[clientName]?.status === "connected",
+ )
- const toolsResult = await client.listTools().catch((e) => {
- log.error("failed to get tools", { clientName, error: e.message })
- const failedStatus = {
- status: "failed" as const,
- error: e instanceof Error ? e.message : String(e),
- }
- s.status[clientName] = failedStatus
- delete s.clients[clientName]
- return undefined
- })
- if (!toolsResult) {
- continue
- }
+ const toolsResults = await Promise.all(
+ connectedClients.map(async ([clientName, client]) => {
+ const toolsResult = await client.listTools().catch((e) => {
+ log.error("failed to get tools", { clientName, error: e.message })
+ const failedStatus = {
+ status: "failed" as const,
+ error: e instanceof Error ? e.message : String(e),
+ }
+ s.status[clientName] = failedStatus
+ delete s.clients[clientName]
+ return undefined
+ })
+ return { clientName, client, toolsResult }
+ }),
+ )
+
+ for (const { clientName, client, toolsResult } of toolsResults) {
+ if (!toolsResult) continue
const mcpConfig = config[clientName]
const entry = isMcpConfigured(mcpConfig) ? mcpConfig : undefined
const timeout = entry?.timeout ?? defaultTimeout