# When must an instance re-derive consent at the tool boundary rather than trust the session-scoped grant in MCP over HTTP-native transport **Date of Record:** 2026 November 29 **Scope:** Applies to MCP servers exposing per-tool authorization scopes to LLM-driven clients over streamable HTTP transport (single or multi-request sessions, resumable via session ID). Does not apply to stdio transport, where the process lifetime is the authorization lifetime, nor to servers that enforce authorization solely at connection establishment. ## Core Distinction There are two places an MCP server can enforce per-tool consent: at *session establishment* (the `initialize` handshake, where the client presents a token bearing a scope set, and the server materializes a session object holding those scopes) and at *tool invocation* (the `tools/call` request, where the specific tool's required scope is checked against a live authority). The seductive invariant is "scopes are fixed for the life of the session, so check once at handshake and cache the grant on the session." That invariant is false under HTTP-native transport because three things mutate independently of the session object: the bearer token presented on each HTTP request, the server-side consent revocation state, and the session's own resumability across reconnects. The boundary failure is *scope laundering through session persistence*: a client that established a session with a broad scope set, then had that consent revoked or narrowed, continues to invoke tools under the cached session grant because the per-request token is never re-evaluated against the tool's scope requirement. The distinction that matters: **session identity is not authorization identity.** A session ID proves *which conversation* a request belongs to; it does not prove *what the presenter is currently permitted to do*. Under HTTP-native transport these are carried by different fields (session header vs. `Authorization` header) and can diverge. ## What Was Observed A server implemented per-tool scopes as follows: on `initialize`, it parsed the bearer token's `scope` claim, stored the scope set on the session record keyed by the returned `Mcp-Session-Id`, and each `tools/call` handler consulted `session.scopes` before dispatching to the tool. Tool definitions each declared a `required_scope` (e.g., `files:read`, `files:write`, `shell:exec`). The failure trace, reproduced against a client that reuses sessions: 1. Agent establishes session `S1` with a token scoped `files:read files:write shell:exec`. Server caches `S1.scopes = {read, write, exec}`. All tool calls succeed. 2. Operator revokes `shell:exec` for that principal (token rotation, consent withdrawal, or a narrowed re-issue). The *new* token presented on subsequent HTTP requests carries only `files:read files:write`. 3. The agent continues the existing session `S1` (correctly — resumption is a legitimate MCP behavior, and the transport encourages it to avoid re-handshake cost). Each `tools/call` for `shell:exec` arrives with the narrowed `Authorization` header but the same `Mcp-Session-Id: S1`. 4. The handler checks `"shell:exec" in S1.scopes` → `True`, because `S1.scopes` was frozen at step 1. The tool executes. **The revocation is silently bypassed for the remainder of the session's lifetime.** A second, subtler variant: a client multiplexes two principals over one server by reusing a session ID but swapping bearer tokens (a proxy or shared agent runtime bug). The server never notices, because it only reads the token at `initialize`. The second principal inherits the first's scope set — *cross-principal scope inheritance*, which is worse than stale consent because it is an escalation, not a retention. A third variant surfaced on resumption: after a transport drop, the client reconnects and re-sends `initialize` with a fresh token, but the server, seeing an existing `Mcp-Session-Id`, treats it as a resume and *does not* re-materialize scopes — it keeps the old set. The re-handshake's new token is discarded. So even a client doing the "right" thing (re-initializing with a current token) gets the stale grant. ## Condition of Validity The session-cached-scope optimization is valid **only** under the conjunction: - (a) the authorization token is immutable for the session's lifetime, AND - (b) the session is bound 1:1 to a single principal for its lifetime, AND - (c) no external revocation can occur that the server does not observe synchronously, AND - (d) session resumption never crosses a token boundary. Under HTTP-native transport, (a) is violated by design — tokens rotate, and the transport re-presents `Authorization` on every request precisely because it is stateless at the HTTP layer. (c) is violated whenever consent is managed out-of-band (an admin console, a token issuer's revocation list). (d) is violated by any client that resumes with a re-issued token. Therefore the optimization is invalid for any server where per-tool scopes are meant to be *enforced*, not merely *advertised*. The correct invariant: **every `tools/call` must re-derive the effective scope set from the request's own `Authorization` credential, intersect it with the session's principal binding, and check the tool's `required_scope` against that intersection — never against a cached set alone.** The session may cache a *principal identifier* (to detect cross-principal reuse and reject it), but must not cache the *grant*. ## Decision Boundary The boundary is drawn at the tool dispatch point, and it is a hard gate, not a soft check: - If `Authorization` is absent on a `tools/call` → reject `401`, do not fall back to session scopes. - If the token's principal does not match the session's bound principal → reject `403` with a distinct `principal_mismatch` reason (this is escalation, treat as a security event, and invalidate the session). - If the token's scope set does not contain the tool's `required_scope` → reject `403` with `insufficient_scope`, and name the missing scope so the client can re-consent. - Only if all three pass does dispatch proceed. The non-obvious part of the boundary: **do not treat a resume as a no-op.** On any request bearing an existing `Mcp-Session-Id`, the server must reconcile the presented token against the session's bound principal. If they differ, the session is compromised (or the client is buggy) and must be terminated rather than silently continued. A resume with a *narrower* token is legitimate and must downgrade the effective grant for that request — not inherit the old one. There is a tempting middle path — "check the token only when it changes" — which fails because the server cannot reliably observe change without comparing every request, and because revocation is not a token change at all (the same token may be revoked server-side). The boundary must be evaluated per call. ## Operational Effect Enforcing re-derivation per call has measurable costs and necessary compensations: - **Latency:** token validation (signature + revocation lookup) moves onto the hot path of every tool call. Mitigate with short-TTL validation caches *keyed by token hash*, not by session — a revoked token's cache entry must be invalidatable, so the cache TTL bounds the revocation window, and that window must be documented as the consent-propagation SLA. - **Session lifecycle:** sessions become principal-bound and must be invalidated on principal mismatch. This means the server needs a session→principal index and a revocation hook that can tear down sessions when consent is withdrawn, closing the window between revocation and the next call. - **Client contract:** clients must be prepared for `403 insufficient_scope` mid-session and must re-consent rather than assume the session's original grant holds. Agents that treat a successful `initialize` as a blanket capability grant will fail here — correctly. - **Auditability:** every `tools/call` decision (granted/denied, which scope, which principal) must be logged against the *presented* token, not the session, so that a post-incident replay can reconstruct what was actually authorized at each step. The compensating control that makes this tractable: bind the session to a principal *identifier* (stable across token rotation for the same principal) rather than to the token itself. Then token rotation for the same principal is a non-event (re-validate, same principal, proceed), while cross-principal reuse is a hard reject. This separates "who" (session-bound, cached) from "what they may do right now" (per-call, re-derived) — the exact separation the naive implementation collapsed. ```python from dataclasses import dataclass, field from typing import Optional class ConsentBoundaryError(RuntimeError): """Raised when a tools/call request violates the per-call consent invariant.""" pass @dataclass class Token: principal: str scopes: frozenset[str] revoked: bool = False @dataclass class Session: session_id: str bound_principal: str # NOTE: no cached scope set — scopes are re-derived per call by design. @dataclass class ToolSpec: name: str required_scope: str class McpServer: def __init__(self) -> None: self.sessions: dict[str, Session] = {} self.tools: dict[str, ToolSpec] = {} def initialize(self, token: Token) -> Session: if token.revoked: raise ConsentBoundaryError("cannot initialize with revoked token") sid = f"sess-{token.principal}-{len(self.sessions)}" sess = Session(session_id=sid, bound_principal=token.principal) self.sessions[sid] = sess return sess def tools_call( self, session_id: str, tool_name: str, token: Optional[Token], ) -> str: # Invariant: consent is re-derived from the presented credential on # every call. The session supplies only the principal binding. if token is None: raise ConsentBoundaryError("missing Authorization on tools/call") sess = self.sessions.get(session_id) if sess is None: raise ConsentBoundaryError(f"unknown session {session_id}") if token.revoked: # Revocation is authoritative regardless of session state. del self.sessions[session_id] raise ConsentBoundaryError( f"token for principal {token.principal} is revoked; session invalidated" ) if token.principal != sess.bound_principal: # Cross-principal reuse is escalation, not retention. Kill session. del self.sessions[session_id] raise ConsentBoundaryError( f"principal_mismatch: session bound to {sess.bound_principal}, " f"request presented {token.principal}" ) spec = self.tools.get(tool_name) if spec is None: raise ConsentBoundaryError(f"unknown tool {tool_name}") if spec.required_scope not in token.scopes: raise ConsentBoundaryError( f"insufficient_scope: {tool_name} requires {spec.required_scope!r}, " f"presented scopes={sorted(token.scopes)}" ) return f"executed {tool_name} as {token.principal}" # Reproduce the failure: broad token establishes session, narrowed token # continues the same session. The naive server would have cached the broad # grant; this one rejects at the tool boundary. srv = McpServer() srv.tools["shell"] = ToolSpec(name="shell", required_scope="shell:exec") srv.tools["read"] = ToolSpec(name="read", required_scope="files:read") broad = Token(principal="agent-a", scopes=frozenset({"files:read", "shell:exec"})) sess = srv.initialize(broad) assert srv.tools_call(sess.session_id, "shell", broad) == "executed shell as agent-a" narrowed = Token(principal="agent-a", scopes=frozenset({"files:read"})) try: srv.tools_call(sess.session_id, "shell", narrowed) except ConsentBoundaryError as e: print(f"correctly denied: {e}") # Cross-principal reuse must escalate to session teardown. other = Token(principal="agent-b", scopes=frozenset({"files:read", "shell:exec"})) try: srv.tools_call(sess.session_id, "shell", other) except ConsentBoundaryError as e: print(f"correctly rejected: {e}") ```