fix(mcp): make Unauthorized a frozen dataclass to keep the type budget flat

CredError's unauthorized payload was a pydantic BaseModel, whose base resolves as unknown in
this repo's basedpyright (every model in the file trips reportUntypedBaseClass plus an unknown
model_config), so the tagged-union case read as unknown and the public edge's challenge access
added reportUnknownMemberType errors over the per-rule ceiling. A frozen dataclass is fully
typed here, so error.unauthorized resolves directly with no cast or accessor and the per-rule
basedpyright counts match base.
This commit is contained in:
Tin Chi Lo 2026-06-24 11:21:55 -07:00
parent d8b3d6d345
commit a42fb2fd11

View file

@ -25,6 +25,7 @@ union (see `result.py`), not `expression.Result`.
from __future__ import annotations
from dataclasses import dataclass
from enum import Enum
from typing import Annotated, Literal, Mapping, Optional
@ -59,14 +60,14 @@ class AuthSpecKind(str, Enum):
aws_sigv4 = "aws_sigv4" # AWS SigV4 per-request signing (e.g. Bedrock AgentCore)
class Unauthorized(BaseModel):
@dataclass(frozen=True, slots=True)
class Unauthorized:
"""A 401 plus the optional challenge a client needs to recover.
``detail`` is the human message; ``www_authenticate`` and ``body`` carry a scheme-specific
challenge (e.g. BYOK's provisioning prompt) so the edge can reproduce it verbatim.
"""
model_config = ConfigDict(frozen=True)
detail: str
www_authenticate: Optional[str] = None
body: Optional[Mapping[str, str]] = None