diff --git a/crates/mcp/src/tools.rs b/crates/mcp/src/tools.rs index bdd8078ed..8ecb1559d 100644 --- a/crates/mcp/src/tools.rs +++ b/crates/mcp/src/tools.rs @@ -195,7 +195,7 @@ fn tools() -> Vec { tool( "create_node", "Create layer", - "Create a layer (engine `node.create`) and return its id and inspected properties. Coordinates are page units, y down; x/y are relative to the parent frame (the page when there is none, so then they are page coordinates; groups don't count). Inside an auto-layout frame the position is decided by the layout. The new layer becomes the selection. `warnings` reports a fontStyle that draws in another face.", + "Create a layer (engine `node.create`) and return its id and inspected properties. Coordinates are page units, y down; x/y are relative to the parent frame (the page when there is none, so then they are page coordinates; groups don't count). Inside an auto-layout frame the position is decided by the layout. The new layer becomes the selection. `warnings` reports a fontStyle that draws in another face. `fields` / `outline` shrink the returned layer as they do for get_node; the layer is created either way.", obj( json!({ "type": {"type": "string", "enum": ["frame", "rectangle", "ellipse", "polygon", "star", "line", "arrow", "text", "vector", "section", "component", "slice"], "description": "Layer type"}, @@ -212,6 +212,8 @@ fn tools() -> Vec { "closed": boolean("For type vector: close the path"), "select": boolean("Select the new layer (default true)"), "props": {"type": "object", "description": "Any set_properties keys applied at creation, e.g. {\"fill\":\"#3366FF\",\"cornerRadius\":12,\"fontSize\":24,\"layout\":\"vertical\",\"gap\":8,\"padding\":16}"}, + "fields": fields_schema(), + "outline": outline_schema(), }), &["type"], ), @@ -220,9 +222,14 @@ fn tools() -> Vec { tool( "set_properties", "Set properties", - "Set properties on one or more layers as one undo step (engine `node.set`). Keys: name, visible, locked, opacity (0-1), blend, x, y (relative to the parent frame; groups don't count), width, height, rotation (degrees), absoluteRotation (degrees on the page), fill (colour) / fills (array of paints: \"#hex\" or {\"type\":\"solid\",\"color\":\"#hex\"} or {\"type\":\"linearGradient\",\"stops\":[\"#hex\",\"#hex\"]} or stops [{\"position\":0..1,\"color\":\"#hex\"}], optional from/to handles in the unit box; radialGradient too), stroke / strokes, strokeWeight, strokeAlign (inside|center|outside), cornerRadius (n or [tl,tr,br,bl]), effects (array, e.g. {\"type\":\"dropShadow\",\"color\":\"#00000040\",\"offset\":[0,4],\"radius\":8}), clip, layout (null|horizontal|vertical|grid), gap, padding (n or [t,r,b,l]), mainAlign (min|center|max|spaceBetween|spaceAround|spaceEvenly), crossAlign, wrap, contentAlign (auto|spaceBetween: wrapped lines), sizingH / sizingV (fixed|hug|fill), constraints {horizontal, vertical}, characters, fontFamily, fontStyle, fontSize, lineHeight, letterSpacing, textAlign, textAutoResize. Auto layout keys (gap, padding, mainAlign, crossAlign, wrap, …) apply to frames, components and instances only: other layers among the ids are skipped and named in `warnings`, and with none that can take them the call is an error. A fontStyle draws in the family's nearest face; `warnings` says when that face has another weight or slant than the name asks for. Run list_commands with filter \"node.set\" for the full list. Unknown keys are an error. Returns the updated layers.", + "Set properties on one or more layers as one undo step (engine `node.set`). Keys: name, visible, locked, opacity (0-1), blend, x, y (relative to the parent frame; groups don't count), width, height, rotation (degrees), absoluteRotation (degrees on the page), fill (colour) / fills (array of paints: \"#hex\" or {\"type\":\"solid\",\"color\":\"#hex\"} or {\"type\":\"linearGradient\",\"stops\":[\"#hex\",\"#hex\"]} or stops [{\"position\":0..1,\"color\":\"#hex\"}], optional from/to handles in the unit box; radialGradient too), stroke / strokes, strokeWeight, strokeAlign (inside|center|outside), cornerRadius (n or [tl,tr,br,bl]), effects (array, e.g. {\"type\":\"dropShadow\",\"color\":\"#00000040\",\"offset\":[0,4],\"radius\":8}), clip, layout (null|horizontal|vertical|grid), gap, padding (n or [t,r,b,l]), mainAlign (min|center|max|spaceBetween|spaceAround|spaceEvenly), crossAlign, wrap, contentAlign (auto|spaceBetween: wrapped lines), sizingH / sizingV (fixed|hug|fill), constraints {horizontal, vertical}, characters, fontFamily, fontStyle, fontSize, lineHeight, letterSpacing, textAlign, textAutoResize. Auto layout keys (gap, padding, mainAlign, crossAlign, wrap, …) apply to frames, components and instances only: other layers among the ids are skipped and named in `warnings`, and with none that can take them the call is an error. A fontStyle draws in the family's nearest face; `warnings` says when that face has another weight or slant than the name asks for. Run list_commands with filter \"node.set\" for the full list. Unknown keys are an error. Returns the updated layers (up to 20); `fields` / `outline` shrink them as they do for get_node.", obj( - json!({"ids": ids_schema("Layer ids (default: the selection)"), "props": {"type": "object", "description": "Property values to set"}}), + json!({ + "ids": ids_schema("Layer ids (default: the selection)"), + "props": {"type": "object", "description": "Property values to set"}, + "fields": fields_schema(), + "outline": outline_schema(), + }), &["props"], ), false, @@ -836,6 +843,8 @@ fn create_node(b: &mut dyn Backend, a: &Map) -> Result) -> Result) -> Result) -> Result = ids.iter().take(20).filter_map(|i| b.call("node.get", json!({"id": i, "depth": 0})).ok()).collect(); + let nodes: Vec = ids.iter().take(20).filter_map(|&i| node_get(b, i, 0, &options).ok()).collect(); let mut out = json!({"ok": true, "nodes": nodes}); if let Some(w) = warnings { out["warnings"] = w; @@ -941,12 +952,17 @@ fn inspect_at(b: &mut dyn Backend, depth: u64, all: bool, options: &Value) -> Re Ok((value, wire)) } -/// One layer's subtree at `depth`, and what its text block would take on the wire. -fn node_at(b: &mut dyn Backend, id: u64, depth: u64, options: &Value) -> Result<(Value, usize), String> { +/// One layer's subtree at `depth`, with the `fields` / `outline` options applied. +fn node_get(b: &mut dyn Backend, id: u64, depth: u64, options: &Value) -> Result { let mut params = options.clone(); params["id"] = json!(id); params["depth"] = json!(depth); - let value = b.call("node.get", params)?; + b.call("node.get", params) +} + +/// One layer's subtree at `depth`, and what its text block would take on the wire. +fn node_at(b: &mut dyn Backend, id: u64, depth: u64, options: &Value) -> Result<(Value, usize), String> { + let value = node_get(b, id, depth, options)?; let wire = wire_size(&value); Ok((value, wire)) } diff --git a/crates/mcp/tests/it/inspect_fields.rs b/crates/mcp/tests/it/inspect_fields.rs index 0351cd02c..a8ea22eae 100644 --- a/crates/mcp/tests/it/inspect_fields.rs +++ b/crates/mcp/tests/it/inspect_fields.rs @@ -35,7 +35,7 @@ fn compact_keys(node: &Value, outline: bool) { fn tool_schemas_describe_compact_inspection_options() { let mut c = Client::new(); let tools = c.rpc("tools/list", json!({})); - for name in ["inspect_document", "get_node"] { + for name in ["inspect_document", "get_node", "create_node", "set_properties"] { let tool = tools["result"]["tools"].as_array().unwrap().iter().find(|t| t["name"] == name).unwrap(); let props = &tool["inputSchema"]["properties"]; assert_eq!(props["fields"]["type"], "array"); @@ -193,6 +193,61 @@ fn compact_examples_run_verbatim_from_the_docs() { } } +/// The mutation tools return the layers they touched; with `fields` or `outline` that echo is cut +/// down to what the agent asked for, and without them it stays complete. +#[test] +fn mutation_results_take_fields_and_outline() { + let mut c = Client::new(); + let card = json!({"type": "frame", "name": "Card", "width": 280, "height": 160, "props": {"fill": "#F0F0F0", "cornerRadius": 12}}); + let full = c.ok("create_node", card.clone()); + let mut args = card.clone(); + args["fields"] = json!(["name"]); + let picked = c.ok("create_node", args); + compact_keys(&picked["node"], false); + assert_eq!(picked["node"]["name"], "Card"); + assert!(picked.to_string().len() < full.to_string().len(), "{picked} vs {full}"); + let mut args = card; + args["outline"] = json!(true); + let outlined = c.ok("create_node", args); + compact_keys(&outlined["node"], true); + assert_eq!(outlined["node"]["type"], full["node"]["type"]); + + let ids = json!([full["id"], picked["id"], outlined["id"]]); + let set = c.ok("set_properties", json!({"ids": ids, "props": {"opacity": 0.5}})); + let slim = c.ok("set_properties", json!({"ids": ids, "props": {"opacity": 0.4}, "fields": ["opacity"]})); + let (set, slim) = (set["nodes"].as_array().unwrap(), slim["nodes"].as_array().unwrap()); + assert_eq!(slim.len(), set.len(), "every layer is still reported"); + for (whole, cut) in set.iter().zip(slim) { + assert_eq!(cut["id"], whole["id"]); + assert!(cut["opacity"].as_f64().is_some_and(|o| (o - 0.4).abs() < 1e-6), "{cut}"); + assert!(cut.as_object().unwrap().len() < whole.as_object().unwrap().len(), "{cut} vs {whole}"); + } + let outlined = c.ok("set_properties", json!({"ids": ids, "props": {"opacity": 1}, "outline": true})); + for node in outlined["nodes"].as_array().unwrap() { + compact_keys(node, true); + } +} + +/// A bad option is caught before the edit runs: the call fails and the document is as it was. +#[test] +fn a_bad_option_on_a_mutation_changes_nothing() { + let mut c = Client::new(); + let id = c.create(json!({"type": "rectangle", "name": "Keep"})); + let before = c.doc(); + for bad in [json!({"fields": ["Name"]}), json!({"outline": true, "fields": []}), json!({"outline": "yes"})] { + let mut create = json!({"type": "ellipse", "name": "Extra"}); + let mut set = json!({"ids": [id], "props": {"name": "Changed"}}); + for (k, v) in bad.as_object().unwrap() { + create[k] = v.clone(); + set[k] = v.clone(); + } + assert!(!c.err("create_node", create).is_empty()); + assert!(!c.err("set_properties", set).is_empty()); + } + let after = c.doc(); + assert_eq!(after["pages"], before["pages"], "a rejected call left the layers as they were"); +} + #[test] fn invalid_compact_options_fail_in_tools_and_headless_control() { let mut c = Client::new(); diff --git a/docs/mcp.md b/docs/mcp.md index 10350d628..b93d52248 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -437,8 +437,8 @@ a later step can use `{"$step": 0, "field": "ids/0"}` to target the first match. | `list_commands {filter?}` | Every command: id, label, menu, shortcut, undoable, params doc. | | `run_command {command, params}` | Run any command (e.g. `align.left`, `layout.add`, `component.create`, `instance.place` (drop an instance at a page point into the frame or auto layout slot under it), `component.exposeInstance` / `instance.exposed` (nested instance properties on instances), `component.makeSlot` / `instance.slotInsert` / `instance.resetSlot` (slots, below), `inspect.code` (CSS, HTML + CSS for a whole frame, React, Leptos, Vue, SwiftUI, Jetpack Compose, ArkUI or Flutter for a layer; components take their properties as parameters and instances are calls, see Developer Mode below), `inspect.properties` (layout, auto layout, typography, fills, strokes and effects with their style and variable names; `colorFormat`: hex, rgb, css, hsl or hsb), `inspect.assets` (layers under the selection with export settings, icons and images, each with its `kind`), `inspect.code` takes `unit: rem` and `rootFontSize` for CSS, HTML, React, Leptos and Vue, `style.create`, `variable.bind`, `variable.update` (rename, describe, scope), `variable.set` with `{alias}` or a colour calculation (`{alpha}`, `{mix}`), `variable.renameMode` / `variable.removeMode`, `variable.deleteCollection`, `proto.interaction.add`, `codeConnect.set` (components linked to real code, see Developer Mode below)). | | `batch {commands: [{command, params}], label?}` | Several commands as one undo step (`command.batch`), which keeps one copy of the document however many steps there are (an `edit.undo` step undoes the batch's edits so far together); all-or-nothing for open documents and their document state. Failed inner commands are removed from the journal; preferences, clipboard, tool state and UI requests are not rolled back. A step can use what an earlier step returned: name it with `"as": "card"` and `{"$ref": "card"}` anywhere in a later step's params becomes the `id` in its result (`{"$step": n}` does the same by zero-based position); `"field"` takes another key or a slash path such as `ids/0` (see Step references below). | -| `create_node {type, x, y, width, height, parent, index, name, text, path, props}` | Create a frame, rectangle, ellipse, polygon, star, line, arrow, text, vector, section, component or slice; returns `{id, node}`. `warnings` reports a fontStyle that draws in another face. | -| `set_properties {ids, props}` | `node.set` on layers (geometry, fills, strokes, effects, corner radius, auto layout, sizing, constraints, masks (`isMask`, `maskType: alpha\|vector\|luminance`), handoff status (`devStatus: none\|readyForDev\|completed`; marking again clears "Changed"), a section's `sectionContentsHidden`, text…); returns the updated layers. | +| `create_node {type, x, y, width, height, parent, index, name, text, path, props, fields?, outline?}` | Create a frame, rectangle, ellipse, polygon, star, line, arrow, text, vector, section, component or slice; returns `{id, node}`. `warnings` reports a fontStyle that draws in another face. `fields` / `outline` shrink `node` as they do for `get_node`; a bad option is an error and creates nothing. | +| `set_properties {ids, props, fields?, outline?}` | `node.set` on layers (geometry, fills, strokes, effects, corner radius, auto layout, sizing, constraints, masks (`isMask`, `maskType: alpha\|vector\|luminance`), handoff status (`devStatus: none\|readyForDev\|completed`; marking again clears "Changed"), a section's `sectionContentsHidden`, text…); returns the updated layers (up to 20), which `fields` / `outline` shrink as they do for `get_node`; a bad option is an error and sets nothing. | | `inspect_document {depth, allPages, fields?, outline?}` | The document as JSON (its `id`, layer tree, styles, selection, history); `fields` selects layer properties, `outline: true` gives a compact tree (below). The tools that act on a document also take `document` (see Naming the document below). | | `get_node {id, depth, fields?, outline?}` | One layer as JSON; takes the same `fields` and `outline` options; `pluginData` (`{key: value}`, values as strings) when the layer or page has layer data written with `set_properties {props: {pluginData}}`. | | `design_context {ids?, scope?, depth?, maxNodes?, maxBytes?}` | Everything needed to build a design in one read: see [Design context](#design-context). | diff --git a/docs/roadmap.md b/docs/roadmap.md index 389ef400f..060b4d3c4 100644 --- a/docs/roadmap.md +++ b/docs/roadmap.md @@ -76,6 +76,7 @@ blockers. | Date | Change | Summary | |---|---|---| +| 2026-11-28 | minor | Smaller mutation results (M0.9, #2535): `create_node` and `set_properties` take the same `fields` and `outline` options as `get_node`, so the layers they return can be cut to the keys an agent needs. A bad option is rejected before the edit runs, and without either option the result is unchanged. | | 2026-11-26 | minor | #1396, craft-contrib#95: `figcraft-cli` follows RFC-0018. The CLI is a library with `run(args, out, err)` (`main` is a thin wrapper), failures are typed errors (exit 1, usage errors exit 2), output goes through the caller's writers, a closed stdout is quiet, `-V` works after subcommands, `FIGCRAFT_NO_SYSTEM_FONTS` and `FIGCRAFT_SERVER_KEY` are declared on `--no-system-fonts` and `plugin publish --key`, the packages install the man pages and Bash, Zsh and Fish completions (Linux and FreeBSD). Changed behaviour: `convert`/`run` refuse an output that is the input unless `--in-place` is given (it needs `--in`/`--out`); `export -o` and `render -o` refuse the file they read; `plugin publish` accepts `--key`; a blank `FIGCRAFT_NO_SYSTEM_FONTS` counts as unset and an unrecognised value is a usage error. Tests in `apps/figcraft-cli/tests/it/rfc18.rs`. Numbers unchanged | | 2026-11-10 | minor | Zoom in without coarse previews (#312 follow-up): a zoom in to at most 4× the image on screen, inside the area it covers, shows that image enlarged until the refined one comes, measured from what the screen shows, a preview included; it is at least as sharp as a preview with a quarter of the pixels each way. During a pinch or a held zoom each step used to get a preview and drop its refined image for the next step's, so the canvas stayed coarse until the zoom stopped. Zoom outs, other pages and larger zoom ins still get previews. | | 2026-11-19 | minor | M12, #2237 (step 1 of 4): code blocks in the document and engine. `board.codeBlock` places a dark panel of monospace text as tall as its lines, `board.setLanguage` picks one of 16 languages, and `board.nextSticky` makes the next block beside it; the toolbar entry, language menu, highlighting, line numbers and `.jam` import are missing. Numbers unchanged. |