# MCP and agents

This page is for an agent operating a Durable app, and for the person setting one up. It teaches what exists for an agent today: every docs page as Markdown, the OpenAPI document, `durable-sdk explain`, the graph's verbs over the index the template writes and `durable-sdk index` rewrites, the `AGENTS.md` and the four skills every app carries; and names what is coming: `durable-sdk mcp` (DS-025) and the hosted MCP at `https://durablesdk.com/mcp` (DS-026).

## What exists

| Surface                                                                                                    | Where                                                                               | What it is                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| ---------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `/llms.txt`                                                                                                | `https://durablesdk.com/llms.txt`                                                   | The index: the product in one paragraph, then every docs page as `- [title](url): summary`, the API and the CLI reference first.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| `/llms-full.txt`                                                                                           | `https://durablesdk.com/llms-full.txt`                                              | Every docs page's Markdown in order, each under its H1, a `---` rule between.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| The `.md` twins                                                                                            | `https://durablesdk.com/docs/<slug>.md`, or `Accept: text/markdown`                 | Every page's source, front matter stripped, the links absolute. Fetch the page you need and follow its links; never scrape the HTML.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| `/openapi.json`                                                                                            | `https://durablesdk.com/openapi.json`                                               | The platform API, OpenAPI 3.1, rendered from the route table: every route, its scope, its schemas, `PlaneError`; the operator contract's catalogue under `/apps/{slug}/console/<path>`. [API reference](https://durablesdk.com/docs/reference/api.md).                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| `durable-sdk explain <code>`                                                                               | the CLI, offline                                                                    | The registry row for an error code, a refusal id a door threw, or a doctor rule: the sentence, the trap, the remedy. `--json` for the row as data. The platform's `plane.*` codes and the engine's are one table. [Errors](https://durablesdk.com/docs/reference/api/errors.md).                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| `--json` on every verb                                                                                     | the CLI                                                                             | The route's answer verbatim on stdout, progress on stderr, a refusal as `{ "error": { "code", "message", "remedy", "docs" } }`; the exit grammar 0/1/2/3. [CLI reference](https://durablesdk.com/docs/reference/cli.md#--json).                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| `AGENTS.md`                                                                                                | the root of every app `durable-sdk init` writes                                     | What the app is, its file map, the commands, the rules a workflow must keep, where the console is, how to log in, the docs URL. `CLAUDE.md` is `@AGENTS.md`. Beside it, `.claude/skills/durable/`: the four generated skills (write a workflow, debug a run, redrive safely, ask the graph), the SDK's procedures rendered for the app, every command and tool in them checked against the CLI and the MCP at generation.                                                                                                                                                                                                                                                                                                                                     |
| `durable-sdk doctor --host`                                                                                | the CLI, offline                                                                    | Every guard rule over the tree; a finding is one line with its fix and the rule's id; `--explain <rule id>` says the law and the hazard. Run it before and after any change.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| `durable-sdk explain <subject>`, `graph walk`, `graph path`, `graph impact --changed`, `graph diff --base` | the CLI, offline, over the `graph-index.json` the template writes at the app's root | The graph asked, never read whole: a door's card with the run it admits, a workflow's steps with their writes, a fact's listeners, the closure from any node, the first chain between two, the blast radius of a change (what it reaches) and what the graph gained, lost and changed against a ref. The index is `durable-sdk index`'s, written at the root: the template's build runs it and `durable-sdk test --changed` checks it first. `--api <url>` reads a deployment's live graph with its bearer; a hosted app's bearer is sealed, so `--api` is a self-hosted app's, and the hosted walk is the console proxy's `GET /api/v1/apps/<slug>/console/catalog/graph?from=<node>`. [Vibe coding with the graph](https://durablesdk.com/docs/guide/vibe-coding-with-the-graph.md). |

## Coming

- **`durable-sdk mcp [--app <slug>]`** (DS-025): the MCP server over the platform's console proxy with your key, stdio, for a laptop's agent: the tools derived from the operator contract (runs, a run's bundle, limbo, redrive, explain, `graph_walk` for the graph's walk, and the checkout's two, `graph_explain` for its card and `graph_impact` for a change's radius, read off the index of the directory the server runs in), the two prompts (`triage`, `explain_run`), the resources (`durable://limbo`, `durable://runs/{id}`). `durable-sdk mcp install --client claude-code|cursor` will write the client's config with a `${DURABLE_API_KEY}` reference, never a value.
- **The hosted MCP at `https://durablesdk.com/mcp`** (DS-026): streamable HTTP, the key as bearer, the same tools, no install.

Until then an agent reads an app's runs through the console proxy routes of the API (`GET /apps/:slug/console/runs`, `.../runs/limbo`, `.../runs/:id/bundle`) with a key, its graph through `GET /apps/:slug/console/catalog/graph?from=<node>&depth=2&format=text` (the walk's lines, the body edges once the build has run `durable-sdk index`), and redrives with `POST /apps/:slug/console/runs/:id/redrive`. A destructive action (a dismiss, an undo) is a person's, from the dashboard, under every surface.

## For agents

### Sign up with a key

A key is minted by a person. Ask for one from `https://durablesdk.com/dashboard/keys` with the scope the task needs (`read` to look, `deploy` to deploy and operate, `admin` to create or delete an app), and hold it in the environment:

```bash
export DURABLE_API_KEY="dsk_live_…"
printf '%s' "$DURABLE_API_KEY" | durable-sdk login --with-key
durable-sdk whoami --json
```

A key never mints a key (`plane.key.mint_by_person`); do not try. A key expires (90 days from the device flow; 30, 90 or 365 from the dashboard): `whoami` says when.

### The commands to run first

```bash
npx durable-sdk init my-app          # the template; judged under the slug grammar first
cd my-app
durable-sdk doctor --host            # green before you change anything
durable-sdk test --changed           # the template's own test passes
durable-sdk apps create my-app       # provisioned; .durable-sdk/app.json written
durable-sdk deploy --prod --json     # the Deployment as data; exit 0 on promoted
curl -s https://my-app.durablesdk.com/health
durable-sdk logs --follow
```

In an app that exists: `durable-sdk apps link <slug>` once, then `deploy`, `logs`, `secrets`, `runs limbo` take the app from `.durable-sdk/app.json`.

### How to read an answer

- Exit 0: the thing asked stands. Exit 1: the verb's own red (a failed build, a red check); read the `error` on the `--json` body and run `durable-sdk explain <code>`. Exit 2: the request was refused or a flag is wrong; the `remedy` is the next action. Exit 3: the platform is unreachable; wait and retry with the same `Idempotency-Key`.
- A sentence a door throws in your own code is a refusal id (`workflow.key.reads_clock`, `step.undo.declares`): `durable-sdk explain <id>` says the trap and the remedy. Do not work around a refusal; do what it says.
- A deployment's `check` rows name what the platform read on the new build before promoting it; a `fail` row stands on its own hostname and was never promoted.

### What never to do

- Never print, log, store or echo a key, a read string, `ADMIN_TOKEN` or any value from `durable-sdk secrets set`. A value moves on stdin; `--env-file` writes the read string to a file.
- Never call `beginRun`, `runSaga`, `finishRun` or `appendLedger` by hand; every side effect is a step inside a `defineWorkflow()` started with `.execute()`.
- Never read the clock, randomness or the environment in a key or a run body outside a step; the moment rides in the input as `requestId`.
- Never write a step without an `undo` or an `irreversible: "<reason>"`; never catch around `ctx.step`; never `Promise.all` over steps (`ctx.all`).
- Never edit a ledger row, delete the engine's tables or run `migrate down` on production.
- Never set a reserved variable name (`DATABASE_URL`, `CRON_SECRET`, `ADMIN_TOKEN`, …) as a secret; the door refuses it and the platform owns them.
- Never deploy with a red `durable-sdk doctor --host`.

### The reading order

1. `https://durablesdk.com/llms.txt`.
2. [Quickstart](https://durablesdk.com/docs/quickstart.md) and [Concepts](https://durablesdk.com/docs/concepts.md).
3. [Writing a workflow](https://durablesdk.com/docs/guide/writing-a-workflow.md), [Steps and undo](https://durablesdk.com/docs/guide/steps-and-undo.md), [Vibe coding with the graph](https://durablesdk.com/docs/guide/vibe-coding-with-the-graph.md).
4. [CLI reference](https://durablesdk.com/docs/reference/cli.md), [API reference](https://durablesdk.com/docs/reference/api.md), [Errors](https://durablesdk.com/docs/reference/api/errors.md).
5. The app's own `AGENTS.md`.

Every docs page carries a `task` line in its front matter, one sentence an agent can be handed, and a "Copy as prompt" control that wraps it: read this page as Markdown, do the task, run `durable-sdk doctor --host` before and after, and treat a refused line as a refusal id for `durable-sdk explain`.

---

Prompt for an agent:

```text
Read https://durablesdk.com/docs/reference/mcp-and-agents.md, then set up an agent to deploy and operate a Durable app with an API key, reading the docs as Markdown and every error through durable-sdk explain; run durable-sdk doctor --host before and after; a refused line is a refusal id: durable-sdk explain <id>
```
