Token VaultDocs
Get Started

How it works

Sequence diagrams and a who-saw-what table for every Token Vault hot path, from storing a value and fetching it by 307 to MCP tool calls, OAuth sign-in, own-app OAuth connect and denials.

Every path has the same shape. Token Vault decides and signs. Your webhook holds the value and does the work. Token Vault checks who is asking, what access they hold and every policy that applies. If all pass, it signs a short-lived ticket with the HMAC secret it shares with your webhook. The value then moves between the caller and your webhook, or between your webhook and the upstream API. It never moves through Token Vault, with one exception: the legacy tv-refresh capability, used only for tokens from Token Vault's old built-in OAuth apps and off by default in the reference webhook (details).

PathCallerToken Vault endpointWebhook endpointTicket purpose
Store a valueBrowser or tvaultPOST /api/vault/store-ticketPOST /v1/storestore
Fetch a valueAgent, key, scriptGET /api/agents/credentialsGET /v1/credentialagent_credential
MCP tool callMCP app/api/mcp/{service}/{server}POST /v1/proxyproxy
Token Vault sign-in callMCP app/api/mcp/{service}/{server}nonenone
OAuth sign-inMCP app/api/mcp-oauth/*nonenone
Own OAuth appBrowserPOST /api/oauth-apps/{provider}/connectGET /v1/oauth/start, /v1/oauth/callbackoauth_connect

Tickets

A ticket is base64url(json).hex_hmac, signed with HMAC-SHA256 under your webhook's HMAC secret. Your webhook checks the signature, the expiry, the purpose and the service before it touches storage.

Decoded ticket payload
{
  "sub": "<your user id>",
  "svc": "github",
  "pur": "agent_credential",
  "aid": "<agent id>",
  "iat": 1793613600,
  "exp": 1793613660,
  "nonce": "9c2f4e1a7b3d8e605f1c2a9d4b7e3f10"
}

Credential, store and proxy tickets live 60 seconds. The OAuth state ticket lives 10 minutes. The reference webhook also refuses a nonce it has seen. Full field list: Tickets and capabilities.

Store a value

The browser (Add credential, Rotate) and tvault add / tvault set all store this way.

Loading diagram...
3: browser → webhook
POST /v1/store HTTP/1.1
Host: tv-webhook.example.workers.dev
Content-Type: application/json

{"ticket":"eyJzdmMiOiJnaXRodWIiLCJwdXIiOiJzdG9yZSIs…fQ.a71c…90bd","service":"github","tokenData":{"tokenType":"PlainText","accessToken":"ghp_…"}}

tvault --dry-run shows the split without sending anything:

$ printf %s "$GITHUB_PAT" | tvault --dry-run add github
[dry-run] POST /api/vault/store-ticket {serviceName: "github", intent: "create"}
[dry-run] POST <webhook>/v1/store (accessToken, value redacted)
HopWhat movedSaw the value
1. Caller → Token VaultThe name githubNo
2. Token Vault → callerSigned ticket, webhook URLNo
3. Caller → webhookTicket + the valueWebhook
4. Webhook → callerstatus, service, non-secret metaNo

Fetch a value (307)

For scripts, CI and the CLI. The caller needs Value access.

Loading diagram...
1-2: agent ↔ Token Vault
GET /api/agents/credentials?service=github HTTP/1.1
Host: api.tokenvault.uk
Authorization: Bearer tvagent_…

HTTP/1.1 307 Temporary Redirect
Location: https://tv-webhook.example.workers.dev/v1/credential?ticket=eyJzdWIiOi…fQ.3f9a…c21e&service=github
5: webhook → agent
{
  "token": {
    "accessToken": "ghp_…",
    "serviceName": "github",
    "tokenType": "PlainText",
    "createdAt": "2026-11-02T10:12:03Z",
    "hasRefreshToken": false
  }
}

curl -L, Go's HTTP client and the tvault CLI follow the 307 by themselves. They drop only the Authorization (and Cookie) header when the host changes, so a key sent as Authorization: Bearer never reaches your webhook. The ticket alone authorizes the read. On this endpoint use Authorization: Bearer: X-Agent-Key is refused (400 AGENT_KEY_HEADER_NOT_ACCEPTED), because clients would send that header on to your webhook. Never use ?key= (refused).

HopWhat movedSaw the value
1. Agent → Token VaultAgent key, service nameNo
2. Token Vault → agent307 with a ticketNo
3. Agent → webhookTicketNo
4. Webhook → agentThe valueWebhook and agent

Token Vault records AGENT_CREDENTIAL_ACCESS in Activity; the copy it forwards to your webhook also carries zero_knowledge: true. The MCP tool get_credential works the same way: it returns a fetch URL, not the value. Reference: Agent credentials.

MCP tool call

The main path for MCP apps. The agent needs MCP access. It calls the MCP server's tools and is never handed the value.

Loading diagram...
2: Token Vault → webhook, POST /v1/proxy (trimmed)
{
  "ticket": "eyJzdmMiOiJnaXRodWIiLCJwdXIiOiJwcm94eSIs…fQ.4b1d…e09c",
  "service": "github",
  "upstream": {
    "url": "https://api.githubcopilot.com/mcp/",
    "method": "POST",
    "body": "<base64 of the JSON-RPC body>"
  },
  "headerTemplates": {
    "Authorization": "Bearer ${TOKEN}",
    "Accept": "application/json, text/event-stream"
  }
}

Token Vault stores only the template. A header whose name looks like a credential (Authorization, Cookie, X-Api-Key, …) must contain the ${TOKEN} placeholder: Token Vault refuses a literal secret there. The webhook answers with the upstream's raw response (same status, same body, Mcp-Session-Id kept), and Token Vault streams it back.

HopWhat movedSaw the value
1. App → Token Vaulttvsess_… session, JSON-RPC bodyNo
2. Token Vault → webhookTicket, body, upstream URL, header templatesNo
3. Webhook → upstreamBody + the real headerWebhook and upstream
4-6. Upstream → webhook → Token Vault → appTool resultNo. Token Vault sees the result in transit and does not log it

Token Vault fetches each MCP server's tool list the same way, through /v1/proxy, when you add the MCP server. Activity records the call as SECRET_ACCESS with source: "proxy", channel MCP tools. Where your Token Vault has it enabled, the single URL /api/agents/mcp gives one URL for all your MCP servers; those calls take this same path. Reference: MCP server endpoint.

Token Vault sign-in call

The one path where Token Vault calls an MCP server itself. It is for an MCP server you run that only needs to know which agent is calling. A Token Vault sign-in credential holds no value, so there is nothing for your webhook to hold.

Loading diagram...

The pass is Token Vault's own identity token. It is not a credential for any service, and it cannot call Token Vault. The app never holds it. Token Vault never sends it to your webhook, and a ${TOKEN} MCP server is never called directly.

HopWhat movedSaw a credential value
1. App → Token Vaulttvsess_… session, JSON-RPC bodyNo (none exists)
2. Token Vault → your MCP serverThe pass, bodyNo
3. Your MCP server → Token VaultThe pass, to check itNo
4-5. Result backTool resultNo. Token Vault sees it in transit and does not log it

OAuth sign-in for MCP apps

How Claude.ai, ChatGPT, Claude Code, Cursor and the rest get a session without a pasted key. No credential value is involved: the session only says which agent is calling.

Loading diagram...
2: the challenge
HTTP/1.1 401 Unauthorized
WWW-Authenticate: Bearer resource_metadata="https://api.tokenvault.uk/.well-known/oauth-protected-resource/api/mcp/github/github"
9: token response
{
  "access_token": "tvsess_…",
  "token_type": "Bearer",
  "expires_in": 3600,
  "refresh_token": "tvrefresh_…",
  "scope": "…"
}
HopWhat movedSaw a credential value
Discovery, registrationMetadata, client idNo
ConsentYour sign-in, the agent you pickNo
Tokentvsess_…, tvrefresh_… for that agentNo. These identify the agent to Token Vault only

A tvsess_ issued for one MCP URL is refused on another. Every refresh re-checks the agent: a suspended agent gets no new session. Redirect hosts must be on Settings > Trusted hosts. Details: OAuth for MCP apps.

Connect with your own OAuth app

Store a Google, GitHub or Spotify token without pasting it. The provider redirects to your webhook, which exchanges the code with a client secret only it holds (OAUTH_PROVIDERS_JSON). Needs the webhook capability oauth-callback.

Loading diagram...
HopWhat movedSaw the token or secret
1-2. Browser ↔ Token VaultProvider, service name, a signed 10-minute state ticketNo
3-7. Browser ↔ webhook ↔ providerConsent, authorization codeWebhook (the code)
8-9. Webhook ↔ providerCode + client secret, then the tokensWebhook and provider
10. Webhook → browserstatus, service, providerNo

Token Vault never gets the code, the token or the client secret, and makes no outbound call. Your webhook refreshes the token itself, on its own timer; Token Vault only sends /v1/refresh-notify when you press Refresh. The old Connect through Token Vault's own OAuth app is off and returns 410 OAUTH_CONNECT_DISABLED. Setup: Your own OAuth app.

When a call is refused

Every check runs before Token Vault signs a ticket or calls your webhook. A refused call never reaches it.

Loading diagram...

Order for a value fetch: key (MISSING_KEY 401, INVALID_KEY 403) → penalty-box lockout → kill switch (VAULT_LOCKED) and agent status (AGENT_INACTIVE) → scope credentials:read (SCOPE_DENIED) → Token Vault's own rate limits (429) → access (NO_GRANT 404, GRANT_EXPIRED 403, GRANT_TOOLS_ONLY 403) → policies (POLICY_DENIED, 403 or 429). An MCP tool call runs the same kinds of check: session, MCP access covering that MCP server, rate limits, kill switch, then policies on the server, agent, credential and their labels.

Access refusals use Token Vault's standard envelope:

403, MCP-only access asked for the value
{"detail":{"code":"GRANT_TOOLS_ONLY","message":"This grant does not allow reading the credential value; it can only be used through MCP access."}}

Policy refusals are flat. An agent or key gets the short form:

403 POLICY_DENIED, as an agent sees it
{
  "error": "Access denied by policy",
  "policy": "eu-only",
  "rule": "geo_restrict",
  "reason": "Access denied: country US is not in the allowed list",
  "code": "POLICY_DENIED"
}

You (signed in to the web app, or your own tvault login) also get where the policy came from and its settings. Agents never get these, so they cannot route around a policy:

Extra fields for the owner
{
  "policyId": "<policy id>",
  "appliedVia": {"type": "label", "id": "work", "carriedBy": ["token"]},
  "ruleSettings": {"mode": "allow", "countryCodes": ["GB", "DE"]}
}

A rate_limit refusal is 429 with Retry-After and retryAfter. Activity shows each refusal in plain words, such as claude-code can use github through MCP but not read the value. Full contract: Denials.

Who holds what

Token VaultYour webhook
Credential valuesNeverYes
Encryption keyNoYes (the reference webhook derives it from TV_WEBHOOK_SEED)
OAuth client secretsNo (client ids only)Yes (OAUTH_PROVIDERS_JSON)
HMAC secretYes, to sign ticketsYes, to verify them
Agents, access, policies, labelsYesNo
MCP server URLs and header templatesYes (${TOKEN} or ${AGENT_SESSION} placeholders, no values)Reads them from each proxy call (${TOKEN} MCP servers only)
Sign-in passes (identity only, 15 minutes)Mints and sends them to your MCP serverNever sees them
Tool lists and tool resultsCaches tool lists; relays results without logging themYes, in transit
ActivityMetadata, 90 daysA forwarded copy of most events

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