Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat(canvas): grid canvas MCP tools and composing-grid-canvases skill (#83547)

Peter Kirkham0c011226d8fb
diff --git a/products/canvas/mcp/tools.yaml b/products/canvas/mcp/tools.yaml
index a6dfeef2c7c8..3f52d734e98b 100644
--- a/products/canvas/mcp/tools.yaml
+++ b/products/canvas/mcp/tools.yaml
@@ -49,6 +49,16 @@ tools:
"Id of the channel to create the canvas in — the channel the task was created in, from the task's context.
Use channel-list only to resolve a channel the user named; never pick a channel from the listing
yourself (the personal #me channel is not a default)."
+ kind:
+ description:
+ "What to create: 'freeform' (a standalone app — the default), 'component' (a reusable widget for grid
+ canvases; its published project must declare a `component` placement contract), or 'grid' (a
+ composition of components, edited via canvas-layout-patch). See canvas-list (kind=component) before
+ creating a component."
+ description:
+ description:
+ Short prose describing the canvas. For components this is the store-search text — say what the widget shows
+ and what its config controls, so future searches find it.
canvas-draft-create:
operation: canvases_draft_create
enabled: true
@@ -112,6 +122,77 @@ tools:
param_overrides:
id:
description: ID of the canvas whose source to edit.
+ canvas-layout-get:
+ operation: canvases_layout_retrieve
+ enabled: true
+ scopes:
+ - canvas:read
+ annotations:
+ readOnly: true
+ destructive: false
+ idempotent: true
+ title: Read grid canvas layout
+ description: >
+ Read a grid canvas's live layout document (grid definition + placements) and its `current_version_id`.
+ Always call this before patching or publishing: pass the returned version id as
+ `expected_current_version_id` so concurrent edits are not overwritten. A grid canvas with no versions yet
+ returns the default empty layout with a null version id. Placements reference component canvases
+ (kind=component) — resolve their contracts via canvas-list.
+ exclude_params:
+ - version_id
+ param_overrides:
+ id:
+ description: ID of the grid canvas whose layout to read.
+ canvas-layout-patch:
+ operation: canvases_layout_patch_create
+ enabled: true
+ scopes:
+ - canvas:write
+ annotations:
+ readOnly: false
+ destructive: false
+ idempotent: false
+ title: Patch grid canvas layout
+ description: >
+ Apply surgical operations to a grid canvas's layout — the DEFAULT way to change one: add_placement (a new
+ widget box), update_placement (fill a box with a component, move/resize it, change its status or config),
+ remove_placement, set_grid. Operations apply in order to the current layout, the result is validated
+ atomically, and the new version is live immediately (layout is data — no build).
+ `expected_current_version_id` is REQUIRED (from canvas-layout-get; null only before the first layout
+ publish) — a stale base is rejected with 409 version_conflict; re-read the layout, re-apply, and patch
+ again. To fill a drawn box: update_placement with changes {status: "live", component: <component canvas id>,
+ config: {...}}. The component must be published (canvas-list kind=component shows component_meta and
+ published_build_id) and the config must match its configSchema.
+ param_overrides:
+ id:
+ description: ID of the grid canvas whose layout to patch.
+ canvas-layout-publish:
+ operation: canvases_layout_publish_create
+ enabled: true
+ scopes:
+ - canvas:write
+ annotations:
+ readOnly: false
+ destructive: false
+ idempotent: false
+ title: Publish grid canvas layout
+ description: >
+ Publish a COMPLETE layout document as a grid canvas's new head version. Prefer canvas-layout-patch for
+ incremental changes — full publish is for creating an initial layout or restructuring the whole grid. The
+ layout is validated first (grid bounds, overlaps, component references, per-placement config against each
+ component's configSchema); errors reject the publish and leave the canvas untouched. The new version is live
+ immediately — no build. `expected_current_version_id` is REQUIRED (from canvas-layout-get; null only before
+ the first layout publish) — a stale base is rejected with 409 version_conflict; re-read the layout, rebuild
+ the document on the new head, and publish again.
+ param_overrides:
+ id:
+ description: ID of the grid canvas whose layout to publish.
+ expected_current_version_id:
+ description:
+ The `current_version_id` this document was built on, from canvas-layout-get (null only for a grid canvas
+ that has never published a layout). A whole document replaces the head, so without the guard a
+ layout the user changed after you read it is silently discarded.
+ required: true
canvas-list:
operation: canvases_list
enabled: true
@@ -124,11 +205,19 @@ tools:
title: List canvases
description: >
List the project's canvases (newest first), optionally scoped to one channel via `channel`. Use this to
- resolve which canvas a request refers to before reading or publishing source. Each row's `url` is that
- canvas's only valid link — share it verbatim; never construct a canvas URL yourself.
+ resolve which canvas a request refers to before reading or publishing source. With `kind=component` this is
+ the COMPONENT STORE: reusable widgets grid canvases place. Before building a new widget, ALWAYS search here
+ first (`kind=component` plus `search=<what the widget shows>`) — placing an existing component with the
+ right `config` beats authoring a duplicate. A component is placeable when `component_meta` (its size
+ contract and configSchema) and `published_build_id` are both set. Each row's `url` is that canvas's only
+ valid link — share it verbatim; never construct a canvas URL yourself.
param_overrides:
channel:
description: Only return canvases in this channel (channel id).
+ kind:
+ description: Only return canvases of this kind. kind=component lists the component store.
+ search:
+ description: Case-insensitive match on name and description — use to find store components by what they show.
canvas-promote-create:
operation: canvases_promote_create
enabled: true
@@ -247,15 +336,6 @@ tools:
canvases-home-create:
operation: canvases_home_create
enabled: false
- canvases-layout-patch-create:
- operation: canvases_layout_patch_create
- enabled: false
- canvases-layout-publish-create:
- operation: canvases_layout_publish_create
- enabled: false
- canvases-layout-retrieve:
- operation: canvases_layout_retrieve
- enabled: false
canvases-partial-update:
operation: canvases_partial_update
enabled: false
diff --git a/products/canvas/skills/building-canvases/SKILL.md b/products/canvas/skills/building-canvases/SKILL.md
index 7fa736a03949..ce0e89becd77 100644
--- a/products/canvas/skills/building-canvases/SKILL.md
+++ b/products/canvas/skills/building-canvases/SKILL.md
@@ -1,12 +1,13 @@
---
name: building-canvases
description: >
- Create or edit a PostHog canvas — a sandboxed browser application (data board, document, form,
- small tool, graphics experiment) stored in PostHog and rendered by the desktop/web app. Use when
- a task asks to build, generate, update, or fix a canvas, or when a canvas id is given as the
- publish target. Covers resolving or creating the target canvas, choosing an implementation
- approach (React + Quill vs plain HTML/browser APIs), the read → edit → validate → publish →
- build loop, and which companion canvas skills to load for the details.
+ Create or edit a PostHog freeform canvas — a sandboxed browser application (data board, document,
+ form, small tool, graphics experiment) stored in PostHog and rendered by the desktop/web app. Use
+ when a task asks to build, generate, update, or fix a standalone canvas app, or when a freeform
+ canvas id is given as the publish target. For grid/home canvases, widget placements, or reusable
+ components, use composing-grid-canvases instead. Covers resolving or creating the target canvas,
+ choosing an implementation approach (React + Quill vs plain HTML/browser APIs), the read → edit →
+ validate → publish → build loop, and which companion canvas skills to load for the details.
---
# Building canvases
@@ -20,6 +21,13 @@ Canvas work can start from any ordinary task. A dedicated canvas mode or pre-cre
not required. When the user asks for a board, document, form, visualization, or small app that
should live in PostHog, treat that as a canvas request and follow this skill.
+This skill owns `freeform` canvases (standalone apps). Two other canvas kinds exist: `grid`
+canvases (widget grids, including the user's home canvas) and `component` canvases (reusable
+widgets grids place). When the target is a grid or home canvas, a placement, or a reusable
+widget/component, load `composing-grid-canvases` instead — it owns the store search → configure →
+fork → build ladder and the layout patch loop. Authoring a component's source still uses the
+implementation companions below.
+
## Resolve the target canvas
- If the task names a canvas id (canvas-initiated tasks do), that is the target. Do not create another.
diff --git a/products/canvas/skills/composing-grid-canvases/SKILL.md b/products/canvas/skills/composing-grid-canvases/SKILL.md
new file mode 100644
index 000000000000..1968ed059ef4
--- /dev/null
+++ b/products/canvas/skills/composing-grid-canvases/SKILL.md
@@ -0,0 +1,139 @@
+---
+name: composing-grid-canvases
+description: >
+ Compose PostHog grid canvases — widget grids (including the user's home canvas) built from
+ reusable component canvases. Use when a task asks to add, fill, move, resize, or remove a widget
+ on a grid or home canvas, to compose a whole canvas of widgets from one ask, to build a reusable
+ widget/component, or when a placement id or grid canvas id is the target. Covers the component
+ store search → configure → fork → build ladder, the component placement contract (size,
+ configSchema), the placement lifecycle (pending/generating/live/failed), the guarded layout
+ patch loop, and reading the canvas's comment threads.
+---
+
+# Composing grid canvases
+
+A grid canvas is a composition, not an app: a grid of placements, each rendering a **component
+canvas** (a reusable widget with its own source, build, and placement contract). The user's home
+canvas is an ordinary grid canvas in their personal channel. Layout is data — publishing or
+patching one is live immediately, with no build.
+
+Three canvas kinds share one lifecycle:
+
+- `freeform` — a standalone app (the `building-canvases` skill owns these).
+- `component` — a reusable widget. Same source/build pipeline as freeform, plus a placement
+ contract. Visibility rides its channel: personal channel = private, team channel = shared.
+- `grid` — a layout of placements referencing components. No file source; layout only.
+
+## The resolution ladder: configure, fork, build
+
+When a grid placement needs content ("a weather widget here", "a kanban of my tasks"), resolve in
+this order — placing an existing component beats authoring a duplicate:
+
+1. **Search the store**: `canvas-list` with `kind=component` and `search=<what the widget shows>`.
+ A component is placeable when both `component_meta` and `published_build_id` are set. If its
+ `configSchema` can express the request ("weather for Lisbon" → existing weather component with
+ `config: {"location": "Lisbon"}`), place and configure it — write no code.
+2. **Fork** when a component is close but its config cannot express the ask: read its source
+ (`canvas-source-retrieve`), create a new component (`canvas-create` with `kind=component`),
+ adapt, publish. Name the difference in the new component's description.
+3. **Build new** when nothing fits — see "Building a component" below.
+
+New components land in the channel you create them in. Create them in the same channel as the grid
+they serve unless the user asks to share them more widely.
+
+## Building a component
+
+A component is authored exactly like a freeform canvas — load `building-react-quill-canvases` (or
+`building-html-canvases`) plus `querying-canvas-data` and `validating-and-publishing-canvases` —
+with three additions.
+Start from the complete, buildable project in [references/component-example.md](references/component-example.md); its envelope, placement contract, capability declarations, and defensive `ph.state` access are the parts that break when improvised.
+
+- **Create with `kind=component`** and a `description` written for store search: say what the
+ widget shows and what its config controls. Future placements are found by this text.
+- **Declare the placement contract** in the project's top-level `component` key:
+
+ ```json
+ {
+ "component": {
+ "size": { "defaultW": 2, "defaultH": 1, "minW": 1, "minH": 1, "maxW": 4 },
+ "configSchema": {
+ "type": "object",
+ "properties": { "location": { "type": "string", "description": "City to show weather for" } }
+ }
+ }
+ }
+ ```
+
+ Size is in grid units (widths 1–12, heights 1–40); `minW <= defaultW <= maxW`. The range is
+ advisory: users may resize a placement to any size, so it informs defaults and warnings, never
+ rejections. The config schema
+ vocabulary is an allowlist — `type`, `title`, `description`, `default`, `properties`, `required`,
+ `additionalProperties`, `items`, `enum`, `const`, `minimum`, `maximum`, `minLength`, `maxLength`,
+ `minItems`, `maxItems`, `format`. No `$ref`, no `pattern` — validation rejects them.
+
+- **Design responsively.** Fill 100% of the box's width and height, and adapt the layout to any
+ size the user drags: a 2×1 placement is a glanceable tile; a 6×4 is a full app surface. Render
+ usefully at `minW`×`minH`, and treat `config` as the only per-placement input.
+
+Publish and wait for the build like any canvas — a component with no ready build cannot go live on
+a grid.
+
+## Composing a whole canvas
+
+A whole-canvas ask ("a home canvas that summarizes my work in progress") usually means several widgets, not one.
+Plan the full set first — one placement per concern — then resolve each with the ladder above.
+Lay them out together: no overlaps, sizes matched to what each widget shows, the grid filled deliberately rather than tiles scattered in a corner.
+Batch the layout writes (one publish for an initial layout, surgical patches after) instead of one write per widget, and finish with every placement live or failed — never generating.
+
+## Canvas comments
+
+Users leave feedback as comment threads on the canvas, anchored to its conversation task.
+List them with the task comment tools (`tasks-comments-list`, `tasks-comments-retrieve`) on your task before and after changing the canvas, and address the open ones — a comment naming a broken widget is your brief for fixing it.
+
+## Editing a grid
+
+The loop is read → patch, guarded exactly as `validating-and-publishing-canvases` describes for
+source publishes — with `canvas-layout-get` in place of `canvas-source-retrieve`, and
+`canvas-layout-patch` (surgical ops, guard required) or `canvas-layout-publish` (complete
+document, for an initial layout or full restructure) as the write. On a 409, re-read the layout,
+re-apply your change, and patch again.
+
+Operations:
+
+- `add_placement` — a new box: `{id, status, x, y, w, h, ...}`. Placements must not overlap or
+ extend past `grid.columns`.
+- `update_placement` — merge `changes` into the placement with `id`. Filling a drawn box is
+ `{"op": "update_placement", "id": "p1", "changes": {"status": "live", "component": "<component
+canvas id>", "config": {...}}}`.
+- `remove_placement`, `set_grid`.
+
+## The placement lifecycle
+
+A placement's `status` tells the renderer what to show:
+
+- `pending` — the user drew a box but hasn't described it (or the prompt awaits dispatch).
+- `generating` — an agent task is filling it; `generationTaskId` links the task and `prompt`
+ records the ask. Set this when you start working on a placement from a task.
+- `live` — renders its `component` at `version` (`"latest"` by default; a pinned version id is
+ allowed). Requires the component to be published and visible to the acting user.
+- `failed` — generation failed; keep the `prompt` so the user can retry or re-describe.
+
+When a task asks you to fill a placement, its prompt and the box's size are your brief: honor the
+drawn `w`×`h` and keep the placement's `prompt`
+intact for provenance.
+
+## Validation you will hit
+
+Layout publishes validate atomically; every error names its placement. The common ones:
+
+- `component_not_found` — the id is wrong, deleted, not a component, or not visible to the acting
+ user (a component in someone else's personal channel is not placeable).
+- `component_not_published` — the component has never published a placement contract.
+- `placement_config_invalid` — `config` does not match the component's `configSchema`.
+- `placement_size_out_of_contract` — a warning, not an error: the box's `w`/`h` is outside the
+ component's suggested range. The publish still succeeds; the component must render responsively.
+- `placements_overlap` / `invalid_placement` — geometry; fix coordinates rather than removing the
+ other widget.
+
+End your reply by linking the grid canvas with the `url` field the canvas tools return — never
+construct a canvas URL yourself.
diff --git a/products/canvas/skills/composing-grid-canvases/references/component-example.md b/products/canvas/skills/composing-grid-canvases/references/component-example.md
new file mode 100644
index 000000000000..fd8c39ced1e7
--- /dev/null
+++ b/products/canvas/skills/composing-grid-canvases/references/component-example.md
@@ -0,0 +1,144 @@
+# A known-good component
+
+This is a complete, buildable component project — the welcome checklist PostHog seeds onto new home canvases (`products/canvas/backend/welcome.py`, verified against the real canvas builder).
+The envelope below shows the fields you author; its `index.html` and `dependencies` come from `canvas-source-retrieve` and are kept exactly as returned (see [validating-and-publishing-canvases](../../validating-and-publishing-canvases/SKILL.md)) — the placeholders below stand in for them.
+Start from it when building a checklist, settings, or any state-carrying widget, and keep its structure even when you replace the content: the project envelope, the placement contract, the capability declarations, and the defensive `ph.state` access are the parts that break when improvised.
+
+## The project envelope
+
+```json
+{
+ "schemaVersion": 1,
+ "entryHtml": "index.html",
+ "files": {
+ "index.html": "<synthetic shell from canvas-source-retrieve — loads /src/canvas.tsx as a module>",
+ "src/canvas.tsx": "<the component below>"
+ },
+ "dependencies": {
+ "react": "<pinned>",
+ "react-dom": "<pinned>",
+ "@posthog/quill": "<pinned>",
+ "lucide-react": "<pinned>"
+ },
+ "capabilities": {
+ "posthog": { "insights": [], "inlineQueries": false, "captureEvents": [], "state": ["user"], "actions": [] },
+ "network": { "origins": [] }
+ },
+ "component": { "size": { "defaultW": 3, "defaultH": 5, "minW": 2, "minH": 3 } }
+}
+```
+
+- `index.html` must load `/src/canvas.tsx` as a module and every imported package must be in `dependencies` — the retrieved shell and dependency map already satisfy both. Improvising a comment-only entry fails the build with `no_entry_module`; dropping the `@posthog/quill` or `lucide-react` entries fails it with `import_not_declared`.
+- Declare the full `capabilities.posthog` shape (`insights`, `inlineQueries`, `captureEvents`, `state`, `actions`) even when a field is empty, as this example does — the build freezes the declared capabilities into the artifact manifest, which older clients read expecting every field. `insights`, `inlineQueries`, and `captureEvents` are also required by the API: a partial `posthog` object is rejected with a 400 before source validation runs. Populate only what the code calls and leave the rest empty.
+- `capabilities.posthog.state` must name every scope the code passes to `ph.state.*` — validation rejects an undeclared scope.
+- `component.size` is in grid units and advisory; the component still has to render at any size the user drags.
+
+## The component (`src/canvas.tsx`)
+
+```tsx
+import { useEffect, useState } from 'react'
+import { Checkbox, SkeletonText, Text, Tooltip, TooltipContent, TooltipTrigger } from '@posthog/quill'
+import { Info } from 'lucide-react'
+
+const ITEMS = [
+ { id: 'download-desktop', label: 'Download PostHog Desktop', hint: null },
+ {
+ id: 'add-widget',
+ label: 'Add a widget to this canvas',
+ hint: 'Select Edit in the top right, then click and drag anywhere on the dotted grid and describe what should go there.',
+ },
+ {
+ id: 'start-task',
+ label: 'Start your first task',
+ hint: 'Open a space and tell the agent what you want done. It picks the task up and reports back.',
+ },
+]
+
+// Persistence needs both the SDK surface and a host that answers it. An old
+// runtime without ph.state must degrade to session-only ticks, never crash
+// the tile.
+const stateApi = typeof ph !== 'undefined' && ph.state && typeof ph.state.get === 'function' ? ph.state : null
+
+export default function WelcomeChecklist() {
+ const [checked, setChecked] = useState(null)
+
+ useEffect(() => {
+ let cancelled = false
+ if (!stateApi) {
+ setChecked({ 'download-desktop': true })
+ } else {
+ stateApi
+ .get('checked', { scope: 'user' })
+ .then((value) => {
+ if (!cancelled) {
+ setChecked(value && typeof value === 'object' ? value : {})
+ }
+ })
+ .catch(() => {
+ if (!cancelled) {
+ setChecked({})
+ }
+ })
+ }
+ return () => {
+ cancelled = true
+ }
+ }, [])
+
+ const toggle = (id, value) => {
+ if (!checked) {
+ return
+ }
+ const next = { ...checked, [id]: value }
+ setChecked(next)
+ if (stateApi) {
+ stateApi.set('checked', next, { scope: 'user' }).catch(() => {})
+ }
+ }
+
+ const done = checked ? ITEMS.filter((item) => checked[item.id]).length : 0
+
+ return (
+ <div className="flex h-full flex-col gap-2 overflow-y-auto p-3">
+ <div className="flex items-baseline justify-between gap-2">
+ <Text weight="medium">Welcome to PostHog</Text>
+ {checked ? (
+ <Text size="sm" className="text-muted-foreground">
+ {done} of {ITEMS.length} done
+ </Text>
+ ) : null}
+ </div>
+ {checked === null ? (
+ <SkeletonText lines={5} className="text-sm" />
+ ) : (
+ <div className="flex flex-col gap-1.5">
+ {ITEMS.map((item) => (
+ <div key={item.id} className="flex items-center gap-2">
+ <Checkbox checked={!!checked[item.id]} onCheckedChange={(value) => toggle(item.id, value === true)} />
+ <Text size="sm" className={checked[item.id] ? 'text-muted-foreground line-through' : ''}>
+ {item.label}
+ </Text>
+ {item.hint ? (
+ <Tooltip>
+ <TooltipTrigger render={<Info size={13} className="shrink-0 text-muted-foreground" />} />
+ <TooltipContent>
+ <div className="max-w-60">{item.hint}</div>
+ </TooltipContent>
+ </Tooltip>
+ ) : null}
+ </div>
+ ))}
+ </div>
+ )}
+ </div>
+ )
+}
+```
+
+## The rules the example encodes
+
+- One file, one `export default` React component, no props, no `createRoot` — the host mounts it.
+- Imports only from the platform allowlist (`react`, `@posthog/quill`, `lucide-react`, `recharts`, `dayjs`).
+- `ph` is a host-injected global — never import it, and feature-detect optional surfaces like `ph.state` so the widget degrades instead of crashing on an older runtime.
+- Loading state renders a skeleton, never a blank; every async access has a `.catch` that lands in a renderable state.
+- Fill 100% of the box (`h-full`) and let content scroll; the user controls the placement's size.
diff --git a/products/canvas/skills/querying-canvas-data/SKILL.md b/products/canvas/skills/querying-canvas-data/SKILL.md
index 684d89cf7abf..23ec2237562e 100644
--- a/products/canvas/skills/querying-canvas-data/SKILL.md
+++ b/products/canvas/skills/querying-canvas-data/SKILL.md
@@ -2,7 +2,7 @@
name: querying-canvas-data
description: >
Get PostHog data into a canvas correctly: the host-injected `ph` SDK (loadInsight, query,
- capture, openExternal, navigate), the data hierarchy (saved insights first, typed query nodes
+ capture, state, openExternal, navigate), the data hierarchy (saved insights first, typed query nodes
second, inline HogQL last), per-insight-type result shapes, date-range wiring, and event capture
from a canvas. Use whenever a canvas shows metrics, charts, tables, or any PostHog data, or
needs to send analytics events.
diff --git a/products/canvas/skills/validating-and-publishing-canvases/SKILL.md b/products/canvas/skills/validating-and-publishing-canvases/SKILL.md
index 1de24a9d4acc..533120d7e26d 100644
--- a/products/canvas/skills/validating-and-publishing-canvases/SKILL.md
+++ b/products/canvas/skills/validating-and-publishing-canvases/SKILL.md
@@ -104,6 +104,13 @@ every few seconds (up to ~2 minutes) until the build you queued is terminal:
build never replaces the last good one, so the canvas keeps rendering the previous version —
finishing the task here would leave the user with a stale canvas and a silent failure.
+Runtime error reports (filed on the authoring task when a rendered canvas throws) name the build
+they came from. A report from an **older build id** is history, not evidence about your current
+code — check it against the build you just published before acting on it. In particular, a report
+that a documented `ph` API is undefined (e.g. `ph.state`) means that artifact was baked by an
+older host runtime: republish so a current build replaces it. Never "fix" it by removing the API
+or its capability declaration.
+
## Draft, then promote
Publishing goes live the moment its build is ready. For a canvas that **already has a live
diff --git a/services/mcp/schema/generated-tool-definitions.json b/services/mcp/schema/generated-tool-definitions.json
index 0123e36399e9..11774afde204 100644
--- a/services/mcp/schema/generated-tool-definitions.json
+++ b/services/mcp/schema/generated-tool-definitions.json
@@ -1096,8 +1096,50 @@
"readOnlyHint": false
}
},
+ "canvas-layout-get": {
+ "description": "Read a grid canvas's live layout document (grid definition + placements) and its `current_version_id`. Always call this before patching or publishing: pass the returned version id as `expected_current_version_id` so concurrent edits are not overwritten. A grid canvas with no versions yet returns the default empty layout with a null version id. Placements reference component canvases (kind=component) — resolve their contracts via canvas-list.",
+ "category": "Canvas",
+ "feature": "canvas",
+ "summary": "Read grid canvas layout",
+ "title": "Read grid canvas layout",
+ "required_scopes": ["canvas:read"],
+ "annotations": {
+ "destructiveHint": false,
+ "idempotentHint": true,
+ "openWorldHint": true,
+ "readOnlyHint": true
+ }
+ },
+ "canvas-layout-patch": {
+ "description": "Apply surgical operations to a grid canvas's layout — the DEFAULT way to change one: add_placement (a new widget box), update_placement (fill a box with a component, move/resize it, change its status or config), remove_placement, set_grid. Operations apply in order to the current layout, the result is validated atomically, and the new version is live immediately (layout is data — no build). `expected_current_version_id` is REQUIRED (from canvas-layout-get; null only before the first layout publish) — a stale base is rejected with 409 version_conflict; re-read the layout, re-apply, and patch again. To fill a drawn box: update_placement with changes {status: \"live\", component: <component canvas id>, config: {...}}. The component must be published (canvas-list kind=component shows component_meta and published_build_id) and the config must match its configSchema.",
+ "category": "Canvas",
+ "feature": "canvas",
+ "summary": "Patch grid canvas layout",
+ "title": "Patch grid canvas layout",
+ "required_scopes": ["canvas:write"],
+ "annotations": {
+ "destructiveHint": false,
+ "idempotentHint": false,
+ "openWorldHint": true,
+ "readOnlyHint": false
+ }
+ },
+ "canvas-layout-publish": {
+ "description": "Publish a COMPLETE layout document as a grid canvas's new head version. Prefer canvas-layout-patch for incremental changes — full publish is for creating an initial layout or restructuring the whole grid. The layout is validated first (grid bounds, overlaps, component references, per-placement config against each component's configSchema); errors reject the publish and leave the canvas untouched. The new version is live immediately — no build. `expected_current_version_id` is REQUIRED (from canvas-layout-get; null only before the first layout publish) — a stale base is rejected with 409 version_conflict; re-read the layout, rebuild the document on the new head, and publish again.",
+ "category": "Canvas",
+ "feature": "canvas",
+ "summary": "Publish grid canvas layout",
+ "title": "Publish grid canvas layout",
+ "required_scopes": ["canvas:write"],
+ "annotations": {
+ "destructiveHint": false,
+ "idempotentHint": false,
+ "openWorldHint": true,
+ "readOnlyHint": false
+ }
+ },
"canvas-list": {
- "description": "List the project's canvases (newest first), optionally scoped to one channel via `channel`. Use this to resolve which canvas a request refers to before reading or publishing source. Each row's `url` is that canvas's only valid link — share it verbatim; never construct a canvas URL yourself.",
+ "description": "List the project's canvases (newest first), optionally scoped to one channel via `channel`. Use this to resolve which canvas a request refers to before reading or publishing source. With `kind=component` this is the COMPONENT STORE: reusable widgets grid canvases place. Before building a new widget, ALWAYS search here first (`kind=component` plus `search=<what the widget shows>`) — placing an existing component with the right `config` beats authoring a duplicate. A component is placeable when `component_meta` (its size contract and configSchema) and `published_build_id` are both set. Each row's `url` is that canvas's only valid link — share it verbatim; never construct a canvas URL yourself.",
"category": "Canvas",
"feature": "canvas",
"summary": "List canvases",
diff --git a/services/mcp/schema/tool-definitions-all.json b/services/mcp/schema/tool-definitions-all.json
index 8444b4bb75b3..e2d39d627f3b 100644
--- a/services/mcp/schema/tool-definitions-all.json
+++ b/services/mcp/schema/tool-definitions-all.json
@@ -1111,8 +1111,50 @@
"readOnlyHint": false
}
},
+ "canvas-layout-get": {
+ "description": "Read a grid canvas's live layout document (grid definition + placements) and its `current_version_id`. Always call this before patching or publishing: pass the returned version id as `expected_current_version_id` so concurrent edits are not overwritten. A grid canvas with no versions yet returns the default empty layout with a null version id. Placements reference component canvases (kind=component) — resolve their contracts via canvas-list.",
+ "category": "Canvas",
+ "feature": "canvas",
+ "summary": "Read grid canvas layout",
+ "title": "Read grid canvas layout",
+ "required_scopes": ["canvas:read"],
+ "annotations": {
+ "destructiveHint": false,
+ "idempotentHint": true,
+ "openWorldHint": true,
+ "readOnlyHint": true
+ }
+ },
+ "canvas-layout-patch": {
+ "description": "Apply surgical operations to a grid canvas's layout — the DEFAULT way to change one: add_placement (a new widget box), update_placement (fill a box with a component, move/resize it, change its status or config), remove_placement, set_grid. Operations apply in order to the current layout, the result is validated atomically, and the new version is live immediately (layout is data — no build). `expected_current_version_id` is REQUIRED (from canvas-layout-get; null only before the first layout publish) — a stale base is rejected with 409 version_conflict; re-read the layout, re-apply, and patch again. To fill a drawn box: update_placement with changes {status: \"live\", component: <component canvas id>, config: {...}}. The component must be published (canvas-list kind=component shows component_meta and published_build_id) and the config must match its configSchema.",
+ "category": "Canvas",
+ "feature": "canvas",
+ "summary": "Patch grid canvas layout",
+ "title": "Patch grid canvas layout",
+ "required_scopes": ["canvas:write"],
+ "annotations": {
+ "destructiveHint": false,
+ "idempotentHint": false,
+ "openWorldHint": true,
+ "readOnlyHint": false
+ }
+ },
+ "canvas-layout-publish": {
+ "description": "Publish a COMPLETE layout document as a grid canvas's new head version. Prefer canvas-layout-patch for incremental changes — full publish is for creating an initial layout or restructuring the whole grid. The layout is validated first (grid bounds, overlaps, component references, per-placement config against each component's configSchema); errors reject the publish and leave the canvas untouched. The new version is live immediately — no build. `expected_current_version_id` is REQUIRED (from canvas-layout-get; null only before the first layout publish) — a stale base is rejected with 409 version_conflict; re-read the layout, rebuild the document on the new head, and publish again.",
+ "category": "Canvas",
+ "feature": "canvas",
+ "summary": "Publish grid canvas layout",
+ "title": "Publish grid canvas layout",
+ "required_scopes": ["canvas:write"],
+ "annotations": {
+ "destructiveHint": false,
+ "idempotentHint": false,
+ "openWorldHint": true,
+ "readOnlyHint": false
+ }
+ },
"canvas-list": {
- "description": "List the project's canvases (newest first), optionally scoped to one channel via `channel`. Use this to resolve which canvas a request refers to before reading or publishing source. Each row's `url` is that canvas's only valid link — share it verbatim; never construct a canvas URL yourself.",
+ "description": "List the project's canvases (newest first), optionally scoped to one channel via `channel`. Use this to resolve which canvas a request refers to before reading or publishing source. With `kind=component` this is the COMPONENT STORE: reusable widgets grid canvases place. Before building a new widget, ALWAYS search here first (`kind=component` plus `search=<what the widget shows>`) — placing an existing component with the right `config` beats authoring a duplicate. A component is placeable when `component_meta` (its size contract and configSchema) and `published_build_id` are both set. Each row's `url` is that canvas's only valid link — share it verbatim; never construct a canvas URL yourself.",
"category": "Canvas",
"feature": "canvas",
"summary": "List canvases",
diff --git a/services/mcp/src/generated/canvas/api.ts b/services/mcp/src/generated/canvas/api.ts
index e3a7e90cbdc3..3e597c01e092 100644
--- a/services/mcp/src/generated/canvas/api.ts
+++ b/services/mcp/src/generated/canvas/api.ts
@@ -3,7 +3,7 @@
* MCP service uses these Zod schemas for generated tool handlers.
* To regenerate: hogli build:openapi
*
- * PostHog API - MCP 11 enabled ops
+ * PostHog API - MCP 14 enabled ops
* OpenAPI spec version: 1.0.0
*/
import * as zod from 'zod'
@@ -396,6 +396,394 @@ export const CanvasesEditCreateBody = /* @__PURE__ */ zod
})
.describe("Payload for publishing per-file edits against the canvas's current source.")
+/**
+ * Read a grid canvas's layout document and its `current_version_id`.
+ *
+ * Always call this before editing: pass the returned version id as
+ * `expected_current_version_id` on publish/patch so concurrent edits are
+ * not overwritten. A grid canvas with no versions yet returns the
+ * default empty layout with a null version id.
+ */
+export const CanvasesLayoutRetrieveParams = /* @__PURE__ */ zod.object({
+ id: zod.string().describe('A UUID string identifying this canvas.'),
+ project_id: zod
+ .string()
+ .describe(
+ "Project ID of the project you're trying to access. To find the ID of the project, make a call to \/api\/projects\/."
+ ),
+})
+
+export const CanvasesLayoutRetrieveQueryParams = /* @__PURE__ */ zod.object({
+ version_id: zod
+ .string()
+ .optional()
+ .describe('Read this historical layout version instead of the head (for version browsing).'),
+})
+
+/**
+ * Apply surgical operations to the grid canvas's current layout.
+ *
+ * The default write path for both the editor and agents: add, move,
+ * resize, fill, or remove one placement without resending the layout.
+ * `expected_current_version_id` is mandatory so an agent filling a box
+ * and a user rearranging widgets cannot overwrite each other.
+ */
+export const CanvasesLayoutPatchCreateParams = /* @__PURE__ */ zod.object({
+ id: zod.string().describe('A UUID string identifying this canvas.'),
+ project_id: zod
+ .string()
+ .describe(
+ "Project ID of the project you're trying to access. To find the ID of the project, make a call to \/api\/projects\/."
+ ),
+})
+
+export const canvasesLayoutPatchCreateBodyOperationsItemGridOneRowHeightMin = 24
+export const canvasesLayoutPatchCreateBodyOperationsItemGridOneRowHeightMax = 400
+
+export const canvasesLayoutPatchCreateBodyOperationsItemGridOneGapMin = 0
+export const canvasesLayoutPatchCreateBodyOperationsItemGridOneGapMax = 48
+
+export const canvasesLayoutPatchCreateBodyOperationsItemPlacementOneIdMax = 64
+
+export const canvasesLayoutPatchCreateBodyOperationsItemPlacementOneIdRegExp = new RegExp('^[A-Za-z0-9_-]{1,64}$')
+export const canvasesLayoutPatchCreateBodyOperationsItemPlacementOneXMin = 0
+
+export const canvasesLayoutPatchCreateBodyOperationsItemPlacementOneYMin = 0
+
+export const canvasesLayoutPatchCreateBodyOperationsItemPlacementOnePromptMax = 10000
+
+export const canvasesLayoutPatchCreateBodyOperationsItemIdMax = 64
+
+export const canvasesLayoutPatchCreateBodyOperationsItemChangesOneXMin = 0
+
+export const canvasesLayoutPatchCreateBodyOperationsItemChangesOneYMin = 0
+
+export const canvasesLayoutPatchCreateBodyOperationsItemChangesOnePromptMax = 10000
+
+export const CanvasesLayoutPatchCreateBody = /* @__PURE__ */ zod
+ .object({
+ operations: zod
+ .array(
+ zod
+ .object({
+ op: zod
+ .enum(['set_grid', 'add_placement', 'update_placement', 'remove_placement'])
+ .describe(
+ '\* `set_grid` - set_grid\n\* `add_placement` - add_placement\n\* `update_placement` - update_placement\n\* `remove_placement` - remove_placement'
+ )
+ .describe(
+ 'The operation to apply.\n\n\* `set_grid` - set_grid\n\* `add_placement` - add_placement\n\* `update_placement` - update_placement\n\* `remove_placement` - remove_placement'
+ ),
+ grid: zod
+ .object({
+ columns: zod
+ .union([
+ zod.literal(4),
+ zod.literal(6),
+ zod.literal(8),
+ zod.literal(10),
+ zod.literal(12),
+ ])
+ .describe('\* `4` - 4\n\* `6` - 6\n\* `8` - 8\n\* `10` - 10\n\* `12` - 12')
+ .describe(
+ 'Grid width in columns. One of 4, 6, 8, 10, or 12.\n\n\* `4` - 4\n\* `6` - 6\n\* `8` - 8\n\* `10` - 10\n\* `12` - 12'
+ ),
+ rowHeight: zod
+ .number()
+ .min(canvasesLayoutPatchCreateBodyOperationsItemGridOneRowHeightMin)
+ .max(canvasesLayoutPatchCreateBodyOperationsItemGridOneRowHeightMax)
+ .describe('Height of one grid row, in pixels.'),
+ gap: zod
+ .number()
+ .min(canvasesLayoutPatchCreateBodyOperationsItemGridOneGapMin)
+ .max(canvasesLayoutPatchCreateBodyOperationsItemGridOneGapMax)
+ .describe('Gap between placements, in pixels.'),
+ })
+ .describe('The grid a grid canvas lays its placements out on.')
+ .optional()
+ .describe('For set_grid: the new grid definition.'),
+ placement: zod
+ .object({
+ id: zod
+ .string()
+ .max(canvasesLayoutPatchCreateBodyOperationsItemPlacementOneIdMax)
+ .regex(canvasesLayoutPatchCreateBodyOperationsItemPlacementOneIdRegExp)
+ .describe(
+ "Stable placement id, unique within the layout. 1-64 characters of letters, digits, '_', or '-'."
+ ),
+ status: zod
+ .enum(['pending', 'generating', 'live', 'failed'])
+ .describe(
+ '\* `pending` - pending\n\* `generating` - generating\n\* `live` - live\n\* `failed` - failed'
+ )
+ .describe(
+ "Placement lifecycle: 'pending' (box drawn, no prompt yet), 'generating' (an agent task is filling it), 'live' (renders its component), 'failed' (generation failed; re-prompt or remove).\n\n\* `pending` - pending\n\* `generating` - generating\n\* `live` - live\n\* `failed` - failed"
+ ),
+ component: zod
+ .string()
+ .nullish()
+ .describe(
+ 'Id of the component canvas this placement renders. Required once the placement is live.'
+ ),
+ version: zod
+ .string()
+ .nullish()
+ .describe(
+ 'Component version to render: \"latest\" (the default — follows the component\'s published build) or a pinned source version id.'
+ ),
+ x: zod
+ .number()
+ .min(canvasesLayoutPatchCreateBodyOperationsItemPlacementOneXMin)
+ .describe('Left edge, in grid columns (0-based).'),
+ y: zod
+ .number()
+ .min(canvasesLayoutPatchCreateBodyOperationsItemPlacementOneYMin)
+ .describe('Top edge, in grid rows (0-based).'),
+ w: zod.number().min(1).describe('Width, in grid columns.'),
+ h: zod.number().min(1).describe('Height, in grid rows.'),
+ config: zod
+ .record(zod.string(), zod.unknown())
+ .nullish()
+ .describe(
+ "Per-placement settings, validated against the component's configSchema."
+ ),
+ prompt: zod
+ .string()
+ .max(canvasesLayoutPatchCreateBodyOperationsItemPlacementOnePromptMax)
+ .nullish()
+ .describe(
+ 'For pending\/generating\/failed placements: what the user asked this box to become.'
+ ),
+ generationTaskId: zod
+ .string()
+ .nullish()
+ .describe(
+ 'Id of the agent task currently filling this placement, when one is running.'
+ ),
+ })
+ .describe('One placed widget on a grid canvas.')
+ .optional()
+ .describe('For add_placement: the placement to add.'),
+ id: zod
+ .string()
+ .max(canvasesLayoutPatchCreateBodyOperationsItemIdMax)
+ .optional()
+ .describe('For update_placement\/remove_placement: the target placement id.'),
+ changes: zod
+ .object({
+ status: zod
+ .enum(['pending', 'generating', 'live', 'failed'])
+ .describe(
+ '\* `pending` - pending\n\* `generating` - generating\n\* `live` - live\n\* `failed` - failed'
+ )
+ .optional()
+ .describe(
+ "Placement lifecycle: 'pending' (box drawn, no prompt yet), 'generating' (an agent task is filling it), 'live' (renders its component), 'failed' (generation failed; re-prompt or remove).\n\n\* `pending` - pending\n\* `generating` - generating\n\* `live` - live\n\* `failed` - failed"
+ ),
+ component: zod
+ .string()
+ .nullish()
+ .describe(
+ 'Id of the component canvas this placement renders. Required once the placement is live.'
+ ),
+ version: zod
+ .string()
+ .nullish()
+ .describe(
+ 'Component version to render: \"latest\" (the default — follows the component\'s published build) or a pinned source version id.'
+ ),
+ x: zod
+ .number()
+ .min(canvasesLayoutPatchCreateBodyOperationsItemChangesOneXMin)
+ .optional()
+ .describe('Left edge, in grid columns (0-based).'),
+ y: zod
+ .number()
+ .min(canvasesLayoutPatchCreateBodyOperationsItemChangesOneYMin)
+ .optional()
+ .describe('Top edge, in grid rows (0-based).'),
+ w: zod.number().min(1).optional().describe('Width, in grid columns.'),
+ h: zod.number().min(1).optional().describe('Height, in grid rows.'),
+ config: zod
+ .record(zod.string(), zod.unknown())
+ .nullish()
+ .describe(
+ "Per-placement settings, validated against the component's configSchema."
+ ),
+ prompt: zod
+ .string()
+ .max(canvasesLayoutPatchCreateBodyOperationsItemChangesOnePromptMax)
+ .nullish()
+ .describe(
+ 'For pending\/generating\/failed placements: what the user asked this box to become.'
+ ),
+ generationTaskId: zod
+ .string()
+ .nullish()
+ .describe(
+ 'Id of the agent task currently filling this placement, when one is running.'
+ ),
+ })
+ .describe('Fields to merge into an existing placement (all optional; id cannot change).')
+ .optional()
+ .describe('For update_placement: the fields to merge into the placement.'),
+ })
+ .describe('One surgical layout operation.')
+ )
+ .describe("Operations applied in order to the canvas's current layout, at most 64."),
+ prompt: zod
+ .string()
+ .optional()
+ .describe('Short description of the change, stored on the appended version history entry.'),
+ expected_current_version_id: zod
+ .string()
+ .nullable()
+ .describe(
+ 'Required optimistic-concurrency guard: the current_version_id the operations are based on (null when the canvas has no layout versions yet). A moved head is rejected with 409 version_conflict — patches cannot apply unguarded.'
+ ),
+ })
+ .describe("Payload for applying surgical operations to the canvas's current layout.")
+
+/**
+ * Publish a complete layout document as the grid canvas's new head version.
+ *
+ * Layout is data, not code: the new version is live immediately, with no
+ * build. Validation errors reject the publish (400) and leave the canvas
+ * untouched; a stale `expected_current_version_id` is rejected with 409.
+ */
+export const CanvasesLayoutPublishCreateParams = /* @__PURE__ */ zod.object({
+ id: zod.string().describe('A UUID string identifying this canvas.'),
+ project_id: zod
+ .string()
+ .describe(
+ "Project ID of the project you're trying to access. To find the ID of the project, make a call to \/api\/projects\/."
+ ),
+})
+
+export const canvasesLayoutPublishCreateBodyLayoutOneGridOneRowHeightMin = 24
+export const canvasesLayoutPublishCreateBodyLayoutOneGridOneRowHeightMax = 400
+
+export const canvasesLayoutPublishCreateBodyLayoutOneGridOneGapMin = 0
+export const canvasesLayoutPublishCreateBodyLayoutOneGridOneGapMax = 48
+
+export const canvasesLayoutPublishCreateBodyLayoutOnePlacementsItemIdMax = 64
+
+export const canvasesLayoutPublishCreateBodyLayoutOnePlacementsItemIdRegExp = new RegExp('^[A-Za-z0-9_-]{1,64}$')
+export const canvasesLayoutPublishCreateBodyLayoutOnePlacementsItemXMin = 0
+
+export const canvasesLayoutPublishCreateBodyLayoutOnePlacementsItemYMin = 0
+
+export const canvasesLayoutPublishCreateBodyLayoutOnePlacementsItemPromptMax = 10000
+
+export const CanvasesLayoutPublishCreateBody = /* @__PURE__ */ zod
+ .object({
+ layout: zod
+ .object({
+ schemaVersion: zod
+ .literal(1)
+ .describe('\* `1` - 1')
+ .describe('Layout schema version. Currently always 1.\n\n\* `1` - 1'),
+ grid: zod
+ .object({
+ columns: zod
+ .union([zod.literal(4), zod.literal(6), zod.literal(8), zod.literal(10), zod.literal(12)])
+ .describe('\* `4` - 4\n\* `6` - 6\n\* `8` - 8\n\* `10` - 10\n\* `12` - 12')
+ .describe(
+ 'Grid width in columns. One of 4, 6, 8, 10, or 12.\n\n\* `4` - 4\n\* `6` - 6\n\* `8` - 8\n\* `10` - 10\n\* `12` - 12'
+ ),
+ rowHeight: zod
+ .number()
+ .min(canvasesLayoutPublishCreateBodyLayoutOneGridOneRowHeightMin)
+ .max(canvasesLayoutPublishCreateBodyLayoutOneGridOneRowHeightMax)
+ .describe('Height of one grid row, in pixels.'),
+ gap: zod
+ .number()
+ .min(canvasesLayoutPublishCreateBodyLayoutOneGridOneGapMin)
+ .max(canvasesLayoutPublishCreateBodyLayoutOneGridOneGapMax)
+ .describe('Gap between placements, in pixels.'),
+ })
+ .describe('The grid a grid canvas lays its placements out on.')
+ .describe('The grid placements are laid out on.'),
+ placements: zod
+ .array(
+ zod
+ .object({
+ id: zod
+ .string()
+ .max(canvasesLayoutPublishCreateBodyLayoutOnePlacementsItemIdMax)
+ .regex(canvasesLayoutPublishCreateBodyLayoutOnePlacementsItemIdRegExp)
+ .describe(
+ "Stable placement id, unique within the layout. 1-64 characters of letters, digits, '_', or '-'."
+ ),
+ status: zod
+ .enum(['pending', 'generating', 'live', 'failed'])
+ .describe(
+ '\* `pending` - pending\n\* `generating` - generating\n\* `live` - live\n\* `failed` - failed'
+ )
+ .describe(
+ "Placement lifecycle: 'pending' (box drawn, no prompt yet), 'generating' (an agent task is filling it), 'live' (renders its component), 'failed' (generation failed; re-prompt or remove).\n\n\* `pending` - pending\n\* `generating` - generating\n\* `live` - live\n\* `failed` - failed"
+ ),
+ component: zod
+ .string()
+ .nullish()
+ .describe(
+ 'Id of the component canvas this placement renders. Required once the placement is live.'
+ ),
+ version: zod
+ .string()
+ .nullish()
+ .describe(
+ 'Component version to render: \"latest\" (the default — follows the component\'s published build) or a pinned source version id.'
+ ),
+ x: zod
+ .number()
+ .min(canvasesLayoutPublishCreateBodyLayoutOnePlacementsItemXMin)
+ .describe('Left edge, in grid columns (0-based).'),
+ y: zod
+ .number()
+ .min(canvasesLayoutPublishCreateBodyLayoutOnePlacementsItemYMin)
+ .describe('Top edge, in grid rows (0-based).'),
+ w: zod.number().min(1).describe('Width, in grid columns.'),
+ h: zod.number().min(1).describe('Height, in grid rows.'),
+ config: zod
+ .record(zod.string(), zod.unknown())
+ .nullish()
+ .describe(
+ "Per-placement settings, validated against the component's configSchema."
+ ),
+ prompt: zod
+ .string()
+ .max(canvasesLayoutPublishCreateBodyLayoutOnePlacementsItemPromptMax)
+ .nullish()
+ .describe(
+ 'For pending\/generating\/failed placements: what the user asked this box to become.'
+ ),
+ generationTaskId: zod
+ .string()
+ .nullish()
+ .describe(
+ 'Id of the agent task currently filling this placement, when one is running.'
+ ),
+ })
+ .describe('One placed widget on a grid canvas.')
+ )
+ .describe('The placed widgets, at most 24. Placements may not overlap or extend past the grid.'),
+ })
+ .describe("A grid canvas's layout document — its entire 'source'.")
+ .describe('The complete layout document to publish.'),
+ prompt: zod
+ .string()
+ .optional()
+ .describe('Short description of the change, stored on the appended version history entry.'),
+ expected_current_version_id: zod
+ .string()
+ .nullish()
+ .describe(
+ 'Optimistic-concurrency guard: the current_version_id the layout was based on (null when the canvas has no versions yet). A moved head is rejected with 409 version_conflict. Omit to publish unguarded.'
+ ),
+ })
+ .describe('Payload for publishing a complete layout document.')
+
/**
* Make a draft version the canvas's live head.
*
diff --git a/services/mcp/src/tools/generated/canvas.ts b/services/mcp/src/tools/generated/canvas.ts
index 84a044d2215e..e66deaf4d5bb 100644
--- a/services/mcp/src/tools/generated/canvas.ts
+++ b/services/mcp/src/tools/generated/canvas.ts
@@ -12,6 +12,11 @@ import {
CanvasesDraftsRetrieveQueryParams,
CanvasesEditCreateBody,
CanvasesEditCreateParams,
+ CanvasesLayoutPatchCreateBody,
+ CanvasesLayoutPatchCreateParams,
+ CanvasesLayoutPublishCreateBody,
+ CanvasesLayoutPublishCreateParams,
+ CanvasesLayoutRetrieveParams,
CanvasesListQueryParams,
CanvasesPromoteCreateBody,
CanvasesPromoteCreateParams,
@@ -50,6 +55,12 @@ const CanvasCreateSchema = CanvasesCreateBody.extend({
channel_id: CanvasesCreateBody.shape['channel_id'].describe(
"Id of the channel to create the canvas in — the channel the task was created in, from the task's context. Use channel-list only to resolve a channel the user named; never pick a channel from the listing yourself (the personal #me channel is not a default)."
),
+ kind: CanvasesCreateBody.shape['kind'].describe(
+ "What to create: 'freeform' (a standalone app — the default), 'component' (a reusable widget for grid canvases; its published project must declare a `component` placement contract), or 'grid' (a composition of components, edited via canvas-layout-patch). See canvas-list (kind=component) before creating a component."
+ ),
+ description: CanvasesCreateBody.shape['description'].describe(
+ 'Short prose describing the canvas. For components this is the store-search text — say what the widget shows and what its config controls, so future searches find it.'
+ ),
})
const canvasCreate = (): ToolBase<typeof CanvasCreateSchema, Schemas.Canvas> => ({
@@ -159,8 +170,96 @@ const canvasEditCreate = (): ToolBase<typeof CanvasEditCreateSchema, Schemas.Can
},
})
+const CanvasLayoutGetSchema = CanvasesLayoutRetrieveParams.omit({ project_id: true }).extend({
+ id: CanvasesLayoutRetrieveParams.shape['id'].describe('ID of the grid canvas whose layout to read.'),
+})
+
+const canvasLayoutGet = (): ToolBase<typeof CanvasLayoutGetSchema, Schemas.CanvasLayoutResponse> => ({
+ name: 'canvas-layout-get',
+ schema: CanvasLayoutGetSchema,
+ handler: async (context: Context, params: z.infer<typeof CanvasLayoutGetSchema>) => {
+ const projectId = await context.stateManager.getProjectId()
+ const result = await context.api.request<Schemas.CanvasLayoutResponse>({
+ method: 'GET',
+ path: `/api/projects/${encodeURIComponent(String(projectId))}/canvases/${encodeURIComponent(String(params.id))}/layout/`,
+ })
+ return result
+ },
+})
+
+const CanvasLayoutPatchSchema = CanvasesLayoutPatchCreateParams.omit({ project_id: true })
+ .extend(CanvasesLayoutPatchCreateBody.shape)
+ .extend({
+ id: CanvasesLayoutPatchCreateParams.shape['id'].describe('ID of the grid canvas whose layout to patch.'),
+ })
+
+const canvasLayoutPatch = (): ToolBase<typeof CanvasLayoutPatchSchema, Schemas.CanvasLayoutPublishResponse> => ({
+ name: 'canvas-layout-patch',
+ schema: CanvasLayoutPatchSchema,
+ handler: async (context: Context, params: z.infer<typeof CanvasLayoutPatchSchema>) => {
+ const projectId = await context.stateManager.getProjectId()
+ const body: Record<string, unknown> = {}
+ if (params.operations !== undefined) {
+ body['operations'] = params.operations
+ }
+ if (params.prompt !== undefined) {
+ body['prompt'] = params.prompt
+ }
+ if (params.expected_current_version_id !== undefined) {
+ body['expected_current_version_id'] = params.expected_current_version_id
+ }
+ const result = await context.api.request<Schemas.CanvasLayoutPublishResponse>({
+ method: 'POST',
+ path: `/api/projects/${encodeURIComponent(String(projectId))}/canvases/${encodeURIComponent(String(params.id))}/layout/patch/`,
+ body,
+ })
+ return result
+ },
+})
+
+const CanvasLayoutPublishSchema = CanvasesLayoutPublishCreateParams.omit({ project_id: true })
+ .extend(CanvasesLayoutPublishCreateBody.shape)
+ .extend({
+ id: CanvasesLayoutPublishCreateParams.shape['id'].describe('ID of the grid canvas whose layout to publish.'),
+ expected_current_version_id: CanvasesLayoutPublishCreateBody.shape['expected_current_version_id']
+ .unwrap()
+ .describe(
+ 'The `current_version_id` this document was built on, from canvas-layout-get (null only for a grid canvas that has never published a layout). A whole document replaces the head, so without the guard a layout the user changed after you read it is silently discarded.'
+ ),
+ })
+
+const canvasLayoutPublish = (): ToolBase<typeof CanvasLayoutPublishSchema, Schemas.CanvasLayoutPublishResponse> => ({
+ name: 'canvas-layout-publish',
+ schema: CanvasLayoutPublishSchema,
+ handler: async (context: Context, params: z.infer<typeof CanvasLayoutPublishSchema>) => {
+ const projectId = await context.stateManager.getProjectId()
+ const body: Record<string, unknown> = {}
+ if (params.layout !== undefined) {
+ body['layout'] = params.layout
+ }
+ if (params.prompt !== undefined) {
+ body['prompt'] = params.prompt
+ }
+ if (params.expected_current_version_id !== undefined) {
+ body['expected_current_version_id'] = params.expected_current_version_id
+ }
+ const result = await context.api.request<Schemas.CanvasLayoutPublishResponse>({
+ method: 'POST',
+ path: `/api/projects/${encodeURIComponent(String(projectId))}/canvases/${encodeURIComponent(String(params.id))}/layout/publish/`,
+ body,
+ })
+ return result
+ },
+})
+
const CanvasListSchema = CanvasesListQueryParams.extend({
channel: CanvasesListQueryParams.shape['channel'].describe('Only return canvases in this channel (channel id).'),
+ kind: CanvasesListQueryParams.shape['kind'].describe(
+ 'Only return canvases of this kind. kind=component lists the component store.'
+ ),
+ search: CanvasesListQueryParams.shape['search'].describe(
+ 'Case-insensitive match on name and description — use to find store components by what they show.'
+ ),
})
const canvasList = (): ToolBase<typeof CanvasListSchema, Schemas.PaginatedCanvasList> => ({
@@ -309,6 +408,9 @@ export const GENERATED_TOOLS: Record<string, () => ToolBase<ZodObjectAny>> = {
'canvas-draft-create': canvasDraftCreate,
'canvas-drafts-retrieve': canvasDraftsRetrieve,
'canvas-edit-create': canvasEditCreate,
+ 'canvas-layout-get': canvasLayoutGet,
+ 'canvas-layout-patch': canvasLayoutPatch,
+ 'canvas-layout-publish': canvasLayoutPublish,
'canvas-list': canvasList,
'canvas-promote-create': canvasPromoteCreate,
'canvas-publish-create': canvasPublishCreate,
diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/canvas-create.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/canvas-create.json
index 1344bca5a16f..9f454fc7f92b 100644
--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/canvas-create.json
+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/canvas-create.json
@@ -7,12 +7,12 @@
},
"description": {
"default": "",
- "description": "Short prose describing the canvas. For components this is the store-search text agents match against — say what the widget shows and what its config controls.",
+ "description": "Short prose describing the canvas. For components this is the store-search text — say what the widget shows and what its config controls, so future searches find it.",
"type": "string"
},
"kind": {
"default": "freeform",
- "description": "What to create: 'freeform' (a standalone app), 'component' (a reusable widget for grids — its published project must declare a `component` placement contract), or 'grid' (a composition of components, edited through the layout endpoints).\n\n* `freeform` - freeform\n* `grid` - grid\n* `component` - component",
+ "description": "What to create: 'freeform' (a standalone app — the default), 'component' (a reusable widget for grid canvases; its published project must declare a `component` placement contract), or 'grid' (a composition of components, edited via canvas-layout-patch). See canvas-list (kind=component) before creating a component.",
"enum": ["freeform", "grid", "component"],
"type": "string"
},
diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/canvas-layout-get.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/canvas-layout-get.json
new file mode 100644
index 000000000000..1aadab4a45c0
--- /dev/null
+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/canvas-layout-get.json
@@ -0,0 +1,11 @@
+{
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
+ "properties": {
+ "id": {
+ "description": "ID of the grid canvas whose layout to read.",
+ "type": "string"
+ }
+ },
+ "required": ["id"],
+ "type": "object"
+}
diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/canvas-layout-patch.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/canvas-layout-patch.json
new file mode 100644
index 000000000000..06a52d4cb20e
--- /dev/null
+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/canvas-layout-patch.json
@@ -0,0 +1,280 @@
+{
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
+ "properties": {
+ "expected_current_version_id": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "description": "Required optimistic-concurrency guard: the current_version_id the operations are based on (null when the canvas has no layout versions yet). A moved head is rejected with 409 version_conflict — patches cannot apply unguarded."
+ },
+ "id": {
+ "description": "ID of the grid canvas whose layout to patch.",
+ "type": "string"
+ },
+ "operations": {
+ "description": "Operations applied in order to the canvas's current layout, at most 64.",
+ "items": {
+ "description": "One surgical layout operation.",
+ "properties": {
+ "changes": {
+ "description": "For update_placement: the fields to merge into the placement.",
+ "properties": {
+ "component": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "description": "Id of the component canvas this placement renders. Required once the placement is live."
+ },
+ "config": {
+ "anyOf": [
+ {
+ "additionalProperties": {},
+ "propertyNames": {
+ "type": "string"
+ },
+ "type": "object"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "description": "Per-placement settings, validated against the component's configSchema."
+ },
+ "generationTaskId": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "description": "Id of the agent task currently filling this placement, when one is running."
+ },
+ "h": {
+ "description": "Height, in grid rows.",
+ "minimum": 1,
+ "type": "number"
+ },
+ "prompt": {
+ "anyOf": [
+ {
+ "maxLength": 10000,
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "description": "For pending/generating/failed placements: what the user asked this box to become."
+ },
+ "status": {
+ "description": "Placement lifecycle: 'pending' (box drawn, no prompt yet), 'generating' (an agent task is filling it), 'live' (renders its component), 'failed' (generation failed; re-prompt or remove).\n\n* `pending` - pending\n* `generating` - generating\n* `live` - live\n* `failed` - failed",
+ "enum": ["pending", "generating", "live", "failed"],
+ "type": "string"
+ },
+ "version": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "description": "Component version to render: \"latest\" (the default — follows the component's published build) or a pinned source version id."
+ },
+ "w": {
+ "description": "Width, in grid columns.",
+ "minimum": 1,
+ "type": "number"
+ },
+ "x": {
+ "description": "Left edge, in grid columns (0-based).",
+ "minimum": 0,
+ "type": "number"
+ },
+ "y": {
+ "description": "Top edge, in grid rows (0-based).",
+ "minimum": 0,
+ "type": "number"
+ }
+ },
+ "type": "object"
+ },
+ "grid": {
+ "description": "For set_grid: the new grid definition.",
+ "properties": {
+ "columns": {
+ "anyOf": [
+ {
+ "const": 4,
+ "type": "number"
+ },
+ {
+ "const": 6,
+ "type": "number"
+ },
+ {
+ "const": 8,
+ "type": "number"
+ },
+ {
+ "const": 10,
+ "type": "number"
+ },
+ {
+ "const": 12,
+ "type": "number"
+ }
+ ],
+ "description": "Grid width in columns. One of 4, 6, 8, 10, or 12.\n\n* `4` - 4\n* `6` - 6\n* `8` - 8\n* `10` - 10\n* `12` - 12"
+ },
+ "gap": {
+ "description": "Gap between placements, in pixels.",
+ "maximum": 48,
+ "minimum": 0,
+ "type": "number"
+ },
+ "rowHeight": {
+ "description": "Height of one grid row, in pixels.",
+ "maximum": 400,
+ "minimum": 24,
+ "type": "number"
+ }
+ },
+ "required": ["columns", "rowHeight", "gap"],
+ "type": "object"
+ },
+ "id": {
+ "description": "For update_placement/remove_placement: the target placement id.",
+ "maxLength": 64,
+ "type": "string"
+ },
+ "op": {
+ "description": "The operation to apply.\n\n* `set_grid` - set_grid\n* `add_placement` - add_placement\n* `update_placement` - update_placement\n* `remove_placement` - remove_placement",
+ "enum": ["set_grid", "add_placement", "update_placement", "remove_placement"],
+ "type": "string"
+ },
+ "placement": {
+ "description": "For add_placement: the placement to add.",
+ "properties": {
+ "component": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "description": "Id of the component canvas this placement renders. Required once the placement is live."
+ },
+ "config": {
+ "anyOf": [
+ {
+ "additionalProperties": {},
+ "propertyNames": {
+ "type": "string"
+ },
+ "type": "object"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "description": "Per-placement settings, validated against the component's configSchema."
+ },
+ "generationTaskId": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "description": "Id of the agent task currently filling this placement, when one is running."
+ },
+ "h": {
+ "description": "Height, in grid rows.",
+ "minimum": 1,
+ "type": "number"
+ },
+ "id": {
+ "description": "Stable placement id, unique within the layout. 1-64 characters of letters, digits, '_', or '-'.",
+ "maxLength": 64,
+ "pattern": "^[A-Za-z0-9_-]{1,64}$",
+ "type": "string"
+ },
+ "prompt": {
+ "anyOf": [
+ {
+ "maxLength": 10000,
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "description": "For pending/generating/failed placements: what the user asked this box to become."
+ },
+ "status": {
+ "description": "Placement lifecycle: 'pending' (box drawn, no prompt yet), 'generating' (an agent task is filling it), 'live' (renders its component), 'failed' (generation failed; re-prompt or remove).\n\n* `pending` - pending\n* `generating` - generating\n* `live` - live\n* `failed` - failed",
+ "enum": ["pending", "generating", "live", "failed"],
+ "type": "string"
+ },
+ "version": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "description": "Component version to render: \"latest\" (the default — follows the component's published build) or a pinned source version id."
+ },
+ "w": {
+ "description": "Width, in grid columns.",
+ "minimum": 1,
+ "type": "number"
+ },
+ "x": {
+ "description": "Left edge, in grid columns (0-based).",
+ "minimum": 0,
+ "type": "number"
+ },
+ "y": {
+ "description": "Top edge, in grid rows (0-based).",
+ "minimum": 0,
+ "type": "number"
+ }
+ },
+ "required": ["id", "status", "x", "y", "w", "h"],
+ "type": "object"
+ }
+ },
+ "required": ["op"],
+ "type": "object"
+ },
+ "type": "array"
+ },
+ "prompt": {
+ "description": "Short description of the change, stored on the appended version history entry.",
+ "type": "string"
+ }
+ },
+ "required": ["id", "operations", "expected_current_version_id"],
+ "type": "object"
+}
diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/canvas-layout-publish.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/canvas-layout-publish.json
new file mode 100644
index 000000000000..0e161bcb6560
--- /dev/null
+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/canvas-layout-publish.json
@@ -0,0 +1,184 @@
+{
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
+ "properties": {
+ "expected_current_version_id": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "description": "The `current_version_id` this document was built on, from canvas-layout-get (null only for a grid canvas that has never published a layout). A whole document replaces the head, so without the guard a layout the user changed after you read it is silently discarded."
+ },
+ "id": {
+ "description": "ID of the grid canvas whose layout to publish.",
+ "type": "string"
+ },
+ "layout": {
+ "description": "The complete layout document to publish.",
+ "properties": {
+ "grid": {
+ "description": "The grid placements are laid out on.",
+ "properties": {
+ "columns": {
+ "anyOf": [
+ {
+ "const": 4,
+ "type": "number"
+ },
+ {
+ "const": 6,
+ "type": "number"
+ },
+ {
+ "const": 8,
+ "type": "number"
+ },
+ {
+ "const": 10,
+ "type": "number"
+ },
+ {
+ "const": 12,
+ "type": "number"
+ }
+ ],
+ "description": "Grid width in columns. One of 4, 6, 8, 10, or 12.\n\n* `4` - 4\n* `6` - 6\n* `8` - 8\n* `10` - 10\n* `12` - 12"
+ },
+ "gap": {
+ "description": "Gap between placements, in pixels.",
+ "maximum": 48,
+ "minimum": 0,
+ "type": "number"
+ },
+ "rowHeight": {
+ "description": "Height of one grid row, in pixels.",
+ "maximum": 400,
+ "minimum": 24,
+ "type": "number"
+ }
+ },
+ "required": ["columns", "rowHeight", "gap"],
+ "type": "object"
+ },
+ "placements": {
+ "description": "The placed widgets, at most 24. Placements may not overlap or extend past the grid.",
+ "items": {
+ "description": "One placed widget on a grid canvas.",
+ "properties": {
+ "component": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "description": "Id of the component canvas this placement renders. Required once the placement is live."
+ },
+ "config": {
+ "anyOf": [
+ {
+ "additionalProperties": {},
+ "propertyNames": {
+ "type": "string"
+ },
+ "type": "object"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "description": "Per-placement settings, validated against the component's configSchema."
+ },
+ "generationTaskId": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "description": "Id of the agent task currently filling this placement, when one is running."
+ },
+ "h": {
+ "description": "Height, in grid rows.",
+ "minimum": 1,
+ "type": "number"
+ },
+ "id": {
+ "description": "Stable placement id, unique within the layout. 1-64 characters of letters, digits, '_', or '-'.",
+ "maxLength": 64,
+ "pattern": "^[A-Za-z0-9_-]{1,64}$",
+ "type": "string"
+ },
+ "prompt": {
+ "anyOf": [
+ {
+ "maxLength": 10000,
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "description": "For pending/generating/failed placements: what the user asked this box to become."
+ },
+ "status": {
+ "description": "Placement lifecycle: 'pending' (box drawn, no prompt yet), 'generating' (an agent task is filling it), 'live' (renders its component), 'failed' (generation failed; re-prompt or remove).\n\n* `pending` - pending\n* `generating` - generating\n* `live` - live\n* `failed` - failed",
+ "enum": ["pending", "generating", "live", "failed"],
+ "type": "string"
+ },
+ "version": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "description": "Component version to render: \"latest\" (the default — follows the component's published build) or a pinned source version id."
+ },
+ "w": {
+ "description": "Width, in grid columns.",
+ "minimum": 1,
+ "type": "number"
+ },
+ "x": {
+ "description": "Left edge, in grid columns (0-based).",
+ "minimum": 0,
+ "type": "number"
+ },
+ "y": {
+ "description": "Top edge, in grid rows (0-based).",
+ "minimum": 0,
+ "type": "number"
+ }
+ },
+ "required": ["id", "status", "x", "y", "w", "h"],
+ "type": "object"
+ },
+ "type": "array"
+ },
+ "schemaVersion": {
+ "const": 1,
+ "description": "Layout schema version. Currently always 1.\n\n* `1` - 1",
+ "type": "number"
+ }
+ },
+ "required": ["schemaVersion", "grid", "placements"],
+ "type": "object"
+ },
+ "prompt": {
+ "description": "Short description of the change, stored on the appended version history entry.",
+ "type": "string"
+ }
+ },
+ "required": ["id", "layout", "expected_current_version_id"],
+ "type": "object"
+}
diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/canvas-list.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/canvas-list.json
index 1cafad562613..c205e682f564 100644
--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/canvas-list.json
+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/canvas-list.json
@@ -19,7 +19,7 @@
"type": "number"
},
"search": {
- "description": "Only return canvases whose name or description contains this text (case-insensitive).",
+ "description": "Case-insensitive match on name and description — use to find store components by what they show.",
"type": "string"
}
},