mirror of
https://github.com/webstudio-is/webstudio.git
synced 2026-12-01 21:05:42 +09:00
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:
1 parent
dd99e49fbe
commit
03aeb535ef
20 files changed
+6934
-104
No files matched your search
@@ -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.
|
||||
|
||||
@@ -429,7 +429,7 @@ Before authoring unfamiliar expressions, read `webstudio://project/expressions`
|
||||
- POST, PUT, and DELETE resources default to `exposeAsDataSource:false`, even with a scope. Set `exposeAsDataSource:true` only for an intentional render-time read such as a GraphQL POST query; provide `scopeInstanceId` and inspect the returned warning. Set it to `false` during `update-resource` to detach existing render-time exposure.
|
||||
- For dynamic resource query parameters prefer `searchParams`, for example `{"name":"tag","value":"filters.tag"}`. Use `{"type":"literal","value":"website"}` for fixed request text. Header values can be expressions such as `"\"Bearer \" + auth.token"`. Body can be an object expression, including GraphQL payloads such as `{ query: "...", variables: { slug: system.params.slug } }`.
|
||||
- Resource methods are `get`, `post`, `put`, and `delete`. Optional resource controls are `graphql` and `system`. Use `control:"graphql"` for GraphQL POST resources with query bodies. Use `control:"system"` for built-in local resource URLs such as `"/$resources/current-date"` and for resources reading the built-in `system` parameter. The built-in system fields are `system.origin`, `system.pathname`, `system.params`, and `system.search`; do not use `system.path`.
|
||||
- Whenever an array or object from a resource or data variable should render repeated UI, use Collection. Insert `ws:collection` with `insert-component`, bind its `data` prop to the complete iterable rather than the response wrapper or one indexed item, preserve the generated `item`/`itemKey` parameters, and bind descendants to the current iteration context. Wrap multiple repeated siblings in one Element, and give repeated Radix items stable unique `value` bindings.
|
||||
- Whenever an array or object from a resource or data variable should render repeated UI, call `insert-collection` with the complete iterable and one repeated-item JSX root. The command creates the Collection, private item parameters, iterable binding, and descendant item bindings atomically. Use `collectionItem` and `collectionItemKey` expressions in the item JSX. Wrap multiple repeated siblings in one Element, and give repeated Radix items stable unique `value` bindings.
|
||||
- Expressions are single JavaScript expressions, not statements or functions. Functions, arrow functions, classes, `new`, `this`, `await`, imports, arbitrary calls, increment/decrement, and assignment outside actions are unsupported. Prefer optional chaining, nullish coalescing, ternaries, property/index access, operators, and the documented string/array methods.
|
||||
|
||||
## Pick Read Command
|
||||
|
||||
Reference in new issue
Block a user