> ## Documentation Index
> Fetch the complete documentation index at: https://docs.mobster.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Scripts and the API

> Run tasks from shell scripts with mobster run, or drive Mobster from your own code through the local HTTP API.

`mobster run` runs one task per call, for shell scripts and CI. The HTTP API that `mobster serve` starts is for programs that run longer: they answer approvals and stream events. Both save each task in a private journal before it acts.

## Run a task from a script

```sh theme={"theme":"css-variables"}
mobster run "Open Settings and check that About shows the iOS version." --execute
mobster run "Open Settings and check that About shows the iOS version." --execute --json
```

`--execute` runs the task on your Claude or OpenAI key. On a terminal it prints one line per step. Piped, written to a file, or with `--json`, it prints each event as one JSON line, and the last line is always the `result`.

Mobster asks in the terminal before it sends, buys, posts or deletes, before it opens an app you haven't allowed, and before it types a one-time code. The app card takes `y` (Allow, for this task), `a` (Always allow) or `n` (Not now). With no terminal to ask in, such as a script or CI, the answer is no. Apps you allowed in Mobster for Mac count. For a script, list apps in `MOBSTER_APPS_ALLOWED`, or set `MOBSTER_APP_ACCESS=all` ([Configuration](https://docs.mobster.dev/configuration.md)).

Each task is saved in the journal before it acts, so `mobster history` lists it, and a run killed mid-task shows as `interrupted` the next time `mobster run` or the terminal UI starts ([History and resume](https://docs.mobster.dev/tui.md#history-and-resume)). One `mobster run` or terminal UI has the journal open at a time. Another `mobster run` prints a `result` with `error_type` `LeaseHeld` and exits 3 without reaching the phone. To run tasks on several phones at once, give each run its own journal with `--state-db PATH`.

### Read the JSON events

Every line is one JSON object with an `event` field. The ones most scripts need:

| event | when | useful fields |
| - | - | - |
| `observation` | the screen was read, once per step | `step`, `bundle_id`, `keyboard`, `elements` (id, label, role, rect, value; each label and value cut to 200 characters) |
| `decision` | Mobster chose an action | `step`, `operation` (`TAP`, `TYPE`, `SWIPE_UP`, `DONE`…), `target`, `target_label`, `confidence`, `goal_probability`, `latency_ms` |
| `action_check` | the action was checked against the request | `support`: `allowed`, `unclear` or `mismatch` |
| `action_started`, then `action_acknowledged` or `action_not_dispatched` | the action is about to be sent, then the phone accepted it or it was never sent | `operation`, `act_ms` |
| `observation_after_action` | the screen after the action | `changed`, `settle_ms` |
| `permission_decision` | the permission mode asked before an action | `decision` (`ask`), `kind`, `act` (`send`, `code`…), `mode`. No label and no text |
| `result` | the run ended (always last) | `status`, `reason`, `data`, `data_status`, `actions`, `elapsed_ms`, `citations`, and `blocks` when the answer has result blocks (Results) |

Keep event output private: an `observation` lists each field's `value`, so text Mobster typed into a field appears there.

A run that may not use an app ends with `status` `blocked`, and `reason` says why. An error before or around the run prints a `result` too: `{"event": "result", "status": "error", "ok": false, "error_type": "...", "error": "...", "exit_code": N}`. `ctrl+c` or SIGTERM ends the run at its next safe point with `status` `stopped`, and `mobster run` exits 130 (143 for SIGTERM).

### Check how a task ended

```sh theme={"theme":"css-variables"}
mobster run "Open Settings and check that About shows the iOS version." --execute --json \
  | jq -c 'select(.event == "result") | {status, data, reason}'
```

| `status` | meaning | exit code |
| - | - | - |
| `completed` | Mobster finished the goal, and the result is backed by what it saw on the screen | 0 |
| `completed_unverified` | Mobster judged the goal met. Nothing checked it independently | 0 |
| `completion_not_confirmed`, `inconsistent_completion` | it looked done but couldn't be confirmed; `data_status` says why an answer is missing | 1 |
| `blocked`, `no_progress`, `needs_clarification` | it couldn't go on | 1 |
| `approval_denied`, `approval_timeout` | the answer to an approval was no, or nobody answered in 10 minutes | 1 |
| `max_steps`, `timeout`, `spend_cap` | it hit a limit | 1 |
| `stopped`, `error` | stopped, or failed; the reason says whether an action may have run | 1 (130 with `ctrl+c`, 143 with SIGTERM; 3 when no phone answered or another Mobster has the journal open) |

`data` quotes text Mobster saw on the screen. When there is none, `data` is `null` and `data_status` is `insufficient_evidence`.

## Get an alert when a scheduled task fails

Set `MOBSTER_ALERT_WEBHOOK_URL` to an https webhook, in Settings in Mobster for Mac or in the env file. Mobster posts there when a scheduled task fails, stops before it finishes, or waits a minute or more for your approval. Slack, Discord and ntfy addresses get their own format. Any other address gets JSON:

```json theme={"theme":"css-variables"}
{"workflow": "Morning summary", "status": "max_steps", "reason": "It ran out of steps.", "runId": "3f2a9c1b7d4e", "at": "2026-10-05T07:01:12+00:00", "text": "Mobster: “Morning summary” didn't finish (max_steps). It ran out of steps. Open the Mobster app to see it."}
```

A connector's service that signs you out (next release) posts once, with `status` `connection_signed_out`, the connector's name in `workflow` and a `null` `runId`. It posts only for a sign-in or token that worked until the service refused it, once per sign-in ([Connectors](https://docs.mobster.dev/connectors.md)).

The post never holds the task's answer, a screenshot or anything it typed. `mobster alerts test` sends a test post.

## Use the phone outside a task

`mobster phone clipboard set TEXT` puts text on the phone's clipboard for a task to paste, `mobster phone clipboard get` prints the phone's clipboard, `mobster phone install PATH` installs a signed build, `mobster phone password --app BUNDLE --field NAME` types a password you enter at a hidden prompt into a focused secure field (Type a password privately), and `mobster phone record --output FILE` saves a USB iPhone's screen to a new `.mov`. Each except `record` takes the device's lock while it works and prints JSON with `--json` ([CLI reference](https://docs.mobster.dev/reference/cli/phone.md)).

## Call the HTTP API

`mobster serve` starts an HTTP server on `127.0.0.1:8765`, the same server Mobster for Mac runs. Each launch makes a random API token and writes it to a private file, named in the first line the server prints. Send it as `Authorization: Bearer <token>` on every request.

```sh theme={"theme":"css-variables"}
mobster serve --wda-url http://127.0.0.1:8100 --enable-live --env-file "$MOBSTER_ENV_FILE" > /tmp/mobster-serve.log &
TOKEN=$(cat "$(head -1 /tmp/mobster-serve.log | jq -r .tokenFile)")
curl -s -H "Authorization: Bearer $TOKEN" http://127.0.0.1:8765/api/status | jq '{device_ready, live_enabled, limitations}'
```

### Start and follow tasks

| Request | What it does |
| - | - |
| `POST /api/runs` | start a task: `{"appId": "settings", "goal": "Open Settings and check that About shows the iOS version."}`. Optional: `device` (an id, UDID or name; one task per device, and tasks on different devices run at once), `phones` (one task on each, as one group: [Several phones](https://docs.mobster.dev/devices.md#one-task-on-several-phones)), `outputFormat`, `outputSchema`, `allowedBundles`, `permissionMode` (`ask_all`, `ask_important` or `dont_ask`; asking less than Settings needs Mobster for Mac), `pinnedApps` (1 to 5 app ids: the task starts in the first), `account` (a profile), `connectors` (up to 8), `sendTo` (a destination: [Send results to other tools](https://docs.mobster.dev/webhooks.md)) and `queue` (default `true`: a held phone queues the task; `false` answers 409 `run_active`: [Sharing a phone](https://docs.mobster.dev/devices.md#sharing-a-phone)). An `Idempotency-Key` header makes retries safe. `"dryRun": true` starts nothing and answers `{"dryRun": {apps, asks, cost, ...}}` ([Dry run](https://docs.mobster.dev/safety.md#dry-run)) |
| `GET /api/runs`, `GET /api/runs/{id}` | the task list (`?device={id}` for one device's history), and one task with its events and any pending `approval` |
| `GET /api/runs/{id}/events` | the task's events as server-sent events, from the start; `Last-Event-ID` resumes |
| `POST /api/runs/{id}/approval` | answer an approval: `{"id": "<approval id>", "approve": true}` ([Answer plans and drafts](#plans-and-drafts-to-review)) |
| `POST /api/runs/{id}/stop` | stop at the next safe point |
| `GET /api/inbox` | what needs you now, most urgent first, as **Needs you** lists it: `items`, each with `kind` (`approval`, `question`, `review`, `repair`, `draft` or `reconnect`), `runId`, `goal`, `app` and `at`. A draft is answered with `POST /api/runs/{runId}/blocks/{blockId}/items/{itemId}` |
| `GET /api/groups`, `GET /api/groups/{id}` | tasks on several phones, with each phone's state and, once all are done, the merged summary |
| `POST /api/groups/{id}/stop`, `POST /api/groups/{id}/approvals` | stop every phone; answer the approvals you showed, `{"approve": true, "approvals": {"<run id>": "<approval id>"}}` |
| `GET /api/events?topics=runs` | events across tasks as server-sent events (`run_created`, `run_finished`, `run_reviewed`, `run_block_decided`, `run_deleted`). Name several topics with commas (`topics=runs,workflows`). Each event has an id `<boot>-<seq>`; `Last-Event-ID` resumes, and after a restart the stream starts with `{"event": "reset"}`: fetch your lists again. `400 invalid_topics` answers a topic that isn't 3 to 16 lowercase letters, optionally with `:` and a 12-character id |

### Read and change settings

| Request | What it does |
| - | - |
| `GET /api/status` | version, whether the phone is ready, `app_session` (whether Mobster for Mac holds approvals), configured models, what limits live tasks, and `engine` ([Check that the phone is ready](#engine-health)) |
| `GET /api/apps` | the apps a task can run in (the catalog plus the installed apps of the USB iPhone, or of the simulator `mobster serve --device` named), and `inventory`: `{state, at}`, where `state` is `live`, `cached`, `none` or `unknown` |
| `GET`, `POST /api/settings` | `askBeforeActing`, `taskCostLimitUsd` (0.05 to 100; `null` turns the per-task stop off), `monthlyLimitUsd` (1 to 10,000; `null` for none) and `phoneBatteryPause` (1 to 50 percent; `null` turns it off). With Mobster for Mac running, changing `askBeforeActing` or either limit needs it (`403 app_only`) |
| `GET`, `POST /api/permissions` | Settings › Safety: `permissionMode`, `appAccess`, each app's standing, `approvedApps` and `exceptions`. Changing them needs Mobster for Mac |
| `GET /api/approvals`, `POST /api/approvals/{id}` | the approvals agents outside Mobster raised (an MCP client's tap, a first use of an app, a one-time code), and answering one (Mobster for Mac only). `?wait=` long-polls up to 20 seconds |
| `GET /api/usage` | tokens and spend by provider and model, `monthUsd`, and each plan's limits |
| `GET /api/devices`, `GET /api/devices/{id}`, `GET /api/devices/{id}/status` | every device with its state, its task, its pending approval, who holds it and its queue, and one device's battery, heat and the Mac's power ([Several phones](https://docs.mobster.dev/devices.md)) |
| `GET`, `POST /api/accounts` | your profiles, and adding one (Profiles) |
| `GET`, `POST /api/workflows`, `POST /api/workflows/{id}/run` | saved workflows, and running one with `rows` (Workflows) |
| `GET /api/connectors`, `GET /api/outlets`, `GET /api/plugins` | your connectors with their tools and `health`, your destinations, and your plugins. Changing any of them needs Mobster for Mac |
| `GET /api/packs`, `GET /api/harness/hints` | each app pack's health, and what Mobster knows about an app ahead of time (When an app changes) |

These routes belong to the pages that explain them: sharing a result and saving it as a file (Results), Home's summary (See your workflows on Home), adding the Mobster MCP server to an agent ([Add it from Mobster for Mac](https://docs.mobster.dev/mcp-server.md#add-it-from-the-mac-app)), the composer's phones ([The composer's phone](https://docs.mobster.dev/devices.md#the-composers-phone)), managing a phone ([Manage a device](https://docs.mobster.dev/phones.md#manage-a-device)), teaching a task (Teach Mobster a task), a team's Mac ([A team's Mac](https://docs.mobster.dev/account.md#a-teams-mac)) and passkey approvals ([Answer with your passkey](https://docs.mobster.dev/safety.md#answer-with-your-passkey)).

### Hold a conversation

These routes are behind Conversations: Mobster for Mac uses them. JSON uses camelCase and milliseconds since the epoch.

| Route | Body or query | Answer |
| - | - | - |
| `GET /api/threads` | `?limit` (1–100, default 50), `before` (the previous page's `next`), `device`, `q`, `archived` (`true`, `false` or `all`) | `{threads, next}`, newest first |
| `POST /api/threads` | `{title?, device?, message?}`, optional `Idempotency-Key` | 201 `{thread, item?, run?}` |
| `GET /api/threads/{id}` | `?after=<seq>` | `{thread, items, runs}`: the items in order and the runs they name |
| `POST /api/threads/{id}` | `{title?, archived?, pinned?}` | `{thread}` |
| `DELETE /api/threads/{id}` | `?runs=delete` (default) or `keep` | `{deleted, runsDeleted}`; 409 `run_active` while its task runs |
| `POST /api/threads/{id}/messages` | a message, optional `Idempotency-Key` | 201 `{item, run}` (a new task), 201 with `routed: "remember"` (a message that only asks Mobster to remember something), 202 `{item, routed: "steer" or "answer"}`, or 409 |

A message is `{text, attachmentIds?, appId?, engine?, outputFormat?, outputSchema?, device?, mode?, via?}`:

* `text`: 1–4,000 characters to start a task, at most 2,000 to steer, at most 500 to answer a question.
* `mode`: `auto` (Steer a task while it runs) or `new_task`.
* `device`: the phone; the conversation's phone when left out.
* It also takes `phones`, `pinnedApps`, `permissionMode`, `account`, `sendTo`, `queue` and `longform`, as `POST /api/runs` does.

A retry with the same `Idempotency-Key` returns the first answer with `"replayed": true`. The same key with another body is 409 `idempotency_conflict`. When Mobster can't tell whether the first request started a task, the retry is 409 `request_outcome_unknown` and nothing is sent again: check the conversation before you start another. An error with `"started": false` means nothing was recorded or sent, so a new request is safe. Without that field, a 5xx may have started a task.

| Code | Status | When |
| - | - | - |
| `thread_not_found` | 404 | No such conversation in this Mobster |
| `approval_pending` | 409 | The task waits for an approval |
| `steer_unsupported` | 409 | Codex, Claude Code or Gemini CLI is working. The run's `steerable` is `false` |
| `steer_attachments` | 409 | Files go with a new task, not to a running one |
| `steer_not_allowed` | 403 | The task was started over MCP or Mobster Remote and the message comes from elsewhere, or the reverse |
| `group_running` | 409 | The conversation's phones are still working on its last task |
| `thread_full` | 409 | 2,000 items or 8 MB: "This conversation is full. Start a new one." |
| `thread_archived` | 409 | Restore it to continue |
| `thread_expired` | 410 | The conversation was deleted |
| `unavailable` | 503 | Conversations couldn't open their data |

Every item has `id`, `seq`, `at` and `kind`:

| Kind | Fields |
| - | - |
| `user` | `text`, `via` (`composer`, `voice`, `cli`, `tui`, `mcp`, `remote`), `attachments`, `routed` (`new_run`, `steer`, `answer`, `unread`, `remember`), `runId` |
| `run` | `runId`, `goal`, `appName`, `engine`, `device`, and once it ends `result`: `{status, outcome, answer, facts, costUsd, elapsedMs}` |
| `clarify` | `runId`, `approvalId`, `question`, `choices`, and once answered `answer` and `resolution` |
| `remote_origin` | `app`: `{id, name, known}`, first in a conversation an app started through Mobster Remote |

A thread is `{id, title, createdAt, updatedAt, device, deviceName, archived, pinned, status, lastRunId, rules}`. `status` is `idle`, `running` or `waiting` (for you). `GET /api/events?topics=threads,thread:<id>` streams `thread_created`, `thread_updated` and `thread_deleted` with `{thread}`, and for one conversation `thread_item`, `thread_item_updated` and `run_event`.

### Check that the phone is ready

`GET /api/engine` answers with one state. Mobster for Mac, `mobster serve` and `mobster mcp`'s `status` read the same one, and `mobster doctor` says it in the same words.

```sh theme={"theme":"css-variables"}
curl -s -H "Authorization: Bearer $TOKEN" http://127.0.0.1:8765/api/engine | jq '{state, cause, message, next_step}'
```

```json theme={"theme":"css-variables"}
{
  "state": "waiting_for_phone",
  "cause": "locked",
  "message": "Work iPhone is locked.",
  "next_step": "Unlock Work iPhone: the task goes on as soon as it's unlocked.",
  "fix": { "kind": "yours" }
}
```

| `state` | `cause` |
| - | - |
| `ready` | none |
| `waiting_for_phone` | `locked`, `unplugged`, `wifi_lost`, `needs_you`, `helper_restarting`, `developer_mode_off`, `trust_needed`, `ui_automation_off`, `not_responding` |
| `helper_down` | `not_built`, `signature_expired`, `failing`, `stopped`, `exposed`, `not_answering` |
| `no_phone` | `none_chosen`, `none_attached` |
| `model_unavailable` | `no_key`, `no_credit`, `key_rejected` |
| `live_off` | `disabled` |
| `stopping` | `closing` |

`fix` says what to do. Its `kind` is `auto` (Mobster does it: `start_helper` or `rebuild_helper`), `ask` (Mobster does it after you say yes: `free_port` or `restart_service`), `guided` (`mobster login` or `mobster setup`), `yours` (you, on the iPhone or with the cable), `run` (a `command` for you to run) or `wait` (it clears by itself). `mobster doctor --fix` runs the `auto` and `ask` fixes ([Device setup](https://docs.mobster.dev/device-setup.md#fix-what-doctor-finds)).

When several stand, `state` is the one that blocks most, and `issues` lists all of them, each with its `source` and `since`. A simulator in the device list that is shut down is off, not an issue, unless the server drives it as its own address (`--wda-url`): `GET /api/devices` lists it as shut down. If an action was on its way when the phone went away, `action_unknown` is `true`: Mobster looks at the screen before it goes on and doesn't send that action again. `GET /api/events?topics=engine` sends an `engine_health` event each time the state changes. To tell a frozen server from a slow one, ask `GET /api/engine` every 2 seconds and read `liveness`.

### Answer plans and drafts

A task may show a plan before it starts, or put several drafts up for review together. Both are approvals: the task waits, Stop ends it, and nobody answering in 10 minutes ends the wait.

| `approval.kind` | What it carries | How to answer |
| - | - | - |
| `plan` | `plan`: `summary`, `apps` (`name`, `bundleId`, `does`), `steps`, `policy`; a long task's plan also has `long` and `choices` | `approve: true` starts it, with `choice` for another budget and `"allowCost": true` for the raise its plan proposed; `false` skips it; `false` with `instruction` says what to change |
| `proposals` | `items`: `id`, `app`, `act`, `to`, `title`, `text` (the draft), `context` (what it answers), `decision` | `{"approve": true, "items": ["<draft id>"]}` sends that draft, with `"text"` to send it edited; `false` skips it; no `items` decides every draft still open |

A decision on a draft is final. Drafts nobody decided are skipped, and Stop skips them all. Sending needs Mobster for Mac; skipping doesn't. Draft text is never in the task's events or its saved history.

## Keep the API on this Mac

The server listens on `127.0.0.1` and takes requests only from local origins. It has one user, you, and no rate limits. Don't expose it on a network. At most 8 event streams stay open at once; another gets `429 stream_limit`. Every `GET` answer carries an `ETag`: send it back in `If-None-Match` and the answer is `304` while nothing changed.

When Mobster for Mac runs the server, these work only from the app, and anything else that has the token gets `403 app_only`: approving an action, changing `askBeforeActing` or Settings › Safety, answering an outside agent's approval, starting a task that asks less than Settings, putting a file on the phone and resetting the Wi-Fi link. Declining, stopping and reading stay open to the token. Starting a task there also needs this Mac signed in to your account, or the answer is `403 plan_required` ([What needs a sign-in](https://docs.mobster.dev/account.md#what-needs-a-sign-in)). A server you start with `mobster serve` takes the token alone.

A task's optional `X-Mobster-Origin` header (`app`, `tui`, `cli`, `mcp`, `remote` or `console`) labels where it came from and grants no access. A `remote` task, from Mobster Remote, always asks before acting. A task with `projectEnv` resolves `${NAME}` from that project's secrets, and only Mobster for Mac's own session may send it (`403 app_only` otherwise).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.