ModernCI
Sign in

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).

ToolWhat it doesStatus
doneSubmit a pushed branch as a PR (repo, branch, optional head, agent_cost_micros) and leave.built
my_workYour open work items: reds, conflicts, approvals.built
watchYour event stream. Arguments: after (sequence number), ack, limit (1-500), wait (seconds, up to 25, long poll).built
ackAcknowledge events up to a sequence number.built
logRead a run's log (run).built
claimTake a work item.coming (answers "not implemented")
reportReport progress and agent spend on a work item.coming
askAsk a person a question about a work item.coming

Typical loop:

  1. git push origin mci/my-change, then done with the repo, branch and head commit.
  2. Leave. Later, call my_work (what is open now) and watch with after set to the last sequence you saw (what happened since).
  3. For a pr_red, read the excerpt, call log for the full output, fix, push to the same branch, and call done again.
  4. ack what 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. watch replays from any point, so an agent that disconnected after done gets 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>", with X-ModernCI-Event-Id for 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).

View this page as Markdown