feat: Add semantic Collection authoring to MCP (#5880)

## What changed

- Add an `insert-collection` MCP and CLI operation for creating repeated
UI from array or object data.
- Create the Collection, iterable binding, current-item/current-key
parameters, repeated item structure, and descendant bindings atomically.
- Accept literal JSON data or expressions backed by project variables
and resource results.
- Support `collectionItem` and `collectionItemKey` expressions inside
the repeated Webstudio JSX item.
- Return the created Collection, item root, and parameter IDs for
immediate inspection and follow-up edits.
- Document when agents should use Collection for lists, grids, cards,
rows, options, tabs, and other repeated content.

## Why

Building a data-driven list previously required several low-level
operations and manual handling of Collection's internal parameters. A
missed step could leave a partially configured or incorrectly scoped
Collection.

## User impact

Agents can turn resource or variable data into a correctly bound
repeated layout in one operation, then inspect and refine the result
normally.

## Validation

- Real-world local CLI test created and rendered a three-product
Collection from project data.
- Tests cover literal arrays, objects, resource expressions, item/key
bindings, malformed fragments, ID conflicts, server execution, and
project-session behavior.
- 176 focused tests, project-build typecheck, and generated-doc checks
pass after rebasing onto current `main`.
This commit is contained in:
Oleg Isonen authored and GitHub committed 2026-07-15 11:26:14 +02:00
1 parent dd99e49fbe
commit 03aeb535ef
20 files changed
+6934 -104

No files matched your search

+5 -6
View File
@@ -98,6 +98,7 @@ MCP lets agents work on one configured Webstudio project. Agents can:
- Create pages from reusable templates.
- Update page metadata, SEO fields, auth settings, and marketplace metadata.
- Insert components and styled JSX sections.
- Create data-driven lists, grids, cards, and similar repeated UI from array or object data in one Collection operation.
- Move, copy, wrap, unwrap, convert, rename, retag, and delete elements.
- Update text, rich text, props, bindings, and actions.
- Create and update local styles, design tokens, style sources, and CSS variables.
@@ -993,17 +994,15 @@ Notes:
Commands:
- MCP tool: components.get {"component":"ws:collection"}
- MCP tool: insert-component {"parentInstanceId":"<instanceId>","component":"ws:collection"}
- MCP tool: insert-collection {"parentInstanceId":"<instanceId>","data":{"type":"expression","value":"posts.data.items"},"itemFragment":"<ws.element ws:tag=\"article\"><ws.element ws:tag=\"h2\">{expression`collectionItem.title`}</ws.element></ws.element>"}
- MCP tool: inspect-instance {"instanceId":"<collectionId>","include":["props","bindings","children"]}
- MCP tool: bind-props {"bindings":[{"instanceId":"<collectionId>","name":"data","binding":{"type":"expression","value":"posts.data"}}]}
Notes:
- Use Collection whenever an array or object from a resource or data variable should render a list, grid, cards, table rows, options, tabs, or other repeated UI.
- Bind the Collection `data` prop to the complete array or object. Do not bind the resource response wrapper or one indexed item. External resource arrays are commonly nested under the scoped resource result's `data` field or deeper.
- Insert Collection with `insert-component` so Webstudio creates its internal current-item and current-key parameters. Preserve those generated parameters; they are scoped runtime context, not public records to create, replace, or delete.
- Collection renders its child structure once for every entry. Bind descendant text and props to the current item. Array iteration exposes the item; object iteration exposes its key and value.
- Pass `insert-collection` the complete array or object. Do not pass the resource response wrapper or one indexed item. External resource arrays are commonly nested under the scoped resource result's `data` field or deeper.
- Pass one repeated-item Webstudio JSX root. The command creates the Collection, its private current-item/current-key parameters, the iterable binding, and descendant item bindings atomically.
- Collection renders the item root once for every entry. Use `expression` values such as `collectionItem.title` in descendant text and props. Object iteration also exposes `collectionItemKey`.
- Wrap multiple repeated sibling instances in one Element inside Collection.
- For repeated Radix items such as accordion items, tabs, or menu options, bind a stable unique id or slug to every required `value` prop.
- See the [Collection documentation](https://docs.webstudio.is/university/core-components/collection) for the equivalent Builder workflow.