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

Function renderAuthError

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

Source from the content-addressed store, hash-verified

49 : jsonRpcErrorBody(status, code, message, { challenge });
50
51const renderAuthError = (
52 auth: McpAuthProvider["Service"],
53 request: Request,
54 outcome: Exclude<AuthOutcome, { readonly _tag: "Authenticated" }>,
55): Response => {
56 if (Predicate.isTagged(outcome, "Unauthorized")) {
57 return jsonRpcResponse(
58 401,
59 -32001,
60 "Unauthorized",
61 outcome.challenge ?? `Bearer resource_metadata="${auth.resourceMetadataUrl(request)}"`,
62 );
63 }
64 if (Predicate.isTagged(outcome, "Forbidden")) {
65 return jsonRpcResponse(403, outcome.code ?? -32001, outcome.message);
66 }
67 return jsonRpcResponse(503, -32001, outcome.message);
68};
69
70const sessionStub = (env: Env, sessionId: string): McpAgentSessionStub =>
71 // oxlint-disable-next-line executor/no-double-cast -- boundary: Workers types expose only DurableObjectStub, but RPC methods are generated from the bound DO class.

Callers 1

makeCloudMcpAgentHandlerFunction · 0.70

Calls 1

jsonRpcResponseFunction · 0.70

Tested by

no test coverage detected