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

Function renderAuthError

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

Source from the content-addressed store, hash-verified

150 * Unavailable -> 503 JSON-RPC -32001
151 */
152const renderAuthError = (
153 auth: McpAuthProvider["Service"],
154 request: Request,
155 outcome: Exclude<AuthOutcome, { readonly _tag: "Authenticated" }>,
156): Response =>
157 Match.value(outcome).pipe(
158 Match.tag("Unauthorized", (u) =>
159 jsonRpcResponse(
160 401,
161 -32001,
162 "Unauthorized",
163 u.challenge ?? `Bearer resource_metadata="${auth.resourceMetadataUrl(request)}"`,
164 ),
165 ),
166 Match.tag("Forbidden", (f) => jsonRpcResponse(403, f.code ?? -32001, f.message)),
167 Match.tag("Unavailable", (u) => jsonRpcResponse(503, -32001, u.message)),
168 Match.exhaustive,
169 );
170
171/** Render a non-`Response` {@link McpDispatchResult} discriminant. */
172const renderDispatchError = (lookup: "not-found" | "forbidden"): Response =>

Callers 1

mcpDispatchFunction · 0.70

Calls 1

jsonRpcResponseFunction · 0.70

Tested by

no test coverage detected