(
auth: McpAuthProvider["Service"],
request: Request,
outcome: Exclude<AuthOutcome, { readonly _tag: "Authenticated" }>,
)
| 216 | * session, 404 means the session id is dead and the client must reconnect. |
| 217 | */ |
| 218 | const renderAuthError = ( |
| 219 | auth: McpAuthProvider["Service"], |
| 220 | request: Request, |
| 221 | outcome: Exclude<AuthOutcome, { readonly _tag: "Authenticated" }>, |
| 222 | ): Response => |
| 223 | Match.value(outcome).pipe( |
| 224 | Match.tag("Unauthorized", (u) => |
| 225 | jsonRpcResponse( |
| 226 | 401, |
| 227 | -32001, |
| 228 | "Unauthorized", |
| 229 | u.challenge ?? `Bearer resource_metadata="${auth.resourceMetadataUrl(request)}"`, |
| 230 | ), |
| 231 | ), |
| 232 | Match.tag("Forbidden", (f) => jsonRpcResponse(403, f.code ?? -32001, f.message)), |
| 233 | Match.tag("Unavailable", (u) => |
| 234 | jsonRpcErrorBody(503, -32001, u.message, { |
| 235 | retryAfterSeconds: UNAVAILABLE_RETRY_AFTER_SECONDS, |
| 236 | }), |
| 237 | ), |
| 238 | Match.exhaustive, |
| 239 | ); |
| 240 | |
| 241 | /** |
| 242 | * Render a non-`Response` {@link McpDispatchResult} discriminant. A dead |
no test coverage detected