Skip to content
Documentation menu

Let an AI or a script edit your site safely

In this guide you let an AI assistant or a script change your content without losing control. You choose what its key may do, which changes wait for a person, and how to preview, apply and undo a change.

Before you start

  • An owner account and a running site. Your assistant talks to it over MCP, the Model Context Protocol, a standard way for AI tools to read and change a site (a script can use REST). Connect an AI agent shows how to hand over the key.
  • A shell on the server with the service's settings loaded, so DATABASE_URL (where its database is) is set.
  • An Editor account for the key to act as. See Users and API keys.

Steps

Your admin address is private to your install, for example /k7qm-x2rf-9tdc. Print it on the server with hatamoto admin-url. This page writes it as <admin>.

Make a limited key

  1. An API key is a secret string a program uses to act on your site. It acts as the account it is made for, so it never does more than that account's current role, what it may do, and stops working if the account is removed. Make it on the server for your Editor account (editor@example.com is a placeholder), with only the scopes, the limits on what a key may do, it needs: read:entities reads content and history, write:entities also edits, publishes, unpublishes and restores:
    hatamoto apikey create --name "docs agent" --scopes read:entities,write:entities --as editor@example.com --out ./agent.key
  2. Do not use a key made in the admin: it belongs to you, the owner, and skips Review. Revoke it, or never give it Write entities. MCP server lists the tools and scopes.

Hold its changes for review

  1. Review is off by default. With it off, a key that has Write entities publishes and edits live content with no human step.
  2. Switch Review on at <admin>/settings/review. A key follows its creator's role: Owner and Reviewer keys publish directly even with Review on, while Editor, Author and Contributor keys wait: a change to published content, publishing a draft and scheduling are held. REST answers 202, MCP returns status: pending_review with a changeset_id, and nothing is stored until a reviewer approves it.
  3. Review does not hold everything. Taking a page offline (unpublish) is never held: a key with Write entities does it at once. A new person entry created as public goes live at once.
  4. A key never approves a change, not even its own. New pages and posts made by a key are drafts.

Preview, apply and undo

  1. Read the entry first. Its version counts attribute changes: the ETag header over REST, entity.version from entities_get over MCP.
  2. Preview first: ?dry_run=1 over REST, dry_run: true in entities_update. Nothing is stored. The answer lists changes (path, before, after), the version, any errors, and pending_review: true if the real change would be held.
  3. Apply the change with that version (REST: If-Match). If the entry changed meanwhile, the write is refused (412 over REST, conflict: stale version over MCP).
  4. attributes replace the stored ones by default. To change only some keys, use merge: true (MCP) or PATCH with Content-Type: application/merge-patch+json (REST). null removes a key.
  5. To undo, restore an earlier version: it is stored as a new version, so history is kept. Use entities_versions, entities_version_get and entities_restore over MCP, or POST /api/v1/entities/{id}/restore/{version} over REST. Restoring published content is held.

See what it did

  1. Owners read the Audit log at <admin>/audit. A REST change shows as Source API. An MCP write adds two rows under the key's name: the tool call (Source Agent, refused calls too) and the change (Source API).
  2. Version history tags direct changes [api-key:<name>] (REST) or [mcp:<name>] (MCP). Changes approved in review and REST restores are untagged, and publish and unpublish write no version. For a held change, <admin>/review names the account that asked while it waits, and the Audit log keeps the submission under the key's name.

Example: cancel a live event

This assumes Review on and the Editor key from step 1, so the change is held. Blocks are MCP tool input; <id> is the event's id, and its type has a notice field. Call entities_get, which returns the entry with version 7:

{"id": "<id>"}

Preview with entities_update:

{"id": "<id>", "attributes": {"notice": "Cancelled"}, "merge": true, "version": 7, "dry_run": true}
{"dry_run": true, "version": 7, "changes": [{"path": "notice", "before": null, "after": "Cancelled"}], "errors": [], "pending_review": true}

Send the same call without dry_run. It returns status: pending_review; the event stays at version 7 until you approve it in <admin>/review, then moves to 8. To undo, call entities_restore, held again until approved:

{"id": "<id>", "version": 7, "expected_version": 8}

Over REST, with <your-key> its secret:

curl -X PATCH -H "X-API-Key: <your-key>" -H "Content-Type: application/merge-patch+json" -H 'If-Match: "7"' -d '{"attributes": {"notice": "Cancelled"}}' "https://example.com/api/v1/entities/<id>?dry_run=1"

Check it worked

The Audit log shows the change under the key's name, and a held change waits in <admin>/review until you approve it.

If you see conflict: stale version, read, preview and retry. If something went live that you wanted held, check that Review is on, that the key is not an Owner or Reviewer key, and that it was not a new public person entry.

Next steps