Agents & MCP
Agent recipes
A good agent session is a few short loops, each ending in something you can check. These six cover most of the work. Every call here was run on one small document, a pricing card, and the ids (100:1 for the card, 100:4 for its note, 100:5 for its button) are the ones those runs returned. Yours will differ: an agent reads them from each reply.
Design, check, fix#
Ask for a draft, then make the agent review its own work before you do.
Draw a 320 wide pricing card for the Pro plan with auto layout. Then run check_design on it, fix what it finds, and show me a preview.The agent draws with create_nodes, then calls check_design:
{ "root": "100:1" }
The first draft had a pale note. The reply says so in numbers:
{
"checked": "100:1",
"counts": { "contrast": 1 },
"findings": [
{
"check": "contrast", "node": "100:4", "name": "Note",
"problem": "#B8BCC6 on #FFFFFF: a contrast of 1.90 to 1, where 4.5 to 1 is asked for ordinary text",
"fix": "darken or lighten the text or what is behind it"
}
],
"total": 1
}
It fixes the note, and raises the button from 28 to 44 while it is there, with one update_nodes:
{
"changes": [
{ "id": "100:4", "fill": "#5E6472", "font_size": 15, "line_height": 22 },
{ "id": "100:5", "height": 44 }
]
}
check_design again returns "total": 0. Then render_preview with { "node": "100:1", "max_size": 640 } returns the picture.

- Look at the marked card on the canvas.
- Press Accept in the pill, or Revert all to take the turn back.
A screen as a build spec, then the build compared#
To turn a design into code, an agent reads it as a specification, not as a picture.
get_design_spec:
{ "node": "100:1" }
The reply holds the size (320 × 228), a tree of every layer with all its properties and its box measured from the card's top-left corner, the colors and typography used with how often, the tokens (variables) followed, and assets, the nodes to write out as files. Code is written from a token's name, not from the value it holds.
When the build exists, take a screenshot of the built card alone, cropped to its edges, as a PNG at any scale. Then compare_image:
{ "node": "100:1", "image": "/Users/me/Project/build/plan-card.png" }
In this run the build's button was the wrong blue. The reply said "matches": false, "differs_percent": 15.76, and listed where, the most different first:
{
"node": "100:5", "name": "Button", "kind": "frame",
"box": { "x": 24.0, "y": 160.0, "width": 272.0, "height": 44.0 },
"differs_percent": 95.85, "design_colour": "#6161D7", "built_colour": "#3774ED"
}
A box that differs all over, in another color, is a wrong color or state. One that differs along an edge is out of place or another size. Fix the code and compare again until matches is true.

Several changes as one step#
Use batch when a change is one thing to you, or when half of it would leave the design broken. This one makes a component and two instances of it:
{
"operations": [
{ "tool": "create_nodes", "arguments": { "nodes": [
{ "kind": "component", "name": "Chip", "x": 400, "y": 0, "width": "hug", "height": 32, "fill": "#EEF0FF", "corner_radius": 16,
"layout": { "direction": "horizontal", "padding": [0, 14], "cross_align": "center" },
"children": [
{ "kind": "text", "name": "Label", "text": "Chip", "font_family": "Inter", "font_size": 13, "font_weight": 600, "fill": "#4338CA" }
] }
] } },
{ "tool": "create_nodes", "arguments": { "nodes": [
{ "kind": "instance", "component": "@0.0", "x": 400, "y": 60 },
{ "kind": "instance", "component": "@0.0", "x": 500, "y": 60 }
] } }
]
}
"@0.0" is the first node the first operation made. The reply has each operation's result and "undo_steps": 1. If any operation fails, the ones before it are taken back and the reply says which failed and why. A batch of three whose last operation misnamed a property answered: operation 2 (update_nodes) failed: unknown property radius … Nothing was changed: the 2 before it were taken back.
A reference like "@0.0" names a top-level node an operation made, not a layer inside it. To override a text inside the new component, read its id from the reply and make a second call.
Restyle by variables#
Put the palette in variables once, and a restyle is one call. set_variables makes the set:
{
"set": "Theme",
"modes": ["Light", "Dark"],
"variables": [
{ "name": "color/surface", "values": { "Light": "#FFFFFF", "Dark": "#1B1E26" } },
{ "name": "color/text", "values": { "Light": "#111318", "Dark": "#F4F5F8" } },
{ "name": "color/text-muted", "values": { "Light": "#5E6472", "Dark": "#A3A9B8" } },
{ "name": "color/accent", "values": { "Light": "#5B5BD6", "Dark": "#8E8EF5" } },
{ "name": "radius/card", "values": 16 }
]
}
update_nodes binds the layers to them, by name:
{
"changes": [
{ "id": "100:1", "bindings": { "fill": "color/surface", "corner_radius": "radius/card" } },
{ "id": "100:2", "bindings": { "fill": "color/accent" } },
{ "id": "100:3", "bindings": { "fill": "color/text" } },
{ "id": "100:4", "bindings": { "fill": "color/text-muted" } },
{ "id": "100:5", "bindings": { "fill": "color/accent" } }
]
}
Now render_preview with "mode": "Dark" draws the card in dark without changing the document. And a new accent is one variable:
{ "set": "Theme", "variables": [{ "name": "color/accent", "values": { "Light": "#0F766E", "Dark": "#2DD4BF" } }] }

For colors that follow no variable, replace_color swaps one for another through a node and everything in it. list_colors shows what is there first. Here the chip component, 100:7, goes from violet to teal tint:
{ "ids": ["100:7"], "from": "#EEF0FF", "to": "#E6F4F1" }
The reply is {"changed": 1}, and both instances follow.
After a restyle, run check_design. Its tokens check lists each color set by hand that a variable already holds, such as a white label on a button: bind those, or they will not change with the mode.
Export every asset#
export_assets writes nodes to a folder, named after each node, at each scale:
{ "ids": ["100:1", "100:5"], "folder": "/Users/me/Project/assets", "scales": [1, 2], "effects": true }
This wrote Plan card.png, Plan card@2x.png, Button.png and Button@2x.png. With effects: true each picture has room for its shadow: the card's picture is 392 × 301 for a 320 × 228 card. It is all or none, and an existing file is kept unless overwrite is true. Add "format": "webp" for WebP, and "mode": "Theme=Dark" to write the dark set without changing the document.
To find what to export on a large screen, read assets.list in the get_design_spec reply: it names every node filled with a picture and every drawn shape, with the file names they would get.
- Select the layers.
- Choose File › Export… (⇧⌘E).
Translate a screen#
extract_strings gives every text of a frame a text variable in the set Language, and binds the text to it:
{ "node": "100:1" }
The reply lists the keys, named from the frame and the layer: plan-card.price, plan-card.note, plan-card.label. A language is a mode of that set. import_strings brings translations in from a file (path) or inline (text), as .xcstrings, .strings, JSON or CSV:
{
"format": "csv",
"text": "key,en,de\nplan-card.plan,Pro,Pro\nplan-card.price,$12 / month,12 $ / Monat\nplan-card.note,\"Everything in Free, plus design tools and agents.\",\"Alles aus Free, dazu Designwerkzeuge und Agenten.\"\nplan-card.label,Start free trial,Kostenlos testen\n"
}
The reply was "changed": 4, "modes_added": ["de"]. Now render_preview with "mode": "Language=de" shows the card in German, laid out again around the longer words. Before any translation exists, import_strings with { "made_up": "long" } fills a made-up language 40% longer, as the mode Long (+40%), to see where a layout would break.
Choose File › Import Strings… to bring a translation file in, and File › Export Strings… to write the strings out.