Skip to content
undertext developers
Skip to Content
undertext developers
REST API

Agents

List, name, limit and revoke the AI agents your users connected to their documents.

An agent is an MCP client, such as Claude Code or Codex, that one of your users approved to work in their documents. It connects to your platform's MCP address at https://mcp.undertext.sh/acme, and Undertext issues its tokens; your server never holds them. These endpoints are for your settings screens: show people their agents, let them name each, choose which documents each reaches, and revoke them. Agents are created by approving an agent request. See Agents.

An agent's access is either:

  • all: every document its person can open, editing at most.
  • chosen: only the documents you give it a role in.

Either way, what it may do in a document is the lower of that and its person's current role there, checked on every call. It never owns a document.

The agent object

AttributeTypeDescription
idstringUndertext's id for the agent, starting agt_.
userstringThe Undertext id of the person it acts for.
namestringWhat its person calls it: at first what its client calls itself, until you name it. Its edits are credited as this name and its person's: "Research (Ada's agent)".
client_namestringWhat its client calls itself, such as "Claude Code", as the person saw when approving it.
hoststringThe domain the client is published from, checked by Undertext. Two agents can share a name; the host tells them apart.
localbooleanWhether the client is an app on its person's own device, such as a command-line tool or desktop app, that registered to come back to a loopback address or its own scheme. Its host is then that address, which says nothing people can check: show "On your computer" instead.
accessstringall or chosen.
connected_attimestampWhen its person approved it.
last_used_attimestamp or nullWhen it last called a tool, or null if it hasn't yet.
expires_attimestamp or nullUntil when it can renew its access unused: its newest refresh token lapses then, 90 days after it last renewed. Past it, or at null, its person approves it again.
{
  "id": "agt_3Vn8Qx2K",
  "user": "usr_5Kq2Lm8R",
  "name": "Research",
  "client_name": "Claude Code",
  "host": "claude.ai",
  "local": false,
  "access": "all",
  "connected_at": "2026-10-13T21:30:02Z",
  "last_used_at": "2026-10-13T22:58:41Z",
  "expires_at": "2027-01-11T22:58:41Z"
}

List a user's agents

GET /v1/users/{user_id}/agents

The agents a user has connected, newest first.

ParameterTypeDescription
user_idstring, path, requiredThe user's Undertext id.
documentstringA document id: each agent then has one more field, document_role, the role you gave it there, or null. For a document's sharing screen.
limitinteger1 to 100. Default 50.
afterstringThe next cursor from the previous page.
curl https://api.undertext.sh/v1/users/usr_5Kq2Lm8R/agents \
  -H "Authorization: Bearer $UNDERTEXT_SECRET_KEY"
{
  "data": [
    {
      "id": "agt_6Bw4Ys7J",
      "user": "usr_5Kq2Lm8R",
      "name": "Codex",
      "host": "openai.com",
      "access": "chosen",
      "connected_at": "2026-10-13T22:31:15Z",
      "last_used_at": "2026-10-13T22:38:09Z"
    },
    {
      "id": "agt_3Vn8Qx2K",
      "user": "usr_5Kq2Lm8R",
      "name": "Claude Code",
      "host": "claude.ai",
      "access": "all",
      "connected_at": "2026-10-13T21:30:02Z",
      "last_used_at": "2026-10-13T22:58:41Z"
    }
  ],
  "next": null
}

Retrieve an agent

GET /v1/agents/{agent_id}

ParameterTypeDescription
agent_idstring, path, requiredThe agent's id.
curl https://api.undertext.sh/v1/agents/agt_3Vn8Qx2K \
  -H "Authorization: Bearer $UNDERTEXT_SECRET_KEY"

Returns the agent, or 404 agent_not_found once it has been revoked.

Update an agent

PATCH /v1/agents/{agent_id}

Names an agent, or switches it between reaching all its person's documents and only the ones you choose, or both. A new name shows at once in the documents open now, and on everything the agent wrote; the access applies to its next tool call. Approving the same client again later keeps the name.

Switching to chosen keeps any roles you set before. An agent switched to chosen with no roles reaches nothing until you give it a document.

ParameterTypeDescription
agent_idstring, path, requiredThe agent's id.
namestringWhat its person calls it: 1 to 48 characters, trimmed, without control or invisible characters.
accessstringall or chosen.

Give name, access or both.

curl https://api.undertext.sh/v1/agents/agt_3Vn8Qx2K \
  -X PATCH \
  -H "Authorization: Bearer $UNDERTEXT_SECRET_KEY" \
  -H "Content-Type: application/json" \
  -d '{"name": "Research", "access": "chosen"}'

Returns the updated agent.

List an agent's documents

GET /v1/agents/{agent_id}/documents

The documents you've given an agent a role in, most recently edited first. These roles apply while its access is chosen; with all, it reaches every document its person can open and this list is kept for when you switch.

ParameterTypeDescription
agent_idstring, path, requiredThe agent's id.
limitinteger1 to 100. Default 50.
afterstringThe next cursor from the previous page.
curl https://api.undertext.sh/v1/agents/agt_6Bw4Ys7J/documents \
  -H "Authorization: Bearer $UNDERTEXT_SECRET_KEY"
{
  "data": [
    {
      "agent": "agt_6Bw4Ys7J",
      "document": "doc_8Hq2Lm4R",
      "title": "On the Analytical Engine",
      "role": "suggester",
      "effective_role": "suggester"
    },
    {
      "agent": "agt_6Bw4Ys7J",
      "document": "doc_3Wp7Zc1V",
      "title": "Notes for Thursday",
      "role": "editor",
      "effective_role": "suggester"
    }
  ],
  "next": null
}
AttributeTypeDescription
rolestringThe role you gave the agent: editor, suggester or viewer.
effective_rolestring or nullWhat it can do now: the lower of role and its person's current role. null when its person can no longer open the document.

Set an agent's role in a document

PUT /v1/agents/{agent_id}/documents/{document_id}

Gives an agent a role in one document, or changes it.

ParameterTypeDescription
agent_idstring, path, requiredThe agent's id.
document_idstring, path, requiredThe document's id.
rolestring, requirededitor, suggester or viewer. An agent is never an owner.
curl https://api.undertext.sh/v1/agents/agt_6Bw4Ys7J/documents/doc_8Hq2Lm4R \
  -X PUT \
  -H "Authorization: Bearer $UNDERTEXT_SECRET_KEY" \
  -H "Content-Type: application/json" \
  -d '{"role": "suggester"}'
{
  "agent": "agt_6Bw4Ys7J",
  "document": "doc_8Hq2Lm4R",
  "title": "On the Analytical Engine",
  "role": "suggester",
  "effective_role": "suggester"
}
ErrorWhen
400 invalid_parameter on rolerole is owner, or not a role.
404 document_not_foundThe document doesn't exist.

Remove an agent's role in a document

DELETE /v1/agents/{agent_id}/documents/{document_id}

Takes a document off an agent's list. With chosen access, it can no longer reach the document.

ParameterTypeDescription
agent_idstring, path, requiredThe agent's id.
document_idstring, path, requiredThe document's id.
curl https://api.undertext.sh/v1/agents/agt_6Bw4Ys7J/documents/doc_8Hq2Lm4R \
  -X DELETE \
  -H "Authorization: Bearer $UNDERTEXT_SECRET_KEY"
{
  "agent": "agt_6Bw4Ys7J",
  "document": "doc_8Hq2Lm4R",
  "removed": true
}

Revoke an agent

DELETE /v1/agents/{agent_id}

Disconnects an agent for good. Its tokens stop working at once, mid-call included, and Undertext sends agent.revoked. What it already wrote stays in documents, credited to it. To connect it again, its person approves it again.

ParameterTypeDescription
agent_idstring, path, requiredThe agent's id.
curl https://api.undertext.sh/v1/agents/agt_3Vn8Qx2K \
  -X DELETE \
  -H "Authorization: Bearer $UNDERTEXT_SECRET_KEY"
{
  "id": "agt_3Vn8Qx2K",
  "revoked": true
}

On this page