Token VaultDocs
ReferenceOAuth

Introspection & Gateway Gating

Validate tvsess_ tokens from your own MCP gateway or webhook with one HTTP call, including the resource (aud) audience check and schedule enforcement.

POST /api/mcp-oauth/introspect is an RFC 7662-shaped endpoint for one job: let a service you host accept tvsess_ tokens as its auth. Your own MCP gateway can use it. So can the /mcp endpoint of your webhook, which asks it to authorise each tool call. Token Vault stays the identity and policy plane.

Loading diagram...

Passes Token Vault sends to your MCP server

If you add a Token Vault sign-in credential, Token Vault itself puts a tvsess_ token in the Authorization header of every call to your MCP server. This is that pass:

ItemValue
Who it namesThe agent that is calling. One pass per agent and MCP server
audThe URL of your MCP server
Lifetime15 minutes
RightsIdentity only. It cannot call Token Vault or read a credential. This endpoint is the only place that accepts it
Kept by the agent?No. Token Vault adds it. The agent never sees it

Check it as below. Send ?resource= with your own URL, and deny a pass whose aud is another URL.

Bearer-as-subject

There is no separate caller credential. The token being checked is the Authorization header (the OIDC UserInfo pattern), so a caller can only introspect tokens it already holds.

POST /api/mcp-oauth/introspect?resource=https://gw.example/mcp HTTP/1.1
Host: api.tokenvault.uk
Authorization: Bearer tvsess_...
QueryRequiredMeaning
resourceno, except for a Token Vault sign-in passThe resource your service is. A session issued for a different resource returns {"active": false}. A sign-in pass is {"active": false} without it
200 OK, token valid
{
  "active": true,
  "sub": "firebase-uid",
  "email": "owner@example.com",
  "agent_id": "agent-doc-id",
  "agent_name": "My Agent",
  "agent_description": "Does things",
  "exp": 1751234567,
  "aud": "https://gw.example/mcp",
  "authorization": { "allowed": true, "reason": null, "retry_after": null }
}

aud is the resource (RFC 8707) the session was issued for. It is present only when the session is bound to one.

200 OK, not active
{ "active": false }

active: false covers all of these, with no way to tell them apart:

  • The token is unknown, expired or malformed.
  • The agent is suspended or deleted.
  • The owner pressed Stop all access, or the lock check could not be completed (fails closed).
  • ?resource= names a different resource than the session's aud, or the session's resource could not be read.
  • The session is a Token Vault sign-in pass (minted for one agent and one MCP server) and ?resource= is missing or is not that server's URL.

A session with no stored resource (issued before audience binding) matches any ?resource=, except that a sign-in pass always has one.

Audience check

Always send ?resource= with the URL your service is. Without it, a session issued for another service passes your check. With it, a token minted for Token Vault's own MCP URL, or for another hub, is refused. Also compare aud with your own URL in your code (lower-case the scheme and host, drop a default port, a trailing / and any fragment before you compare). If aud is another URL, deny the call and do not cache the answer. See the resource parameter for how a session gets its audience.

Gating a gateway in ~20 lines

gateway_auth.py
import requests

MY_RESOURCE = "https://gw.example/mcp"

def check(bearer: str) -> tuple[bool, str | None]:
    r = requests.post(
        "https://api.tokenvault.uk/api/mcp-oauth/introspect",
        params={"resource": MY_RESOURCE},
        headers={"Authorization": f"Bearer {bearer}"},
        timeout=5,
    )
    if r.status_code != 200:
        return False, f"introspect failed: {r.status_code}"
    body = r.json()
    if not body.get("active"):
        return False, "invalid or revoked token"
    authz = body.get("authorization") or {}
    if not authz.get("allowed"):
        return False, authz.get("reason") or "blocked by policy"
    return True, None

The authorization block

The response carries the verdict of ambient policy evaluation: the time_window rules attached to the agent. Your gateway enforces schedules without a policy engine.

FieldTypeMeaning
allowedboolNo ambient policy denies access right now
reasonstring or nullHuman-readable denial reason
retry_afterint or nullSeconds until the window next opens

Only time_window is evaluated. Request-scoped rules (ip_allowlist, geo_restrict) would see your gateway's IP, not the agent's. Stateful rules (rate_limit, max_usage) must not fire on a passive check. manual_approval is unavailable and denies wherever it applies (see Policies). Those rules stay enforced on Token Vault's own surfaces.

Fail closed: if policy evaluation errors, the response is active: true with authorization.allowed: false and Cache-Control: no-store. The token is valid, the gate is shut for now, and the next call re-evaluates.

Caching

CaseCache-Control
active: false (every cause above)no-store
Valid, no time_window policyprivate, max-age=min(60, ttl)
Valid, time_window presentprivate, max-age=min(15, ttl)
Valid, policy evaluation errorno-store

ttl is the seconds left on the session. Success responses carry Vary: Authorization: the bearer is the subject, so a cache must key by token, never by URL. A suspended agent shows as active: false within the cache window (60 s, or 15 s with a schedule).

Errors

HTTPBodyWhen
401{"detail":{"error":"invalid_token","error_description":"Missing or malformed Authorization header"}}No Authorization: Bearer header, or an empty token
429{"detail":{"error":"rate_limited","error_description":"Too many requests"}}Over 600 per minute per IP. Honour Retry-After

Ready to try it?

Sign in with Google or email. Your credentials stay on your own webhook, and the quickstart gets Claude Code making its first MCP tool call in about 15 minutes.

On this page