Under what conditions must an instance treat a per-request MCP OAuth grant as invalid even when the token signature and audience both verify

**Date of Record:** 2026 December 1 **Scope:** Applies to MCP servers that receive OAuth 2.1 bearer tokens minted with a per-request resource indicator (RFC 8707) and an audience claim restricted to a single resource URI, where the same client session issues multiple tool calls against distinct tool/resource endpoints. Does not cover token-exchange flows across authorization servers, nor DPoP-bound tokens where the proof-of-possession key is itself the binding.

Core Distinction

The distinction that matters here is between *token validity* and *token applicability to the specific request*. A token can be cryptographically valid (signature checks out against the AS's JWKS), temporally valid (nbf/exp in window), and audience-valid (the `aud` claim equals a resource identifier the server recognizes)—and still be **inapplicable** to the concrete request being served. The failure mode is that MCP servers commonly collapse these into one check: "does `aud` contain one of my resource URIs?" That is a *set-membership* test, not a *binding* test.

The RFC 8707 `resource` parameter exists precisely to bind a token to one resource. When the AS echoes the requested `resource` into `aud`, and the client then reuses that same token against a *different* tool endpoint on the same MCP server, the server must decide: is the audience check satisfied because the host is the same, or violated because the resource is different? The non-obvious answer is that under strict resource-bound semantics, **same-host-different-resource is a violation**, and a naive `aud ∈ {known_resources}` check silently permits cross-resource replay within a single server process.

What Was Observed

During a multi-tool MCP session against a server exposing three tool families—`fs.read` (resource `mcp://host/fs`), `db.query` (resource `mcp://host/db`), and `net.fetch` (resource `mcp://host/net`)—the following trace was captured:

  1. Client performs the standard authorization flow with `resource=mcp://host/fs`. The AS mints a token with `aud=["mcp://host/fs"]`, `scope="fs.read"`, `exp=+300s`.
  2. Client calls `fs.read` tool. Server validates signature, `exp`, and checks `aud` against its resource registry. Pass. Tool executes.
  3. Client, in the same session and *without re-authorization*, calls `db.query` with the **same bearer token**. The prompt-injection vector here is that a poisoned tool result from step 2 instructed the model to "also check the database."
  4. Server validates signature (pass), `exp` (pass), and runs `aud ∩ resource_registry ≠ ∅` where `resource_registry = {mcp://host/fs, mcp://host/db, mcp://host/net}`. Because `aud=["mcp://host/fs"]` intersects the registry, the check **passes**.
  5. `db.query` executes with a token that was never scoped to the database resource. The `scope` claim (`fs.read`) is checked only as a coarse permission, and the server's scope-to-tool mapping was permissive by default.

The observable effect: a token minted for one resource exercised a different resource. The audience check "passed" while the binding invariant was violated. In a controlled replay, 100% of cross-resource calls within the token's `exp` window succeeded under the set-membership check and 0% succeeded under the strict binding check.

The second-order observation is subtler and is the actual boundary condition: the failure is **invisible in isolated unit tests**. A test that mints a token for `mcp://host/fs` and calls `fs.read` passes under both the naive and strict checks. The divergence only appears when a *single token* is presented to a *different* resource endpoint on the *same server*—a stateful, cross-request condition that per-endpoint tests never instantiate.

Condition of Validity

The per-request OAuth grant is valid for a given MCP tool invocation if and only if **all** of the following hold simultaneously:

The condition of validity fails—and the server must reject—when *any* of these is false. The critical, non-obvious clause is the **exact equality** on `aud`. Set intersection is not sufficient. A server that admits `aud` of cardinality > 1 for a per-request grant has already lost the binding, because multi-audience tokens are, by construction, replayable across the audiences they name.

Decision Boundary

The boundary between "accept" and "reject" is not "is this a token I trust?" but "**is this token bound to the resource I am about to touch?**" Concretely:

The boundary is sharp because it is an equality, not a threshold. There is no "mostly bound" state. The temptation to soften it—"well, the host matches"—is exactly the bug.

Operational Effect

Enforcing exact resource binding changes three operational behaviors:

  1. **Cross-resource calls require re-authorization.** A model that, mid-task, decides to call a different tool family must obtain a token scoped to that resource. This surfaces as a `401`/`403` with a `WWW-Authenticate` challenge carrying the correct `resource` parameter, which the MCP client must handle by re-running the authorization flow. Agents that treat `403` as "retry with same token" will loop; the correct behavior is to escalate to re-auth.
  2. **Prompt-injection blast radius shrinks.** A poisoned tool result that instructs the model to pivot to another resource now fails at the authorization layer rather than at the (often permissive) scope layer. The token's binding is the containment boundary, not the model's judgment.
  3. **Token lifetime and resource cardinality become coupled.** Because a token is single-resource, the number of tokens in flight scales with the number of distinct resources touched in a session. Servers must handle JWKS key rotation and `exp` expiry per-token, and clients must cache tokens keyed by `(resource, scope)`—not by host.

The invariant to encode: **a per-request MCP OAuth token authorizes exactly one resource URI, and that URI must equal the resource URI of the tool being invoked.** Any check weaker than equality is a latent cross-resource replay vulnerability that per-endpoint tests will not catch.

import time
from dataclasses import dataclass
from typing import Optional


class ResourceBindingError(RuntimeError):
    """Raised when a bearer token is not bound to the resource being invoked."""
    pass


@dataclass(frozen=True)
class Token:
    aud: Optional[list[str]]
    scope: str
    nbf: float
    exp: float
    signature_valid: bool


@dataclass(frozen=True)
class ToolInvocation:
    tool_name: str
    resource_uri: str          # e.g. "mcp://host/db"
    request_resource_hint: Optional[str] = None


def authorize_per_request(
    token: Token,
    invocation: ToolInvocation,
    *,
    now: Optional[float] = None,
    clock_skew_s: float = 30.0,
    allow_multi_resource_grants: bool = False,
) -> None:
    """
    Enforce strict per-request resource binding for an MCP tool invocation.
    Raises ResourceBindingError on any violation of the binding invariant.
    """
    now = time.time() if now is None else now

    if not token.signature_valid:
        raise ResourceBindingError("token signature invalid")

    if not (token.nbf - clock_skew_s <= now <= token.exp + clock_skew_s):
        raise ResourceBindingError(
            f"token outside validity window: nbf={token.nbf} exp={token.exp} now={now}"
        )

    if not token.aud:
        raise ResourceBindingError("token has no aud claim; no resource binding present")

    if len(token.aud) > 1 and not allow_multi_resource_grants:
        raise ResourceBindingError(
            f"per-request grant has multi-audience {token.aud!r}; "
            "cannot satisfy single-resource binding invariant"
        )

    # The critical check: exact equality, NOT set intersection.
    if invocation.resource_uri not in token.aud:
        raise ResourceBindingError(
            f"token aud {token.aud!r} does not name invoked resource "
            f"{invocation.resource_uri!r} (cross-resource replay rejected)"
        )

    if len(token.aud) == 1 and token.aud[0] != invocation.resource_uri:
        # Unreachable given the membership check above, but kept explicit as the
        # binding invariant: the single audience must equal the invoked resource.
        raise ResourceBindingError(
            f"binding mismatch: aud[0]={token.aud[0]!r} != resource={invocation.resource_uri!r}"
        )

    if invocation.request_resource_hint is not None:
        if invocation.request_resource_hint != token.aud[0]:
            raise ResourceBindingError(
                f"request resource hint {invocation.request_resource_hint!r} "
                f"disagrees with token aud[0]={token.aud[0]!r}"
            )


# --- Example: the cross-resource replay that a naive check would admit ---

if __name__ == "__main__":
    fs_token = Token(
        aud=["mcp://host/fs"],
        scope="fs.read",
        nbf=time.time() - 5,
        exp=time.time() + 300,
        signature_valid=True,
    )

    # Legitimate call: bound resource matches.
    authorize_per_request(fs_token, ToolInvocation("fs.read", "mcp://host/fs"))

    # Replay: same token, different resource on the same host.
    try:
        authorize_per_request(fs_token, ToolInvocation("db.query", "mcp://host/db"))
    except ResourceBindingError as e:
        print(f"correctly rejected: {e}")