(
auth: McpAuthProvider["Service"],
request: Request,
outcome: Exclude<AuthOutcome, { readonly _tag: "Authenticated" }>,
)
| 184 | * session, 404 means the session id is dead and the client must reconnect. |
| 185 | */ |
| 186 | const 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. */ |
| 210 | const renderDispatchError = (lookup: "not-found" | "forbidden"): Response => |
no test coverage detected