Skip to content

Connect over REST

The REST interface takes the same requests as MCP and returns the same result. Use it for services, scripts and frameworks without an MCP client. Start the sandbox first and work in its directory.

Start from a clean sandbox, in its directory:

./sandbox destroy
./sandbox up
AGENT=$(./sandbox token agent)
BASE=http://127.0.0.1:18180
Method and path Purpose
POST /v1/executions Submit one intent or a plan
GET /v1/executions/{id} Read one of your executions
POST /v1/executions/{id}/cancel Cancel one of your executions while it awaits approval

Every request needs Authorization: Bearer <token>.

The body names the intent and its input. Send the idempotency key in the Idempotency-Key header or as idempotency_key in the body. Reads take no key.

curl -sS -i -X POST "$BASE/v1/executions" \
  -H "Authorization: Bearer $AGENT" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: rest-guide-order-0001" \
  -d '{"intent": "procurement.create_purchase_order",
       "input": {"vendor_id": "v_1001", "sku": "HEADSET", "quantity": 4,
                 "unit_price_minor": 9000, "currency": "EUR", "department": "it-ops"},
       "rationale": "Headsets for the support team"}' \
  | grep -iE '^HTTP/|^location:|"status"' | cut -c1-120

A request that needs a person answers 202 with pending_approval. Read the execution until it ends, waiting poll_after_s seconds between reads:

RESPONSE=$(curl -sS -X POST "$BASE/v1/executions" \
  -H "Authorization: Bearer $AGENT" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: rest-guide-order-0002" \
  -d '{"intent": "procurement.create_purchase_order",
       "input": {"vendor_id": "v_1001", "sku": "DESK-OAK", "quantity": 30,
                 "unit_price_minor": 100000, "currency": "EUR", "department": "it-ops"}}')
echo "$RESPONSE" | jq '{status, poll_after_s, expires_at: .approval.expires_at}'
EXECUTION=$(echo "$RESPONSE" | jq -r .execution_id)
curl -sS "$BASE/v1/executions/$EXECUTION" -H "Authorization: Bearer $AGENT" | jq .status

An agent that no longer needs the action should cancel it, so that nobody approves stale work:

curl -sS -X POST "$BASE/v1/executions/$EXECUTION/cancel" -H "Authorization: Bearer $AGENT" \
  | jq '{status, code: .error.code}'

A plan runs its steps in order. A later step can use an earlier step’s output with $ref. The rollback example shows what happens when a step fails.

{
  "steps": [
    { "id": "vendor", "intent": "procurement.create_vendor",
      "input": { "legal_name": "Northwind GmbH", "country": "DE", "tax_id": "DE123456789" } },
    { "id": "order", "intent": "procurement.create_purchase_order",
      "input": { "vendor_id": { "$ref": "steps.vendor.output.vendor_id" }, "sku": "LAPTOP-14",
                 "quantity": 3, "unit_price_minor": 120000, "currency": "EUR", "department": "it-ops" } }
  ],
  "rationale": "Onboard a new supplier"
}

A refusal is a problem document (application/problem+json) with code and the full result in envelope. Once an execution is accepted, reading it answers 200, even if it later failed, so always check its status.

Status Meaning
201 New execution, already finished. Check status
202 New execution, still in progress or awaiting approval
200 A replay of an earlier request, or a read or cancel
400 Idempotency key missing or malformed, or a malformed request
401 Token missing, expired or for another audience
403 POLICY_DENIED, POLICY_ERROR or PRINCIPAL_SUSPENDED
404 UNKNOWN_EXECUTION
409 NOT_CANCELLABLE
422 SCHEMA_VIOLATION, PLAN_INVALID, UNKNOWN_INTENT or IDEMPOTENCY_KEY_REUSED
429 RATE_LIMITED. Wait for Retry-After seconds
503 PAUSED, INTENT_DISABLED, FACT_UNAVAILABLE or LICENSE_EXPIRED. Try again later

Next, decide what your agent does with each result in Handle every outcome.