# 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.
