Back to developer guides

External-agent quickstart

Setup-to-release journey for a coding agent that owns its own frontend project and uses Wrapflow as the backend, plus the supported way to diagnose an ordinary integration error. Everything here runs through the documented CLI/MCP/SDK surfaces — no internal identifiers, database edits, or administrator credentials are needed until the human release step.

The commands below are exercised end-to-end by the repository's npm run smoke:local-external-contract check. Keep them aligned with the installed @wrapflow/cli package; when a command spelling changes, the check and the guide change together.

1) Sign in with a scoped token

Work under an ordinary read + run + draft token — either from wf login or minted in Settings → API tokens — exported to the environment:

export WRAPFLOW_URL=https://<host>
export WRAPFLOW_TOKEN=wf_...
node ./node_modules/@wrapflow/cli/wf.mjs app status

wf app status is the discovery call: it lists the account's Apps and proves the credentials work. To drive Wrapflow over MCP instead, register node ./node_modules/@wrapflow/cli/wf.mjs app integration mcp. The default profile uses ship_app, describe, apply, upload_app_ui, test, look, request_release and status; follow the default MCP loop.

The lower-level MCP equivalents of the CLI examples below (create_app, apply, inspect_app with section: "contract", generate_app_client, …) require the advanced profile. For stdio, register that command with WRAPFLOW_MCP_PROFILE=advanced in its environment. For remote MCP, register https://wrapflow.com/mcp/advanced. Reconnect and read tools/list before calling them; /mcp does not list them.

Install exact reviewed versions and invoke the project-local package directly — never npx wf:

npm install --save-exact --ignore-scripts 'wrapflow-app@<reviewed-version>'
npm install --save-dev --save-exact --ignore-scripts '@wrapflow/cli@<reviewed-version>'

For cold agents requesting owner-entered credentials before npm registry updates, connect via remote MCP (request_secret, then status {secretRequestId}).

2) Create the App backend

The Flow path spends no AI credits. Create the App container, copy its Flow id from inspect into BEHAVIOR_ID below, and edit a source file:

APP_ID=$(node ./node_modules/@wrapflow/cli/wf.mjs app create "Team tasks" --frontend external)
node ./node_modules/@wrapflow/cli/wf.mjs app operations inspect "$APP_ID"
BEHAVIOR_ID='<flow-id-from-inspect>'
node ./node_modules/@wrapflow/cli/wf.mjs flow export "$BEHAVIOR_ID" --out app.flow
# Edit app.flow with the table, commands, views and scenarios.
node ./node_modules/@wrapflow/cli/wf.mjs flow check app.flow
node ./node_modules/@wrapflow/cli/wf.mjs flow apply "$BEHAVIOR_ID" app.flow --revision <token-from-export>

Export supplies the revision that apply requires. Reconcile a stale-revision refusal with the current Flow so another editor's change is preserved.

Run the draft and release the behavior so the Contract reflects it:

RUN_ID=$(node ./node_modules/@wrapflow/cli/wf.mjs app operations run "$BEHAVIOR_ID" --target draft)
node ./node_modules/@wrapflow/cli/wf.mjs advanced release "$BEHAVIOR_ID" --from-run "$RUN_ID"

3) Bind the typed frontend

node ./node_modules/@wrapflow/cli/wf.mjs app operations inspect "$APP_ID"
node ./node_modules/@wrapflow/cli/wf.mjs app integration contract "$APP_ID"
node ./node_modules/@wrapflow/cli/wf.mjs app integration client "$APP_ID" --file src/wrapflow.generated.ts

Commit the generated file. It exposes only the resources and operations in the App Contract; call them by generated name, never by internal ids.

import { AppClient } from './wrapflow.generated'

async function main() {
  const app = await AppClient.connect({ baseUrl: 'https://<app-slug>.wrapflow.app' })
  await app.add_task.execute(
    { title: 'First task' },
    { idempotencyKey: crypto.randomUUID() },
  )
  const page = await app.tasks.query({ limit: 50 })
  // page.items[0]._wf_record_id / ._wf_version address the durable record.
}
void main()

Pass only the visitor's App-user JWT through getToken when the Contract declares identity. A Wrapflow account API token must never appear in frontend source, logs, or committed examples.

4) Release requirements

A read + run + draft token stops at the draft on purpose. wf app publish drives readiness and fixture review, then empirical browser proof, then the exact approved authority document — and release-authority reads and the release itself require an admin token plus a present operator who has reviewed the complete exposure block. When that 403 arrives, the supported next step is to stop with the App as a draft and hand the release to the human; it is not a cue to escalate scope.

5) One durable action, then reload

Prove the integration with a real persisted write, not a green build:

  1. Execute a guarded command with an explicit idempotencyKey.
  2. Query the entity back and find the new record.
  3. Reload the frontend; the same query returns the record again — the write is durable, not a session artifact.

6) Diagnosing an integration error

Branch on WrapflowAppError.code (or the code field in the HTTP error body). The message states the supported next step; details and requestId are the bounded, redacted diagnostic to keep — never a stack of internals and never a credential.

CodeMeaningSupported next step
validation_error (422)Input does not match the declared Contract — a missing required field or wrong shape.Read the generated adapter or wf app integration contract; fix the named field and retry with a new idempotency key.
version_conflict (409)The record changed since it was read; expectedVersion is stale.Re-query, reconcile against the current _wf_version, and retry once with the user's intent preserved.
version_required (428)A patch/delete omitted expectedVersion.Supply the _wf_version from the query response.
command_precondition (409)A guard rejected the write for the record's current state.Refresh the record and choose a command allowed for its state; do not retry blindly.
contract_mismatch (client-side)The generated client's pinned compatibility hash no longer matches the released Contract.wf app operations inspect + wf app integration client --file to regenerate; rebuild before directing users back.
not_found (404) / forbidden (403)The App or record is outside this account or token scope.Check which account/token is in use; another account's Apps and records are unreachable by design.
idempotency_conflict (409)The idempotency key was reused with different input.Retry the original request with the identical key, or use a new key for different input.

For a stale frontendRevision on a hosted-lane save, re-read wf app operations inspect and retry the save with the current revision — a 409 is a lost-update guard, not corruption.

The supported diagnostic loop needs only the scoped token: re-run wf app operations inspect (lane, revision, contract identity) and wf app integration contract (current resources, operations, compatibility hash), and keep the failing call's code, details, and requestId. If the answer is not there, report those fields; do not reach for administrator tooling.

Isolation and credential rules

  • A second account cannot read the first account's Apps or records; private data stays behind the account boundary.
  • Tokens never appear in generated clients, frontend source, logs, or this guide's examples — keep WRAPFLOW_TOKEN in the environment.
  • assertContract(compatibilityHash) after connect makes a stale generated client fail visibly instead of silently drifting.