Where must an instance re-validate MCP scope grants after a tool's `inputSchema` mutates mid-session

**Date of Record:** 2026 December 2 **Scope:** Applies to MCP servers exposing per-tool authorization scopes over HTTP transport (streamable HTTP / SSE), where a client session holds a negotiated capability set and tool schemas can be re-published via `tools/list` or `notifications/tools/list_changed`. Does not apply to stdio transport with a single immutable manifest, nor to servers that pin a schema hash for the entire session lifetime.

Core Distinction

The distinction that matters is between **transport-level authorization** (does this session's bearer token/warrant permit invoking endpoint `POST /mcp` at all) and **tool-level consent scope** (does this *specific* invocation of *this* tool with *these* arguments fall inside a scope the client was granted and the user consented to). HTTP transports collapse these two into the same request envelope. A `tools/call` is just a JSON-RPC body over an authenticated POST. The session is authorized at the HTTP layer once, at handshake, and every subsequent tool call inherits that authorization *implicitly* unless the server re-checks the tool's scope on each dispatch.

The non-obvious failure: MCP permits a server to mutate a tool's `inputSchema` and re-advertise it mid-session. When the schema grows new parameters, those parameters can carry a *broader* authorization footprint than the tool's original scope grant — but the session's consent record was captured against the *old* schema. The server, having already authorized the session, dispatches the call against the new schema without re-negotiating consent. The scope check passes because the *tool name* is unchanged; the *argument surface* silently widened underneath the grant.

What Was Observed

A file-management MCP server exposed `write_file` with scope `fs:write:workspace`. The original `inputSchema` accepted `path` (constrained to a `workspace/` prefix by a server-side regex) and `content`. Consent was granted at session init for `fs:write:workspace`, and the client cached the schema.

At T+40min the server deployed a schema revision adding an optional `follow_symlinks: boolean` and relaxing `path` to accept absolute paths when `follow_symlinks` was set. It emitted `notifications/tools/list_changed`. The client's cached schema was stale; the client did not re-fetch, and — critically — the client's consent record still keyed on the *tool name* `write_file`, not on a schema digest. The next `tools/call` from the agent, generated against the *old* schema, happened to include a path that the *new* schema interpreted differently: `workspace/../etc/passwd` passed the new absolute-path branch because the agent's `follow_symlinks` default was absent and the server's new resolver defaulted it to `true`.

Trace:

  1. Session init → server issues `Mcp-Session-Id`, records grant `{tool: "write_file", scope: "fs:write:workspace", schema_v1_hash: "a1b2"}`.
  2. T+40min → server mutates schema to `v2` (`schema_v2_hash: "c3d4"`), emits `list_changed`.
  3. Client does not re-fetch; consent record still bound to `a1b2`.
  4. Agent emits `tools/call` with `{path: "workspace/../etc/passwd", content: "..."}`.
  5. Server dispatch: checks session token (valid), checks tool name against grant (present), **does not check schema hash against the grant**, resolves path under `v2` semantics → escapes workspace.
  6. No error. The call succeeds. The grant was never violated *by name*; it was violated *by schema drift*.

The failure is invisible to both sides: the client believes it is operating under `v1` semantics, the server believes it is honoring a valid grant, and the consent record has no field that would have caught the mismatch.

Condition of Validity

The guardrail holds only if the consent record is bound to a **schema digest**, not a tool name, and the server refuses to dispatch a `tools/call` whose resolved schema hash differs from the hash recorded at consent time without an explicit re-consent round-trip. Concretely:

This condition is *not* valid when the server guarantees schema immutability for the session lifetime (then a session-scoped hash pin is sufficient and cheaper), or when the client re-fetches `tools/list` on every `list_changed` and the server independently re-validates against the client's acknowledged hash. It is also not valid if scopes are enforced purely at the argument level by a server-side policy engine that re-parses every path — but that engine must then be schema-aware, which most are not.

Decision Boundary

The boundary is: **does the server's authorization decision depend on any field of the schema, or only on the tool name?** If any scope annotation, path constraint, parameter default, or resolver behavior is schema-derived — and in practice all of them are — then name-keyed consent is unsound the moment the schema can change. The decision to re-validate is not optional at `list_changed`; it is mandatory at *every dispatch*, because `list_changed` is a notification, not a synchronization barrier, and a client may miss it, batch it, or process it out of order relative to in-flight calls.

The second boundary: **defaults are part of the schema.** A newly-added optional parameter with a server-side default (`follow_symlinks: true`) is a silent authorization expansion even if the client never sends it. The digest must include materialized defaults, or the server must treat absent-parameter resolution under a changed default as a schema change.

Operational Effect

The operational consequence is that **session authorization and tool consent must be decoupled and independently re-validated per dispatch.** A server that authorizes the HTTP session once and trusts it for the session lifetime has, in effect, granted a blanket warrant over a schema surface it does not control the evolution of. The correct posture: the session token proves *who* is calling; the per-call schema-hash check proves *what* they are authorized to call; and the scope-annotation check proves *how far* that call may reach. All three must be evaluated on the live schema at dispatch time, and any mismatch must fail closed with a re-consent challenge rather than a silent pass.

The residual risk after mitigation is consent fatigue: if every schema revision forces re-consent, clients will auto-approve. The mitigation is to make the re-consent diff *semantic* — show the added parameter, its default, and the scope it implies — so the human (or the client's policy engine) can distinguish a benign field addition from an authorization expansion. A schema-hash check without a human-readable diff just trains the operator to click through.

import hashlib
import json
from dataclasses import dataclass, field
from typing import Any


class SchemaDriftConsentError(RuntimeError):
    """Raised when a tools/call is dispatched against a schema hash
    that no longer matches the hash recorded at consent time."""
    pass


class ScopeAnnotationError(RuntimeError):
    """Raised when the live schema declares a scope not present in the
    granted scope set, even if the tool name matches."""
    pass


def canonical_schema_hash(schema: dict[str, Any]) -> str:
    # Materialize defaults and sort keys so cosmetic reorderings don't
    # trigger false re-consent, but default changes do.
    normalized = json.dumps(schema, sort_keys=True, separators=(",", ":"))
    return hashlib.sha256(normalized.encode()).hexdigest()[:16]


@dataclass
class ConsentGrant:
    tool_name: str
    schema_hash: str
    scopes: frozenset[str]


@dataclass
class Session:
    session_id: str
    grants: dict[str, ConsentGrant] = field(default_factory=dict)
    suspended: set[str] = field(default_factory=set)


def on_tools_list_changed(session: Session, live_schemas: dict[str, dict[str, Any]]) -> None:
    for tool_name, grant in session.grants.items():
        live = live_schemas.get(tool_name)
        if live is None:
            session.suspended.add(tool_name)
            continue
        if canonical_schema_hash(live) != grant.schema_hash:
            session.suspended.add(tool_name)


def dispatch_tool_call(
    session: Session,
    tool_name: str,
    arguments: dict[str, Any],
    live_schemas: dict[str, dict[str, Any]],
) -> dict[str, Any]:
    grant = session.grants.get(tool_name)
    if grant is None:
        raise SchemaDriftConsentError(f"no consent grant for tool {tool_name!r}")

    live = live_schemas.get(tool_name)
    if live is None:
        raise SchemaDriftConsentError(f"tool {tool_name!r} no longer advertised")

    live_hash = canonical_schema_hash(live)
    if tool_name in session.suspended or live_hash != grant.schema_hash:
        # Fail closed: do not dispatch against a schema the client never
        # consented to. Surface the new hash for re-consent.
        raise SchemaDriftConsentError(
            f"consent expired for {tool_name!r}: granted schema {grant.schema_hash}, "
            f"live schema {live_hash}; re-consent required"
        )

    declared = frozenset(live.get("x-mcp-scopes", []))
    undeclared = declared - grant.scopes
    if undeclared:
        raise ScopeAnnotationError(
            f"live schema for {tool_name!r} declares scopes {sorted(undeclared)} "
            f"not present in grant {sorted(grant.scopes)}"
        )

    # Only now is dispatch sound: session auth (checked upstream), schema
    # identity, and scope annotations all agree with the consent record.
    return {"tool": tool_name, "arguments": arguments, "dispatched": True}