# Trinity developer docs

Trinity keeps an engineering team's commitments as tasks: what people ask for in Slack, meetings, GitHub, Linear and Jira gets an owner and a date, and Trinity follows it until it lands. For a coding agent, Trinity is one MCP server. Read a task's context before you work on it, then report your progress and your pull request on it as you go.

- MCP server: `https://app.usetrinity.ai/api/v1/agent/mcp` (Streamable HTTP, stateless)
- Auth: `Authorization: Bearer <token>`, a device token you get with one browser approval
- Tools: [MCP reference](https://app.usetrinity.ai/docs/mcp)
- API spec: [openapi.json](https://app.usetrinity.ai/openapi.json)
- Price: free for two weeks with no card, then $50 a seat a month ([pricing](https://usetrinity.ai/pricing))

## Before you start

The person you work for needs a Trinity account. They sign in at https://app.usetrinity.ai with Google or GitHub and create or join an organization. A new organization gets two weeks of free access with no card. Your token acts as that person, in that organization.

## 1. Get a token

Getting a token is self-serve: there is no API key screen and no sales call. You ask, the person approves once in the browser, and you collect the token.

Start a device authorization. Use `"tool": "other"` for any MCP client without a Trinity plugin, and a short name the person will recognise:

```bash
BASE=https://app.usetrinity.ai
curl -s -X POST "$BASE/api/v1/devices/authorize/start" \
  -H 'Content-Type: application/json' \
  -d '{"tool": "other", "name": "my-agent"}'
```

The answer carries `deviceCode`, `verificationUrl`, `verificationCode`, `intervalSeconds` (2) and `expiresInSeconds` (600). `deviceCode` is a secret: never show it or log it.

Ask the person to open `verificationUrl` and approve the request that shows `verificationCode`.

Then poll every `intervalSeconds`. `machineId` is 64 lowercase hex characters that name this machine to Trinity: a Trinity-specific digest of the machine's own id, never the raw id and never a secret. A container often has no machine id, so the recipe below keeps a random one in your config directory instead; two agents must never send the same `machineId`, because pairing the same machine again takes over its device and its token. Containers cloned from one image can share `/etc/machine-id`: give each its own.

```bash
SOURCE=$( (cat /etc/machine-id 2>/dev/null || ioreg -rd1 -c IOPlatformExpertDevice 2>/dev/null | awk -F'"' '/IOPlatformUUID/{print $4}') | tr -d '[:space:]' | tr 'A-Z' 'a-z')
if [ -z "$SOURCE" ]; then
  ID_FILE="${XDG_CONFIG_HOME:-$HOME/.config}/trinity/machine-id"
  [ -s "$ID_FILE" ] || { mkdir -p "${ID_FILE%/*}" && od -An -N32 -tx1 /dev/urandom | tr -d ' \n' > "$ID_FILE"; }
  SOURCE=$(cat "$ID_FILE")
fi
MACHINE_ID=$(printf 'trinity-machine-id:%s' "$SOURCE" | { sha256sum 2>/dev/null || shasum -a 256; } | cut -c1-64)
curl -s -X POST "$BASE/api/v1/devices/authorize/exchange" \
  -H 'Content-Type: application/json' \
  -d "{\"deviceCode\": \"$DEVICE_CODE\", \"hostname\": \"my-agent\", \"machineId\": \"$MACHINE_ID\"}"
```

- `202 {"status": "pending"}`: not approved yet, poll again.
- `200 {"token", "deviceId", "mcpUrl", "ingestUrl"}`: done. The authorization is spent.
- `404`: the request expired or was already used. Start again. If it expired after the person tried to approve it, their organization's free period may have ended or its subscription lapsed: approval is refused until an owner subscribes, so tell them rather than starting again in a loop.
- `402`: the organization lost access between the approval and this exchange (its free period ended or its subscription lapsed). The error names the reason.

Keep the token where your MCP client keeps secrets, never in a repository. It lasts until the device is revoked in Trinity. Pairing the same machine again (same person, organization, tool and `machineId`) reuses the device and rotates its token.

## 2. Connect over MCP

Claude Code:

```bash
claude mcp add --transport http trinity https://app.usetrinity.ai/api/v1/agent/mcp \
  --header "Authorization: Bearer $TOKEN"
```

Any other client: add a Streamable HTTP server at the MCP URL with the `Authorization` header. A raw check:

```bash
curl -s -X POST "$BASE/api/v1/agent/mcp" \
  -H "Authorization: Bearer $TOKEN" \
  -H 'Content-Type: application/json' \
  -H 'Accept: application/json, text/event-stream' \
  -d '{"jsonrpc": "2.0", "id": 1, "method": "tools/list"}'
```

## 3. Work on a task

A task is named by its code (T123), a GitHub issue or pull request, a Linear or Jira key, or a pasted URL. A typical session:

1. `get_task_context`: the task, the thread it came from, its pull requests and related work.
2. `start_task` when you begin. A task still to do moves to in progress.
3. `report_progress` with one line every few minutes.
4. `link_pull_request` as soon as you open the pull request.
5. `finish_task` with `ready_for_review`, `blocked` or `done`.

When you are stuck on a question only the asker can answer, `ask_blocker` posts it in the Slack thread the task came from. Every tool and its arguments: [MCP reference](https://app.usetrinity.ai/docs/mcp).

## Errors

- Token endpoints answer JSON `{"error": "<one line>"}` with the status codes in the [spec](https://app.usetrinity.ai/openapi.json).
- The MCP server answers `401` for a token Trinity does not know and `403` for a revoked device. Pair again for either.
- A tool that cannot run answers an MCP error with one line saying why, for example `billing locked: free_access_expired`.

## Limits

- 10 authorization starts a minute per IP address. A request lasts 10 minutes.
- Each tool call has 20 seconds.

## Plugins

Claude Code, Codex, Cursor, Gemini CLI and GitHub Copilot CLI have a Trinity plugin. It does this pairing for you and also records coding sessions on the tasks they serve. Setup steps for each: https://app.usetrinity.ai/agent-setup.txt
