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

Function renderAuthError

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

Source from the content-addressed store, hash-verified

184 * session, 404 means the session id is dead and the client must reconnect.
185 */
186const renderAuthError = (
187 auth: McpAuthProvider["Service"],
188 request: Request,
189 outcome: Exclude<AuthOutcome, { readonly _tag: "Authenticated" }>,
190): Response =>
191 Match.value(outcome).pipe(
192 Match.tag("Unauthorized", (u) =>
193 jsonRpcResponse(
194 401,
195 -32001,
196 "Unauthorized",
197 u.challenge ?? `Bearer resource_metadata="${auth.resourceMetadataUrl(request)}"`,
198 ),
199 ),
200 Match.tag("Forbidden", (f) => jsonRpcResponse(403, f.code ?? -32001, f.message)),
201 Match.tag("Unavailable", (u) =>
202 jsonRpcErrorBody(503, -32001, u.message, {
203 retryAfterSeconds: UNAVAILABLE_RETRY_AFTER_SECONDS,
204 }),
205 ),
206 Match.exhaustive,
207 );
208
209/** Render a non-`Response` {@link McpDispatchResult} discriminant. */
210const renderDispatchError = (lookup: "not-found" | "forbidden"): Response =>

Callers 1

mcpDispatchFunction · 0.70

Calls 2

jsonRpcErrorBodyFunction · 0.85
jsonRpcResponseFunction · 0.70

Tested by

no test coverage detected