Let Claude Code or Cursor read your runs (weft mcp)
weft mcp is a stdio MCP server over a running Studio’s read API. Register it with Claude Code or Cursor, and the coding agent answers “why did run X fail” from the same JSON routes the Studio UI reads. It adds no route, computes nothing Studio does not serve, and never writes: every one of its 22 tools is a GET.
go install github.com/weftgo/weft/cmd/weft@latestweft devclaude mcp add weft -- weft mcpweft dev (or weft studio) runs Studio on 127.0.0.1:7331 and writes the discovery file with its URL and dev token. weft mcp, started by Claude Code with no flags, reads that file and talks to that Studio with that token. Claude Code shows the tools as mcp__weft__*. weft mcp ships in every release since v0.15.0; weft mcp -h lists the tools your binary has.
Set it up
Section titled “Set it up”Claude Code. claude mcp add weft -- weft mcp registers it with nothing to configure. To name a Studio yourself:
claude mcp add weft -- weft mcp --url http://127.0.0.1:7331claude mcp add weft -e WEFT_STUDIO_TOKEN=<token> -- weft mcp --url http://127.0.0.1:7331--token <token> works too. Both forms land in the client’s config in clear; the difference is at run time: an argument shows in ps to every user of the machine, an environment value does not, so prefer -e WEFT_STUDIO_TOKEN=…. Claude Code expands ${VAR} in a project-scoped .mcp.json, so a shared one can read "env": {"WEFT_STUDIO_TOKEN": "${WEFT_STUDIO_TOKEN}"} and each developer exports their own. With the discovery file there is no token to store at all.
Cursor, .cursor/mcp.json (Claude Code’s project-scoped .mcp.json has the same shape):
{"mcpServers": {"weft": {"command": "weft", "args": ["mcp"]}}}Use "args": ["mcp", "--url", "http://127.0.0.1:7331"] to name a Studio, and "env": {"WEFT_STUDIO_TOKEN": "…"} beside args for a token.
VS Code, .vscode/mcp.json, has a different shape: its top-level key is servers:
{"servers": {"weft": {"type": "stdio", "command": "weft", "args": ["mcp"]}}}Each convenience has an override, first match wins:
| What | Order |
|---|---|
| The Studio | --url, WEFT_STUDIO_URL, the discovery file (skipped under WEFT_DISCOVERY=off), http://127.0.0.1:7331 |
| The token | --token, WEFT_STUDIO_TOKEN, the discovery file’s, only when that file names the Studio resolved above |
The token travels in the Authorization header only and is never printed. The one line weft mcp writes to stderr at start says where the token came from:
weft mcp: 22 read-only tools over stdio for the Studio at http://127.0.0.1:7331 (token from the discovery file)The other values are from --token, from WEFT_STUDIO_TOKEN and none.
Which tool answers which question
Section titled “Which tool answers which question”Every answer has three parts: a one-line summary, the route’s JSON, and a note when the output was cut at max_bytes.
| Tool | Reads | Answers |
|---|---|---|
explain_failure | the run, every step, its child runs, the transcript | Why a run failed, or how it ended: the first error anywhere in the run, a digest of every step and child, decisions, holes, the run’s own last text (below) |
runs | GET /api/runs | Runs, newest first, as compact rows |
search | GET /api/search | Runs by text (prompt, answer, error, tool names) and filters; the error_class facet |
stats | GET /api/stats | Numbers across runs by agent, model, tool, error type or step: runs, failures, tokens, cost, latency, retries, denials (Track agent health) |
run | GET /api/runs/{id} | One run’s row: status, error, steps, usage, cost, children, holes |
step | GET /api/runs/{id}/steps/{n} | One step assembled: request, attempts, events, tool calls and results, children, holes |
request | GET /api/runs/{id}/requests | The exact model input per step (prompt, catalog, params); transcript: true with step adds the messages that call carried |
events | GET /api/runs/{id}/events | The run’s durable event stream, paged with after and limit |
tools | GET /api/runs/{id}/tools | The tool catalogs the run offered the model |
diff | GET /api/diff | Two runs compared step by step: what changed, what is not comparable |
export | GET /api/runs/{id}/export | The whole run as one document, json, jsonl or otlp; not wefttest, which is weft export <id> --wefttest dir in a terminal |
sessions | GET /api/sessions | Sessions, compact |
session | GET /api/sessions/{id} | One session with its turns, compact |
logs | GET /api/runs/{id}/logs | The app’s own log lines under a run’s spans |
spans | GET /api/runs/{id}/spans | A run’s spans, compact: timing, status, model, tokens, tool; tree: true adds every descendant run’s |
trace | GET /api/traces/{id} | One trace’s spans by trace id, weft or stock OTel, compact |
transcript | GET /api/runs/{id}/transcript | A run’s messages, input and its own; step adds what step N’s model call carried |
live | GET /api/runs?status=running | The runs running now, compact: a snapshot, not the stream |
agents | GET /api/manifest | The agents Studio knows: manifests and their sources |
experiments | GET /api/experiments | The playground’s saved experiments, or one with its command and runs |
runtimes | GET /api/runtimes | The connected runtimes: agents, breakpoints, connected or not |
meta | GET /api/meta | What this Studio is and can do: versions, capabilities and why one is off, debug_scope, retention |
The parameters each tool takes, besides max_bytes on every one. id is required where listed: a missing one fails the tool’s input schema, and a blank one is id is required. full: true answers the route’s JSON as served instead of compact rows on runs, search, stats, sessions, session, live, spans and trace:
| Tool | Parameters |
|---|---|
explain_failure, run, tools | id |
runs | agent, status (running, succeeded, failed, interrupted, parked or cancelled), session, public_id, experiment_id, error_class, parent (that run’s subagent children), all (children too), limit, before and before_id (the previous answer’s next_before and next_before_id), full |
search | q, agent, tool, status, model, error (substring), error_class, since, until (RFC 3339), min_tokens, min_cost (USD), sort (started, duration, tokens, cost), session, public_id, all, limit, offset, full |
stats | by (agent, model, tool, error_type or step), since (RFC 3339 or a duration back: 90m, 24h, 7d; default 24h), until, agent, tag (key → value), public_id, parent, playground, experiment_id, status, full |
step | id, n (the step ordinal from 0; a negative n is the error n is a step ordinal, 0 or more) |
request | id, step, from (the previous answer’s next_from), limit, refs (prompt and catalog by hash instead of inline: smaller), transcript (needs step) |
events | id, after (the previous answer’s next_after), limit |
diff | a (the base run), b |
export | id, format (json by default, jsonl, otlp) |
sessions | agent, public_id, limit, before, before_id, full |
session | id (the session id), full |
logs | id, severity (at or above: trace, debug, info, warn, error, fatal), from, limit (100 when 0, at most 1000) |
spans | id, tree, full |
trace | trace_id (32 hex, a run row’s trace_id), full |
transcript | id, step |
live | agent, limit, full |
experiments | id (one experiment; else the list), limit (50 when 0, at most 200) |
agents, runtimes, meta | none |
The events tool renames the route’s done to run_terminal: the run has ended, which is not “this is the last page”. Its summary counts the page’s events and names their positions, the next cursor, and whether the run is terminal: run <id> events: 12 events (pos 0–11); more: after=11; the run may still record events, or …; no more recorded; the run is terminal.
| The question | Call | Then |
|---|---|---|
| Why did run X fail? | explain_failure {"id": X} | its first_error and digest; then its next: step, request, events |
| It succeeded, but something went wrong inside | explain_failure {"id": X} | first_error names the run (a child’s own) and the step |
| What did the model see at step N? | request {"id": X, "step": N, "transcript": true} | step {"id": X, "n": N} for the whole step |
| Which runs called refund and failed? | search {"tool": "refund", "status": "failed"} | explain_failure on a hit |
| Which failures keep happening? | search {"status": "failed", "all": true}: its facets.error_class | runs {"error_class": "<class>"} for that class’s runs |
| How is agent X doing? | stats {"by": "agent", "since": "7d"} | a group’s runs_query is the search that lists its runs |
| Where did the refund tool return an error? | step {"id": X, "n": N} (each call’s result.is_error) or events {"id": X} (tool_finish with is_error) | search does not filter on tool results |
| What differs between run A and B? | diff {"a": A, "b": B} | step on the first changed step |
| Where did the time go? | spans {"id": X} (tree: true with the child runs) | trace {"trace_id": T} for a stock OTel app’s trace |
| What did the app log? | logs {"id": X, "severity": "warn"} | a not_recorded hole names otel.Slog() |
| What is running now? | live {} (call again for a later snapshot) | explain_failure on one |
| What can this Studio do? | meta {} | after a 404 or 403 elsewhere: is the capability off, and why |
search finds runs, not tool results: a tool’s error is data the model sees, and the run often goes on and succeeds, so q and error match the run’s error text, never a tool result’s.
Compact rows
Section titled “Compact rows”A coding agent pays for every byte, so the list tools (runs, search, sessions, session, live, and stats’ groups) answer a projection of the route’s JSON:
- Empty, zero, false and null fields are omitted, so absent reads as that. A
*_knownflag is kept only when false, andcacheonly when it is notexact. - A run row keeps its identity, outcome and size: id, parent, agent,
modelasprovider/name, session and turn, status,err(cut to 200 characters), steps, pending, stop reason, the resume links, usage, cost and its badge, the problem counters, children counts, the prompt preview,startedandduration_ms. It leaves out the trace id, the content hashes, the record counts andmeta; theruntool has them. A hash a row keeps is cut to 12 characters. - Cost reasons are lifted out of the rows into one top-level
cost_reasonslist,{reason, rows}, whererowsare the ids of the rows that gave it (instats, the group keys), at most 20, thenmore. - A session’s turns omit the agent, session and public id the session names, cut
prompt_previewto 80 characters, and omit their model, cost badge, stop reason and stopped-by when equal toturn_defaults.turn_defaultsholds, per key, the value most turns share (a tie goes to the earlier turn), only when two turns or more share it; a turn with none where the default has one readsnone. The session’s outcomes strip becomesoutcome_counts. - A
statsgroup leaves out its 24-bucketseries. spansandtraceanswer each span as its name, ids,start_msanddur_msfrom the first span, status and the attributes that say what it was (model, tokens, tool, step, attempt, error, HTTP status), leaving out content attributes; events are kept as a count.
A nine-turn session, each turn a tool call and an answer, answers 3.2 KB compact against 13.6 KB as served. full: true on any of these tools answers the route’s JSON as served.
Explain a failure
Section titled “Explain a failure”explain_failure reads the whole run: every step, at most 25 per run, and its subagent child runs, at most 12 listed and two levels deep for a first error, in at most 60 reads per answer. It answers:
first_error: the first error anywhere in the run, in step order,{run, agent, step, tool, error, via}. A failed call’s child run comes before the call’s own text. An error nothing recovered from comes first; only when there is none, the first model attempt a retry fixed, marked(retried, attempt N ok).digest: one line per step (each call and what it returned, failed model attempts, holes) and one per child (its outcome, a park, its own first error), each line at most 1 KB with+n more, at most 40 lines. Every cap it hit is said at its end. In the JSON it comes afternextandlast_assistant_textand before the step’s bulk (attempts,tool_calls,children): a cut atmax_bytestakes the bulk first, then the digest, and keeps the fields above it.decisions, andresumed_byorresumed_fromfor a park a resume decided.last_assistant_text: the run’s own last text, never an earlier turn’s carried in a thread turn’s input;nullwithlast_assistant_notewhen the run wrote none.next: the calls to follow (step,request,events).
A child run is matched to its call by the step’s child_run_id, since call ids repeat across steps. These examples are weft’s own, from its MCP recipe: the output of make mcp-check, a real weft studio on a free port, read by the real weft mcp over stdio. A run that hit MaxSteps(1):
> explain_failure {"id":"a1100000000000000000000000000001"}run a1100000000000000000000000000001 (support): failed before step 1 started (step 0, its last recorded step, finished): weft: run failed at step 1: weft: run exceeded the maximum number of steps; stop_reason tool_calls; tool calls: lookup_order ok; no assistant text this run — http://127.0.0.1:33933/runs/a1100000000000000000000000000001A budget failure (MaxSteps, UsageLimit, DetectLoops) is about earlier steps: the budget stops the run before it would call the model again, so the step shown is the last one that ran, and the calls that spent the budget sit in it and the steps before it.
A run that succeeded while a child failed: a shipping-quote subagent’s provider is down, and the parent answers with a fallback. first_error is the child’s own:
> explain_failure {"id":"c5b0000000000000000000000000f001"}run c5b0000000000000000000000000f001 (checkout-assistant): succeeded, last step 1; stop_reason stop; first error: step 0 shipping_quote → child c5b0000000000000000000000000f001/0/q1 (shipping-quoter) step 0: model attempt 1: model stream: carrier API outage: DHL rates unavailable; digest: 2 of 3 lines report an error, a park or a failed child; last assistant text "Express quotes are down; standard shipping is €7.90, 4–6 days." — http://127.0.0.1:33933/runs/c5b0000000000000000000000000f001digest: step 0: ok (tool_calls): shipping_quote error "SUBAGENT_FAILED: agent \"shipping_quote\" failed at step 0: model stream: carrier API outage: DHL rates unavailable" step 1: ok (stop) child c5b0000000000000000000000000f001/0/q1 (shipping-quoter) ← shipping_quote: failed (model_error) "weft: run failed at step 0: model stream: carrier API outage: DHL rates unavailable"A parked run is not a failure. Once a resume decided it, it reads decided, with who, why and the turn that resumed it, never “awaiting”:
> explain_failure {"id":"s_chk_ops-t1"}run s_chk_ops-t1 (ops-bot): succeeded, last step 0; stop_reason tool_calls; parked, decided: deploy denied by alice: change freeze until Monday → resumed as s_chk_ops-t2; tool calls: deploy denied by alice; digest: 1 of 1 lines report an error, a park or a failed child; no assistant text this run — http://127.0.0.1:33933/runs/s_chk_ops-t1An open park reads parked: 1 call awaiting a decision (refund_order). A run whose process died mid-tool reads interrupted, the call listed with no result; a run derived from a stock OpenTelemetry GenAI app answers from its spans, with the derived hole. The run tool’s line says the same of a decided park.
Read only, by construction
Section titled “Read only, by construction”weft mcp never approves, denies, resolves, steers, cancels, deletes, replays, edits or starts anything. Two walls hold it:
- No write tool is registered, so there is nothing to call. Each tool is annotated read-only, idempotent and closed-world, and the server advertises an experimental
weftcapability,{"read_only": true, "methods": ["GET"]}. - Under every tool sits an HTTP transport that refuses any method but GET and HEAD before the request leaves the process (
weft mcp is read-only: POST refused).
--read-only defaults to true and is the only mode; --read-only=false is a usage error, exit 2. The flag is missing from the usage line (Usage: weft mcp [--url] [--token]), but weft mcp -h lists it under its flags:
weft mcp --read-only=falseweft: --read-only=false: weft mcp has no write mode (write verbs stay out until the approval story for agents exists)The agent hands off to you instead: every explain_failure answer ends with the run’s Studio page (— http://127.0.0.1:7331/runs/<id>, also its url field), where you approve or deny a parked call, steer or cancel a running one, replay from a step, edit a result or delete the run.
Tokens: what each sees
Section titled “Tokens: what each sees”| Token | Where it comes from | What weft mcp reads with it |
|---|---|---|
| The dev token | weft studio or weft dev: <db>.token beside the SQLite file (0600, never printed), and in the discovery file; --token or WEFT_STUDIO_TOKEN override it | Everything every tool offers |
| A read-only panel token | Minted for one public id (/api/panel-tokens, setup C) | That public id’s runs only; system prompts, request records and app logs hidden; session reverse lookups refused |
A route a token may not read answers 403, and the tool returns it as an error (isError): Studio’s own line, then its body (the error, the badge, the reason and the fix when the route gives one), cut at 2,048 bytes. Never an empty result. explain_failure under a read-only panel token still answers, naming the step it cannot read in step_note (hidden (403)), and its next leaves out the request call, which would 403. meta says which token you hold (auth_required, debug_scope).
Bound the output with max_bytes
Section titled “Bound the output with max_bytes”Every tool takes max_bytes: default 65536 (64 KiB, weft’s own tool-result cap), at most 4194304 (4 MiB). A cut output is never silent; it ends with a note, and the cut JSON does not parse. From the recipe:
> export {"format":"jsonl","id":"a1100000000000000000000000000001","max_bytes":2048}run a1100000000000000000000000000001 exported as jsonl (6678 bytes){"record":"run","format":"weft.run.export/1","run":{"id":"a1100000000000000000000000000001", …[truncated: showing 2048 of 6678 bytes — the JSON above is cut and does not parse; raise max_bytes (at most 4194304) or narrow the query (limit, step, refs)]Prefer the narrow tools (run, step, request) to export, and page runs and events with limit and their cursors.
When no Studio answers
Section titled “When no Studio answers”An MCP client starts its servers once, at session start, often before your weft studio or weft dev is up. So a Studio that does not answer is no reason to exit: weft mcp logs one WARN on stderr and serves, and each tool call returns the failure as its error:
time=2026-10-27T13:11:33.479+01:00 level=WARN msg="weft mcp: no Studio answers /api/meta yet; tools will retry per call" err="studio not reachable at http://127.0.0.1:1: Get \"http://127.0.0.1:1/api/meta\": dial tcp 127.0.0.1:1: connect: connection refused (weft studio starts one; --url or WEFT_STUDIO_URL points at another)"weft mcp: 22 read-only tools over stdio for the Studio at http://127.0.0.1:1 (token none)That is weft mcp --url http://127.0.0.1:1 with nothing listening there.
After a transport failure the next call looks again. With no --url it re-reads WEFT_STUDIO_URL and the discovery file, so a Studio started after the coding session, or weft dev on 7332–7340, is found without restarting the client. When the new look lands on a different Studio than before, weft mcp writes one line to stderr, weft mcp: now reading the Studio at <url>. An explicit --url is retried as given. If a Studio is running elsewhere and the file was not used, check that WEFT_DISCOVERY is not off and WEFT_STUDIO_URL is unset in the environment the client starts weft mcp in; Claude Code passes its own environment, plus the -e pairs.
A Studio that answers and refuses is the command’s error, exit 1:
weft: mcp: no Studio answers /api/meta: GET /api/meta: 401 the API requires a token: Authorization: Bearer <token> (--token or WEFT_STUDIO_TOKEN)Give -e WEFT_STUDIO_TOKEN=… or --token. A 401 in mid-session, with no --url, --token or WEFT_STUDIO_TOKEN, ends ”…; the next call looks again (WEFT_STUDIO_URL, the discovery file): no restart needed”: a Studio restarted with a new token is read with the discovery file’s new token on the next call. A tool that answers 404 has a wrong id (run ids are 32 hex characters, otel-… for runs derived from stock spans, <run>/0/call_1 for a subagent child) or a capability that is off; ask meta.
In weft’s repository, make mcp-check builds weft and starts a real weft studio seeded with the record contract’s fixtures. It adds four shapes built on wefttest scripts: a failed subagent, six failing reviewers at once, a turn denied by alice and resumed, a nine-turn session. It drives weft mcp over stdio through the MCP Go SDK’s client, the way Claude Code drives it, asserts each answer, and ends MCP CHECK PASS. It is not part of make test, since it listens on a port.
Best practices & gotchas
Section titled “Best practices & gotchas”- Let the discovery file carry the token. With no
--urland no token anywhere, nothing secret is stored in the client’s config. (Source:docs/mcp-recipe.md§1) - Prefer
-e WEFT_STUDIO_TOKEN=…to--token. An argument shows inpsto every user of the machine. (Source:docs/mcp-recipe.md§1) - Start with
explain_failure, then follownext. It walks the whole run and its children to the first error, and putsnextbefore the digest, so a cut atmax_byteskeeps it. (Source:cmd/weft/mcp_explain.go) - Read
run_terminal, not the page, to know a run ended. A terminal run’s first page is not its last: follownext_afterwhile the summary saysmore. A page with no more recorded events of a run that is not terminal means the run may still record more. (Source:cmd/weft/mcp.goeventsSummary) - Ask for
full: trueonly when you need a field the compact row drops. Theruntool already answers one run’s row whole. (Source:cmd/weft/mcp_compact.go) - Raise
max_bytesor narrow the query when the note says truncated. The cut JSON does not parse. (Source:cmd/weft/mcp.go)