BrandBrain Flow Orchestrator
v0.4.0Compose BrandBrain asset flows, run mock/live generation, and fetch outputs
MCP server for BrandBrain FlowSpec sessions and asset-generation workflow execution. This server sits on top of the BrandBrain backend flow-session API. It does not talk to model providers directly. The backend remains the source of truth for: Six calls from nothing to images. Every step works on an ordinary MCP client; no task capability is required anywhere on this path.
Summary extracted from the README.
Flow Orchestrator MCP
MCP server for BrandBrain FlowSpec sessions and asset-generation workflow execution.
This server sits on top of the BrandBrain backend flow-session API. It does not talk to model providers directly. The backend remains the source of truth for:
- canonical template bundles
- persisted flow sessions
- validation
- mock and live execution
- run traces and artifacts
Quickstart — the happy path
Six calls from nothing to images. Every step works on an ordinary MCP client; no task capability is required anywhere on this path.
login_brandbrain # only if a flow tool returns "Not authenticated"
list_asset_flows # what canvases already exist (optional `query` filter)
create_asset_flow { title, goal } # goal is written into the flow's brief prompt node
apply_flow_edits { sessionId, ops } # any structural change: one ordered op list, one save
start_asset_flow_run { sessionId, mode: "mock" }
get_asset_flow_task { taskId } # poll until status is "completed" or "failed"
get_flow_outputs { sessionId } # metadata + fetchable artifact URLs + inline previews
open_flow_gallery { sessionId } # visual review in the browser
Concretely:
- Find or create.
list_asset_flowsreturnsid,title,revision,updated_at, graph size, and acanvas_urlfor every stored canvas, so you never need to already hold a session id.create_asset_flow { title, goal }infers a starter template from the goal text and writes that goal into the scaffold's brief prompt node, so the created flow generates your subject rather than the template's placeholder. The response reports which node received it asgoal_applied_to_node_id. - Edit with
apply_flow_edits. The backend validates the whole graph on every save, so build or extend a generate chain with one ordered op list rather than several single-node calls. See Incremental editing. - Run with
start_asset_flow_run+get_asset_flow_task. This is the canonical run path for every client.mode: "mock"costs nothing;mode: "live"spends real money and requiresBRANDBRAIN_MAX_PROVIDER_SPEND_USD_MICROSplus fresh, call-specific user confirmation. - Collect with
get_flow_outputs. Each output carriesartifact_url(a backend/api/v1/canvas/...URL, fetchable with this server's own auth) andopen_in_browser(the app URL a signed-in human can open).open_flow_galleryopens the whole run gallery.
Asset-set flows (a plan node with a named, approved manifest) have their own two-approval lifecycle — see Asset-set authoring and delivery. Nothing in this quickstart bypasses it.
What it is for
Use this MCP server when an LLM or operator needs to:
- seed a new asset-generation flow from a canonical template
- build or refine a stored asset canvas workflow on demand
- validate chaining and node structure before generation
- run the workflow in
mockmode first - run a confirmed provider call in
livemode, or restart supported local asset-set processing from a preserved source sheet - fetch a canvas URL that opens the stored workflow in the app
Quickstart
The server is published on npm as brandbrain-flow-orchestrator-mcp and runs over stdio — no global install needed:
npx -y brandbrain-flow-orchestrator-mcp
Point any MCP client at it with the production endpoints:
{
"mcpServers": {
"brandbrain-flow-orchestrator": {
"command": "npx",
"args": ["-y", "brandbrain-flow-orchestrator-mcp"],
"env": {
"BRANDBRAIN_API_URL": "https://api.brandbrain.dev",
"BRANDBRAIN_APP_URL": "https://brandbrain.dev"
}
}
}
}
Then call login_brandbrain (browser OAuth) and verify with whoami_brandbrain.
Connect Codex or Claude
The transport is local stdio. Codex and Claude start the server on your computer;
the server connects to BrandBrain over HTTPS. There is no hosted /mcp endpoint or
MCP OAuth discovery endpoint in this package. Browser sign-in is provided by the
login_brandbrain tool, so codex mcp login is not the sign-in path for this server.
Codex (CLI and desktop share the MCP configuration):
codex mcp add brandbrain-flow-orchestrator --env BRANDBRAIN_API_URL=https://api.brandbrain.dev --env BRANDBRAIN_APP_URL=https://brandbrain.dev -- npx -y brandbrain-flow-orchestrator-mcp
Remote connector (Claude connectors / plugins)
The hosted endpoint is a single URL — add it as a custom connector and sign in with your BrandBrain account when prompted (OAuth 2.1 + PKCE):
https://api.brandbrain.dev/mcp
claude mcp add --transport http brandbrain-flow-orchestrator https://api.brandbrain.dev/mcp
The connector serves OAuth discovery (RFC 8414/9728), dynamic client registration, and PKCE authorization-code + refresh grants; connector credentials map to your BrandBrain agent session. The same endpoint works for claude.ai connectors and any remote-MCP client.
Claude Code (stdio)
claude mcp add --transport stdio --scope user brandbrain-flow-orchestrator -e BRANDBRAIN_API_URL=https://api.brandbrain.dev -e BRANDBRAIN_APP_URL=https://brandbrain.dev -- npx -y brandbrain-flow-orchestrator-mcp
Claude Desktop: merge the JSON above into your existing mcpServers configuration,
then restart the app. See the Claude Code MCP guide
and Claude Desktop local-server guide.
To run changes in this checkout that are not yet released on npm, build and register the local server:
cd mcp/flow-orchestrator
npm ci
npm run build
node dist/index.js config codex --local
node dist/index.js config claude-code --local
node dist/index.js config claude-desktop --local
Each config command prints a command or configuration to copy; it does not modify
client settings. --local uses the absolute Node executable and built server path,
including correct quoting for checkout paths with spaces. Omit --local to print
configuration for the npm package.
Connect once, then check the account:
node dist/index.js login
node dist/index.js status
The standalone login gives the browser five minutes without an MCP request timeout.
Codex and Claude on the same computer share that account for the same backend. Tokens
stay in the local credential cache; provider keys stay on the backend. Use
node dist/index.js logout to revoke and remove that shared login. Set a separate
BRANDBRAIN_FLOW_MCP_SESSION_FILE for clients that need independent accounts.
To resume a canvas, send the agent: “Use BrandBrain flow <session-id>. Inspect the
stored graph, help me refine it, validate it, and run a mock preview. Ask before paid
generation.” Flow IDs come from the canvas URL or list_asset_flows.
Installer script
From a repo checkout, ./install.sh detects Claude Code, Claude Desktop, and Codex, registers the
server with the production env, and offers to install the bundled agent skill (see
Agent skill):
cd mcp/flow-orchestrator
./install.sh # or ./install.sh --yes to accept every prompt
Registries
A server.json is included for the official MCP Registry
(dev.brandbrain/flow-orchestrator), which powers the MCP server marketplaces in VS Code
and other clients. The registry verifies ownership via the mcpName field in
package.json, so the npm package must be published before mcp-publisher publish will
succeed.
A smithery.yaml is included for the Smithery registry (stdio, npx
command, config schema for the env vars).
Live runs need a spend ceiling
Live (paid) runs are refused unless the server's environment sets
BRANDBRAIN_MAX_PROVIDER_SPEND_USD_MICROS (USD micros; 1000000 = $1.00) — see
Environment. Mock runs work without it.
Backend contract
The server wraps these backend endpoints:
GET /api/v1/canvas/templatesGET /api/v1/canvas/sessionsPOST /api/v1/canvas/sessionsGET /api/v1/canvas/sessions/:sessionIdPUT /api/v1/canvas/sessions/:sessionIdDELETE /api/v1/canvas/sessions/:sessionId— idempotent archival (204), not permanent deletionPUT /api/v1/canvas/sessions/:sessionId/asset-set-plans/:planNodeIdPOST /api/v1/canvas/sessions/:sessionId/asset-set-plans/:planNodeId/approvePOST /api/v1/canvas/sessions/:sessionId/asset-set-plans/:planNodeId/approve-and-runGET /api/v1/canvas/sessions/:sessionId/asset-set-plans/:planNodeId/historyPOST /api/v1/canvas/sessions/:sessionId/validatePOST /api/v1/canvas/sessions/:sessionId/runsGET /api/v1/canvas/sessions/:sessionId/runs/:runIdGET /api/v1/canvas/sessions/:sessionId/runs/:runId/outputsGET /api/v1/canvas/sessions/:sessionId/runs/:runId/artifacts/:artifactIdPOST /api/v1/canvas/sessions/:sessionId/regenerate
In production, the backend must have access to the canonical flow bundles at BRANDBRAIN_FLOW_TEMPLATE_ROOT.
Environment
BRANDBRAIN_API_URL- Backend API base URL.
- Default:
https://api.brandbrain.devin this checkout. Explicitly set it for local development.
BRANDBRAIN_APP_URL- Optional app base URL used to generate returned canvas links.
- Default:
https://brandbrain.dev, orhttp://localhost:3333when the API uses local HTTP.
BRANDBRAIN_FLOW_MCP_BEARER_TOKEN- Optional static bearer token.
- Usually not needed once browser OAuth login is configured.
BRANDBRAIN_FLOW_MCP_SESSION_FILE- Optional absolute path for an isolated local credential cache. By default all clients
using the same backend share
~/.brandbrain/flow-mcp-session-<backend-hash>.json.
- Optional absolute path for an isolated local credential cache. By default all clients
using the same backend share
BRANDBRAIN_MAX_PROVIDER_SPEND_USD_MICROS- The most this server may authorise a single
liverun to spend, in USD micros (1000000= $1.00). The backend caps any one run at100000000($100.00) regardless. - There is no default and no value meaning unlimited. Leave it unset and
every
liverun is refused before any request reaches the backend; onlymockruns work. - This is deliberately process environment rather than a tool argument, so an agent driving this server cannot choose its own spend ceiling. Set it yourself, in your MCP client configuration, to the most you are willing to lose on one run.
- The amount actually authorised is never this number. It is the backend's own conservative estimate for that exact run; this value only decides whether the run is allowed to proceed at all.
- The most this server may authorise a single
See .env.example.
Install and run
From a repo checkout (mcp/flow-orchestrator):
cd mcp/flow-orchestrator
npm install
npm run build
BRANDBRAIN_API_URL=http://127.0.0.1:4444 npm start
For local iteration:
cd mcp/flow-orchestrator
npm install
BRANDBRAIN_API_URL=http://127.0.0.1:4444 npm run dev
MCP client configuration
Published package (preferred — see Quickstart):
{
"mcpServers": {
"brandbrain-flow-orchestrator": {
"command": "npx",
"args": ["-y", "brandbrain-flow-orchestrator-mcp"],
"env": {
"BRANDBRAIN_API_URL": "https://api.brandbrain.dev",
"BRANDBRAIN_APP_URL": "https://brandbrain.dev"
}
}
}
}
Built server from a checkout:
{
"mcpServers": {
"brandbrain-flow-orchestrator": {
"command": "node",
"args": [
"<repo-checkout>/mcp/flow-orchestrator/dist/index.js"
],
"env": {
"BRANDBRAIN_API_URL": "https://api.brandbrain.dev",
"BRANDBRAIN_APP_URL": "https://brandbrain.dev"
}
}
}
}
Agent skill
The source of truth for the agent skill that teaches agents how to drive this server safely lives
in this repository at skill/ (SKILL.md + references/ + agents/openai.yaml). It
also ships inside the published npm package, next to this README.
The skill encodes the intended usage pattern for agent sessions:
- list templates first
- create template-backed flows when possible
- validate after edits
- run
mockbeforelive - return
canvas_urlto the user
To install it for Codex, copy the directory into the skills root:
cp -R skill/ ~/.codex/skills/brandbrain-flow-orchestrator/
For other agents, copy skill/ into their skills directory (or point them at the packaged copy
inside brandbrain-flow-orchestrator-mcp). ./install.sh offers the Codex copy automatically.
Dev server with tsx:
{
"mcpServers": {
"brandbrain-flow-orchestrator": {
"command": "npx",
"args": [
"tsx",
"<repo-checkout>/mcp/flow-orchestrator/src/index.ts"
],
"env": {
"BRANDBRAIN_API_URL": "http://127.0.0.1:4444",
"BRANDBRAIN_APP_URL": "http://127.0.0.1:3000"
}
}
}
}
Tools
| Tool | Purpose | Typical use |
|---|---|---|
login_brandbrain |
Open BrandBrain browser login and store a local MCP session | First step when the backend is protected and no local agent session exists |
whoami_brandbrain |
Inspect the locally stored MCP session | Confirm the active BrandBrain agent identity before editing flows |
logout_brandbrain |
Revoke the stored MCP refresh session and clear local credentials | Explicitly end a local MCP login |
list_asset_flow_templates |
Discover canonical starter flows | First step when the user describes a goal but not a template |
list_asset_flows |
List active canvases (id, title, revision, updated_at, node/edge counts, canvas_url), with optional client-side query and limit; archived: true lists archived flows and their archived_at timestamps instead |
Find an existing canvas or its retained history |
create_asset_flow |
Create a stored flow session from a template, goal, or explicit flowSpec; the goal is written into the scaffold's brief prompt node |
Start a new workflow |
get_asset_flow |
Fetch the stored session and flow spec | Inspect current graph before editing |
edit_asset_flow |
Replace title/description and optionally replace the stored flowSpec |
Structural edits after creation |
update_asset_set_plan |
Atomically update asset-set authoring fields and persist a complete draft manifest proposal | Configure a named asset set before asking the user to approve it |
approve_asset_set_plan |
Approve the exact persisted manifest revision and content hash | Record explicit user approval without forging manifest authority fields |
approve_and_run_asset_set_plan |
Approve the exact persisted manifest revision/hash and start its run in one durable, idempotent backend launch | The user has approved that exact manifest and (for live) that exact paid call |
get_asset_set_plan_history |
Fetch manifest revisions and approval events | Audit the persisted asset-set lifecycle |
validate_asset_flow |
Run backend graph validation | After every material edit and before any run |
start_asset_flow_run |
Start a background mock or live run and return a pollable task envelope; pass targetNodeId to run one branch of a multi-generate graph |
Standard MCP clients that only support ordinary tool calls |
get_asset_flow_task |
Poll a background task started by the MCP server | Check status until completed or failed |
start_regenerate_asset_flow_node |
Start a background regeneration request from a target node | Polling clients; asset-set local targets rerun the set-scoped pipeline from split, while legacy graphs may invoke the full runner |
run_asset_flow |
Execute the session in mock or live mode — task-capable clients only |
Task-backed execution for long-running runs; other clients get pointed back to start_asset_flow_run |
regenerate_asset_flow_node |
Start a task-backed regeneration request from a target node — task-capable clients only | Asset-set local reprocessing or a separately confirmed legacy regeneration whose full reachable scope has been inspected |
get_asset_flow_run |
Inspect a stored run result and traces | Audit what happened after execution |
compare_image_models |
Clone a one-generate-node session once per model (same prompt, style, references), preflight all of them, and start the runs — live only under a total ceiling you pass | Compare engines on the same brief: OpenRouter's Gemini/Flux/Seedream against gpt-image-2; each sibling is an ordinary session with its own gallery |
list_image_models |
Every provider's image models with lifecycle, reference support and the preflight's own ceiling for one 1024² image | Pick a model — and a price — before authoring a generate node; the only way to discover OpenRouter's model ids |
get_flow_processor_health |
Read normalized local processor readiness and pinned revisions | Verify zero-token local split/background/vector processing is available before relying on it |
get_flow_outputs |
Return every durable output's metadata, a backend artifact_url and a browser open_in_browser URL, with a bounded inline preview |
View/validate generated assets after a run (run the flow first) |
get_flow_trace |
Per-node run trace: status, timing, resolved prompts, provider request highlights, artifacts, errors | Investigate why a run/node failed or what was sent to the provider |
open_flow |
Open the flow's canvas (/crm/canvas/{id}) in your default browser |
Jump from MCP to the visual editor |
open_flow_gallery |
Open the flow's run gallery (/crm/canvas/{id}/gallery) in your default browser |
Review every run's output images + per-image cost/trace after running |
Providers and models
A generate node names a provider and a model_id; the backend's image-model catalogue is the
only authority on which pairs are valid, and list_image_models reads it:
| Provider | Model ids | Notes |
|---|---|---|
openai |
gpt-image-2 (default), gpt-image-1.5, gpt-image-1 |
OpenAI's own endpoint; per-image pricing by quality and size |
gemini |
gemini-2.5-flash-image |
Google's own endpoint |
openrouter |
forty-odd, by vendor-qualified id: google/gemini-3.1-flash-image, black-forest-labs/flux.2-klein-4b, bytedance-seed/seedream-4.5, recraft/recraft-v4, meta/muse-image, openai/gpt-image-2, … |
One key for every vendor; no default model, so model_id is required. Needs OPENROUTER_API_KEY on the backend (production keeps provider keys in the brandbrain-api-provider-env secret) |
Prices differ by an order of magnitude — a 1024² image runs from about $0.01 (Muse Image, flat per
generated image) and $0.015 (Flux.2 klein) through $0.04 (Seedream, Recraft) and $0.08 (Gemini 3.1
flash via OpenRouter) to $0.21 (gpt-image-2) — and the preflight ceiling list_image_models reports
is the same one a live run is authorised against. For token-billed OpenRouter models (Google's and
OpenAI's) that ceiling is derived from the vendors' published per-image token counts at the
expensive end; the actual charge is reported after the call.
Asset-set authoring and delivery
Asset sets use a persisted plan and manifest lifecycle. Do not skip or combine the two approval boundaries: the user first approves the proposed manifest, then later confirms the specific paid provider call immediately before live execution.
Use this sequence for a new or changed asset set:
get_asset_flow
-> update_asset_set_plan
-> present the persisted draft and wait for explicit user manifest approval
-> approve_asset_set_plan
-> validate_asset_flow
-> run_asset_flow(mode="mock") or start_asset_flow_run(mode="mock") + polling
-> present the paid-call scope and wait for explicit confirmation
-> run_asset_flow(mode="live") or start_asset_flow_run(mode="live") + polling
-> get_flow_outputs
-> open_flow_gallery
approve_and_run_asset_set_plan collapses the mechanical approve → prepare → run sequence into
the backend's own durable launch route (.../approve-and-run). It does not collapse the two
approval boundaries:
- it still requires the exact
manifestContentHashthe user approved (a canonicalsha256:<64 hex>digest; anything else is refused locally), plus both expected revisions; mode: "mock"carries no authorization at all;mode: "live"first preflights the plan's single downstream generate node, then authorizes exactly the backend's own estimate for that launch, under the operator'sBRANDBRAIN_MAX_PROVIDER_SPEND_USD_MICROSceiling. Without a configured ceiling the launch is refused before any request reaches the launch route.
It is idempotent: an omitted idempotencyKey is generated, and replaying the same key returns the
same approval and run rather than approving twice. Use it when the user has already approved that
exact manifest (and, for live, that exact paid call); use approve_asset_set_plan on its own
when approval and execution are separated in time.
The four plan-lifecycle tools accept camelCase MCP inputs:
| Tool | Required inputs |
|---|---|
update_asset_set_plan |
sessionId, planNodeId, positive expectedFlowRevision, non-negative expectedManifestRevision, non-empty label, brief, and desiredPurpose, requestedCount from 1 through 64, requestedFormats exactly ["png"] or ["png", "svg"], and the complete proto-JSON manifest object |
approve_asset_set_plan |
sessionId, planNodeId, positive expectedFlowRevision, positive expectedManifestRevision, and the exact non-empty manifestContentHash returned with the persisted draft |
approve_and_run_asset_set_plan |
the same five, with manifestContentHash constrained to a canonical sha256:<64 hex> digest, plus mode (mock default, live) and an optional idempotencyKey |
get_asset_set_plan_history |
sessionId and planNodeId |
update_asset_set_plan is one atomic write: it updates the plan authoring fields and complete
manifest proposal together, recomputes the canonical manifest hash, and persists a new draft. Read
the returned persisted draft, revisions, and content hash; do not calculate or invent approval
fields in the client. Present the named items, layout, required formats, and spend policy to the
user. Only after the user approves that exact proposal should the client call
approve_asset_set_plan using the returned revisions and hash. Stale revision or hash conflicts
must be surfaced to the caller, followed by a fresh get_asset_flow; do not retry with guessed
values. get_asset_set_plan_history is the source of truth for revision and approval records.
The format contract is intentionally narrow:
- Every item must request PNG as both a desired and required format. A transparent PNG is the required master.
- SVG may be the optional second requested format. It is desired and published only after the sanitizer, complexity, and raster-fidelity gates pass.
- Mark SVG required in the manifest only when the user explicitly requires vector delivery and accepts that a failed SVG gate leaves that item requiring review. An optional SVG failure must not erase or fail a valid PNG master.
Generic graph-editing tools cannot author or alter an asset-set plan node. This includes
edit_asset_flow, apply_flow_edits, and the individual incremental edit tools: they cannot add,
remove, or change plan fields, manifest contents, or approval state. Use
update_asset_set_plan for authoring changes and approve_asset_set_plan for approval.
After approval, require validate_asset_flow to return valid=true, then finish a terminal mock
run before considering live execution. Immediately before a provider-backed source-generation run:
- Inspect the persisted graph and selected execution target. Exactly one provider-backed node may be reachable by that live run; if more than one is reachable, stop instead of using regeneration as a workaround. A zero-provider asset-set local reprocessing run is a distinct recovery path described below and must be verified from its returned target and usage evidence.
- Tell the user the operation, provider/model when known, item or set scope, expected size/quality, and estimated or bounded cost when available. Ask for explicit confirmation of that one call.
- After confirmation, start one live run with a new
idempotencyKey. Further provider calls need fresh confirmation.
For asset-set templates configured for local review, the approved source sheet then proceeds through the canonical local split, background removal, trim/normalization, vectorization, review, and output stages. These local post-processing stages consume no model/provider tokens and incur no provider cost; verify that claim from returned usage, trace, or cost evidence. Do not claim an unverified zero-token result. If semantic provider review is enabled, stop before an atomic live run because the current MCP surface cannot separately confirm and dispatch that additional paid stage.
Finish with get_flow_outputs and open_flow_gallery. get_flow_outputs returns the complete
outputs metadata array for the selected run. Every durable output carries two links:
artifact_url— the backend${BRANDBRAIN_API_URL}/api/v1/canvas/sessions/.../artifacts/...URL. This is the one an agent can actually fetch, because it is served by the same API this server authenticates against.open_in_browser— the app${BRANDBRAIN_APP_URL}/api/canvas/...URL, for a signed-in human.
Neither link carries credentials or a signed query string. get_flow_outputs inlines previews for
at most 16 outputs, subject to the per-image byte cap; outputs beyond that preview limit remain
present in metadata with both URLs. Use those URLs for individual PNG/SVG delivery and the gallery
for visual review.
Incremental editing
Edit a stored canvas without resending the whole graph (preferred over edit_asset_flow, which
replaces the entire flowSpec).
Asset-set plan nodes are the exception: generic whole-flow and incremental edits cannot add, remove, or modify them. Follow the dedicated asset-set authoring and delivery lifecycle instead.
Important — the backend validates the WHOLE graph on every save. Each single-op tool below does its own
PUT, so it is rejected (HTTP 400) if it leaves the graph transiently invalid. A generate node needs ≥1 input edge and ≥1 output edge, so you cannot add a bare generate node and wire it up in separate calls. To build or extend a generate chain, useapply_flow_edits, which applies an ordered op list in memory and saves once — only the final graph is validated.
| Tool | Purpose |
|---|---|
apply_flow_edits |
Batch: apply an ordered list of ops in one save. Use this to build/extend chains. |
add_flow_node |
Add one node (type = prompt/reference/style/generate/output/frame/note); auto-positions and auto-ids if omitted. Safe alone only for nodes valid while unwired (prompt/style/reference/note/frame). |
update_flow_node |
Patch a node's fields and/or position by nodeId |
remove_flow_node |
Remove a node and any edges referencing it |
connect_flow_nodes |
Add an edge between two existing nodes (prompt|reference|style|output -> generate, or generate -> output) |
disconnect_flow_nodes |
Remove an edge by edgeId, or by sourceNodeId+targetNodeId |
set_generate_target |
Set a generate node's surface/aspectRatio/composition target |
Tool inputs are camelCase (modelId, sourceNodeId); they are emitted to the backend as the
canonical snake_case proto-JSON. Each tool returns the backend validation result.
Example — build a full prompt+style → generate → output chain in one call:
apply_flow_edits {
"sessionId": "flow_session_...",
"ops": [
{ "op": "add_node", "type": "prompt", "id": "bp", "text": "A bold packshot on seamless paper" },
{ "op": "add_node", "type": "style", "id": "bs", "palette": ["#0a0a0a", "#f5f5f0"] },
{ "op": "add_node", "type": "generate", "id": "bg", "provider": "openai", "modelId": "gpt-image-1" },
{ "op": "add_node", "type": "output", "id": "bo" },
{ "op": "connect", "sourceNodeId": "bp", "targetNodeId": "bg" },
{ "op": "connect", "sourceNodeId": "bs", "targetNodeId": "bg" },
{ "op": "connect", "sourceNodeId": "bg", "targetNodeId": "bo" },
{ "op": "set_generate_target", "nodeId": "bg", "surface": "packshot", "aspectRatio": "1:1" }
]
}
Task-backed run tools
run_asset_flow and regenerate_asset_flow_node are registered as MCP task tools.
- plain
client.callTool(...)is not the right API for these tools - task-capable clients should use
client.experimental.tasks.callToolStream(...) - this avoids the default short request timeout problem on real image generation
- the MCP task stays
workingwhile the backend run isqueuedorrunning; it does not complete merely because the asynchronous dispatch returned a run ID - backend
completedandpartialruns complete the MCP task; backendfailed,cancelled, andoutcome_unknownruns fail it while retaining the terminal run and error in the stored task result - a requested task TTL that is shorter than the bounded backend polling window is raised to a safe accepted TTL so the SDK task store cannot expire before terminal evidence is persisted
- accepted TTLs are capped at
2,147,000,000ms(just below Node's signed 32-bit timer maximum), including when a client requests a larger value - terminal polling retries only transient read failures (network/timeouts, HTTP 429, and HTTP 5xx) with bounded exponential backoff and jitter inside one overall deadline; authentication, other HTTP 4xx, and unsupported backend statuses fail immediately
- the default poll deadline is mode-aware:
liveruns poll for up to 30 minutes (a ~10-minute asset-set generation fits inside one task), whilemockruns keep the short ~9.5-minute default; a constructor/configuredrunPollTimeoutMsalways overrides the default - each run read has a wall-clock timeout that aborts the request and releases the poll loop even if bearer-token resolution or another dependency ignores cancellation; late settlement cannot change the terminal task result
- access-token refreshes are coalesced within a process and locked across local clients (refresh tokens are single-use), bounded to 10 seconds, and receive the run-read cancellation signal while callers wait; transient failures preserve the session and any still-valid access token
- task-backed and standard tools share one 32-operation execution limit across dispatch and terminal polling; capacity is released when that lifecycle reaches a terminal outcome
Clients without task augmentation (Claude Code included) should use the polling pair. A plain
callToolofrun_asset_floworregenerate_asset_flow_nodeno longer produces a bare-32601: the server answers with an error result naming the tool to use instead (start_asset_flow_run/start_regenerate_asset_flow_node, thenget_asset_flow_task) and a machine-readablestructuredContentof{ error: "task_augmentation_required", use_instead: [...] }. No run is dispatched by that guidance response.
Example:
const stream = client.experimental.tasks.callToolStream(
{
name: "run_asset_flow",
arguments: { sessionId, mode: "mock" },
},
CallToolResultSchema,
{ task: { ttl: 600000 } },
);
for await (const message of stream) {
if (message.type === "result") {
console.log(message.result.structuredContent);
}
}
Standard polling tools
Some MCP clients do not support the experimental task streaming API and can only issue ordinary
callTool(...) requests. For those clients, the server also exposes a polling pair:
start_asset_flow_runget_asset_flow_task
and the regenerate equivalents:
start_regenerate_asset_flow_nodeget_asset_flow_task
start_* returns immediately with a task payload like:
{
"task": {
"id": "flow_task_...",
"kind": "run",
"status": "working",
"session_id": "flow_session_...",
"mode": "mock",
"poll_interval_ms": 1000
}
}
Poll until the task is terminal. queued and running backend runs remain working; completed
and partial map to completed, while failed, cancelled, and outcome_unknown map to failed.
The terminal polling envelope contains the refreshed backend run, including its result/error
evidence. Dispatch happens once; polling only reads the pinned session/run identity and does not
repeat provider work. Transient reads use bounded backoff; non-transient errors and unknown statuses
fail immediately. While a task is working, run_id, backend_status, poll_attempts, and
updated_at advance with polling progress; last_poll_error is included while retrying a transient
read failure.
Each start_* call creates a distinct dispatch attempt, including keyless calls and repeated calls
with the same explicit idempotency key. This ensures the backend can re-evaluate the latest flow
revision and lineage; canonical idempotency/replay decisions remain backend-owned. If distinct
dispatches return the same immutable session/run ID, the MCP server shares only their terminal GET
FlowRun promise to avoid redundant reads. Each caller independently builds its task result from
that run and its own dispatch envelope, so prepared authority is never borrowed from another caller.
Local processor health
Call get_flow_processor_health before promising no-token local asset processing. It is a read-only,
allowlisted view of /health/processors that reports enabled, available, platform,
execution_class, provider_token_cost, revisions.vtracer, revisions.resvg, and any health
error. Its capabilities object reports split, trim_normalize, vectorize, local_review,
and the background-removal fields deterministic_matte_or_alpha, local_model_fallback, and
production_ready. Background removal is production-ready only when the deterministic path is
present and the configured local BiRefNet fallback passes its provenance-aware health probe. A
runtime without BiRefNet can still preserve valid alpha or remove a known matte, but callers must
not promise general-purpose background removal when production_ready is false. Missing capability
fields from older backends default to false. Unknown backend fields are dropped so credentials and
transport details cannot be exposed. An unavailable optional processor is returned as health
evidence even when the backend health route uses HTTP 503. These checks are local and have no
provider-token cost.
Then poll:
const started = await client.callTool({
name: "start_asset_flow_run",
arguments: { sessionId, mode: "mock" },
});
const taskId = (started.structuredContent as { task?: { id?: string } }).task?.id;
for (;;) {
const polled = await client.callTool({
name: "get_asset_flow_task",
arguments: { taskId },
});
const payload = polled.structuredContent as {
task?: { status?: string };
run?: { id?: string };
};
if (payload.task?.status === "completed" || payload.task?.status === "failed") {
console.log(payload);
break;
}
await new Promise((resolve) => setTimeout(resolve, 1000));
}
Notes:
get_asset_flow_taskreturns the finalrunpayload once the background task completes- after completion, use
get_asset_flow_runif you want the persisted run again later - the polling task registry is in-memory to the MCP server process, so task IDs are not durable across MCP restarts
- the shared execution coordinator rejects new work before backend dispatch when its 32-operation capacity is full, regardless of whether work came from a standard or task-backed tool
- capacity is released after dispatch and terminal-poll failures as well as normal completion; a rejected shared poll is removed before the next attempt, so a retry performs a fresh backend read
- the standard registry retains at most 128 tasks, evicts the oldest terminal entries as needed, and expires terminal entries after 10 minutes
- prepared POST requests still carry the expected flow revision and resolved-policy hash, but those values are not exposed as fenced durable identity because the persisted FlowRun does not echo them. Retained dispatch identity contains only matchable fields: session, execution mode, actual target, generated or supplied idempotency key, approved manifest hash, and execution lineage. Durable failed-run evidence is accepted only from the typed error around the actual run or regenerate POST and only when every retained field matches; get-session/prepare/authentication failures never carry run evidence, and legacy fields that were not sent remain absent
- retained failure diagnostics follow the real FlowRun ProtoJSON shape and are explicitly allowlisted
and bounded, with a hard 64 KiB serialized budget across the result diagnostic envelope. Later
entries are deterministically dropped, and
diagnostics_truncatedis set whenever a count limit, per-string bound, or global byte budget clips retained diagnostics. Safe trace/checkpoint/processor/item/artifact identifiers, statuses, issue codes, dimensions, sizes, hashes, MIME types, and durations may be retained; prompts, request/response bodies, provider usage, evidence JSON, credentials, filesystem paths, URLs, provenance, secrets, and unknown fields are discarded
Browser OAuth login
The preferred auth path is browser-based Google OAuth through BrandBrain:
- call
login_brandbrain - the MCP server opens
/login/agenton the BrandBrain app with a localhostagent_callback - BrandBrain redirects to the backend Google OAuth start endpoint
- after Google authentication, the backend redirects back to the local MCP callback with an OTC
- the MCP server checks a per-login callback nonce, exchanges the OTC for agent tokens, and atomically stores them in an owner-readable credential file
The callback listens only on loopback, ignores unrelated requests, does not log the one-time code, and closes after completion, cancellation, or timeout. The backend parses callback URLs and rejects credentials, non-loopback hosts and invalid ports. Session refreshes use a shared file lock so simultaneous Codex and Claude requests cannot redeem the same single-use refresh token. Crashed locks expire automatically.
Use whoami_brandbrain to confirm the current session and logout_brandbrain to revoke it.
If a flow tool returns Not authenticated. Run login_brandbrain first., do that before retrying.
Recommended workflow
1. Log in when needed
login_brandbrainwhoami_brandbrain
2. Start from templates unless you have a reason not to
Preferred path:
list_asset_flow_templatescreate_asset_flowwith:titlegoalif you want the tool to infer a templatetemplateIdif you know the exact starter
- read back
canvas_url
This keeps the first graph aligned with the checked-in canonical bundles.
goal does two things: it infers the template, and it is written into the scaffold's brief prompt
node (the node named prompt_brief, or the first prompt node if the template does not name one) in
one additional save. The response reports the node as goal_applied_to_node_id; if the scaffold has
no prompt node at all, the tool says so instead of silently dropping the goal.
description is still session metadata only and does not reach the graph. Two template details the
goal does not cover: the starter campaign-visual graph also wires prompt_guardrails into the
assembled provider prompt, and injects the template's style palette/theme — neutralize
style_primary with update_flow_node if the template look fights your subject.
3. Validate structure before spending tokens
Always call validate_asset_flow before run_asset_flow.
Use mock mode first and poll or stream it to a terminal completed result. Inspect the persisted
mock run before continuing. It verifies:
- graph validity
- runnable generates
- downstream output materialization
- stage/regeneration semantics
- stored session integrity
4. Edit only when template inference is not enough
Use edit_asset_flow with a replacement flowSpec when:
- the user needs non-template structure
- you need to add or remove nodes explicitly
- you want to rewrite edges or stages
If you only need a different starting point, create a new flow from a better template instead of over-editing the old one.
5. Confirm each live provider call
Before any provider-backed live run:
- Require the current graph to pass validation and a completed mock run.
- Inspect the persisted graph and selected execution target. Exactly one provider-backed node may be reachable; stop if more than one is reachable because the current runner cannot isolate those calls. If none is reachable, treat the operation as local processing rather than a paid call and verify that from the returned target and usage evidence.
- Disclose the operation, provider/model when known, item or set scope, expected size/quality, estimated or bounded cost when available, and whether a preserved source can avoid a new call.
- Ask for fresh, explicit confirmation immediately before dispatching that one provider call.
A live run additionally requires BRANDBRAIN_MAX_PROVIDER_SPEND_USD_MICROS to be configured on
this server. Without it the run is refused locally and nothing is dispatched. That ceiling is the
user's, not the agent's: it is not a tool argument and cannot be raised from a tool call.
The user's earlier desire for real outputs, manifest approval, or the presence of provider credentials is not authorization to spend. Confirmation is call-specific: every additional source generation, provider-backed review, retry, or regeneration needs its own immediate confirmation.
6. Pick the execution path that matches the client
start_asset_flow_run/start_regenerate_asset_flow_nodeplusget_asset_flow_taskis the canonical pair and works on every client — prefer it unless you have a reason not torun_asset_flowandregenerate_asset_flow_nodeare the task-streaming equivalents for clients that support MCP task augmentation; on any other client they return guidance pointing back at the polling pair
7. Regenerate without assuming provider isolation
For an asset-set session, regenerate_asset_flow_node or
start_regenerate_asset_flow_node may target a local process node such as split,
remove-background, trim-normalize, vectorize, or review. The backend anchors this operation
at split and reruns the full set-scoped local pipeline from the latest eligible persisted raw
sheet. It does not expose per-item processing or a caller-selected source run/artifact. After the
run starts, inspect get_asset_flow_run and require the returned target to be local-only and
downstream-only, with its base run/attempt and input checkpoint/artifact lineage, before claiming
that it preserved the source and incurred no provider cost.
On legacy/non-asset-set graphs, regeneration records targetNodeId but may still invoke the full
runner. It does not guarantee a single-node or single-output provider retry. Inspect the complete
reachable provider scope; if any provider-backed work can run, disclose that scope/cost and obtain
fresh explicit confirmation immediately before regeneration. Stop when multiple provider-backed
nodes are reachable.
Example operator flows
Create a new workflow from a goal
Input:
{
"title": "Spring launch system",
"goal": "Build a campaign system with a hero and story adaptation"
}
Tool:
create_asset_flow
The goal both selects campaign-system and becomes the text of the created flow's brief prompt
node (goal_applied_to_node_id in the response).
Follow-up:
validate_asset_flowstart_asset_flow_runwithmode=mock- poll
get_asset_flow_taskuntilcompleted get_flow_outputs, thenopen_flow_galleryorcanvas_url
Task-stream alternative:
validate_asset_flowrun_asset_flowwithmode=mock- inspect
canvas_url
Edit and rerun an existing session
list_asset_flows(optionally withquery) if you do not already hold the session idget_asset_flow- modify the returned
flow_spec edit_asset_flowvalidate_asset_flowstart_asset_flow_run- poll
get_asset_flow_task
Restart asset-set local processing from a preserved sheet
{
"sessionId": "flow_session_...",
"targetNodeId": "split",
"mode": "live"
}
Tool:
regenerate_asset_flow_node
For a standard client, use start_regenerate_asset_flow_node with the same arguments, poll
get_asset_flow_task, then inspect get_asset_flow_run. Do not use this example for a provider
retry: the zero-provider claim depends on the returned asset-set target being set-scoped,
local-only, downstream-only, and anchored to the persisted raw-sheet lineage.
Validation and test commands
cd mcp/flow-orchestrator
npm test
npm run test:integration
npm run build
Troubleshooting
A tool change did not take effect
MCP clients spawn node dist/index.js once per session and never reload it, so a stale dist/
speaks a stale backend contract — and the backend sanitizes rejections to Invalid request., which
looks like a server bug and is not. Run task doctor to compare dist/ against src/, then
task build and reconnect the MCP client (Claude Code: /mcp → reconnect).
Invalid request. / HTTP 400 while editing a graph
The backend validates the whole graph on every save. A generate node needs at least one input
edge and one output edge, so adding a bare generate node and wiring it up in separate
add_flow_node / connect_flow_nodes calls is rejected at the intermediate state. Use
apply_flow_edits: it folds an ordered op list in memory and saves once, so only the final graph is
validated.
Invalid request. / HTTP 400 from update_asset_set_plan
The commonest causes are shape traps in the manifest payload:
items[].grid_indexmust be present and distinct. An omittedgrid_indexdefaults to0; two items on the same cell reject the whole update with no detail.- Do not send
content_hashorapprovalinside an updated manifest — the server recomputes the hash and owns the approval record. - The manifest must be the complete backend shape (
title,purpose,layout,retry_policy,spend_policy, fullitems[]), not a partial patch.
The backend deliberately sanitizes these to a bare Invalid request.. When running your own
backend, set BRANDBRAIN_DEBUG_SERVICE_ERRORS=true on the backend server process to include
the underlying error in invalid_request responses.
Mock approve_and_run_asset_set_plan fails with invalid_request
Backends older than the zero-spend launch fix reject every MOCK launch: a mock preflight
legitimately prices at zero (its generators resolve to the mock provider), but the old launch
validators required positive expected spend unconditionally. Fall back to approve_asset_set_plan
followed by start_asset_flow_run until the backend is updated.
Everything fails with Not authenticated in ~10 ms
Verify the configured backend and account with node dist/index.js status from this
checkout. Older npm releases default to http://127.0.0.1:4444; set both production
endpoints explicitly in client configuration. This checkout defaults to production.
After changing the endpoint, reconnect the account: credentials are scoped to a backend.
A field I set does not appear in the stored flow
Tool inputs are camelCase (modelId, sourceNodeId), but the persisted flow_spec is protojson in
snake_case (model_id, source_node_id). The edit tools convert for you; hand-written
flowSpec payloads must already be snake_case, and code reading a fetched flow_spec must read
snake_case keys.
start_asset_flow_run returned an error instead of a task
That is the refusal, and it is deliberate. Preflight and spend authorisation run before a
polling task is created, so a live run the configured ceiling cannot cover (or one with no
ceiling at all, or a session that does not exist) comes back as the call's own error with
nothing dispatched. It used to come back as a task in working that failed in the background —
indistinguishable, for a script that starts a run and exits, from a run in flight. Read the
message: it carries the backend's own estimate and the ceiling it exceeded.
A chained live run fails after its first generate
A graph of the shape generate → output → generate runs to completion in mock and fails live at
the second generate, after the first has been paid for. Two distinct causes were found and fixed
on 2026-09-05 (grants resolved with the wrong resolver; a mock run's asset ids frozen into later
live snapshots), and then a third that is architecture, not a bug: the durable paid runtime
allows exactly one provider call per attempt — the paid-call owner index is attempt_id and
each run holds one pristine reservation — and a manifest-less run may not derive from a base run.
The journal line reads prepare paid owner already belongs to "paid-image-…": runstate conflict.
So a live run may contain one generate node. To condition a generation on an earlier image, give
it a reference node and run one session per output. storage_path takes either an https://
URL of the image (public host, 10 MB cap, png/jpeg/webp/gif/svg) or the image itself as a
data:image/webp;base64,… URL (same cap), which needs no hosting at all — shrink the source to a
768-square webp first, since a 1 MB provider output does not fit a shell argument once encoded.
That is how babybub's plates are chained: one session per image, each referenced on the plate
landed before it. A mock run shows references:["data"] in the request evidence before anything
is billed. list_asset_flow_runs shows what a session has already spent.
A live run ends failed or outcome_unknown — where the reason is
Since 2026-09-06 a durable live run that does not complete carries the provider's own words:
get_asset_flow_run (result.error), get_flow_trace (error), list_asset_flow_runs (each line)
and the task's failure summary all show, for example,
provider_rejected_400: OpenRouter images api 400: Black Forest Labs blocked this request through content moderation. A definite 4xx is failed with provider_rejected_<status> and cost nothing;
outcome_unknown means the call may have been billed (timeout, 5xx) and carries its reason after
provider dispatch returned no durable response:. Before this, such runs showed only the status and
zero trace entries; the reason was in the backend log alone.
A mock run with an idempotencyKey fails with "Request conflicts with the current resource state"
On a backend before #226 (2026-09-05), every start_asset_flow_run in mock mode that carried
a caller key 409'd against Postgres for single-generate flows, while the same run without a key
completed: the synchronous mock path persisted the key on a legacy run the Postgres store refuses.
Fixed; until it is deployed, mock runs go through without a key (the server mints one).
Tool run_asset_flow requires task augmentation
Your client does not support MCP task augmentation. Use start_asset_flow_run and poll
get_asset_flow_task; use start_regenerate_asset_flow_node instead of
regenerate_asset_flow_node. The server returns this as guidance with a
task_augmentation_required structuredContent rather than a bare -32601.
No templates available
The backend cannot see the canonical flow bundle root. Check:
BRANDBRAIN_FLOW_TEMPLATE_ROOT- deployed bundle files under
/opt/brandbrain/evals/flowsin production
400 validation on create or edit
The backend rejected the provided flowSpec. Call validate_asset_flow or inspect the returned validation payload.
401 or 403
Set BRANDBRAIN_FLOW_MCP_BEARER_TOKEN if the backend APIs are protected.
live runs fail
The MCP server is not the model execution layer. Check provider credentials and backend runtime config, not the MCP package. Credentials are only an execution prerequisite; they never replace the fresh user confirmation required immediately before each provider call.
login_brandbrain times out
login_brandbrain blocks until you finish the browser round-trip. MCP clients enforce a request
timeout (the SDK default is 60s), which can abort the call before you sign in. Options:
- complete the Google sign-in promptly, or
- run
node dist/index.js loginfrom a current build (five-minute browser window, no MCP layer), thennode dist/index.js status; both use the same session file as MCP clients. - the legacy
node scripts/login.mjshelper also works from a checkout (15-minute window).
Local verification scripts
scripts/ contains a stdio client for exercising the server end to end without a full MCP client:
node scripts/login.mjs # browser OAuth, 15-min window, writes the session file
node scripts/smoke.mjs list # list registered tool names
node scripts/smoke.mjs whoami # check the stored session
node scripts/smoke.mjs templates # list flow templates
node scripts/smoke.mjs create '{"title":"X","templateId":"campaign-system"}'
node scripts/smoke.mjs call '{"name":"apply_flow_edits","arguments":{ ... }}'
node scripts/smoke.mjs runflow '{"sessionId":"flow_session_...","mode":"mock"}'
All read BRANDBRAIN_API_URL / BRANDBRAIN_APP_URL from the environment.
License
MIT — see LICENSE.