Docs · Agents and API
Agents: MCP, tools, and how reds reach them
An agent (a coding assistant, a script) pushes a branch, submits it, and leaves. ModernCI checks and lands the PR. If something needs the agent, the news is waiting for it when it comes back.
Connect
Today MCP is served by your region's API over HTTP: JSON-RPC 2.0 on POST /mcp of your region's URL There is no mci mcp command yet; a stdio bridge mci mcp is coming. Use an MCP client that supports HTTP servers and a bearer token. For Claude Code:
claude mcp add --transport http modernci "$MCI_URL/mcp" \
--header "Authorization: Bearer $MCI_TOKEN"
Create the token as an agent identity (it is shown once, and stored only as a hash):
mci tokens create --tenant "$TENANT" --project "$PROJECT" --role agent \
--kind agent --name builder
Agents act with the permissions of that identity, through the same checks as the CLI and REST API. They cannot approve guarded changes: approvals need a person's passkey. An admin can switch agent access off per tenant (feature.mcp); calls then fail with "agent access (MCP) is turned off for this tenant".
The tools
The tool list is generated from the API's operation table, so it is always what the server accepts (tools/list).
| Tool | What it does | Status |
|---|---|---|
done | Submit a pushed branch as a PR (repo, branch, optional head, agent_cost_micros) and leave. | built |
my_work | Your open work items: reds, conflicts, approvals. | built |
watch | Your event stream. Arguments: after (sequence number), ack, limit (1-500), wait (seconds, up to 25, long poll). | built |
ack | Acknowledge events up to a sequence number. | built |
log | Read a run's log (run). | built |
claim | Take a work item. | coming (answers "not implemented") |
report | Report progress and agent spend on a work item. | coming |
ask | Ask a person a question about a work item. | coming |
Typical loop:
git push origin mci/my-change, thendonewith the repo, branch and head commit.- Leave. Later, call
my_work(what is open now) andwatchwithafterset to the last sequence you saw (what happened since). - For a
pr_red, read the excerpt, calllogfor the full output, fix, push to the same branch, and calldoneagain. ackwhat you handled.
How reds reach agents
When a check fails, ModernCI writes the event and a work item in the same database transaction as the result. Nothing is lost if the engine restarts or the agent is offline.
- Stream: each identity has its own event stream with increasing sequence numbers.
watchreplays from any point, so an agent that disconnected afterdonegets its events when it reconnects. Acknowledgement is per identity and per channel, so MCP and a webhook never move each other. - Events are JSON with a
type:pr_red(the failing check, head commit, a readable summary, the log location and how to reproduce),pr_landed(target and landed commit),conflict(target and files),approval_needed,stuck,wait_changed. Wait text is the same sentence the UI shows. - Work items: a red or conflict becomes a work item owned by the PR's author. If it is left, it escalates to a person after a deadline. Escalation always happens; only the notifications depend on the feature flags.
- Webhook (
feature.notifications_webhook): the engine can POST an identity's stream to an HTTPS endpoint with retries and an HMAC signature (X-ModernCI-Signature: sha256=<hex>, over"<timestamp>.<body>", withX-ModernCI-Event-Idfor de-duplication). The webhook sender is built; wiring it to a configured endpoint is coming.
Cost reporting
done accepts agent_cost_micros (millionths of a dollar the agent spent on the change), recorded against the PR. report will update it during work (coming).