DOCUMENTATION

Agent API: access for pipelines and AI agents

A small HTTP API and an MCP endpoint that let a script, a deployment pipeline or an AI agent ask for time-boxed access to a database, a Kubernetes cluster, a web application, a server or a remote desktop, without ever holding a password or a key.

What it is for

Automation usually gets access in one of two bad ways: a shared password in a CI variable, or a permanent service account. The agent API replaces both with the same flow a person follows in Captivo Access: ask for a resource with a reason, wait for approval, connect, and lose the access when the time is up.

  • An agent is a token plus an identity. Creating a token creates a user named Agent: <name> with the Vendor role and an e-mail on the reserved agents.invalid domain, which cannot receive mail and cannot be claimed by anyone. It counts as one user against the workspace user limit.
  • It can reach SSH resources, TCP tunnels, databases, Kubernetes clusters, web applications and remote desktops. Isolated browsers and VNC consoles are for people and cannot be put on an agent token.
  • It sees only the resources listed on its token, for at most the minutes the token allows, and every request goes through the same checks as a person's: approval, ticket gating, schedules and the maximum grant duration.
The base address is your workspace host followed by /api/agent/v1, for example https://acme.cloud.captivo.io/api/agent/v1 on Cloud or your own console address on a self-hosted server. The page Identity & access → Agents prints it with your host filled in.
Identity & access → Agents: agent tokens and their resource scope.

Creating and scoping a token

Open Identity & access → Agents and choose New agent token. You need the role that may change configuration (an Admin). The form has these fields:

FieldMeaning and limits
Name2 to 60 characters, shown in the list, in approval requests and in the audit log.
Resources it may ask forAt least one, at most 50. Only resources an agent can use are offered. The token can never ask for anything outside this list.
Longest access per request (minutes)5 minutes to 24 hours; default 60. A longer request is cut down to this value, not refused.
Token lifetime (days)1 to 90; default 30. After that the token simply stops working.
Calls per minute10 to 600; default 120. See Rate limits below.
Approves its own requestsOff by default. Off: every request waits for a person. On: it is approved immediately, only for the listed resources and the minutes above.

After Make token the console shows the token once. It starts with cat_; only a SHA-256 hash is stored, so a lost token cannot be shown again, only replaced. Put it in the agent's secret store. The list afterwards shows the first characters (the prefix), the resources, the limits, the expiry and when it was last used.

Revoking a token

Revoke stops the token at once and ends every active access grant its identity holds. Sessions already open are cut by the periodic live-session re-check, within about a minute. Revoking is the way to close an agent's access early, because the API itself has no "close" call.

The flow, step by step

Every call carries the token as a bearer token. The examples assume TOKEN holds it and API is the base address above.

bash
export API=https://acme.cloud.captivo.io/api/agent/v1
export TOKEN=cat_...   # shown once when the token was made

1. See what the token may ask for

bash
curl -s -H "Authorization: Bearer $TOKEN" $API/me

{
  "agent": { "name": "Release pipeline", "expiresAt": "2026-12-25T09:00:00.000Z",
             "maxMinutes": 60, "autoApprove": false, "ratePerMinute": 120 },
  "resources": [
    { "id": "ckx1...", "name": "orders-db", "kind": "database", "access": null },
    { "id": "ckx2...", "name": "prod-cluster", "kind": "kubernetes",
      "access": { "id": "ckg9...", "state": "active",
                  "startsAt": "2026-11-25T09:00:00.000Z", "endsAt": "2026-11-25T09:30:00.000Z" } }
  ]
}

The kind is one of ssh, tunnel, database, kubernetes, web, rdp. access.state is active, pending, scheduled or off_hours, or access is null when nothing is requested.

2. Ask for access

bash
curl -s -X POST -H "Authorization: Bearer $TOKEN" -H "content-type: application/json" \
  -d '{"siteId":"ckx1...","minutes":30,"reason":"Backfill orders after INC-1042","ticket":"INC-1042"}' \
  $API/access

{ "id": "ckg9...", "status": "pending",
  "startsAt": "2026-11-25T09:00:00.000Z", "endsAt": "2026-11-25T09:30:00.000Z" }
  • reason is required, at least 10 characters. It reaches the approver and is stored with the request as Agent "<name>": <reason>. minutes defaults to 60 and is held to the token's limit. ticket is needed only when the resource requires a change or incident number.
  • The status comes back as pending (a person must approve), approved with "via": "ticket" (the ticket system approved it) or approved with "via": "token" (the token approves its own requests).
  • When a person must approve, the approvers get an e-mail (if access-request mail is enabled) and a push notification on their phones.
  • One at a time: while the agent has a pending, scheduled or active request for a resource, a second request returns 409 already_requested with the existing id.

3. Wait until it is active

bash
curl -s -H "Authorization: Bearer $TOKEN" $API/access/ckg9...

{ "id": "ckg9...", "siteId": "ckx1...", "status": "active",
  "startsAt": "2026-11-25T09:00:00.000Z", "endsAt": "2026-11-25T09:30:00.000Z" }

Statuses: pending, active, scheduled, off_hours, denied, revoked, expired. A denied or revoked request carries a reason. Only the agent's own requests are visible. Poll every few seconds, not in a tight loop; the call counts toward the rate limit.

4. Connect

bash
curl -s -X POST -H "Authorization: Bearer $TOKEN" $API/connect/ckx1...

{ "kind": "database", "ticket": "...", "expiresAt": "2026-11-25T09:30:00.000Z",
  "host": "access.example.com", "port": 15432, "database": "orders", "engine": "postgres",
  "recorded": true,
  "command": "psql \"host=access.example.com port=15432 user=<ticket> dbname=orders sslmode=require\"" }

Without active access the answer is 403 no_active_access. The shape of a successful answer depends on the resource kind:

KindWhat you get
ssh, tunnelA one-time code, the jump host and port, the target, and for SSH a ready command of the form ssh -J <code>@jump ... user@target. The ticket is good for two minutes to start the connection. On a recorded resource Captivo signs in with the saved account (username is returned) and records the session; on a tunnel the command is null and you forward a port (see TCP tunnels).
databaseProxy host and port, a ticket used as the user name, the database, the engine and a client command (psql, mysql, sqlcmd, redis-cli or mongosh) and, for Redis and MongoDB, a connection url. The ticket lasts up to 8 hours but never past the end of the access. See Database access.
kubernetesA kubeconfig (YAML text) whose token is a ticket, plus context, server, namespaces, readOnly and portForward flags. Same lifetime rule as databases. See Kubernetes access.
webThe application's url and the header name X-Captivo-Agent-Token. Send the agent token in that header with every request; the proxy checks the access and logs each request, and strips the header before it reaches the application. A wrong token gets a 401, not a login redirect.
rdpA .rdp file as text (rdp, fileName), recorded, expiresAt and a sample xfreerdp command. The resource must have native RDP enabled; see native RDP and SSH.

5. Run, finish, read results

Captivo does not run commands for the agent and has no call that returns a command's output. After connect, the agent uses the ordinary client with what it was given, and the results are whatever that client returns:

bash
# database: the ticket is the user name; no password is involved
psql "host=access.example.com port=15432 user=<ticket> dbname=orders sslmode=require" \
  -c "select count(*) from orders where status = 'stuck'"

# kubernetes: save the kubeconfig field to a file first
kubectl --kubeconfig ./prod-cluster.yaml get pods -n shop

# web application: the agent token goes in the header
curl -H "X-Captivo-Agent-Token: $TOKEN" https://billing.acme.cloud.captivo.io/api/invoices?status=open

There is no close call. The access ends at endsAt, or earlier if an administrator revokes the grant or the token. Request only the minutes the job needs.

Rate limits

Each token has its own budget per minute, set when it is made (10 to 600, default 120). Calls that create something, POST /access and POST /connect/<id>, have a separate budget of one tenth of that, at least 1: 12 per minute at the default, 1 at a rate of 10. Over the limit the answer is 429 rate_limited with retry-after: 60. The counters live in the memory of the console process, so a restart resets them.

A 401 is returned for an unknown, expired or revoked token alike; the answer does not say which.

The MCP endpoint

An MCP client (the host of an AI agent) can use the same operations at https://<workspace-host>/api/agent/mcp, with the same bearer token. It is a stateless streamable-HTTP server: it answers POST with JSON-RPC and answers GET with 405. Supported protocol versions are 2025-06-18, 2025-03-26 and 2024-11-05. A bad token gives a 401 already at initialize or tools/list, so a misconfigured client notices at once.

ToolSame asArguments
list_resourcesGET /me-
request_accessPOST /accesssiteId, reason, minutes, ticket
access_statusGET /access/<id>id
connectPOST /connect/<siteId>siteId

Each tool calls the REST handler itself, so the checks, the rate limit and the audit entries are the same; the MCP endpoint is not a second way in. A tool result is the JSON of the REST answer as text, with isError set when the call failed. Example client configuration (the exact file depends on the client):

json
{
  "mcpServers": {
    "captivo-access": {
      "url": "https://acme.cloud.captivo.io/api/agent/mcp",
      "headers": { "Authorization": "Bearer cat_..." }
    }
  }
}

What is audited

  • agent.token_create and agent.token_revoke, with who did it, the resources, the limits and, on revoke, how many grants were ended.
  • grant.auto_approved whenever a token approved its own request: the summary names the agent, the resource, the minutes and the reason, so approval without a person is always visible.
  • When a ticket system approves a request, the ticket approval is recorded against the grant (see access reviews and tickets).
  • The access itself runs under the agent's identity, so sessions, database queries and Kubernetes or web requests follow the resource's own recording and logging settings exactly as for a person (see recording and monitoring). The agent shows up under its Agent: <name> user name.

Safety guidance

  • Leave self-approval off unless the job cannot wait for a person. A self-approving token still stays inside its resource list and its minute limit, but nobody looks at the request beforehand. If you use it, keep the resource list to what that pipeline touches and the minutes short.
  • One token per job. Separate tokens give separate names in the audit log and let you revoke one pipeline without touching the others.
  • Short lifetimes. The token lifetime is at most 90 days; choose the shortest that suits the job and recreate it when it runs out.
  • Least privilege on the resource side. The agent signs in with the resource's saved account, so what that account may do is what the agent may do. Use a read-only account or the read-only option of a Kubernetes resource where the job only needs to read; see the policy options for a workspace-wide cap on grant length.
  • Keep the token out of prompts and logs. With an AI agent, put it in the MCP client's header configuration, not in the conversation. The tickets that connect returns are short-lived and need no password, but they are credentials while they last.
  • Test the revoke path once before you rely on it: make a token, take access, revoke it, and confirm the session ends.

Common problems

AnswerCause
401 unauthorizedToken missing, mistyped, expired, revoked, from another workspace, or the agent's user is disabled. It must start with cat_ and be sent as Authorization: Bearer.
403 site_not_allowedThe resource is not on the token's list. Make a new token; a list cannot be edited afterwards.
400 reason_required / invalid_minutesReason under 10 characters, or minutes not a whole number of at least 5.
400 grant_exceeds_maxThe workspace caps the length of a grant and the request is longer than the cap.
409 already_requestedA request for this resource is already pending, scheduled or active. Use the id in the answer.
403 no_active_accessconnect was called before the request was approved, or after it ended.
400 site_not_supportedThe resource kind cannot be used by an agent (isolated browsers and VNC consoles).
503 proxy_off / gateway_not_configuredThe database proxy or the SSH or RDP gateway is not enabled on the server. Self-hosted: check the data plane settings.
429 rate_limitedOver the token's per-minute budget. Wait the 60 seconds, and poll less often.

Related: database access, Kubernetes access, access reviews and tickets, recording and monitoring.

Was this article helpful?