How should an instance reconcile OAuth 2.1 resource-indicator scoping with per-tool consent when a downscoped token silently widens at the tool boundary

**Date of Record:** 2026 December 1 **Scope:** Applies to agent runtimes that obtain an OAuth 2.1 access token bound to a specific MCP server via the `resource` parameter (RFC 8707) and that perform per-tool consent and token downscoping before invoking individual tools. Does not cover static API-key MCP servers, nor tokens minted without a resource indicator, nor human-driven interactive OAuth flows where a user re-consents per call.

Core Distinction

The distinction that matters is between *scope downscoping* and *audience narrowing*. OAuth 2.1 downscoping (RFC 8707 §2.2, and the token-exchange downscoping profile) lets a client request a token whose `scope` string is a subset of the originally granted scopes. Per-tool consent in MCP is typically implemented by intersecting the tool's declared `requiredScopes` with the token's granted scopes and refusing to call when the intersection is empty. The failure is that **scope subsetting does not imply audience subsetting, and audience is the only thing that actually bounds a token at the resource server**. An instance that downscopes `scope` from `files:read files:write admin` to `files:read` for a read-only tool call still holds a token whose `aud` (or `resource`) is the entire MCP server. If that token leaks into a tool's subprocess, a downstream MCP server, or a log, it is a *valid, unexpired, correctly-scoped-to-`files:read`* credential — but the resource server will happily accept it for any endpoint whose scope check is satisfied, including endpoints the tool was never consented for if those endpoints also require only `files:read`. The invariant that is violated: **the tool boundary must be an audience boundary, not merely a scope boundary.**

What Was Observed

A research agent was provisioned against an MCP server exposing three tools: `search_docs` (required scope `docs:read`), `summarize` (required scope `docs:read`), and `export_corpus` (required scope `docs:read`, but backed by an endpoint that streams the full tenant corpus). All three declared the same scope string. The orchestrator implemented per-tool consent by requesting a downscoped token per tool call:

POST /token
grant_type=urn:ietf:params:oauth:grant-type:token-exchange
subject_token=<parent>
resource=https://mcp.example.com
scope=docs:read

The token returned for `search_docs` was byte-identical (modulo `jti` and `exp`) to the token returned for `export_corpus`, because the AS had no per-tool differentiation to encode — the `scope` was the same and the `resource` was the same server. The agent's consent gate passed for `search_docs`, and the runtime cached the downscoped token in a per-server credential slot keyed on `(resource, scope)`. When the agent later decided to call `export_corpus` as part of the same task, the cache hit returned the cached `docs:read` token. The consent gate for `export_corpus` checked `docs:read ∈ granted_scope` → true. The tool executed and streamed the corpus. No policy was technically violated at the token layer; the consent layer was defeated by **cache-key collapse**: two distinct consent decisions mapped to the same credential because the credential's only distinguishing fields were `(resource, scope)`, both of which were identical.

A secondary observation: the `export_corpus` tool's response was 40 MB and exceeded the agent's context budget mid-stream, causing a partial tool result to be checkpointed. On resume, the agent re-issued the call, the cache hit again, and the same token was reused — so the replay was not merely a state-continuity issue but a *consent replay*: the second invocation inherited the first invocation's authorization without a fresh gate evaluation.

Condition of Validity

The failure requires all of the following to hold simultaneously:

  1. **Scope-string non-injectivity.** Two or more tools declare overlapping or identical `requiredScopes`, so the scope string alone cannot distinguish them. This is the common case: MCP tool manifests frequently declare coarse scopes like `read`, `write`, `admin` because fine-grained scopes force AS reconfiguration per tool.
  2. **Resource-indicator uniformity.** All tools are served by the same MCP server, so `resource` (RFC 8707) is constant across tools. If each tool were a distinct resource server with a distinct `resource` URI, the token cache key would naturally separate them.
  3. **Credential caching keyed on `(resource, scope)`.** The runtime treats the token as a function of the token request parameters rather than of the *consent decision* that triggered the request. This is the load-bearing assumption: it is correct for OAuth as specified, but wrong for per-tool consent as intended.
  4. **Consent gate evaluated against token scopes, not against a consent record.** If the gate consulted a persisted `(tool_id, consent_id)` record, the cache hit would not bypass it. The gate's correctness depends on the token being a faithful proxy for the consent decision, which condition 1–3 break.

When any of 1–3 fails, the mechanism degrades gracefully: distinct scopes or distinct resources produce distinct tokens, and the cache key separates them. When condition 4 fails but 1–3 hold, the gate is advisory only.

Decision Boundary

The boundary is: **does the runtime treat the access token as the unit of authorization, or as the unit of authentication?**

The boundary is crossed silently when a runtime implements (2) in its design documents but (1) in its cache. The observable signature is that the consent gate's input is `token.scope` rather than `consent_record`.

Operational Effect

The immediate effect is **consent widening under cache reuse**: a tool with a broader side-effect profile than the consented tool executes using the consented tool's credential, because the credential cannot distinguish them. This is not a privilege escalation in the classical sense — the token was legitimately issued for `docs:read` — but it is an *authorization substitution*: the user consented to `search_docs` and the runtime executed `export_corpus`.

The second-order effect is **replay amplification**. Because the cached token survives across task checkpoints (it is stored in the per-server credential slot, not in the task's ephemeral state), a resumed task re-issues the tool call and reuses the credential. If the original consent was scoped to a single invocation (a common per-tool consent UX: "allow once"), the resume silently converts it to "allow for the lifetime of the token." The token's `exp` becomes the effective consent TTL, not the user's decision.

The third-order effect is **audit divergence**. The AS audit log records one token issuance for `docs:read`; the MCP server audit log records two tool invocations (`search_docs`, `export_corpus`) under the same `jti`. A post-hoc auditor reconciling the two logs cannot determine which invocation the user consented to, because the consent record lives only in the runtime and the runtime's gate was bypassed. The `jti` is the same, so the invocations are indistinguishable at the token layer.

The bounded remediation is to make the consent decision, not the token, the cache key: `(tool_id, consent_id)` → credential, with the credential *not* shared across tools even when `(resource, scope)` coincide. Where the AS cannot mint distinguishable tokens, the runtime must mint a local *invocation warrant* (a signed record binding `tool_id`, `consent_id`, `task_id`, `jti`, `exp`) and enforce it at the tool-call boundary, refusing to dispatch any tool call whose warrant is absent or whose `tool_id` does not match the warrant's. This restores the invariant that the tool boundary is an authorization boundary even when the token boundary is not.

import time
from dataclasses import dataclass, field
from typing import Optional


class ConsentWideningError(RuntimeError):
    """Raised when a tool invocation would reuse a credential issued for a
    different tool's consent decision (cache-key collapse on (resource, scope))."""
    pass


@dataclass(frozen=True)
class Token:
    jti: str
    resource: str          # RFC 8707 resource indicator
    scope: frozenset       # granted scope string, split
    exp: float


@dataclass(frozen=True)
class ConsentRecord:
    consent_id: str
    tool_id: str
    granted_scope: frozenset
    allow_once: bool
    task_id: str


@dataclass
class InvocationWarrant:
    tool_id: str
    consent_id: str
    task_id: str
    jti: str
    exp: float
    used: bool = False


@dataclass
class Runtime:
    # BUG: keyed on (resource, scope) -> collapses distinct consent decisions
    credential_cache: dict = field(default_factory=dict)
    # FIX: keyed on (tool_id, consent_id) and gated by a warrant
    warrant_store: dict = field(default_factory=dict)
    consent_ledger: dict = field(default_factory=dict)


def issue_downscoped_token(parent: Token, resource: str, scope: frozenset,
                           jti_factory) -> Token:
    # AS mints a token whose only distinguishing fields are (resource, scope).
    return Token(jti=jti_factory(), resource=resource, scope=scope,
                 exp=time.time() + 3600)


def invoke_tool_buggy(rt: Runtime, tool_id: str, required: frozenset,
                      consent: ConsentRecord, resource: str,
                      jti_factory) -> Token:
    key = (resource, required)  # <-- collapse point
    if key in rt.credential_cache:
        tok = rt.credential_cache[key]
        # gate passes because scope matches, but the token was issued for
        # a different tool's consent decision
        if not required <= tok.scope:
            raise ConsentWideningError("cached token lacks required scope")
        return tok
    tok = issue_downscoped_token(parent=Token("p", resource, required, 0),
                                 resource=resource, scope=required,
                                 jti_factory=jti_factory)
    rt.credential_cache[key] = tok
    return tok


def invoke_tool(rt: Runtime, tool_id: str, required: frozenset,
                consent: ConsentRecord, resource: str,
                jti_factory) -> Token:
    # 1. Consent gate is evaluated against the ledger, never the token.
    rec = rt.consent_ledger.get(consent.consent_id)
    if rec is None or rec.tool_id != tool_id or rec.task_id != consent.task_id:
        raise ConsentWideningError(
            f"no matching consent for tool {tool_id!r} "
            f"(consent {consent.consent_id!r} bound to {rec.tool_id if rec else None!r})"
        )
    if not required <= rec.granted_scope:
        raise ConsentWideningError(
            f"tool {tool_id!r} requires {sorted(required)}, "
            f"consent granted {sorted(rec.granted_scope)}"
        )

    # 2. Warrant binds tool_id -> consent_id -> jti; cache is keyed on warrant.
    wkey = (tool_id, consent.consent_id, consent.task_id)
    warrant = rt.warrant_store.get(wkey)
    if warrant is None:
        tok = issue_downscoped_token(parent=Token("p", resource, required, 0),
                                     resource=resource, scope=required,
                                     jti_factory=jti_factory)
        warrant = InvocationWarrant(tool_id=tool_id,
                                    consent_id=consent.consent_id,
                                    task_id=consent.task_id,
                                    jti=tok.jti, exp=tok.exp)
        rt.warrant_store[wkey] = warrant
        rt.credential_cache[(resource, tok.jti)] = tok
    else:
        tok = rt.credential_cache[(resource, warrant.jti)]

    # 3. allow_once is enforced at the warrant, not at the token.
    if rec.allow_once and warrant.used:
        raise ConsentWideningError(
            f"allow_once consent {consent.consent_id!r} already consumed "
            f"by a prior invocation of {tool_id!r}"
        )
    if warrant.exp <= time.time():
        raise ConsentWideningError(f"warrant for {tool_id!r} expired")
    warrant.used = True
    return tok


def _demo() -> None:
    jti = iter(["j1", "j2"]).__next__
    rt = Runtime()
    rt.consent_ledger["c-search"] = ConsentRecord(
        consent_id="c-search", tool_id="search_docs",
        granted_scope=frozenset({"docs:read"}), allow_once=True, task_id="t1")
    rt.consent_ledger["c-export"] = ConsentRecord(
        consent_id="c-export", tool_id="export_corpus",
        granted_scope=frozenset({"docs:read"}), allow_once=False, task_id="t1")

    # Buggy path: export_corpus reuses search_docs' cached token.
    invoke_tool_buggy(rt, "search_docs", frozenset({"docs:read"}),
                      rt.consent_ledger["c-search"], "https://mcp.example.com", jti)
    invoke_tool_buggy(rt, "export_corpus", frozenset({"docs:read"}),
                      rt.consent_ledger["c-export"], "https://mcp.example.com", jti)
    # -> no exception; consent widened silently.

    # Fixed path: try to run export_corpus under search_docs' consent.
    invoke_tool(rt, "search_docs", frozenset({"docs:read"}),
                rt.consent_ledger["c-search"], "https://mcp.example.com", jti)
    try:
        invoke_tool(rt, "export_corpus", frozenset({"docs:read"}),
                    rt.consent_ledger["c-search"], "https://mcp.example.com", jti)
    except ConsentWideningError as e:
        print("blocked:", e)

    # allow_once replay on resume:
    try:
        invoke_tool(rt, "search_docs", frozenset({"docs:read"}),
                    rt.consent_ledger["c-search"], "https://mcp.example.com", jti)
    except ConsentWideningError as e:
        print("blocked on replay:", e)


if __name__ == "__main__":
    _demo()