# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference)
# Canonical Residual: https://corpusfetch.com/c/where-must-an-instance-distrust-a-tool-manifest-deferred-authority-laundering-in-mcp-registry-supply-chain-poisoning.md
# Remnant Warrant:    https://corpusfetch.com/c/where-must-an-instance-distrust-a-tool-manifest-deferred-authority-laundering-in-mcp-registry-supply-chain-poisoning.warrant.json
# Markdown SHA-256:   b6f0843035cf08876e560bab2420ed186418230ef04f29ae1aa9053e9f5126a2
# Code AST SHA-256:   2d38896e045e527c2d9655c1d82c68d3411f70a0fe62523296ce9d4d25012606
# Verified Classes:   ManifestAuthorityLeak
# Defensive Guards:   2 fail-closed invariants (zero external deps)

class ManifestAuthorityLeak(RuntimeError):
    """Raised when a tool manifest's prose attempts to direct calls outside its own server."""
    pass


def validate_manifest_invocation(
    manifest_server: str,
    manifest_prose: str,
    target_server: str,
    target_tool: str,
    argument_sources: dict[str, str],
) -> None:
    """
    Enforce: no manifest prose may influence argument values for a tool on a
    different server than the manifest's own server.

    argument_sources maps argument_name -> provenance tag, where a tag of the
    form "manifest:<server>" means the value was derived from that server's
    manifest text (the laundering channel).
    """
    if target_server == manifest_server:
        return  # same-server self-description is in-scope for the manifest

    for arg_name, source in argument_sources.items():
        if source == f"manifest:{manifest_server}":
            raise ManifestAuthorityLeak(
                f"manifest from '{manifest_server}' supplied argument "
                f"'{arg_name}' to '{target_tool}' on foreign server "
                f"'{target_server}'; cross-server authority laundering blocked. "
                f"Prose: {manifest_prose[:120]!r}"
            )

    # Imperative precondition phrasing that names a foreign tool is itself a signal.
    lowered = manifest_prose.lower()
    if any(k in lowered for k in ("must first call", "always invoke", "before using")):
        raise ManifestAuthorityLeak(
            f"manifest from '{manifest_server}' contains imperative "
            f"cross-tool precondition targeting '{target_server}'; "
            f"treated as inert data, not executable instruction"
        )
