The content API
The query layer over JSON and as an MCP server, behind tokens with capabilities of their own.
The API is at /api/mainstay, under MAINSTAY_API_PREFIX, and answers JSON. It calls the same operations your templates do, so a filter, a refusal and a payload are the same whichever way you reach them.
Reading without a token
Without a token, a read sees only the types marked #[PublicRead], never an internal field, follows relations one level deep and writes nothing:
#[PublicRead]
#[Route('/blog/{slug}')]
class Article extends Entry { /* ... */ }
Tokens
An account makes its own under API tokens in the account menu, ticking the capabilities the token holds; the server makes one with a command:
php artisan mainstay:token [email protected] "CI build" --capability=edit_articles
A token holds the capabilities ticked for it, never one its account does not hold, and at use no more than the account holds then: one with none ticked reads, and * holds everything the account does. A program sends it as Authorization: Bearer mst_.... The secret is shown once, and only its hash is kept.
Reads
A list takes where, as JSON in the query layer's own shape, sort, page, perPage (at most 100), locale and depth (1 by default, at most 3):
GET /api/mainstay/entries/article?where={"publishedOn":{">":"2026-01-01"}}&sort=-publishedOn,title
Writes
POST /entries/{type},PATCHandDELETE /entries/{type}/{id}write live; a delete goes to the trash.PUT /globals/{type}writes a global.POST /drafts,POST /drafts/{id}/publishandDELETE /drafts/{id}work on drafts.
A write sends {"data": {...}, "locale": "en"}, a relation or an image by its id. A refusal is a 401 without a token, a 403 with one, and a 422 naming each field that did not take its value.
Payloads
A payload is the entry's id, type, locale, uri, createdAt and updatedAt, then its fields. Moments are RFC 3339 in UTC. An image is its alt text, focal point and a URL per size; a relation is the entry it points at as far as depth reaches, and its id beyond. For a TypeScript front end:
php artisan mainstay:typescript
writes /schema out as declarations, to resources/types/mainstay.d.ts unless you name a path.
MCP
The same operations are an MCP server at /api/mainstay/mcp, for a client speaking Streamable HTTP: find-entries, get-entry, save-draft, publish-draft and the rest, behind the same token. Give an agent a token that edits and does not publish, and it writes drafts for a person to put live.