fix(httpapi): preserve mcp oauth error parity (#24706)

This commit is contained in:
Kit Langton
2026-04-27 22:33:21 -04:00
committed by GitHub
parent 4d74849c1a
commit 796b652d2b
4 changed files with 122 additions and 12 deletions
@@ -20,6 +20,10 @@ const AuthCallbackPayload = Schema.Struct({
const AuthRemoveResponse = Schema.Struct({
success: Schema.Literal(true),
}).annotate({ identifier: "McpAuthRemoveResponse" })
class UnsupportedOAuthError extends Schema.ErrorClass<UnsupportedOAuthError>("McpUnsupportedOAuthError")(
{ error: Schema.String },
{ httpApiStatus: 400 },
) {}
export const McpPaths = {
status: "/mcp",
@@ -57,7 +61,7 @@ export const McpApi = HttpApi.make("mcp")
HttpApiEndpoint.post("authStart", McpPaths.auth, {
params: { name: Schema.String },
success: AuthStartResponse,
error: HttpApiError.BadRequest,
error: UnsupportedOAuthError,
}).annotateMerge(
OpenApi.annotations({
identifier: "mcp.auth.start",
@@ -80,7 +84,7 @@ export const McpApi = HttpApi.make("mcp")
HttpApiEndpoint.post("authAuthenticate", McpPaths.authAuthenticate, {
params: { name: Schema.String },
success: MCP.Status,
error: HttpApiError.BadRequest,
error: UnsupportedOAuthError,
}).annotateMerge(
OpenApi.annotations({
identifier: "mcp.auth.authenticate",
@@ -149,7 +153,9 @@ export const mcpHandlers = Layer.unwrap(
})
const authStart = Effect.fn("McpHttpApi.authStart")(function* (ctx: { params: { name: string } }) {
if (!(yield* mcp.supportsOAuth(ctx.params.name))) return yield* new HttpApiError.BadRequest({})
if (!(yield* mcp.supportsOAuth(ctx.params.name))) {
return yield* new UnsupportedOAuthError({ error: `MCP server ${ctx.params.name} does not support OAuth` })
}
return yield* mcp.startAuth(ctx.params.name)
})
@@ -161,7 +167,9 @@ export const mcpHandlers = Layer.unwrap(
})
const authAuthenticate = Effect.fn("McpHttpApi.authAuthenticate")(function* (ctx: { params: { name: string } }) {
if (!(yield* mcp.supportsOAuth(ctx.params.name))) return yield* new HttpApiError.BadRequest({})
if (!(yield* mcp.supportsOAuth(ctx.params.name))) {
return yield* new UnsupportedOAuthError({ error: `MCP server ${ctx.params.name} does not support OAuth` })
}
return yield* mcp.authenticate(ctx.params.name)
})
@@ -8,6 +8,21 @@ import { lazy } from "@/util/lazy"
import { Effect } from "effect"
import { jsonRequest, runRequest } from "./trace"
const UnsupportedOAuthError = z
.object({
error: z.string(),
})
.meta({ ref: "McpUnsupportedOAuthError" })
const unsupportedOAuthErrorResponse = {
description: "MCP server does not support OAuth",
content: {
"application/json": {
schema: resolver(UnsupportedOAuthError),
},
},
}
export const McpRoutes = lazy(() =>
new Hono()
.get(
@@ -85,7 +100,8 @@ export const McpRoutes = lazy(() =>
},
},
},
...errors(400, 404),
400: unsupportedOAuthErrorResponse,
...errors(404),
},
}),
async (c) => {
@@ -157,7 +173,8 @@ export const McpRoutes = lazy(() =>
},
},
},
...errors(400, 404),
400: unsupportedOAuthErrorResponse,
...errors(404),
},
}),
async (c) => {