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
| Attribute | Type | Description |
|---|---|---|
id | string | Undertext's id for the agent, starting agt_. |
user | string | The Undertext id of the person it acts for. |
name | string | What 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_name | string | What its client calls itself, such as "Claude Code", as the person saw when approving it. |
host | string | The domain the client is published from, checked by Undertext. Two agents can share a name; the host tells them apart. |
local | boolean | Whether 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. |
access | string | all or chosen. |
connected_at | timestamp | When its person approved it. |
last_used_at | timestamp or null | When it last called a tool, or null if it hasn't yet. |
expires_at | timestamp or null | Until 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.
| Parameter | Type | Description |
|---|---|---|
user_id | string, path, required | The user's Undertext id. |
document | string | A 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. |
limit | integer | 1 to 100. Default 50. |
after | string | The 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}
| Parameter | Type | Description |
|---|---|---|
agent_id | string, path, required | The 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.
| Parameter | Type | Description |
|---|---|---|
agent_id | string, path, required | The agent's id. |
name | string | What its person calls it: 1 to 48 characters, trimmed, without control or invisible characters. |
access | string | all 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.
| Parameter | Type | Description |
|---|---|---|
agent_id | string, path, required | The agent's id. |
limit | integer | 1 to 100. Default 50. |
after | string | The 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
}| Attribute | Type | Description |
|---|---|---|
role | string | The role you gave the agent: editor, suggester or viewer. |
effective_role | string or null | What 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.
| Parameter | Type | Description |
|---|---|---|
agent_id | string, path, required | The agent's id. |
document_id | string, path, required | The document's id. |
role | string, required | editor, 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"
}| Error | When |
|---|---|
400 invalid_parameter on role | role is owner, or not a role. |
404 document_not_found | The 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.
| Parameter | Type | Description |
|---|---|---|
agent_id | string, path, required | The agent's id. |
document_id | string, path, required | The 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.
| Parameter | Type | Description |
|---|---|---|
agent_id | string, path, required | The 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
}