fix(mcp): surface OAuth completion errors (#34145)
This commit is contained in:
parent
71c3a7c8f2
commit
e1e0304a96
2 changed files with 12 additions and 11 deletions
|
|
@ -28,7 +28,7 @@ import { McpAuth } from "./auth"
|
||||||
import { EventV2Bridge } from "@/event-v2-bridge"
|
import { EventV2Bridge } from "@/event-v2-bridge"
|
||||||
import { TuiEvent } from "@/server/tui-event"
|
import { TuiEvent } from "@/server/tui-event"
|
||||||
import open from "open"
|
import open from "open"
|
||||||
import { Cause, Effect, Exit, Layer, Option, Context, Schema, Stream } from "effect"
|
import { Cause, Effect, Exit, Layer, Context, Schema, Stream } from "effect"
|
||||||
import { EffectBridge } from "@/effect/bridge"
|
import { EffectBridge } from "@/effect/bridge"
|
||||||
import { InstanceState } from "@/effect/instance-state"
|
import { InstanceState } from "@/effect/instance-state"
|
||||||
import { ChildProcess, ChildProcessSpawner } from "effect/unstable/process"
|
import { ChildProcess, ChildProcessSpawner } from "effect/unstable/process"
|
||||||
|
|
@ -928,16 +928,17 @@ export const layer = Layer.effect(
|
||||||
const pending = pendingOAuthTransports.get(mcpName)
|
const pending = pendingOAuthTransports.get(mcpName)
|
||||||
if (!pending) throw new Error(`No pending OAuth flow for MCP server: ${mcpName}`)
|
if (!pending) throw new Error(`No pending OAuth flow for MCP server: ${mcpName}`)
|
||||||
|
|
||||||
const result = yield* Effect.tryPromise({
|
const error = yield* Effect.tryPromise({
|
||||||
try: () => pending.transport.finishAuth(authorizationCode).then(() => true as const),
|
try: () => pending.transport.finishAuth(authorizationCode),
|
||||||
catch: (error) => {
|
catch: (error) => error,
|
||||||
return error
|
}).pipe(
|
||||||
},
|
Effect.match({
|
||||||
}).pipe(Effect.option)
|
onFailure: (error) => (error instanceof Error ? error.message : String(error)),
|
||||||
|
onSuccess: () => undefined,
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
|
||||||
if (Option.isNone(result)) {
|
if (error) return { status: "failed", error: `OAuth completion failed: ${error}` } satisfies Status
|
||||||
return { status: "failed", error: "OAuth completion failed" } satisfies Status
|
|
||||||
}
|
|
||||||
|
|
||||||
yield* Effect.promise(() => pending.provider?.commit() ?? Promise.resolve())
|
yield* Effect.promise(() => pending.provider?.commit() ?? Promise.resolve())
|
||||||
yield* auth.clearCodeVerifier(mcpName)
|
yield* auth.clearCodeVerifier(mcpName)
|
||||||
|
|
|
||||||
|
|
@ -263,7 +263,7 @@ mcpTest.instance(
|
||||||
|
|
||||||
expect(yield* mcp.finishAuth(name, "invalid-code")).toEqual({
|
expect(yield* mcp.finishAuth(name, "invalid-code")).toEqual({
|
||||||
status: "failed",
|
status: "failed",
|
||||||
error: "OAuth completion failed",
|
error: "OAuth completion failed: Token exchange failed",
|
||||||
})
|
})
|
||||||
const entry = yield* auth.get(name)
|
const entry = yield* auth.get(name)
|
||||||
expect(entry?.tokens?.accessToken).toBe("working-token")
|
expect(entry?.tokens?.accessToken).toBe("working-token")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue