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 withhatamoto admin-url. This page writes it as<admin>.
Make a limited key
- 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.comis a placeholder), with only the scopes, the limits on what a key may do, it needs:read:entitiesreads content and history,write:entitiesalso edits, publishes, unpublishes and restores:hatamoto apikey create --name "docs agent" --scopes read:entities,write:entities --as editor@example.com --out ./agent.key - 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
- Review is off by default. With it off, a key that has Write entities publishes and edits live content with no human step.
- 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 answers202, MCP returnsstatus: pending_reviewwith achangeset_id, and nothing is stored until a reviewer approves it. - 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.
- A key never approves a change, not even its own. New pages and posts made by a key are drafts.
Preview, apply and undo
- Read the entry first. Its
versioncounts attribute changes: theETagheader over REST,entity.versionfromentities_getover MCP. - Preview first:
?dry_run=1over REST,dry_run: trueinentities_update. Nothing is stored. The answer listschanges(path,before,after), theversion, anyerrors, andpending_review: trueif the real change would be held. - Apply the change with that
version(REST:If-Match). If the entry changed meanwhile, the write is refused (412over REST,conflict: stale versionover MCP). attributesreplace the stored ones by default. To change only some keys, usemerge: true(MCP) or PATCH withContent-Type: application/merge-patch+json(REST).nullremoves a key.- To undo, restore an earlier version: it is stored as a new version, so history is kept. Use
entities_versions,entities_version_getandentities_restoreover MCP, orPOST /api/v1/entities/{id}/restore/{version}over REST. Restoring published content is held.
See what it did
- 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). - 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>/reviewnames 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.