What you declare
- State. The fields the flow collects, as a map of Zod schemas. State is type-inferred.
- Nodes. Handlers that return state updates, an interrupt signal, or a widget signal.
- Edges. How nodes connect. Direct or conditional.
.compile() on the graph to get a RegisteredFlow, then register it on your MCP server.
Minimal flow
Execution model
Every tool call drives the engine until it hits one of three outcomes:- Interrupt. Pause and ask the user one or more questions. The response carries
status: "interrupt". - Widget. Pause and delegate rendering to a display tool. The response carries
status: "widget". - Complete. The graph reached
END. The response carriesstatus: "complete"and server-side state is deleted.
_meta. The default store is WaniwaniFlowStore, backed by the WaniWani API (reads WANIWANI_API_KEY and WANIWANI_API_URL from env). It works out of the box in serverless runtimes.
Tool contract
A compiled flow exposes a tool with this input shape:startbegins a new run.intentis a short summary of why the user triggered the flow.stateUpdatescan pre-fill any known fields so the engine auto-skips those questions.continueresumes the current run with the user’s latest answers instateUpdates.
status: "interrupt" | "widget" | "complete" | "error". The protocol is documented inside the generated tool description, so the model knows how to call it. You do not parse responses yourself in normal usage.
What to read next
State
Declare the fields the flow collects. Type inference flows from here.
Nodes
The three kinds of nodes and the context they receive.
Edges
Direct edges, conditional edges, loops, and compile-time validation.
Interrupts
Pausing, resuming, validation, and re-ask on error.
Register
Wire the compiled flow onto an MCP server end-to-end.