Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion packages/opencode/src/mcp/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -801,7 +801,25 @@ export const layer = Layer.effect(
const client = new Client({ name: "opencode", version: InstallationVersion })
return client
.connect(transport)
.then(() => ({ authorizationUrl: "", oauthState, client }) satisfies AuthResult)
.then(async () => {
// connect() resolves before the SDK starts the OAuth dance,
// so force a real request to make it run and let onRedirect
// populate capturedUrl before we return.
try {
await client.listTools(undefined, { timeout: 15_000 })
return { authorizationUrl: "", oauthState, client } satisfies AuthResult
} catch (err) {
const start = Date.now()
while (!capturedUrl && Date.now() - start < 5_000) {
await new Promise((r) => setTimeout(r, 50))
}
if (capturedUrl) {
pendingOAuthTransports.set(mcpName, transport)
return { authorizationUrl: capturedUrl.toString(), oauthState } satisfies AuthResult
}
throw err
}
})
},
catch: (error) => error,
}).pipe(
Expand Down
Loading