Skip to content

Authoring interactive pages via MCP tools

Audience: anyone building a MeroFoundry app through the merofoundry MCP tools (create_page, update_page, define_model, upsert_record, …).

What this answers: “Does the platform cover simple client-side state (click a button, a hidden div appears) and does it cover AJAX so my app behaves like a SPA?”

Both, yes. The postback you may have seen — e.g. a flash-card Reveal answer button that reloads the whole page instead of just showing the answer — is an authoring choice, not a platform limit. This doc shows the patterns that avoid it.


A published MeroFoundry app is server-rendered and then hydrated by SvelteKit.

  • The backend does not emit HTML or JavaScript for your page. render_page produces a static JSON tree of blocks (layout, style, custom_css, params) — no scripts, no event handlers.
  • The published route is server-rendered and then hydrated by SvelteKit; the client fetches that JSON tree for client-side navigation. All interactivity — toggles, form submits, data fetches — happens client-side, in the browser, with no full-page reload for same-application navigation.
  • A block’s behaviour fields (on_click, show_when, form source, data bindings) are opaque data to the backend. The client interprets them.

Consequence: interactivity is a property of the blocks you author, not something you turn on. Pick the right block and it just works client-side. Author a button as a link to another page and you get client-side navigation.

create_page(..., layout=<dict>) and update_page(..., data={"layout": <dict>}) take a free-form dict — it is passthrough (dict[str, Any]) and not schema-validated, so a typo in a block field fails silently at render rather than erroring on save. The renderer is the source of truth; to check a shape you’re unsure of, read back a page built in the UI:

get_page(application_id, page_id) # returns the raw layout block tree

The root layout is an object with a blocks array, and every block nests its children under blocks too (never children). A minimal layout:

{ "blocks": [
{ "id": "h", "type": "heading", "content": { "text": "Hello" } }
] }

Every block is:

{
"id": "unique-string",
"type": "heading | text | button | form | collapsible | composite_scope | record-list | ...",
"content": { /* block-specific: label, text, title, items, ... */ },
"source": { /* data/form config: model_id, target_mode, filter, ... */ },
"display": { /* variant, show_when, type, ... */ },
"blocks": [ /* child blocks */ ],
"binding": { /* repeat_over, field, ... */ },
"on_click":[ /* click directives — see §2 */ ]
}

Two runtime keys are real but undeclared in the type (don’t be surprised they’re not in a schema): top-level on_click and content.local_init.


2. Client-side state: hide/show without a reload

Section titled “2. Client-side state: hide/show without a reload”

There are two levels. Use the simplest one that fits.

2a. Native interactive blocks (simplest — use these when they fit)

Section titled “2a. Native interactive blocks (simplest — use these when they fit)”

collapsible, accordion, and tabs show/hide their own content entirely client-side, zero network. A flash-card Reveal answer is a one-block collapsible:

{
"id": "card-1",
"type": "collapsible",
"content": {
"title": "What is the capital of France?",
"content": "Paris"
}
}

Clicking the title reveals content.content — no reload, no server call. If you want a richer body than a string, put child blocks under blocks (they render inside the expanded region; the trigger is always content.title):

{
"id": "card-1",
"type": "collapsible",
"content": { "title": "What is the capital of France?" },
"blocks": [
{ "id": "ans", "type": "heading", "content": { "text": "Paris" } },
{ "id": "img", "type": "image", "content": { "src": "https://…/paris.jpg" } }
]
}
  • accordion — content.items = [{ "title", "content" }], display.type = "single" | "multiple".
  • tabs — content.items = [{ "label", "content" }], display.defaultTab = "tab-1" (values are tab-<n> by position).

For a plain flash card, stop here — collapsible is the whole answer.

A composite is a reusable block tree stored once per application and instantiated by any page with a composite block. Change the composite and every page that references it follows, so a site header, footer or call-to-action band is authored once, not once per page.

Tools, each a thin call to the public /applications/{application_id}/composites resource and gated on the same pages:* permissions that author pages (there is no separate composites permission family):

Tool OAuth scope Backend permission
list_composites pages:read pages:read
create_composite pages:write pages:create
update_composite pages:write pages:update
delete_composite pages:write pages:delete

Every call is checked by the public-API gate: the OAuth grant must be bound to the application_id you pass (otherwise api_key_scope_mismatch), its user must still be active, the backend permission must be inside both the grant’s consented ceiling and the user’s current roles, the public_api capability must be enabled, and the Public API rate limit applies. update_composite and delete_composite also answer not-found for a composite that belongs to another application. create_composite and delete_composite require an idempotency_key; delete_composite is a permanent delete. The public render path expands composites server-side, so published pages need nothing extra.

A definition is {"parameters": [...], "body": <block>}. Parameters are optional; a body may reference them as {{ param.name }} and a page instance supplies values in content.parameter_bindings.

{
"name": "Site header",
"category": "layout",
"definition": {
"parameters": [],
"body": {
"id": "site-header", "type": "container",
"style": { "class": "mx-auto w-full site-header" },
"blocks": [
{ "id": "nav", "type": "text",
"content": { "text": "<a href=\"/\">Brand</a><a href=\"/pricing\">Pricing</a>" } }
]
}
}
}

Instantiate it as the first block of each page:

{ "id": "hdr", "type": "composite",
"content": { "composite_id": "<id from create_composite>", "parameter_bindings": {} } }

Convention: a body whose top-level style.class contains site-header or site-footer is rendered inside a semantic <header> / <footer> element.

2b. General local state: composite_scope + set_field + show_when

Section titled “2b. General local state: composite_scope + set_field + show_when”

Use this when the native blocks don’t fit — one button revealing several scattered blocks, toggling state that other blocks read, swapping a label, etc. Three pieces:

  1. A composite_scope block holds a reactive state object. Its initial values live in content.local_init. State is exposed to descendants under the name local.
  2. A button with on_click writes state. The only directive is set_field; a name starting with local. writes into the scope. No network call.
  3. Any block gated by display.show_when with an expr: against local.

Flash card with a custom layout and an explicit Reveal button:

{
"id": "scope-1",
"type": "composite_scope",
"content": { "local_init": { "revealed": false } },
"blocks": [
{ "id": "q", "type": "heading", "content": { "text": "Capital of France?" } },
{ "id": "reveal", "type": "button",
"content": { "label": "Reveal answer" },
"display": { "show_when": "expr:!local.revealed" },
"on_click": [ { "set_field": { "name": "local.revealed", "value": true } } ] },
{ "id": "a", "type": "heading",
"content": { "text": "Paris" },
"display": { "show_when": "expr:local.revealed" } }
]
}

Clicking Reveal answer flips local.revealed to true in the browser; the answer’s show_when un-hides it and the button’s own show_when:"expr:!local.revealed" hides the button. All client-side, no reload.

show_when grammar (display.show_when):

Value Meaning
omitted / "always" always shown
"authenticated" / "unauthenticated" gated on login state
"expr:local.revealed" shown when the path is truthy
"expr:!local.revealed" shown when the path is falsy
"expr:local.a == local.b" shown when the two paths are equal
"expr:local.a != local.b" shown when they differ
"expr:item.status == \"approved\"" compare with a quoted literal
"expr:item.rank < 3" compare numeric values or numeric strings
"expr:count(query.rows) > 0" show when an array has items
"expr:(local.a && local.b)" group expressions explicitly

Terms combine with && (shown when both terms hold) and || (shown when either term holds):

expr:(local.a || local.b) && local.c
expr:local.a && local.b
expr:local.a || local.b
expr:local.a || local.b && local.c

Each side of && and || is one of the expr: forms in the table. && binds tighter than ||, so the last line means local.a || (local.b && local.c). Parentheses can override this grouping. == and != compare primitive values as strings, so a projected true or 3 equals the URL value "true" or "3"; an absent or null operand only equals another absent or null operand. Either operand may be a whole {{time.<path>}} token. Quoted strings, numbers, true, false and null are literals. Ordering supports <, <=, > and >=: numeric operands compare numerically, other strings lexically; absent values do not order. count(path) returns an array length or zero for a non-array value. Other function calls are refused.

Bare words remain paths: expr:item.status == approved looks up approved. Use expr:item.status == "approved" for a literal comparison. Falsy values are "", null, undefined, false, 0, and the exact strings "false" and "0".

set_field targets: local.<key> writes scope state; any other name writes into an enclosing form’s field buffer; with no form present, a non-local. write is silently dropped. set_field is the only click directive that exists today.

When to use a composite definition instead: for local state, author the composite_scope block directly in the page layout as above. Reach for a reusable, parameterised composite definition (created with create_composite and instantiated with a composite block; see “Shared components: composites”) only when you want a named component shared across pages.


3. AJAX / SPA behaviour: data without a reload

Section titled “3. AJAX / SPA behaviour: data without a reload”

3a. Forms submit via fetch, not POST-and-redirect

Section titled “3a. Forms submit via fetch, not POST-and-redirect”

A form block submits with fetch and updates the page in place. Config lives under source:

source field Meaning
target_mode "create" (default), "edit" (PATCH), "delete", "login", "logout"
model_id target model (create/edit)
record_id target record (edit/delete)
defaults object of initial field values
on_success_toast toast text on success
on_success_set_field [{ "name", "value" }] — writes state after success (local.* or form fields)
on_success_redirect optional href; only navigates if set (shallow for ?/#)
form_id embed a model-bound public form created with create_form instead of binding the model directly; see the identity note below

Which identity a submission carries. A form bound directly to a model (source.model_id, target_mode: create) submits through the consumer create route. On that route the record’s created_by and the rule actor are the application owner, even when an app user is signed in. A form embedded by form_id whose form has settings.access: authenticated submits through forms/{form_id}/submit, where the validated app user is submitted_by and becomes the rule actor. Any rule that stamps ownership from actor.id (a creator grant, for example) must be fed by the embedded form until the direct route is fixed (tracked on the engineering board).

Login forms (target_mode: "login") need model_id set to a login-submission model, not the identity model: see docs/auth-identity.md, “Login form contract”.

Fields are collected from input blocks via binding.field. On success the new record is pushed into the client record cache, the toast shows, on_success_set_field runs, and the page does not reload unless on_success_redirect is set:

For a create or edit, the runtime derives the submission identity from the route: with a valid public app session it uses the app-user record id on the consumer route (/public/apps/{application_id}/...) as both the record creator/changer and the post-save rule actor.id. Without a session, a model that explicitly permits anonymous create uses the generic model route and carries the anonymous (unknown) actor instead; it never substitutes the application owner. The older embedded-form submit route follows the same rule: its submitted_by is the validated app-user record when a session is present and anonymous when one is not.

{
"id": "add-card",
"type": "form",
"source": {
"target_mode": "create",
"model_id": "<flashcards model_id>",
"on_success_toast": "Card added",
"on_success_set_field": [ { "name": "local.revealed", "value": "false" } ]
},
"blocks": [
{ "id": "in-q", "type": "input", "content": { "label": "Question" },
"binding": { "field": "question", "save_mode": "submit" } },
{ "id": "in-a", "type": "input", "content": { "label": "Answer" },
"binding": { "field": "answer", "save_mode": "submit" } },
{ "id": "go", "type": "button", "content": { "label": "Add" },
"display": { "type": "submit" } }
]
}

record-list, data-table, stat, and chart fetch their own data client-side and re-render reactively when records change (a form create/edit/delete updates them without navigation). Query config lives under source:

{ "id": "cards", "type": "record-list",
"source": { "model_id": "<flashcards model_id>", "page_size": 25, "sort": "created_at", "order": "desc" },
"content": { "title": "All cards", "columns": "question,answer" } }
  • stat / chart: source: { model_id, aggregation: "count"|"sum"|"avg", field_name, filters }.
  • Repeat any block over data with binding.repeat_over (a data source), item_var defaults to item:
{ "id": "card", "type": "collapsible",
"binding": { "repeat_over": { "source": "model", "model_id": "<flashcards model_id>" }, "item_var": "item" },
"content": { "title": "{{ item.question }}", "content": "{{ item.answer }}" } }

That renders one client-side collapsible per record — an entire flash-card deck, reveal-on-click, with no page reloads anywhere.

Without live, these blocks update without refreshing only for changes made in the same tab: a form create, edit or delete on the page re-renders them. Changes made by another viewer, another browser tab, or an agent (an MCP tool, an API key, an automation) appear only after a reload.

Add "live": true to a block’s model source, or to a "source": "model" binding.repeat_over, and the published page will update without refreshing when anyone changes that model: other viewers, other tabs and agents. Each change re-reads the block’s own query, keeping its filters, sort, page size and aggregation.

{ "id": "tasks", "type": "record-list",
"source": { "model_id": "<tasks model_id>", "page_size": 25, "sort": "created_at", "order": "desc", "live": true },
"content": { "title": "Tasks", "columns": "title,status" } }
{ "id": "open-tasks", "type": "stat",
"content": { "label": "Open tasks" },
"source": { "model_id": "<tasks model_id>", "aggregation": "count", "filters": { "status": "open" }, "live": true } }
{ "id": "task", "type": "collapsible",
"binding": { "repeat_over": { "source": "model", "model_id": "<tasks model_id>", "filter": { "status": "open" }, "live": true },
"item_var": "task" },
"content": { "title": "{{ task.title }}", "content": "{{ task.notes }}" } }
  • live is opt-in and must be a JSON boolean ("true" or 1 is rejected on save). Absent or false opens no connection.
  • It applies to record-list, data-table, stat, chart and dnd-list with a model_id source, and to a model binding.repeat_over. Saved-query, literal and page-parameter sources ignore it.
  • Every live block on a page that reads one model shares a single connection.
  • Only published pages subscribe; the editor canvas and the admin preview never do.
  • If the connection drops or is refused, the blocks keep their last data, show no error and reconnect with backoff.
  • Anonymous-read rule: live updates follow the read access the page already has and never widen it. An anonymous visitor receives them only for a model whose anonymous READ access covers the whole model, and an anonymous subscription carries no field filters; a signed-in viewer of the application receives them for the rows they may read. A viewer who cannot read the model gets no updates. No record data travels over the connection: every update is a re-read through the normal governed endpoint.

A published record-list labels its columns with the model’s field labels, falling back to the field name when a field has no label.

item_var names the current repeat row’s template namespace, on both the client and the hosted server-side resolver. It defaults to item; when an outer repeat sets a custom name, use that exact name in a nested model-source filter. A nested repeat establishes its own item_var for its descendants (or item when omitted). A dnd-list also accepts display.item_var for existing layouts, while binding.item_var takes precedence when both are present.

{ "id": "grants", "type": "container",
"binding": {
"repeat_over": { "source": "model", "model_id": "<grants model_id>" },
"item_var": "grant"
},
"blocks": [
{ "id": "awards", "type": "container",
"binding": {
"repeat_over": {
"source": "model", "model_id": "<awards model_id>",
"filter": { "grant": "{{ grant.id }}" }
},
"item_var": "award"
},
"content": { "title": "{{ award.title }}" }
}
]
}

Here the nested awards source resolves {{ grant.id }} from the enclosing row; inside each award’s children, {{ award.<field> }} names the inner row.

Server-resolved names in source.filters. The published-page renderer substitutes two namespaces inside a model-source filter: {{current_user.id}} (the app-user record id from the validated public session; empty when anonymous) and, inside a nested repeat, {{<item_var>.<field>}} for the enclosing row. Everything else in a filter is a literal. A current_user.id filter is presentation filtering, not authorization (see the record-level access recipe).

Parameterized saved-query bindings. A saved query whose AST references runtime inputs (a ":status" placeholder in a where/having rule value, or a structured JOIN reference {"parameter": "team_id"}) is bound with one params mapping on the binding definition. The same key is used on a block source (record_list, data-table, stat, chart) and on a container’s binding.repeat_over:

{ "id": "open-tasks", "type": "record_list",
"source": { "source": "saved_query", "saved_query_id": "<id>",
"params": { "status": "{{query.status}}", "team_id": "{{params.record_id}}" } } }
  • Values. Each value is a string, number or boolean. A value that is exactly one {{<namespace>.<path>}} token keeps the referenced value; a token inside other text is substituted as text ("s-{{query.tab}}"); anything else is a literal ("closed", 5, true). Each binding resolves its own values, so two bindings of one saved query on the same page return independently filtered rows.
  • Namespaces. params.* is the page’s route parameters (for example params.record_id on a <page>/<record-id> path) and query.* is the URL query string. They are never merged: a route parameter does not stand in for a missing URL query value or the other way round. Inside a repeat, {{<item_var>.<field>}} reads the enclosing row.
  • Unresolved values. If any referenced value is missing, the binding is unresolved: it is not executed, and it is not treated as an empty result.
  • Required inputs are derived, not declared. Every parameter the saved query’s AST references (where/having placeholders, including nested groups, and JOIN {"parameter": ...} references) must be a key in params. There is no separate required/optional parameter list. Page create and update reject a layout whose saved-query bindings, at any nesting depth (including a container’s empty branch), miss a required input, with a 422 naming the block and the parameter.
  • Server-bound identity. current_user_id (and the temporal now / timezone) are bound by the server and are never required. current_user_id comes only from the validated consumer session; a binding that supplies current_user_id is rejected on create and update, and refused at render.
  • Saved-query edits. Updating a saved query’s AST is rejected (422, naming the page) when a page that already binds the query would no longer supply every required input. A compatible change is accepted.
  • Stored definitions. A binding stored before this validation, or written around it, that misses a required input fails explicitly: the server render leaves the binding unresolved and logs page_render.saved_query_binding.failed, and browser execution gets 400 Missing query parameter. It never runs unbound and never reads as an empty result.
  • Authorization is unchanged. Values only fill parameters. The saved query must still be public and belong to the page’s application, and identity-scoped rows still depend on the validated session.

Empty result for a query-bound container. A container whose binding.repeat_over is a saved query may add binding.empty, a list of blocks rendered once, in place of the repeated container, after the query succeeds with zero rows. Use the empty block for the message:

{ "id": "task-rows", "type": "container",
"binding": {
"repeat_over": { "source": "saved_query", "saved_query_id": "<id>",
"params": { "status": "{{query.status}}" } },
"item_var": "task",
"empty": [ { "id": "no-tasks", "type": "empty",
"content": { "title": "No matching tasks", "description": "Try another status" } } ] },
"blocks": [ { "id": "row", "type": "text", "content": { "text": "{{task.name}}" } } ] }

The empty branch is not shown while the query is loading, after a failed execution, or while the binding’s params are unresolved. A result with one or more rows renders the rows only.

A button/link whose content.href starts with ? (query) or # (hash) is intercepted and routed shallowly (goto(..., { invalidateAll: false })) — no blank-flash reload. An href that changes the path within the same application is routed client-side; use ? or # for in-page state so the current page data is not reloaded.


If a reveal button caused a full postback, it was authored as a path-navigating link — content.href pointing at a path/URL — which the browser follows as a real navigation, re-running the loader and repainting the page. It was not using any no-reload path:

  • no on_click: [{ set_field: … }] (client state write), and
  • no surrounding composite_scope + show_when: "expr:local.*" gate, and
  • it wasn’t a collapsible / accordion / tabs.

Fix: rebuild it as §2a (a collapsible) or §2b (composite_scope + set_field + show_when).


5. End-to-end: build a flash-card app with MCP tools

Section titled “5. End-to-end: build a flash-card app with MCP tools”
# 1. App
create_application(name="Flash Cards", slug="flash-cards")
-> application_id = APP
# 2. Model + fields + publish (records need a PUBLISHED model).
# One-call shortcut: create_form_simple(application_id=APP, name="Card",
# fields=[{name:"question",type:"text"},{name:"answer",type:"text"}])
# …or explicitly:
define_model(application_id=APP, name="flashcard", label="Card", plural_label="Cards")
-> model_id = M
add_field(application_id=APP, model_id=M, name="question", label="Question", type="text")
add_field(application_id=APP, model_id=M, name="answer", label="Answer", type="text")
publish_model(application_id=APP, model_id=M) # required before records work
# 3. Seed a couple of records
upsert_record(application_id=APP, model_id=M,
data={"question":"Capital of France?","answer":"Paris"}, idempotency_key="seed-1")
upsert_record(application_id=APP, model_id=M,
data={"question":"2+2?","answer":"4"}, idempotency_key="seed-2")
# 4. Home page: a deck that reveals each answer client-side (§3b repeat + §2a collapsible)
create_page(application_id=APP, name="Home", slug="home", is_home=True, layout={
"blocks": [
{ "id":"title", "type":"heading", "content":{"text":"Study deck"} },
{ "id":"deck", "type":"collapsible",
"binding": { "repeat_over": { "source":"model", "model_id":"M" }, "item_var":"item" },
"content": { "title":"{{ item.question }}", "content":"{{ item.answer }}" } }
]
})
-> page_id = P
# 5. Publish the page (status transition; pass layout so the tree is preserved)
update_page(application_id=APP, page_id=P, data={"status":"published", "layout": <same layout>})
# 6. Verify what the renderer will emit (composites expanded, bindings resolved)
render_page(application_id=APP, page_id=P)

Replace "M" with the real model_id string. Records queried via MCP use query_records (note: its filter operators are contains / prefix only — there is no equals).

5a. Visual verification of the published site

Section titled “5a. Visual verification of the published site”

After the create/populate, style/publish, and public-URL steps, capture home, capture the whole published site, inspect screenshots and diagnostics, repair, and recapture. The tools observe the anonymous published surface; they do not publish or modify pages.

a successful authoring API response is not visual evidence

screenshots do not replace keyboard, accessibility, form-submission, or navigation tests

When available from the hosted MCP registry, make these calls with real placeholder values:

capture_page_screenshot(application_id=APP)
capture_page_screenshot(application_id=APP, page_id=P)
capture_page_screenshot(application_id=APP, path="/study")
capture_page_screenshot(application_id=APP, viewport="desktop", full_page=True)
capture_page_screenshot(application_id=APP, viewport="mobile", full_page=True)
capture_site_screenshots(application_id=APP)
capture_site_screenshots(application_id=APP, viewport="desktop", max_pages=3)
capture_site_screenshots(application_id=APP, viewport="mobile", max_pages=3)

Review each site-manifest entry’s CaptureDisposition: success means its expected artifact references were produced, failed means that page needs repair or a retry, and omitted means a server-owned whole-job bound deliberately skipped it. A result containing more than one of those values is partial; successful pages remain useful evidence. The signed full-resolution artifact link is opaque, private, and short-lived. It expires, so recapture when a fresh artifact is needed; it is not a durable URL.

Map rendering symptoms to DiagnosticCounts before editing: blank output and absent styling → console_errors and page_errors; missing or unloaded images → unloaded_images; console errors → console_errors; blocked requests → blocked_requests; and failed application or asset requests → failed_requests. Repair the referenced page definition, data, or permitted resource, then repeat the relevant capture. Do not bypass a blocked request.


Start from a layout recipe rather than composing a page from primitives. Fetch the relevant recipe at /llmrecipes/<slug>.txt, then adapt its canonical tree and tenant-specific values: layout-site-shell, layout-hero, layout-feature-grid, layout-contact-form, and layout-record-catalog.

I want… Author this
Click to reveal one hidden answer collapsible (§2a)
One expandable section among several accordion (§2a)
Switch between panes tabs (§2a)
A button that reveals/toggles arbitrary blocks composite_scope + button on_click set_field + show_when (§2b)
Submit data, stay on page form block, no on_success_redirect (§3a)
A list/table/metric that updates after this tab’s form submits record-list / data-table / stat / chart (§3b)
One card per record any block + binding.repeat_over (§3b)
Update without refreshing when other viewers or agents change data "live": true on the model source or binding.repeat_over (§3b)
Navigate without a reload href starting with ? or # (§3c)

Can’t do with MCP tools (2026-09-06): set page settings (requires_auth). It is available on the public REST API with an application-scoped key; see docs/mcp-tools.md, “MCP versus REST”. update_model accepts model metadata, settings, and anonymous policy; use get_model or get_application_schema to inspect draft fields before publishing.

Rules and saved queries are now authorable via MCP: create_rule, list_rules, update_rule, delete_rule, create_saved_query, list_saved_queries, update_saved_query, delete_saved_query, and execute_saved_query.

Composites are authorable via MCP: list_composites (pages:read), and create_composite, update_composite, delete_composite (OAuth scope pages:write; backend pages:create / pages:update / pages:delete).

Small MCP facts that cost people time: add_field has a unique switch plus optional default value and position; fields added concurrently get positions in commit order, add them serially or set positions explicitly; an application-bound OAuth grant answers list_applications with 401 while every application-scoped call succeeds, so start from whoami’s applicationId; anonymous curl of a nested published route without Accept: text/html can return a false 404 while the page renders fine in a browser.

Sibling doc: the same patterns via the public REST API with an api-key — docs/authoring-interactive-pages-api-key.md.