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

Function renderAuthError

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

Source from the content-addressed store, hash-verified

216 * session, 404 means the session id is dead and the client must reconnect.
217 */
218const renderAuthError = (
219 auth: McpAuthProvider["Service"],
220 request: Request,
221 outcome: Exclude<AuthOutcome, { readonly _tag: "Authenticated" }>,
222): Response =>
223 Match.value(outcome).pipe(
224 Match.tag("Unauthorized", (u) =>
225 jsonRpcResponse(
226 401,
227 -32001,
228 "Unauthorized",
229 u.challenge ?? `Bearer resource_metadata="${auth.resourceMetadataUrl(request)}"`,
230 ),
231 ),
232 Match.tag("Forbidden", (f) => jsonRpcResponse(403, f.code ?? -32001, f.message)),
233 Match.tag("Unavailable", (u) =>
234 jsonRpcErrorBody(503, -32001, u.message, {
235 retryAfterSeconds: UNAVAILABLE_RETRY_AFTER_SECONDS,
236 }),
237 ),
238 Match.exhaustive,
239 );
240
241/**
242 * 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