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).
| Path | Caller | Token Vault endpoint | Webhook endpoint | Ticket purpose |
|---|---|---|---|---|
| Store a value | Browser or tvault | POST /api/vault/store-ticket | POST /v1/store | store |
| Fetch a value | Agent, key, script | GET /api/agents/credentials | GET /v1/credential | agent_credential |
| MCP tool call | MCP app | /api/mcp/{service}/{server} | POST /v1/proxy | proxy |
| Token Vault sign-in call | MCP app | /api/mcp/{service}/{server} | none | none |
| OAuth sign-in | MCP app | /api/mcp-oauth/* | none | none |
| Own OAuth app | Browser | POST /api/oauth-apps/{provider}/connect | GET /v1/oauth/start, /v1/oauth/callback | oauth_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.
{
"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.
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)| Hop | What moved | Saw the value |
|---|---|---|
| 1. Caller → Token Vault | The name github | No |
| 2. Token Vault → caller | Signed ticket, webhook URL | No |
| 3. Caller → webhook | Ticket + the value | Webhook |
| 4. Webhook → caller | status, service, non-secret meta | No |
Fetch a value (307)
For scripts, CI and the CLI. The caller needs Value access.
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{
"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).
| Hop | What moved | Saw the value |
|---|---|---|
| 1. Agent → Token Vault | Agent key, service name | No |
| 2. Token Vault → agent | 307 with a ticket | No |
| 3. Agent → webhook | Ticket | No |
| 4. Webhook → agent | The value | Webhook 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.
{
"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.
| Hop | What moved | Saw the value |
|---|---|---|
| 1. App → Token Vault | tvsess_… session, JSON-RPC body | No |
| 2. Token Vault → webhook | Ticket, body, upstream URL, header templates | No |
| 3. Webhook → upstream | Body + the real header | Webhook and upstream |
| 4-6. Upstream → webhook → Token Vault → app | Tool result | No. 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.
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.
| Hop | What moved | Saw a credential value |
|---|---|---|
| 1. App → Token Vault | tvsess_… session, JSON-RPC body | No (none exists) |
| 2. Token Vault → your MCP server | The pass, body | No |
| 3. Your MCP server → Token Vault | The pass, to check it | No |
| 4-5. Result back | Tool result | No. 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.
HTTP/1.1 401 Unauthorized
WWW-Authenticate: Bearer resource_metadata="https://api.tokenvault.uk/.well-known/oauth-protected-resource/api/mcp/github/github"{
"access_token": "tvsess_…",
"token_type": "Bearer",
"expires_in": 3600,
"refresh_token": "tvrefresh_…",
"scope": "…"
}| Hop | What moved | Saw a credential value |
|---|---|---|
| Discovery, registration | Metadata, client id | No |
| Consent | Your sign-in, the agent you pick | No |
| Token | tvsess_…, tvrefresh_… for that agent | No. 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.
| Hop | What moved | Saw the token or secret |
|---|---|---|
| 1-2. Browser ↔ Token Vault | Provider, service name, a signed 10-minute state ticket | No |
| 3-7. Browser ↔ webhook ↔ provider | Consent, authorization code | Webhook (the code) |
| 8-9. Webhook ↔ provider | Code + client secret, then the tokens | Webhook and provider |
| 10. Webhook → browser | status, service, provider | No |
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.
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:
{"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:
{
"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:
{
"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 Vault | Your webhook | |
|---|---|---|
| Credential values | Never | Yes |
| Encryption key | No | Yes (the reference webhook derives it from TV_WEBHOOK_SEED) |
| OAuth client secrets | No (client ids only) | Yes (OAUTH_PROVIDERS_JSON) |
| HMAC secret | Yes, to sign tickets | Yes, to verify them |
| Agents, access, policies, labels | Yes | No |
| MCP server URLs and header templates | Yes (${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 server | Never sees them |
| Tool lists and tool results | Caches tool lists; relays results without logging them | Yes, in transit |
| Activity | Metadata, 90 days | A 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.
Concepts: the Token Vault model
The whole Token Vault model on one page (credentials, MCP servers, agents, access, labels, policies, API keys, Activity and the kill switch) plus what Token Vault holds versus your webhook.
Add a credential
Store a credential on your webhook from one page, attach MCP servers, label it and give apps access, then rotate, delete and watch its health.