MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / renderAuthError

Function renderAuthError

packages/hosts/mcp/src/envelope.ts:288–309  ·  view source on GitHub ↗
(
  auth: McpAuthProvider["Service"],
  request: Request,
  outcome: Exclude<AuthOutcome, { readonly _tag: "Authenticated" }>,
)

Source from the content-addressed store, hash-verified

286 * session, 404 means the session id is dead and the client must reconnect.
287 */
288const renderAuthError = (
289 auth: McpAuthProvider["Service"],
290 request: Request,
291 outcome: Exclude<AuthOutcome, { readonly _tag: "Authenticated" }>,
292): Response =>
293 Match.value(outcome).pipe(
294 Match.tag("Unauthorized", (u) =>
295 jsonRpcResponse(
296 401,
297 -32001,
298 "Unauthorized",
299 u.challenge ?? `Bearer resource_metadata="${auth.resourceMetadataUrl(request)}"`,
300 ),
301 ),
302 Match.tag("Forbidden", (f) => jsonRpcResponse(403, f.code ?? -32001, f.message)),
303 Match.tag("Unavailable", (u) =>
304 jsonRpcErrorBody(503, -32001, u.message, {
305 retryAfterSeconds: UNAVAILABLE_RETRY_AFTER_SECONDS,
306 }),
307 ),
308 Match.exhaustive,
309 );
310
311/**
312 * Render a non-`Response` {@link McpDispatchResult} discriminant. A dead

Callers 1

mcpDispatchFunction · 0.70

Calls 2

jsonRpcErrorBodyFunction · 0.85
jsonRpcResponseFunction · 0.70

Tested by

no test coverage detected