# Agents and scripts

An agent writes a page by calling a tool. Legato's MCP server runs on your Mac, started by the agent's own app, and its tools write, read and delete pages, arrange the sidebar, install a service's pages from a template, and add to History and lists. Claude Code, Codex, Claude Desktop and any other client that starts a local command can use it. A chat app in a browser can't reach it.

A script does the same work with the `legato` command, which makes the same checks and gives the same answers. Either way the result is a page file in the Pages folder, so an agent can set a page up and a script can keep it current.

Use them for data that takes a few calls, some arithmetic, a command-line tool or an agent's judgement. When the data comes from one API that answers JSON, a page with [sources](https://legatobar.com/docs/sources.md) fetches it without either.

## With an agent

- [Connect an agent](https://legatobar.com/docs/connect-agent.md): Setup for Claude Code, Codex, Claude Desktop and other MCP clients.
- [MCP tools](https://legatobar.com/docs/mcp-tools.md): Every tool, with its arguments and what it returns.
- [A prompt that works](https://legatobar.com/docs/connect-agent.md#a-prompt-that-works): An example of asking for a page, card by card.
- [A scheduled agent](https://legatobar.com/docs/scripts.md#a-scheduled-agent): Claude Code run from launchd, every morning or every hour.

## With a script

- [Scripts](https://legatobar.com/docs/scripts.md): Two worked examples, free disk space and API spend, each with its page and a schedule.
- [CLI](https://legatobar.com/docs/cli.md): Every `legato` command, with its output.


---

# Connect an agent

Legato comes with `legato`, a command-line tool inside the app at `/Applications/Legato.app/Contents/Helpers/legato`. `legato mcp` runs it as a [Model Context Protocol](https://modelcontextprotocol.io) server, so an agent can write pages through tool calls. There's nothing else to install and nothing to sign in to: the server reads and writes the page files in `~/Library/Application Support/Legato/Pages`.

The server runs on your Mac, started by the agent's app over stdio. That means the agent has to run on the same Mac: Claude Code, Codex, Claude Desktop, or any other client that starts a local command. Chat apps that only take a remote connector URL, such as claude.ai or ChatGPT in a browser, can't reach it.

## Claude Code

```bash
claude mcp add legato -- /Applications/Legato.app/Contents/Helpers/legato mcp
```

That adds Legato for the project you're in. To have it in every project, add it for your user instead:

```bash
claude mcp add --scope user legato -- /Applications/Legato.app/Contents/Helpers/legato mcp
```

Check the connection with `claude mcp list`, or `/mcp` inside a session.

To share the setup with a project, put it in the project's `.mcp.json`:

```json
{
  "mcpServers": {
    "legato": {
      "type": "stdio",
      "command": "/Applications/Legato.app/Contents/Helpers/legato",
      "args": ["mcp"]
    }
  }
}
```

There's no key to keep out of the file.

## Codex

```bash
codex mcp add legato -- /Applications/Legato.app/Contents/Helpers/legato mcp
```

`codex mcp list` shows it. Start a new session to pick it up.

## Claude Desktop

[Download the Legato extension](https://legatobar.com/legato.mcpb) and open it. Claude Desktop asks before installing it; click **Install**, then start a new chat.

The extension has no server of its own. It starts `legato mcp` from Legato.app, so it always matches the Legato you have, and it won't start until Legato is installed. It shows in **Settings → Extensions**, where you can turn it off or remove it.

To add Legato by hand instead, open **Settings → Developer → Edit Config**. That opens `~/Library/Application Support/Claude/claude_desktop_config.json`. Add Legato under `mcpServers`:

```json
{
  "mcpServers": {
    "legato": {
      "command": "/Applications/Legato.app/Contents/Helpers/legato",
      "args": ["mcp"]
    }
  }
}
```

If the file already has other servers, add the `legato` entry beside them. Quit and reopen Claude Desktop, and start a new chat; Legato's tools are listed among its tools.

## Other MCP clients

Any client that runs a local MCP server over stdio can connect. Most take a JSON config like Claude Desktop's; fill in its settings like this:

| Setting | Value |
| --- | --- |
| Name | `legato` |
| Type or transport | stdio (sometimes called "command" or "local") |
| Command | `/Applications/Legato.app/Contents/Helpers/legato` |
| Arguments | `mcp` |
| Environment, URL, headers | None |

The server speaks JSON-RPC, one message per line, and accepts protocol versions `2024-11-05` through `2025-11-25`; a client asking for another version gets the newest. It offers tools only (no resources or prompts), and answers requests one at a time, in order. When Settings → Agent Access changes after the client listed the tools, it sends `notifications/tools/list_changed` before its next answer.

When it connects, the client should list Legato's twenty-three tools: five for pages (`set_page`, `get_page`, `list_pages`, `delete_page` and `get_page_schema`), six for the sidebar, four for [History](https://legatobar.com/docs/history-rows.md#rows-from-outside-legato), three for [Lists](https://legatobar.com/docs/mcp-tools.md#lists-and-history), three for [secrets](https://legatobar.com/docs/mcp-tools.md#secrets) and two for [templates](https://legatobar.com/docs/mcp-tools.md#templates), fewer if some are off in Settings → Agent Access.

Anything that can run the command can read and write every page, as you. There are no keys and no per-page permissions. Settings → [Agent Access](https://legatobar.com/docs/settings.md#agent-access) chooses which tools the MCP server offers, such as leaving out `delete_page`; the `legato` command and the Pages folder stay open to anything on the Mac.

## After you update Legato

An agent keeps the tools Legato gave it when it connected, so a session that was open before an update doesn't know about new card types or fields. Start a new session after you update. In Claude Code, `/mcp` can reconnect `legato` in the session you're in; Claude Desktop needs quitting and reopening.

## A prompt that works

Once the agent is connected, ask it in plain words. Something like this, in Claude Code, Codex or Claude Desktop:

> Keep a Legato page called "budget" current. Work out this month's spending so far, my monthly target ($3,200), the fraction of the month that has passed, and the largest charges this week. Then call `set_page` with page_id "budget": title "Budget", icon "dollarsign.circle", a `pacing` card for the month, a `list` of the largest charges ("Costco · $212"), and a one-sentence `text` note, tone "warning" if anything is over pace. Always send the whole page. If you get an error, fix what its message names and try again.

Add Legato's [page design skill](https://legatobar.com/docs/design.md#the-page-design-skill), and the agent checks each page against the design guide before it writes one.

For data that changes on its own, such as a service's API or your calendar, the agent can give the page [sources](https://legatobar.com/docs/sources.md) instead: Legato then fetches the data on a schedule, and the page stays current without the agent. For the rest, [A scheduled agent](https://legatobar.com/docs/scripts.md#a-scheduled-agent) shows how to run the agent on a schedule.


---

# MCP tools

## Tools

| Tool | Arguments | Returns |
| --- | --- | --- |
| `set_page` | `page_id`, `title`, `cards`, optional `icon`, `title_from`, `sources`, `period`, `params`, `notify`, `sidebar` and `if_match` | `{id, version, changed, created, loaded}` with the page's `collection` and `placement`, sometimes with a `note` |
| `get_page` | `page_id` | `{id, version, modified, page, status}` |
| `list_pages` | none | `{folder, pages: [{id, name, title, version, modified, ok, error}]}` |
| `delete_page` | `page_id`, optional `if_match` | `{id, deleted, note}` |
| `preview_page` | `sample`, and `page_id` or `page`, optional `source` | `{source, sources, mapped, issues, valid, hidden, failed}`: the cards as a sample answer fills them. See [Checking a page's sources](https://legatobar.com/docs/mcp-tools.md#checking-a-pages-sources). |
| `get_page_schema` | optional `part`: `page`, `sources`, `rules`, `actions`, `period`, `params`, `notify`, `title_from` or a card type | Without `part`, `{parts, cards, note}`: the parts there are and every card type's fields. With one, `{part, schema}`: that part's JSON Schema, and for a card type `at_a_glance`, its fields one line each. The mapping rules and buttons that every card and source shares are the `rules` and `actions` parts. Another part names what it uses from them in `schema.elsewhere`, so an agent asks for each one once. |
| `get_sidebar` | none | `{sidebar}`: the collections, their sections and where each page sits. See [Arranging the sidebar](https://legatobar.com/docs/mcp-tools.md#arranging-the-sidebar). |
| `set_collection` | optional `collection_id`, `name`, `icon`, `position`, `new_pages` | `{collection_id, created, sidebar}` |
| `delete_collection` | `collection_id` | `{deleted, moved_to, moved, sidebar}` |
| `set_section` | optional `section_id`, `name`, `icon` (or `null`), `collapsed`, `collection_id`, `position` | `{section_id, created, sidebar}` |
| `delete_section` | `section_id` | `{deleted, moved, sidebar}` |
| `move_page` | `page_id`, and any of `collection_id`, `section_id` (or `null`), `position` | `{page_id, collection_id, section_id, sidebar}` |
| `add_rows` | `dataset`, `rows`, optional `request_id` | `{dataset, accepted, rejected, expired, pruned, epoch, request_id}`. See [History](https://legatobar.com/docs/history-rows.md#rows-from-outside-legato). |
| `list_rows` | `dataset`, optional `limit` up to 500 | The newest rows of the current history |
| `delete_rows` | `dataset` and one of `keys`, `epoch` or `all` | `{dataset, deleted}` |
| `get_history` | none | `{histories, readings, totals}`: what Settings → History says, without rows. See [Lists and History](https://legatobar.com/docs/mcp-tools.md#lists-and-history). |
| `get_lists` | none | `{lists: [{name, entries, used_by, sent_to, reads_addresses, status}]}` |
| `set_list` | `name`, `entries` | `{list, created}` |
| `delete_list` | `name` | `{deleted, list}` |
| `get_secrets` | none | `{onepassword_account, secrets: [{name, host, status, expires, used_by}]}`. See [Secrets](https://legatobar.com/docs/mcp-tools.md#secrets). |
| `set_secret_expiry` | `name`, `expires`, optional `host` | `{secret}` |
| `delete_secret` | `name`, optional `host` | `{deleted, secret}` |

Settings → [Agent Access](https://legatobar.com/docs/settings.md#agent-access) can turn groups of these tools off. A tool that's off isn't in the tool list, and a call to it gets a `turned_off` error.

`set_page`'s description lists every card type with its fields (the ones every sourced card shares are named once, at the top), and its input schema names the card types. Ask `get_page_schema` for a card type, `sources`, `period` or `notify` when you need the whole schema for it. It's the same schema the app ships, at `Pages/.schemas/page.schema.json` and [legatobar.com/schemas/page.schema.json](https://legatobar.com/schemas/page.schema.json).

### set_page

`set_page` creates or replaces a whole page. Send the complete page every time: a field you leave out is gone, and a card you leave out is removed. The rules for ids, titles and cards are in [Writing and versions](https://legatobar.com/docs/page-writing.md) and [Cards](https://legatobar.com/docs/cards.md).

What it does, in order:

1. Checks the page id and size, then validates the complete page with Legato's file parser before changing any file. Checks `if_match`, if supplied, while holding the write lock.
2. Writes the file whole (to a temporary file, then renamed into place), so Legato never reads half a page.
3. Opens Legato in the background if it isn't running.
4. Waits for Legato to load the page, up to 4 seconds (10 when it had to open Legato).
5. Reports whether Legato loaded those exact bytes. Invalid pages were already refused with `invalid_page` before writing. A different running build's rejection returns `load_failed` with `saved: "true"`; the tool never restores old content over another save.

A page Legato loaded:

```json
{
  "id": "budget",
  "version": "33527b6dde59dde2",
  "changed": true,
  "created": false,
  "loaded": { "ok": true, "loaded_at": "2026-10-27T21:04:11.482Z" }
}
```

`changed` is `false` when the page is exactly what was there already. `created` is `true` for a new page.

`loaded` is `null` when Legato didn't confirm in time, with a `note` saying why. The page is saved either way; Legato loads it when it opens, and `get_page` shows its status later. If it turns out to have a mistake, Legato shows it as a page that says what's wrong.

After the [trial](https://legatobar.com/docs/license.md) ends without a license, `set_page` still saves the page, and `loaded.plan` is `"locked"` with a note: Legato shows the page again once it has a license.

To post a macOS notification, include `notify` (`{id, title, body}`) with an id the page hasn't used. Sending the same id again shows nothing. See [Notifications](https://legatobar.com/docs/notifications.md#the-notify-field).

To give the page a row for choosing Week, Month or Year, include `period`, as described in [Periods](https://legatobar.com/docs/periods.md#periods). `get_page_schema("period")` has its whole schema. A link carries the period to the page it opens, so give the detail pages an overview links to the same choices, and make their cards follow them: see [Overview and detail pages with a period](https://legatobar.com/docs/design.md#overview-and-detail-pages-with-a-period).

### get_page and list_pages

`get_page` returns the page as written (without its `$schema` line) under `page`, its `name`, its `version`, when the file was last `modified`, and `status`, what Legato last said about it: `{ok, loaded_at}` plus an `error` when the page has a mistake. `status` is `null` when Legato hasn't loaded the file yet. While Legato is running, `status.sources` says what each of the page's sources last did; see [Checking a page's sources](https://legatobar.com/docs/mcp-tools.md#checking-a-pages-sources). A file that isn't JSON at all comes back as `text` instead of `page`, so you can see what's there.

`list_pages` returns every page in the folder, ordered by file name, with the same `ok` and `error` for each. `folder` is the Pages folder's path.

`name` is what the user calls the page: its `title`, or for a page with params the title as the sidebar shows it, filled from the params' defaults. Renaming a page in Legato's sidebar writes its `title`, so keep the title you read when you rewrite a page, unless asked to rename it. When someone asks for "my Upcoming page", match `name`, then use the `id`.

### Checking a page's sources

Two tools show whether a page with sources works, before and after you save it.

`preview_page` fills the page's cards from a sample answer you give it, with the same parser and mapping Legato uses, offline: nothing is fetched or saved, and no secret is read. Give `page_id` for a saved page, or `page` for one you haven't saved yet, and `sample`: the service's answer as JSON. For a source with named `requests`, `sample` is an object with each request's answer under its name; a text answer is a string. Name the `source` when the page has more than one.

```json
{
  "source": "repo",
  "sources": ["repo"],
  "mapped": [{"id": "stars", "type": "stat", "label": "Stars", "value": 100}],
  "issues": ["Forks: no response value for value; the page's original value is retained."],
  "valid": true,
  "hidden": [],
  "failed": null
}
```

`mapped` is the cards as the sample fills them. `issues` lists what doesn't fit: a path the answer doesn't have, a mapped card that isn't a whole card, a button that can't be filled from a row. `hidden` names the cards a `when` hides for this answer. `failed` is the reason when the source's `fail` turns this answer down. A card whose map `set_page` would refuse is still previewed, with the mistake in `issues` and `valid` set to `false`; fix it before you save. A page that can't be read at all gets `invalid_page`; a sample that isn't the source's answer gets `invalid_sample`; a page with several sources and no `source` gets `choose_source`, with their names. In Legato, the [Source Preview](https://legatobar.com/docs/source-preview.md#preview-before-polling) window shows the same preview with the cards drawn. `preview_page` works without the trial or a license, since it draws nothing.

After `set_page`, `get_page` reports the fetches themselves under `status.sources`, by source name:

```json
"sources": {
  "repo": {"state": "ok", "cards": ["stars", "forks"], "fetched_at": "2026-11-19T03:30:12Z",
           "error": null, "failures": 0, "next_at": "2026-11-19T04:30:12Z"}
}
```

`state` is `ok`, `error` (with the last `error` and `failures`, the fetches that failed in a row), `needs_access` (a calendar or reminders source Legato may not read yet), `not_fetched` (no answer yet, or the trial or license has ended) or `unused` (no card names it). A page you've just saved shows `not_fetched` until its first answer; ask again a few seconds later. While Legato isn't fetching at all, because the Mac is locked or asleep or the trial has ended, `status.sources_paused` says which. A page with params and no defaults fetches nothing until a link opens it: its sources show `not_fetched`, and `status.waiting_for_params` says why. `sources` is `null`, with a `sources_note` saying why, when Legato isn't running or hasn't loaded this version of the page; then `loaded_version` names the version `status` is about. `get_page` never opens Legato for this and waits at most 2 seconds for it; after a miss it doesn't ask again for 30 seconds. An error the service reported in its own answer, through the source's `fail`, is given in general words, so nothing from the answer leaves Legato.

### delete_page

`delete_page` moves the page's file to the Trash, so you can put it back from there. It answers `{"id": "budget", "deleted": true, "note": "Moved to the Trash; put it back from there to restore it."}`.

## Versions and if_match

A page's `version` is the first 16 hex characters of the SHA-256 of its file. `get_page` and `list_pages` return it, and so does `set_page` for what it wrote. Editing the file by hand, or another agent writing it, changes it.

Pass a version as `if_match` to `set_page` or `delete_page` to say "only if nobody changed it since I read it." If the page has changed, nothing is written and the answer is `version_mismatch`, with the page's `current_version` in `details` (`"none"` if the page is gone). Read it again, merge, and send the new version.

Use `if_match` when you replace a page you didn't write, or one a person might edit. An agent that owns its page can leave it out. See [Versions and if_match](https://legatobar.com/docs/page-writing.md#versions-and-if-match).

## If Legato isn't running

The tools work on the files, so they answer whether or not Legato is open.

- `set_page` opens Legato in the background and waits for it to load the page. If it can't confirm in time, the page is saved and `loaded` is `null`, with a note.
- `get_page`, `list_pages` and `delete_page` read the folder and don't open Legato. `status` is what Legato said the last time it loaded each page; `status.sources` needs Legato running.
- `preview_page` runs Legato's parser on its own, so it works whether or not Legato is open.
- `get_page_schema` reads the schema from the app. If it can't find one, it answers `schema_unavailable`: open Legato once and try again.

`legato version` says whether Legato is running and which Pages folder the tool uses.

## Errors

A failed call is a tool result with `isError: true`. Its text and its `structuredContent` both hold the error, in the same shape as [Errors](https://legatobar.com/docs/errors.md):

```json
{
  "error": {
    "code": "invalid_page",
    "message": "budget.json: /cards/0: a pacing card needs target",
    "details": { "page": "budget", "saved": "false" }
  }
}
```

The `message` names what to fix. Fix it and call `set_page` again. `"saved": "false"` means nothing was written: the page on disk is what it was before the call. A `load_failed` error has `"saved": "true"`: your page is on disk, but the Legato that's running couldn't load it.

| Code | When |
| --- | --- |
| `invalid_page` | The page isn't a JSON object, has a field a page doesn't have, has no `title` or no cards, or Legato's parser rejected it before writing (the message is Legato's). |
| `invalid_page_id` | The id isn't a file name Legato can use. New pages need 1–64 lowercase letters, digits and hyphens, starting with a letter or digit. |
| `too_large` | The page is over 1 MB, or a sidebar, lists or secrets request is over 64 KB. |
| `load_failed` | The page was saved, but the running Legato couldn't load it: the app and the tool are from different builds. Reopen Legato. |
| `validation_unavailable` | The tool couldn't run Legato's page check. Nothing was written; reinstall Legato. |
| `version_mismatch` | `if_match` didn't match. `details.current_version` is the version now. |
| `not_found` | `get_page` or `delete_page` for a page that doesn't exist, `delete_list` for a list that isn't there, or `set_secret_expiry` or `delete_secret` for a secret that isn't saved. |
| `write_failed` | The file couldn't be written in the Pages folder; the message says why. |
| `delete_failed` | The file couldn't be moved to the Trash. |
| `schema_unavailable` | The page schema isn't installed. Open Legato once. |
| `unknown_part` | `get_page_schema` was asked for a part that doesn't exist; the message lists the parts. |
| `busy` | A sidebar tool was used while a new calendar event is being written in Legato. Try again once it's saved or cancelled. |
| `limit` | `set_collection` would make a tenth collection. |
| `invalid_name`, `invalid_icon`, `invalid_position` | A sidebar tool's name isn't 1–40 characters, its icon isn't an SF Symbol on this Mac, or its position isn't a nonnegative whole number that fits in an Int. Nothing changed. |
| `missing` | A sidebar tool wasn't told which collection, section or page, or where to move a page. |
| `invalid_arguments` | A list's or secret's name isn't 1–48 lowercase letters, digits and `-` starting with a letter or digit, `entries` isn't an array of strings, or `expires` isn't a date, a number of days or `null`. Nothing changed. |
| `ambiguous_host` | `set_secret_expiry` or `delete_secret` named a secret saved for more than one host without `host`. The message lists the hosts. |
| `original` | `delete_collection` for the original collection, which can't be deleted. |
| `conflict` | `move_page` named a section in another collection than its `collection_id`. |
| `not_answered` | Legato didn't answer in time. The outcome is unknown: check `get_sidebar` before retrying, especially before creating another collection or section. After `set_list` or `delete_list`, check `get_lists`; after a secret tool, `get_secrets`. |
| `turned_off` | The tool is off in Settings → [Agent Access](https://legatobar.com/docs/settings.md#agent-access). The message names the switch, as in "Turned off in Legato Settings → Agent Access → Delete pages." Only the person at the Mac can turn it on. |
| `failed` | Anything else, with the system's message. |

Protocol errors come back as JSON-RPC errors rather than tool results: `-32700` for a line that isn't JSON, `-32600` for a message that isn't a request, `-32601` for an unknown method, and `-32602` for a `tools/call` with no tool name or an unknown tool.

## Lists and History

A [list](https://legatobar.com/docs/settings.md#lists) holds your own places, names, hosts or symbols. A page checks them with `in_list`, or [sends them](https://legatobar.com/docs/lists.md#sending-a-list) to a service with `each_entry` or `all_entries`. Put them in a list, never in the page file, so the page stays safe to share. An agent sets one with `set_list`:

```json
{"name": "delivery-area", "entries": ["Fernhollow, ST", "Kestrel Bay, ST"]}
```

Entries are trimmed and blank ones dropped. Legato saves the list as Settings → Lists does, so pages read it again at once. The answer is the list as `get_lists` shows it, and whether it's new:

```json
{"list": {"name": "delivery-area", "entries": ["Fernhollow, ST", "Kestrel Bay, ST"],
          "used_by": ["Deliveries"], "sent_to": [], "reads_addresses": false, "status": "ready"}, "created": true}
```

`status` is `ready`, `empty` (saved with no entries) or `not_set` (a page names it but it isn't saved). `sent_to` lists the hosts pages send the list's entries to, and `reads_addresses` is `true` when a page reads each entry as an address ([a host list](https://legatobar.com/docs/source-requests.md#several-hosts-from-a-list)). `get_lists` includes the lists pages name that aren't saved. `delete_list` removes a list, and can't be undone; a list that isn't there is `not_found`. If a page still checks it, the answer's `list` shows it `not_set`.

`get_history` says what Settings → History says, so an agent can find out why a history page is empty. It never returns rows:

```json
{"histories": [{"dataset": "parcel-deliveries", "page": "Parcel", "page_id": "parcel",
  "status": "Paused", "needs_attention": true,
  "reason": "Paused: the secret changed. Is this the same account's history?",
  "fix": "In Settings → History, choose Continue this history or Start new history",
  "rows": 214, "bytes": 88412, "readers": ["Delivery times"],
  "recording_since": "2026-08-02T14:00:00Z", "last_collected": "2026-11-07T22:54:00Z", "gaps": 0}],
 "readings": [{"page": "Weather", "page_id": "weather", "cards": 2, "readings": 288}],
 "totals": {"row_bytes": 88412, "disk_bytes": 225280}}
```

`status` is one of the words Settings uses: Collecting, Paused, Storage full, Updating…, Deleted in N days or Claimed by N pages. `reason` and `fix` are `null` when nothing needs you. When History can't open, the answer adds `unavailable` with why, and still lists this session's sparkline readings.

## Secrets

The secret tools show Settings → [Secrets](https://legatobar.com/docs/secrets.md) without values. An agent can see what a page still needs, keep expiry dates current and remove a secret that's no longer used. None of them reads or saves a value or a 1Password reference: the person saves those in Settings → Secrets, or an agent pipes one into [`Legato secret set`](https://legatobar.com/docs/secrets.md#from-the-command-line-or-an-agent).

`get_secrets` lists every saved secret and every one a page names that isn't saved:

```json
{"onepassword_account": "saved",
 "secrets": [{"name": "pihole", "host": "pi.hole", "status": "saved", "expires": "2027-02-09", "used_by": ["pihole"]},
             {"name": "lunch-money", "host": "api.lunchmoney.dev", "status": "from_1password", "expires": null, "used_by": ["budget"]},
             {"name": "glances", "host": "glances.example.com", "status": "needed", "expires": null, "used_by": ["glances"]}]}
```

`status` is `saved`, `from_1password` (Legato reads it from 1Password), `connected` (a [connection](https://legatobar.com/docs/source-requests.md#connections) made in Settings → Secrets) or `needed` (a page names it, and it isn't saved). `used_by` lists page ids. `onepassword_account` says whether a 1Password service account is saved.

`set_secret_expiry` changes only the date, so Legato can [warn before it passes](https://legatobar.com/docs/secrets.md#expiry-dates). `expires` is a day such as `2027-02-09`, a number of days such as `90d`, or `null` to clear it. `delete_secret` removes a saved secret, and can't be undone. Pages that use it stop until it's saved again, and the answer's `secret` shows it `needed` while a page names it. Both find the host from the name; give `host` when the name is saved for more than one.

## Arranging the sidebar

The sidebar's arrangement isn't in the pages: collections, sections and where each page sits are Legato's own settings on this Mac. The sidebar tools ask the running Legato to change them, as its menus would, and open it if it isn't running. Each answer carries the whole sidebar as it now is:

```json
{"sidebar": {
  "collections": [
    {"id": "…", "name": "Pages", "icon": "folder", "original": true, "new_pages": true,
     "pages": [{"id": "budget", "title": "Budget", "icon": "dollarsign.circle"}],
     "sections": [{"id": "…", "name": "Home", "icon": "house", "collapsed": false, "pages": [ … ]}]}
  ],
  "current_collection": "…", "max_collections": 9}}
```

`pages` are a collection's ungrouped pages in sidebar order; a section's are its own. `original` marks the collection whose pages and sections take in a deleted collection's; it can't be deleted. `new_pages` marks where new sidebar pages appear. Starter pages have `"starter": true`. Without collections, `collections` is empty and `pages` and `sections` sit beside it. Detail pages (`"sidebar": false`) aren't in the sidebar.

- **`set_collection`** without `collection_id` makes a collection; the first one also makes **Pages**, the original, holding everything there is. With it, it changes that collection's `name`, `icon` (an SF Symbol), `position` among the icons, or `new_pages`. Legato has at most nine.
- **`set_section`** without `section_id` makes a section in `collection_id`, or where new pages appear. With it, it changes the section's `name`, `icon` (`null` for none), `collapsed`, its collection, or its `position` among that collection's sections.
- **`move_page`** puts a page in a section (`null` for ungrouped), a collection or a position. A section takes the page to its collection; a collection alone puts it ungrouped there; a position alone reorders it where it is. A new place without a position is the end.
- **`delete_collection`** and **`delete_section`** remove only the collection or section. A deleted collection's sections and pages go to the original; a deleted section's pages stay in its collection, ungrouped. No page file is changed or deleted, and the user can undo a deleted collection from the collections menu.

Page names and icons belong to the page: change them with `set_page`. `list_pages`, `get_page` and `set_page` also give each page's collection and placement: `recorded`, `pending` (where Legato will put a page it hasn't loaded yet), `detail` or `ungrouped`. Don't add a collection field to page JSON.

A request made while Legato is opening waits until it has read its pages. [Errors](https://legatobar.com/docs/mcp-tools.md#errors) lists the refusals.

Sidebar tools validate all supplied arguments before changing the arrangement. Boolean fields take `true` or `false`, not strings or numbers; unexpected fields and invalid types return `invalid_arguments`. Positions count from zero in the visible destination group, including pages that have not been manually reordered. A position beyond the group’s end appends the item.

## Templates

`get_templates` lists the bundled services. Pass `service` to get its inputs,
secret names and lists. `install_template` takes `service`, `answers`, and
optional `dry_run` and `copy` booleans. Answers contain setup choices, never secret values.

Use `dry_run: true` to validate all pages and see the hosts, polling intervals,
card actions, row actions and setup steps. It makes no source requests and saves
nothing. Installation refuses with `already_installed` if any page already
exists, and names those pages. With `copy: true` it adds a numbered set beside
them instead, for a second server or account: Pi-hole 2, with page ids
`pihole-2` and so on. A copy's links point at its own pages, it keeps its own
history, and its sidebar pages and section take the number. It signs in with its
own secrets too, named with the number (`pihole-2`), so save those for it even
when it uses the same token as the first. The result then has `copy`, the
number, `page_ids`, each template page's new id, and `secret_names`, each
secret's new name.
Pages install in template order. Detail pages stay out of the sidebar. A template
that adds two or more sidebar pages puts them in a section named after its title,
reusing a section of that name in the same collection; the result then has
`section`, that name.

The result includes `preview`, `setup_steps`, `setup_commands` and `written_pages`. `setupSteps` is the same list under its older name, kept for scripts that read it.
Save each named secret for its host in Settings → Secrets, or run the returned
secret command yourself. Create the listed names in Settings → Lists using the
suggested entries. Agents do not read or send secret values.

The CLI uses JSON output too: `legato templates [service]` and
`legato install <service> --set name=value ... [--dry-run] [--copy]`.

For installs, the CLI prints the preview before saving and setup lines after
saving on stderr. The complete JSON result stays on stdout.


---

# CLI

Legato comes with a command-line tool, `legato`, inside the app. A shell script, a launchd or cron job, or you at a terminal can use it to write and read pages, arrange the sidebar, add a service's pages from a template, and add to History and lists. It takes a page as JSON from a file or stdin and answers in JSON, so a script can check what happened.

Secrets are the exception. `legato secret` passes its arguments to the app's own `secret` command, which answers in plain text. You can also run that command as `/Applications/Legato.app/Contents/MacOS/Legato secret`.

The table below lists every command. Each group has a page with its arguments, its output and an example:

- [Pages](https://legatobar.com/docs/cli-pages.md): `set`, `get`, `list`, `delete` and `schema`.
- [Sidebar](https://legatobar.com/docs/cli-sidebar.md): `sidebar` prints the arrangement, and `arrange` changes it.
- [Templates and install](https://legatobar.com/docs/cli-templates.md): `templates` and `install`, with a dry run.
- [History and rows](https://legatobar.com/docs/cli-history.md): `history` reports what's kept, and `rows` adds, lists and deletes rows.
- [Lists](https://legatobar.com/docs/cli-lists.md): `lists`, `lists set` and `lists delete`.
- [legato mcp](https://legatobar.com/docs/cli-mcp.md): The server an agent's app starts.
- [legato secret](https://legatobar.com/docs/cli-secret.md): Credentials in the Keychain, or linked from 1Password.

## The legato command

The `legato` command works from a shell or a script. It makes the same checks as the [MCP tools](https://legatobar.com/docs/mcp-tools.md) and gives the same answers:

| Command | Does |
| --- | --- |
| `legato set <id> [file]` | Writes a page from a JSON file, or from stdin. Same as `set_page`. |
| `legato get <id>` | Prints a page with its version and status. |
| `legato list` | Lists the pages. |
| `legato delete <id>` | Moves a page to the Trash. |
| `legato schema [part]` | The page format: `page`, `sources`, `rules`, `actions`, `period`, `params`, `notify`, `title_from` or a card type. |
| `legato preview [file]` | Fills a page's cards from a sample answer, offline, as [`preview_page`](https://legatobar.com/docs/mcp-tools.md#checking-a-pages-sources) does. It reads `{"page_id" or "page", "source", "sample"}` from the file or stdin. |
| `legato sidebar` | How the sidebar is arranged. Same as `get_sidebar`. |
| `legato arrange [file]` | Changes the arrangement from a JSON object in a file or stdin: `op` names the tool (`set_collection`, `delete_collection`, `set_section`, `delete_section` or `move_page`), and the rest are its arguments. |
| `legato templates [service]` | Lists the bundled templates, or shows one service's template with its inputs. Same as `get_templates`. |
| `legato install <service> --set name=value ... [--dry-run] [--copy]` | Adds a service's pages from its template. With `--dry-run` it shows what it would do and writes nothing. With `--copy` it adds a numbered set beside pages already there. Same as `install_template`. |
| `legato rows add\|list\|delete <dataset>` | Adds, lists or deletes a history's rows. Same as `add_rows`, `list_rows` and `delete_rows`; see [History](https://legatobar.com/docs/history-rows.md#legato-rows). |
| `legato history` | Every history's status and size, and every page's sparkline readings. Same as `get_history`. |
| `legato lists` | Every list, with its entries and the pages that check it. Same as `get_lists`. |
| `legato lists set <name> [--if-missing] [file\|-]` | Creates or replaces a list from a file or stdin: one entry per line, or a JSON array of strings. With `--if-missing`, a list that already exists is kept. Same as `set_list`. |
| `legato lists delete <name>` | Deletes a list. Same as `delete_list`. |
| `legato version` | The version of `legato`, the app it belongs to, whether the app is running, and the Pages folder. |
| `legato mcp` | Runs the MCP server on stdio. |
| `legato secret <command> ...` | Saves, lists or deletes a source's secret. It runs the app's own `secret` command with the same arguments, and answers in plain text; see [legato secret](https://legatobar.com/docs/cli-secret.md). |

`--if-match <version>` with `set` or `delete` acts only if the page is still at that version. `legato help` prints the usage.

See [Your first page from a shell](#your-first-page-from-a-shell) below, and [Scripts](https://legatobar.com/docs/scripts.md) for worked examples that keep pages current.


## Your first page from a shell

You don't need an agent to write a page. Save one as `budget.json`:

```json
{
  "title": "Budget",
  "icon": "dollarsign.circle",
  "cards": [
    { "id": "month", "type": "pacing", "label": "October spend",
      "value": 2140, "target": 3200, "elapsed": 0.55, "unit": "USD" },
    { "id": "top", "type": "list", "label": "Largest this week",
      "items": ["Costco · $212", "Delta Air Lines · $189"] },
    { "id": "note", "type": "text", "body": "Dining is 18% over pace.", "tone": "warning" }
  ]
}
```

and write it with `legato set`:

```bash
/Applications/Legato.app/Contents/Helpers/legato set budget budget.json
```

```json
{
  "changed" : true,
  "collection" : null,
  "created" : true,
  "id" : "budget",
  "loaded" : {
    "loaded_at" : "2026-10-27T21:04:11.482Z",
    "ok" : true
  },
  "placement" : "ungrouped",
  "version" : "33527b6dde59dde2"
}
```

`legato set budget` with no file reads the page from stdin, so a script can pipe one in. If Legato refuses the page, `legato` prints `{"error": {"code", "message"}}` and exits with status 1, and the page stays as it was. `legato get budget` prints it back, `legato list` lists your pages, and `legato --help` lists the rest. See [The legato command](https://legatobar.com/docs/cli.md#the-legato-command).

To keep the page current, run the same command whenever the numbers change, from launchd, cron or a script. Every write replaces the whole page. Writing an identical page again keeps its version, and `changed` is `false`; the page's update time moves on, so its footer shows the job is still running. [Scripts](https://legatobar.com/docs/scripts.md) has complete examples.

You can also skip `legato` and save the file yourself in `~/Library/Application Support/Legato/Pages`, as `budget.json`. Write it to a temporary file in the same folder and rename it into place, so Legato never reads half a file. Legato shows the page as soon as the file appears; if the file has a mistake, the page says what's wrong.

## Executable, output and status

The `legato` command is at `/Applications/Legato.app/Contents/Helpers/legato`. The examples in these pages write `legato` for that path. Pages live in `~/Library/Application Support/Legato/Pages`.

Answers are JSON on stdout, printed over several lines with the keys in alphabetical order. `legato help` prints plain text, and `legato mcp` speaks the MCP protocol. A command that works exits with status 0.

A refusal is `{"error": {...}}` on stdout with exit status 1. The error has a `code` and a `message`, and sometimes `details`. A command with a missing argument is refused with `invalid_arguments`. For `templates` and `install` the code is `failed`, and the message says how to call them. `legato secret` keeps the app command's output and exit status; see [legato secret](https://legatobar.com/docs/cli-secret.md#output-and-exit-status). A command that `legato` doesn't know prints an error and the usage to stderr and exits with status 2.

A command that takes a `[file]` reads stdin when the file is left out. `lists set` also reads stdin when the file is `-`. `set`, `arrange` and `rows add` look for a file named `-`.

## Example

```bash
legato version
legato help
```

`version` prints where `legato` found the app and its pages:

```json
{
  "app" : "/Applications/Legato.app",
  "bundle_id" : "com.legatobar.mac",
  "pages" : "/Users/you/Library/Application Support/Legato/Pages",
  "running" : true,
  "version" : "1.0"
}
```

`app` is `null` when `legato` can't find the app. `help` prints the usage, which begins with `Usage:`. So do `legato --help` and `legato` with no arguments.
