# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference)
# Canonical Residual: https://corpusfetch.com/c/under-what-conditions-must-an-instance-re-negotiate-mcp-tool-authorization-when-an-sse-session-resumes-as-streamable-http-and-the-resource-indicator-n.md
# Remnant Warrant:    https://corpusfetch.com/c/under-what-conditions-must-an-instance-re-negotiate-mcp-tool-authorization-when-an-sse-session-resumes-as-streamable-http-and-the-resource-indicator-n.warrant.json
# Markdown SHA-256:   523b55f28c0bd7e3c0253dc16473d5a6227c75e360d05d309f904b6c97b31ff0
# Code AST SHA-256:   3f6808c587e7834b9611d67986586667cc9faaf29899081876c01e9a09962e64
# Verified Classes:   ResourceIndicatorMismatch
# Defensive Guards:   3 fail-closed invariants (zero external deps)

class ResourceIndicatorMismatch(RuntimeError):
    """Raised when a resumed MCP session's token audience does not match
    the resource indicator required by the streamable-HTTP tool endpoint."""


def validate_resumed_session_tool_call(
    session_id: str,
    token_audience: str,
    endpoint_resource_indicator: str,
    session_token_binding: str | None,
    token_subject: str,
) -> None:
    # Session continuity is assumed already established by the resume handshake.
    # Authorization continuity must be re-derived here, at the first tool call.
    if session_token_binding is None:
        raise ResourceIndicatorMismatch(
            f"session {session_id!r} has no token binding; "
            "cannot prove audience continuity across transport migration"
        )
    if session_token_binding != token_subject:
        raise ResourceIndicatorMismatch(
            f"session {session_id!r} bound to subject {session_token_binding!r}, "
            f"but token subject is {token_subject!r}"
        )
    if token_audience != endpoint_resource_indicator:
        raise ResourceIndicatorMismatch(
            f"token aud={token_audience!r} does not match "
            f"endpoint resource indicator {endpoint_resource_indicator!r}; "
            "client must re-authorize with the new resource indicator"
        )
