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

Function renderAuthError

apps/cloud/src/mcp/agent-handler.ts:48–79  ·  view source on GitHub ↗
(
  auth: McpAuthProvider["Service"],
  request: Request,
  outcome: Exclude<AuthOutcome, { readonly _tag: "Authenticated" }>,
)

Source from the content-addressed store, hash-verified

46 : jsonRpcErrorBody(status, code, message, { challenge });
47
48const renderAuthError = (
49 auth: McpAuthProvider["Service"],
50 request: Request,
51 outcome: Exclude<AuthOutcome, { readonly _tag: "Authenticated" }>,
52): Response => {
53 if (Predicate.isTagged(outcome, "Unauthorized")) {
54 return jsonRpcResponse(
55 401,
56 -32001,
57 "Unauthorized",
58 outcome.challenge ?? `Bearer resource_metadata="${auth.resourceMetadataUrl(request)}"`,
59 );
60 }
61 if (Predicate.isTagged(outcome, "Forbidden")) {
62 return jsonRpcResponse(403, outcome.code ?? -32001, outcome.message);
63 }
64 // Unavailable: a transient auth-infra failure (JWKS blip OR a WorkOS
65 // membership-lookup 429/5xx/timeout). Both are retryable, so advertise a
66 // Retry-After so the client (and any polite retry layer) backs off instead of
67 // hammering (same rendering as the shared envelope's Unavailable branch).
68 // Crucially, this path NEVER reaches the session-destroy branch below — a
69 // transient failure must not condemn a live session.
70 //
71 // Note this 503 shares JSON-RPC code -32001 with the terminated-session 404
72 // ("Session timed out, please reconnect"); that is intentional — -32001 is
73 // the generic auth/session envelope code, and the HTTP STATUS is the
74 // discriminator clients act on: 503 = retry the SAME session id, 404 = the
75 // id is dead, reconnect.
76 return jsonRpcErrorBody(503, -32001, outcome.message, {
77 retryAfterSeconds: UNAVAILABLE_RETRY_AFTER_SECONDS,
78 });
79};
80
81const authenticate = (request: Request) =>
82 Effect.gen(function* () {

Callers 1

makeCloudMcpAgentHandlerFunction · 0.70

Calls 2

jsonRpcErrorBodyFunction · 0.85
jsonRpcResponseFunction · 0.70

Tested by

no test coverage detected