Skip to content

Commit c333e91

Browse files
chore: generate
1 parent c7760b4 commit c333e91

2 files changed

Lines changed: 36 additions & 30 deletions

File tree

packages/opencode/src/mcp/index.ts

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ export namespace MCP {
165165
function defs(key: string, client: MCPClient, timeout?: number) {
166166
return Effect.tryPromise({
167167
try: () => withTimeout(client.listTools(), timeout ?? DEFAULT_TIMEOUT),
168-
catch: (err) => err instanceof Error ? err : new Error(String(err)),
168+
catch: (err) => (err instanceof Error ? err : new Error(String(err))),
169169
}).pipe(
170170
Effect.map((result) => result.tools),
171171
Effect.catch((err) => {
@@ -267,15 +267,15 @@ export namespace MCP {
267267
},
268268
catch: (e) => (e instanceof Error ? e : new Error(String(e))),
269269
}),
270-
(t, exit) =>
271-
Exit.isFailure(exit)
272-
? Effect.tryPromise(() => t.close()).pipe(Effect.ignore)
273-
: Effect.void,
270+
(t, exit) => (Exit.isFailure(exit) ? Effect.tryPromise(() => t.close()).pipe(Effect.ignore) : Effect.void),
274271
)
275272

276273
const DISABLED_RESULT: CreateResult = { status: { status: "disabled" } }
277274

278-
const connectRemote = Effect.fn("MCP.connectRemote")(function* (key: string, mcp: Config.Mcp & { type: "remote" }) {
275+
const connectRemote = Effect.fn("MCP.connectRemote")(function* (
276+
key: string,
277+
mcp: Config.Mcp & { type: "remote" },
278+
) {
279279
const oauthDisabled = mcp.oauth === false
280280
const oauthConfig = typeof mcp.oauth === "object" ? mcp.oauth : undefined
281281
let authProvider: McpOAuthProvider | undefined
@@ -333,21 +333,25 @@ export namespace MCP {
333333
status: "needs_client_registration" as const,
334334
error: "Server does not support dynamic client registration. Please provide clientId in config.",
335335
}
336-
return bus.publish(TuiEvent.ToastShow, {
337-
title: "MCP Authentication Required",
338-
message: `Server "${key}" requires a pre-registered client ID. Add clientId to your config.`,
339-
variant: "warning",
340-
duration: 8000,
341-
}).pipe(Effect.ignore, Effect.as(undefined))
336+
return bus
337+
.publish(TuiEvent.ToastShow, {
338+
title: "MCP Authentication Required",
339+
message: `Server "${key}" requires a pre-registered client ID. Add clientId to your config.`,
340+
variant: "warning",
341+
duration: 8000,
342+
})
343+
.pipe(Effect.ignore, Effect.as(undefined))
342344
} else {
343345
pendingOAuthTransports.set(key, transport)
344346
lastStatus = { status: "needs_auth" as const }
345-
return bus.publish(TuiEvent.ToastShow, {
346-
title: "MCP Authentication Required",
347-
message: `Server "${key}" requires authentication. Run: opencode mcp auth ${key}`,
348-
variant: "warning",
349-
duration: 8000,
350-
}).pipe(Effect.ignore, Effect.as(undefined))
347+
return bus
348+
.publish(TuiEvent.ToastShow, {
349+
title: "MCP Authentication Required",
350+
message: `Server "${key}" requires authentication. Run: opencode mcp auth ${key}`,
351+
variant: "warning",
352+
duration: 8000,
353+
})
354+
.pipe(Effect.ignore, Effect.as(undefined))
351355
}
352356
}
353357

@@ -369,7 +373,10 @@ export namespace MCP {
369373
if (lastStatus?.status === "needs_auth" || lastStatus?.status === "needs_client_registration") break
370374
}
371375

372-
return { client: undefined as MCPClient | undefined, status: (lastStatus ?? { status: "failed", error: "Unknown error" }) as Status }
376+
return {
377+
client: undefined as MCPClient | undefined,
378+
status: (lastStatus ?? { status: "failed", error: "Unknown error" }) as Status,
379+
}
373380
})
374381

375382
const connectLocal = Effect.fn("MCP.connectLocal")(function* (key: string, mcp: Config.Mcp & { type: "local" }) {
@@ -392,7 +399,10 @@ export namespace MCP {
392399

393400
const connectTimeout = mcp.timeout ?? DEFAULT_TIMEOUT
394401
return yield* connectTransport(transport, connectTimeout).pipe(
395-
Effect.map((client): { client: MCPClient | undefined; status: Status } => ({ client, status: { status: "connected" } })),
402+
Effect.map((client): { client: MCPClient | undefined; status: Status } => ({
403+
client,
404+
status: { status: "connected" },
405+
})),
396406
Effect.catch((error): Effect.Effect<{ client: MCPClient | undefined; status: Status }> => {
397407
const msg = error instanceof Error ? error.message : String(error)
398408
log.error("local mcp startup failed", { key, command: mcp.command, cwd, error: msg })
@@ -409,9 +419,10 @@ export namespace MCP {
409419

410420
log.info("found", { key, type: mcp.type })
411421

412-
const { client: mcpClient, status } = mcp.type === "remote"
413-
? yield* connectRemote(key, mcp as Config.Mcp & { type: "remote" })
414-
: yield* connectLocal(key, mcp as Config.Mcp & { type: "local" })
422+
const { client: mcpClient, status } =
423+
mcp.type === "remote"
424+
? yield* connectRemote(key, mcp as Config.Mcp & { type: "remote" })
425+
: yield* connectLocal(key, mcp as Config.Mcp & { type: "local" })
415426

416427
if (!mcpClient) {
417428
return { status } satisfies CreateResult
@@ -493,9 +504,7 @@ export namespace MCP {
493504
return
494505
}
495506

496-
const result = yield* create(key, mcp).pipe(
497-
Effect.catch(() => Effect.succeed(undefined)),
498-
)
507+
const result = yield* create(key, mcp).pipe(Effect.catch(() => Effect.succeed(undefined)))
499508
if (!result) return
500509

501510
s.status[key] = result.status
@@ -643,9 +652,7 @@ export namespace MCP {
643652
return Effect.forEach(
644653
Object.entries(s.clients).filter(([name]) => s.status[name]?.status === "connected"),
645654
([clientName, client]) =>
646-
fetchFromClient(clientName, client, listFn, label).pipe(
647-
Effect.map((items) => Object.entries(items ?? {})),
648-
),
655+
fetchFromClient(clientName, client, listFn, label).pipe(Effect.map((items) => Object.entries(items ?? {}))),
649656
{ concurrency: "unbounded" },
650657
).pipe(Effect.map((results) => Object.fromEntries<T & { client: string }>(results.flat())))
651658
}

packages/opencode/test/mcp/lifecycle.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,6 @@ test(
673673
),
674674
)
675675

676-
677676
// ========================================================================
678677
// Test: transport leak — local stdio timeout (#19168)
679678
// ========================================================================

0 commit comments

Comments
 (0)