(
auth: McpAuthProvider["Service"],
request: Request,
outcome: Exclude<AuthOutcome, { readonly _tag: "Authenticated" }>,
)
| 150 | * Unavailable -> 503 JSON-RPC -32001 |
| 151 | */ |
| 152 | const 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. */ |
| 172 | const renderDispatchError = (lookup: "not-found" | "forbidden"): Response => |
no test coverage detected