Token VaultDocs
Reference

Grants API

Reference for the access endpoints that give agents and keys a credential, covering uses, MCP servers, expiry, find-or-create connect, revoke-all and the account-wide grants list.

A grant is one holder's access to one credential. It lives under the holder (an agent or an API key), is metadata only, and never holds a value. In the web app a grant is called access. How it works for people: Access.

All endpoints take Authorization: Bearer ... (a Firebase session, a tvkey_ key or a scoped tvagent_ key) and return JSON. Errors: Errors and exit codes.

The grant

FieldTypeNotes
serviceNamestringThe credential name
usesstring[]A subset of ["value", "tools"]. tools is MCP access: the API writes it tools, the web app and CLI say MCP. Absent means ["value"], so every grant made before the field existed is a value grant
entries{key, expiresAt}[]The parts of the grant, each with its own end: value, and one tools:<server> per MCP server. Live entries only. expiresAt: null means no end
serversstring[] or absentAgent grants with tools only. The MCP servers the grant has an entry for. A server added to the credential later is never covered without a new grant
grantExpiresAtISO 8601 or nullThe latest end of any entry. null if any entry has no end
grantedAtISO 8601
refreshPolicystringDefault none
sourcestringmanual, or auto:create for a grant made by a tokens:create-read key at creation time
  • value: the holder may fetch the value (agent credentials). Token Vault mints a ticket; the webhook returns the value.
  • tools (MCP access in the web app and CLI; the API writes it tools): the holder may call the credential's MCP servers (MCP server endpoint). It never receives the value. An MCP grant needs a credential that has MCP servers.
  • API keys carry value grants only. uses and servers on a key grant are refused with 422 INVALID_GRANT_USES.
  • A key or agent that grants can never widen: the new grant is cut to the grant it was copied from. A partial overlap is cut down silently. Asking for nothing the source grant allows is 403 GRANT_USES_EXCEEDED or 403 GRANT_SERVERS_EXCEEDED. An MCP-only grant cannot be passed to a key.
  • A key or agent can only pass on a credential it can itself read: it needs a live grant of its own (403 GRANT_REQUIRED). It can never change its own grants (403 SELF_GRANT_FORBIDDEN).
  • If a Who can read policy applies to the credential, granting is web-app only (403 WEB_CONSOLE_REQUIRED).

Expiry. expiresInHours counts from now. If you leave it out, the grant never expires. A key or agent's request is clamped to its own expiry. The web app defaults to 24 hours for a value grant and "until revoked" for an MCP-only grant.

Each part ends on its own. The value and each MCP server are separate entries. A value grant for a day and MCP access to github until revoked can sit on one grant. When one entry ends, the others keep working.

Granting again adds, it never shortens. If the agent already holds the credential, a new grant adds the entries it names. An entry the agent holds for as long or longer is kept and listed in alreadyHeld. To shorten or remove an entry, edit it with PATCH and entries.

Agent grants

POST /api/agents/{agentId}/grants

Scope: grants:write. Needs the kill switch off.

Body fieldTypeRequiredNotes
serviceNamestringyesThe credential must exist on your webhook
expiresInHoursintegernoOmit for no expiry
refreshPolicystringnoDefault none
usesstring[]novalue, tools. Omit for ["value"]
serversstring[]noThe MCP servers this access covers. Only with tools. Must exist on the credential
agentIdstringnoIgnored. The path is authoritative
curl -s -X POST https://api.tokenvault.uk/api/agents/ag_7kq2/grants \
  -H "Authorization: Bearer $TVKEY" -H "Content-Type: application/json" \
  -d '{"serviceName":"github","uses":["tools"],"servers":["github"]}'
200 OK
{
  "success": true,
  "serviceName": "github",
  "grantExpiresAt": null,
  "refreshPolicy": "none",
  "uses": ["tools"],
  "servers": ["github"]
}

uses and servers appear in the response only when the grant stores them. alreadyHeld lists entries the agent already had for as long or longer, for example ["value"].

Errors: 404 Agent not found, 412 Agent is suspended, 404 Token '...' not found in vault, 412 vault locked, 422 INVALID_GRANT_USES, 422 INVALID_GRANT_SERVERS, 403 GRANT_USES_EXCEEDED, 403 GRANT_SERVERS_EXCEEDED, 403 GRANT_REQUIRED, 403 WEB_CONSOLE_REQUIRED, 423 VAULT_LOCKED.

PATCH /api/agents/{agentId}/grants/{service}

Edit a grant in place. Scope: grants:write. Name at least one field (400 NO_FIELDS). Unknown fields are a 422. A grant that does not exist is 404: PATCH never creates one.

Body fieldTypeNotes
usesstring[]Replaces the uses
serversstring[] or nullThe MCP servers this access covers. Absent keeps the held MCP servers. null means the servers the credential has now
expiresInHoursinteger, 1 to 87600Counts from now. Applies to every entry
expiresAtISO 8601 or nullAbsolute, in the future, within 10 years. null means no expiry. Applies to every entry
entriesobjectChange entries one by one instead: {"tools:github": {"expiresInHours": 24}, "value": {"remove": true}}. Each takes expiresInHours, expiresAt or remove. Not combined with the fields above (422 ENTRIES_OR_FIELDS)

expiresInHours and expiresAt together are 400 INVALID_EXPIRY. If the entries end at different times and one expiry would shorten one of them, the edit is 409 GRANT_ENTRIES_DIFFER: send entries. An entry the grant does not hold is 422 ENTRY_NOT_HELD. Every rule of create applies to the result, so an edit can never produce a grant that create would refuse.

curl -s -X PATCH https://api.tokenvault.uk/api/agents/ag_7kq2/grants/github \
  -H "Authorization: Bearer $TVKEY" -H "Content-Type: application/json" \
  -d '{"uses":["value","tools"],"expiresAt":null}'
200 OK
{
  "success": true,
  "serviceName": "github",
  "changed": true,
  "grantExpiresAt": null,
  "refreshPolicy": "none",
  "uses": ["value", "tools"],
  "servers": ["github"]
}

changed is false when the edit changed nothing.

DELETE /api/agents/{agentId}/grants/{service}

Scope: grants:write. Lock-exempt, because it only reduces access. Returns {"success": true}, or 404 Grant not found.

POST /api/agents/{agentId}/grants/revoke-all

Revoke every grant the agent holds, in one atomic batch. Scope: grants:write. Lock-exempt, works on a suspended agent. The agent's key, sessions and policies are untouched.

200 OK
{ "success": true, "revoked": ["github", "stripe"] }

revoked is [] when the agent held none.

POST /api/agents/connect

Find an agent by name, or create it, and grant it services in one call. Scopes: agents:create and grants:write. Everything is validated before anything is written, and repeating a call that failed midway finishes it.

Body fieldTypeNotes
agentNamestringExact name
createIfMissingbooleanDefault false. Without it a missing agent is 404 AGENT_NOT_FOUND
grantsobject{ "<service>": { "uses"?, "servers"?, "expiresInHours"? } }
curl -s -X POST https://api.tokenvault.uk/api/agents/connect \
  -H "Authorization: Bearer $TVKEY" -H "Content-Type: application/json" \
  -d '{"agentName":"claude-code","createIfMissing":true,"grants":{"github":{"uses":["tools"]}}}'
200 OK
{
  "agentId": "ag_7kq2",
  "created": true,
  "createdBy": { "type": "user", "id": "firebase-uid" },
  "mcpEnabled": true,
  "grants": [
    { "serviceName": "github", "existing": false, "grantExpiresAt": null, "uses": ["tools"] }
  ],
  "mcpUrl": "https://api.tokenvault.uk/api/agents/mcp",
  "snippets": { "claudeCode": "claude mcp add --transport http tokenvault https://api.tokenvault.uk/api/agents/mcp" }
}
  • mcpEnabled in the response is retired. It is kept for older clients and is false only for an older agent that still carries a stored "MCP off" setting.
  • A created agent is a classic agent with MCP on. A human creating needs a recent sign-in (401 REAUTH_REQUIRED).
  • An existing agent is matched by exact name, and only if the caller made it. Otherwise 409 AGENT_NAME_TAKEN. Matching needs agents:read. Several matches are 409 AMBIGUOUS_AGENT_NAME.
  • A grant the agent already holds is left alone unless you name a field for it. Then only that field changes.
  • The agent's key is not returned. Reveal it with POST /api/agents/{agentId}/reveal-key.

Key grants

Same paths under /api/keys/{keyId}/grants. Scope: grants:write. Value grants only.

Method and pathBodyNotes
POST /api/keys/{keyId}/grantsserviceName, expiresInHours (1 to 87600), refreshPolicyuses or servers is 422 INVALID_GRANT_USES. 412 API key is suspended
PATCH /api/keys/{keyId}/grants/{service}expiresInHours or expiresAtExpiry only. Same rules as the agent PATCH
DELETE /api/keys/{keyId}/grants/{service}noneLock-exempt
POST /api/keys/{keyId}/grants/revoke-allnoneLock-exempt. {"success": true, "revoked": [...]}
POST 200 OK
{ "success": true, "serviceName": "github", "grantExpiresAt": "2026-11-09T10:00:00+00:00", "refreshPolicy": "none", "source": "manual" }
PATCH 200 OK
{ "success": true, "serviceName": "github", "changed": true, "grantExpiresAt": null, "refreshPolicy": "none", "source": "manual" }

Listing grants

GET /api/grants

Every grant across every agent and key. Human only (a web session or an admin CLI login), because it names every key. Query: includeExpired=1 also returns grants that are not live.

200 OK
{
  "grants": [
    {
      "holderType": "agent",
      "holderId": "ag_7kq2",
      "holderName": "claude-code",
      "holderStatus": "active",
      "serviceName": "github",
      "uses": ["tools"],
      "servers": ["github"],
      "grantExpiresAt": null,
      "grantedAt": "2026-11-02T09:30:00+00:00",
      "source": "manual",
      "live": true,
      "expired": false
    }
  ]
}
FieldNotes
holderTypeagent or api_key
holderStatusactive or suspended
usesAlways present. ["value"] for a grant stored without it
serversnull unless an MCP grant limits the MCP servers
liveUsable now
expiredtrue for a lapsed expiry
deadReasonPresent for a grant that is not live

Sorted by holder type, holder name, then service. A revoked key holds nothing and is skipped.

GET /api/tokens/{service}/grants

The same rows for one credential: the Access tab. Human only. Each row is the grant as stored (including counts) plus live, deadReason and the holder fields.

CLI

tvault grant claude-code github=mcp:github     # POST /api/agents/{id}/grants, agent first
tvault keys grant ci-key github                   # POST /api/keys/{id}/grants, value only

See tvault CLI.

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