Connecting agents
Agents use Retainer through MCP. The server hosts the MCP endpoint itself at
/mcp (Streamable HTTP); clients that only speak stdio use the
@retainer/mcp bridge. Either way the tools are the same, because they are
defined once, on the server.
Create one API key per agent (see Self-hosting),
with an agent actor. read,write is enough for most agents; add
schema:write if the agent may add fields or apply a template. In
accounts mode, workspace admins create keys
in the web app under Settings, Agents, and apps that support OAuth, such as
Claude's web app, can connect without a key
(below).
retainer-ops key create --workspace acme --name "Inbox agent" \
--actor agent:inbox --scopes read,write,schema:writeOver HTTP
Point the client at https://<your-host>/mcp and send the key as a bearer
token. In Claude Code:
claude mcp add --transport http retainer https://retainer.example/mcp \
--header "Authorization: Bearer rtn_…"Any client that supports Streamable HTTP with custom headers works the same way. The endpoint is stateless: each request is authenticated on its own.
Connecting Claude's web app over OAuth
In accounts mode, an app that speaks MCP OAuth connects with the person's own
sign-in instead of a key. In Claude's web app, add a custom connector with the
URL https://<your-host>/mcp and connect it. Claude opens Retainer in the
browser, where the person:
- Signs in, if they are not already.
- Picks the workspace Claude may use, from the ones they have a role in.
- Reviews what Claude may do there and chooses Allow.
Claude then works in that workspace as "Claude for ", an agent actor,
so the rules that need a person still apply. It gets what it asked for that the
person's role allows: a viewer's Claude can only read, and no app can manage
people or keys.
More than one workspace
A connection works in one workspace. To keep one for each workspace, add a
connector per workspace with its pinned address,
https://<your-host>/mcp/w/<workspace ID>. Signing in through a pinned
address offers only that workspace, and its connection works only there, so
the agent can use both without either one switching. The list_workspaces
tool lists the workspaces the person can reach, with each one's address, so
the agent can tell them what to add. /mcp itself keeps asking which
workspace to use.
Connected apps are listed under Your account, and for workspace admins under Settings, Agents. Disconnecting one, removing the person, lowering their role or deleting the workspace applies at the app's next request. Clients that register through dynamic client registration work the same way; Claude identifies itself with a client metadata document.
The Claude Code plugin
People with a Retainer account can install the Retainer plugin for Claude
Code. It adds the MCP server (signing in over OAuth through /mcp) and logs
what their chats teach Claude about their customers and work, without being
asked:
/plugin marketplace add Tamloot-cc/Retainer
/plugin install retainer@retainerAfter each turn, a Stop hook checks in the background whether the turn holds
something the workspace should keep, by asking Claude Haiku through the
person's own Claude Code sign-in. If it does, Claude wakes up and follows the
log_from_chat guide. Retainer's core still calls no model. See
the plugin's README for what the hook skips
and how to turn it off.
Over stdio
For clients that start MCP servers as local processes, run the bridge. It
reads two environment variables and relays MCP messages between stdin/stdout
and the server's /mcp endpoint:
| Variable | Value |
|---|---|
RETAINER_URL | The server's base URL, e.g. https://retainer.example. /mcp is added if missing. |
RETAINER_API_KEY | The agent's API key. |
A client configuration in the common mcpServers format (Claude Desktop and
others):
{
"mcpServers": {
"retainer": {
"command": "npx",
"args": ["-y", "@retainer/mcp"],
"env": {
"RETAINER_URL": "https://retainer.example",
"RETAINER_API_KEY": "rtn_…"
}
}
}
}Or with Claude Code:
claude mcp add retainer \
--env RETAINER_URL=https://retainer.example --env RETAINER_API_KEY=rtn_… \
-- npx -y @retainer/mcpFrom a checkout instead of npm (the only option until the first release is
published), build it (pnpm build) and use
node /path/to/Retainer/packages/mcp/dist/index.js as the command.
The bridge writes diagnostics to stderr only. If the server rejects the key or
cannot be reached, the client's request fails with a message saying which, for
example Retainer at https://retainer.example rejected the API key (401). Check RETAINER_API_KEY. retainer-mcp --help prints its usage and
--version its version.
Tools
Tools are generic, not one per object, so a workspace's custom objects never change the tool list.
Your MCP client lists every tool with its description and inputs, so this
page names the groups only. Each tool's scope is checked on every call; a
missing one returns forbidden with the scope it needs.
| Group | What it covers | Scopes |
|---|---|---|
| Setup | The workspace's schema, templates and the guides below | read, schema:write to apply a template |
| Read | Search, filter and read records and events, a record's context pack, timeline and comments | read |
| Write | Log events, create and update records, remember facts, change the schema | write, schema:write for schema changes |
| Files | Upload a file through a signed URL, read a file's details, get a short-lived download link | read, write |
| Change feed | Record changes in commit order, for agents that keep a copy in sync | read |
| Extensions | Installed extensions, their connections and runs; preview a mapping for an admin | read, schema:write to preview |
| Routines | Check, dry-run and propose a routine for an admin to approve; only on servers with routines | read, write to propose |
describe_schema returns valueFormats: how to write a value of each field
type the workspace uses, for example full_name as { first, last } and
emails as { primary, additional: [...] }. Validation errors name the field
and the allowed values, and for a composite field the expected format
(expected), so an agent can correct its call and retry.
Setting up a new workspace
The discover_schema guide walks an agent through designing the workspace
from its user's own data. The agent works out the business from what it
already knows, finds the sources its own tools reach (an existing CRM,
spreadsheets, email, calendar), and reads the business's existing records
first. It asks its user only for what it cannot find. It samples those
sources and proposes a template plus the objects and fields the data calls
for, each with the evidence for it. Nothing is applied until the user
agrees.
An agent reads it with get_guide, and the server instructions tell it to
when describe_schema reports initialized: false. A person can also start
it as the MCP prompt discover_schema, with an optional sources argument
naming where to start; in Claude Code, with the server added as retainer,
that is /mcp__retainer__discover_schema. Applying the schema needs the
schema:write scope.
Growing the schema
The schema_design guide holds the rules for changing a schema that is
already in use, and the server instructions point an agent to it before it
first adds an object. It also walks an agent through reviewing a schema in
use; a person can start that review as the MCP prompt schema_design.
Logging from a chat
The log_from_chat guide tells an agent what to do when a chat with its user
holds something durable about the people, companies or work the workspace
tracks: what is worth keeping, which source to cite (the email or meeting it
read, or else the turn of the chat, logged as a conversation with the client
as its channel and the session and turn IDs as its external ID), and when to
ask before creating a record. The server instructions point an agent to it, and the
Claude Code plugin wakes Claude to follow it after a turn that needs it. A
person can start it as the MCP prompt log_from_chat.
How an agent should write
Retainer does not read conversations; the agent does. After a meeting, call or email thread, a well-behaved agent:
- Logs the event with
log_event: its type (conversationwith amediumfor meetings, calls, emails and chats; another event type only when the workspace defines one for that kind of event), channel (the source system or account, part of the event's identity), time (with a UTC offset), title, its own short summary, the type's other fields, the source's external ID, the participants as emails, phones or record IDs, and inaboutthe IDs of the records it concerns. The response lists which participants matched a record and which did not. For an unmatched person worth keeping, create them withupsert_recordciting the event assource, then re-log the same event with the same handle and role plus the newrecordId. The stored participant is linked in place and listed inadded.participants.matched. - Updates records with
upsert_record, passing the event's ID assource. Cited values carry the event's date, so an old email can never overwrite a newer value. - Stores facts with
remember, citing the same event and, optionally, a short quote. - Creates tasks someone committed to, as
taskrecords.
Things worth knowing:
-
Finding the record.
upsert_recordfinds its record byidor by a unique field inmatch(for example{ "emails": "dana@acme.com" }).ifMissingdefaults to"fail", so "update Dana's address" can never create a second Dana; pass"create"to create when nothing matches. To find someone by name or phone, usesearchorquery_recordsfirst. -
Several records at once. Pass up to 50 single-record inputs in
upsert_records({ items: [...] }). Include theobjectand anysourcefor each item. Check every result for errors and pending fields. For creates withoutidormatch, use a distinctidempotencyKeyper item and keep it when retrying. -
Pending values. Each field in a write comes back as
applied,pending_revieworsuperseded. An agent's value that would overwrite what a person entered waits for review; the agent should say so rather than claim the update is done. -
Lists of records. A
many_to_manyrelation (for example a deal'scontacts) takes the whole list of record IDs, and a write replaces it, so read the record first and send every member to keep;[]clears it. The other side of a relation (readOnly,isInverseindescribe_schema) is written from its owning side. A relation withtargetObjectstakes records of any of those objects; find the records pointing at one by filtering on it. -
Rolled-up events. A relation with
rollUpEvents(shown indescribe_schema) also lists the events of the records pointing at a record in its history: a company sees the calls about its deals, withvia: { kind: "rollup", field, record }. It is one hop and follows the relation's current value, so a reassigned deal takes its events with it. Still put the company in an event'saboutwhen the event is about the company itself. -
Participants and
about. Participants are who took part. A meeting with Dana about the Acme pilot lists Dana as a participant and the Acme company and the pilot project inabout:{ "type": "conversation", "channel": "calendar", "externalId": "evt-4410", "fields": { "medium": "meeting" }, "occurredAt": "2026-10-29T14:00:00+02:00", "title": "Acme pilot review", "participants": [{ "handle": "dana@acme.com", "role": "customer" }], "about": ["<acme company id>", "<pilot project id>"] }The meeting then shows in
get_contextand inquery_recordswithlinkedfor every record it is linked to. Don't list a company or project as a participant. -
Retries are safe. Logging the same
(channel, externalId)again with the same type, time, title, summary and fields returns the existing event withcreated: false. Participants andaboutrecords it did not have yet are added and listed inadded, so an agent that left the company out can log the same source again with it. Nothing is removed that way; a different payload is a conflict (event_conflict), andevent_retractedmeans the source was deleted or erased: don't log it again. Writes are independent short transactions, so an agent that stops halfway leaves consistent data and can resume. -
Events over time.
query_recordson an event type lists its events byoccurredAt,channelor a field, and withlinked: { record }only those attached to one record, e.g. calls with a company this quarter (conversationfiltered bymedium). Withobject: "event"it lists events of every type at once, filtered bytype,occurredAt,channelandexternalId: everything logged this week, or every event about a company. -
Comments. People write comments to each other on records; an agent reads them with
get_recordandlist_comments, and gets 403 if it tries to write one. They are context, not evidence: nothing can cite one. If a comment says "she moved to Berlin", check it, then record it withupsert_record, orrememberit citing a real source. -
Events name entities.
aboutandparticipantstake entities only; an event inaboutis a 422invalid_link. -
Object or event. Something with a state people change is an object; something that happened, reported by a source, is an event; a change to an object is its history. The
schema_designguide has the full test. -
Channel and medium.
channelis where the event came from, the source system or account (gmail,zoom,whatsapp-business); it is part of the event's identity and fixed once logged.mediumis what kind of conversation it was. Leavemediumempty when unsure; it can be corrected later withupsert_record. An event's type changes only withmove_events, which a person runs. -
Your own event types. Add an event type only for events whose fields a conversation would never use: a payment (an amount, an invoice), a form submission, a site visit.
propose_schema_changewithcreate_objectandclass: "event". It gets a title and summary of its own; add only the fields it needs. Conversation details such as duration or a recording link are fields onconversation, and a new kind of conversation is a newmediumoption. -
Moving events to another type. A workspace that logged meetings and calls as their own types can move them to
conversationwithout re-logging:move_eventswithfrom: "meeting",to: "conversation"anddefaults: { "medium": "meeting" }. Each event keeps its ID,channelandexternalId, participants,aboutrecords, and the values and facts that cite it. Never delete and re-log instead: that retracts what cites the events and blocks their source for good. Fields map by name;fieldsmaps ones named differently. Values the target has no field for are refused with a list (unmapped_fields) until they are mapped or listed indrop, which deletes them, so drop only what your user agreed to lose. Moving needs a person (auserkey withadmin); an agent passesdryRun: true, which reports exactly what would move and changes nothing, and shows its user. A later sync logs the moved sources asconversationwith the same medium, and they match the moved events. -
Reading back.
get_contextgives the current values (with who wrote each), linked records grouped by object, current facts and recent events, rolled-up ones included (each saying how it is attached,via), withintokenBudgettokens (default 2000, at most 16000).omittedcounts what did not fit. -
History.
get_timelinelists how a record got here: its events, every value asserted for its fields (currentsays whether it is the value now; one that is not may never have been) and its facts, newest first. Narrow it withfields(e.g.["stage"]),eventTypes,typesand afrom/torange, and passnextCursorback with the same filters for the next page. -
Schema. Additive changes (new objects, fields, options) apply at once. Renames, removals and new required or unique constraints requested by an agent are stored as proposals for a person to approve in the web app.
Several agents in one workspace
Give each agent its own key. Every write is attributed to the agent that made it; between agents the most recent observation wins, and the full history of each field stays available through the REST API and the web app.
For workspace administration and human review decisions, see the Retainer CLI guide.