grafta

v0.7.0
io.github.n0ss4/grafta Checked 10 hours ago Published 6 days ago

Talk to any Figma file with your AI: ask what's in it, change it, or turn it into code.

These tools were reported by the server itself during our smoke test (tools/list), not copied from the README.

open_file

Open a Figma .fig file and keep it open for later calls. Returns a handle and a summary: pages, node counts, components, variable collections, images. Opening a path that is already open returns the same handle without reading it again. Large files take seconds to open; every later call on the handle is fast. Edits the file had not saved when grafta last stopped are replayed, and `recovered` says how many; edits all saved to another file are not, and it says which file.

ParameterTypeDescription
path *stringPath to a .fig file.
recoverbooleanReplay edits this file had not saved when grafta last stopped. Default true; false discards them.

new_file

Create a new, empty .fig at a path that does not exist, and open it: one page and nothing else. `from` is any .fig you have; only its format is used (Figma's schema, which grafta does not invent), none of its content: no pages, components, styles, variables or images. Returns the handle, as open_file does.

ParameterTypeDescription
from *stringAny .fig, whose format the new file uses.
path *stringA new path ending in .fig.
pagestringThe page's name. Default "Page 1".

close_file

Close an open file and free the memory it holds. Edits not saved with save_as are discarded, for good: they are not recovered on the next open. The result says how many there were.

ParameterTypeDescription
handle *stringThe handle open_file returned.

list_open

List the files currently open, with their handles, node counts, unsaved edits, how long each took to open, and the process's memory; and the files open in Figma with grafta's panel on them, `in: "Figma"`, by handle and name, each with the page the person is on and what they have selected.

summarize

Overview of an open file: every page with its id, node count and number of top-level frames, plus totals for nodes, components, component sets, instances, text nodes, variables, styles and images, and the prototype's flows and live interactions.

ParameterTypeDescription
handle *stringThe handle open_file returned.

list_screens

The screens of a page, as a person sees them in Figma, in their order: a page's top-level frames, components, sections and other layers; a deck's slides, across its rows; a site page's breakpoints. Each with id, name, type, size and whether it is visible, ready for render_node. Paged.

ParameterTypeDescription
handle *stringThe handle open_file returned.
page *stringA page's id, from summarize.
budgetintegerMaximum result size in bytes. Default 32768.
cursorstringnext_cursor from the previous page.
limitintegerResults per page.

search_nodes

Find nodes by name (case-insensitive substring), by type (FRAME, TEXT, INSTANCE, COMPONENT, COMPONENT_SET, PAGE, SECTION, GROUP, RECTANGLE, VECTOR, …), by what a text layer says, by a style or variable a layer uses (by name, its own or a run of its text's), or by the component an instance is of (its id, or its component's or set's name). Every criterion given must match; names and text match as case-insensitive substrings. Optionally only inside one node. Returns id, name, type and the path from the page, in document order, paged. Hidden nodes are included.

ParameterTypeDescription
handle *stringThe handle open_file returned.
budgetintegerMaximum result size in bytes. Default 32768.
componentstringInstances of this component: its id, or a case-insensitive substring of its name or its component set's name.
cursorstringnext_cursor from the previous page.
limitintegerResults per page.
namestringCase-insensitive substring of the node name.
stylestringCase-insensitive substring of the name of a fill, stroke, text or effect style the layer uses, or a run of its text.
textstringCase-insensitive substring of a text layer's characters.
typestringNode type, in the plugin API's spelling.
variablestringCase-insensitive substring of the name of a variable the layer binds, in any field or paint, or a run of its text.
withinstringOnly search inside this node id (a page, a frame…).

read_node

Read one node exactly, in Figma's terms: geometry, fills/strokes (hex colours, bound variable names), effects, corner radii, auto-layout, constraints, text and its style, and for an instance its component and variant. A layer's prototype is `reactions` (trigger, actions, destination, transition), as the plugin API names them; a page gives its `flowStartingPoints`, a frame `overflowDirection` and overlay settings. Children to `depth` (default 1). Properties at Figma's default are left out: visible true, opacity 1, rotation 0, no fills/strokes/effects, radius 0, no auto-layout, constraints MIN/M…

ParameterTypeDescription
handle *stringThe handle open_file returned.
id *stringNode id, e.g. 12:345.
budgetintegerMaximum result size in bytes. Default 32768.
children_fromintegerSkip this many children of the node: to resume a result cut for budget.
depthintegerLevels of children to include. 0 = the node alone. Default 1.
geometrybooleanInclude vector path data (SVG d strings). Default false.

read_raw

The node exactly as the file stores it: every field of its node change, including the ones read_node does not model (listed there as `undecoded`). Byte fields are shown as their length and a fingerprint.

ParameterTypeDescription
handle *stringThe handle open_file returned.
id *stringNode id, e.g. 12:345.
budgetinteger
fieldsarrayOnly these top-level fields. Default: all.

list_components

The components this file defines: every component set (with its variant properties and their values) and every standalone component, with id, name, page, component property definitions and how many instances use it. Variants inside a set are not listed separately; read_node on the set lists them as children. Paged.

ParameterTypeDescription
handle *stringThe handle open_file returned.
budgetintegerMaximum result size in bytes. Default 32768.
cursorstringnext_cursor from the previous page.
limitintegerResults per page.
namestringOnly components whose name contains this (case-insensitive).

component_instances

Where a component is used: every instance of it (of any variant, for a component set), with id, name and path. Paged.

ParameterTypeDescription
handle *stringThe handle open_file returned.
id *stringA component or component set id.
budgetintegerMaximum result size in bytes. Default 32768.
cursorstringnext_cursor from the previous page.
limitintegerResults per page.

list_variables

The file's design variables (tokens): each collection with its modes, and each variable's type and value per mode. Colours are hex; an alias is shown as { alias: <variable name> }, not flattened. Paged over variables.

ParameterTypeDescription
handle *stringThe handle open_file returned.
budgetintegerMaximum result size in bytes. Default 32768.
collectionstringOnly this collection (name or id).
cursorstringnext_cursor from the previous page.
limitintegerResults per page.

export_tokens

Write the file's variables as W3C Design Tokens (DTCG 2025.10) JSON, one NEW file per collection and mode, the way Figma imports them: <dir>/<collection>.<mode>.tokens.json. Names split on / into groups; colours exact from the file (sRGB components and alpha, hex beside); numbers without an invented unit; an alias within its collection as a {group.token} reference, to another collection as its value with Figma's com.figma.aliasData. Lists what was not written (unresolved), every name changed to fit the format (renamed), and notes. The folder must exist; no file is written over.

ParameterTypeDescription
dir *stringAn existing folder for the token files.
handle *stringThe handle open_file returned.
collectionstringOnly this collection (name or id); all when left out.

create_variable_collection

Make a variable collection (a set of design tokens) with named modes, e.g. modes: ["Light", "Dark"]. Then create_variable adds variables to it, and set_properties binds a fill to one by name. In a file with no Internal Only Canvas (one from new_file), grafta writes one first, where Figma keeps variables.

ParameterTypeDescription
handle *stringThe handle open_file returned.
modes *arrayMode names, in order.
name *stringThe collection's name, e.g. "Colors".

create_variable

Add a variable to a collection, with a value for every mode: { "Light": "#7C3AED", "Dark": "#A78BFA" }. type is COLOR, FLOAT, STRING or BOOLEAN. A value may be { alias: <variable name or id> }, another local variable of the same type, as semantic tokens alias primitive ones. A COLOR variable can be bound at once with set_properties, fills: [{ type: SOLID, variable: <name> }].

ParameterTypeDescription
collection *stringA collection's name or id.
handle *stringThe handle open_file returned.
name *stringe.g. "Brand/Primary"; slashes group it in Figma's panel.
type *
values *objectMode name → value: "#RRGGBB" or "#RRGGBBAA" for COLOR, a number for FLOAT, a string for STRING, true or false for BOOLEAN, or { "alias": "<variable name or id>" } for another local variable of the s…

set_variable

Change a variable grafta made: rename it, or change its value in the modes named (the others keep theirs). Values are as create_variable takes them, aliases included. Every fill bound to it follows, and a text whose size it binds is estimated again (texts_resized). The file's own variables are refused.

ParameterTypeDescription
handle *stringThe handle open_file returned.
id *stringA variable's id, or its name when only one has it.
namestring
valuesobjectMode name → value: "#RRGGBB" or "#RRGGBBAA" for COLOR, a number for FLOAT, a string for STRING, true or false for BOOLEAN, or { "alias": "<variable name or id>" } for another local variable of the s…

set_variable_collection

Change a collection grafta made: rename it, or add a mode (add_mode: "High contrast"). In a new mode every variable takes its value in the first mode, to change with set_variable. The file's own collections are refused.

ParameterTypeDescription
handle *stringThe handle open_file returned.
id *stringA collection's id or name.
add_modestring
namestring

list_styles

The file's own colour, text and effect styles, with their values: paints in hex, a text style's font, size, line height and letter spacing, effects. Styles removed from the file and a library's are left out. Apply one with set_properties: fillStyle, strokeStyle, effectStyle or textStyle.

ParameterTypeDescription
handle *stringThe handle open_file returned.
type

create_style

Make a style: type FILL with fills (paints, as set_properties takes them), TEXT with fontFamily, fontStyle, fontSize, lineHeight and letterSpacing, or EFFECT with effects. Figma lists it under Local styles. Apply it with set_properties: fillStyle or strokeStyle for a FILL style, effectStyle, textStyle.

ParameterTypeDescription
handle *stringThe handle open_file returned.
name *stringe.g. "Brand/Primary"; slashes group it.
type *
effectsarrayEFFECT: shadows and blurs, as set_properties takes them.
fillsarrayFILL: paints, as set_properties takes them.
fontFamilystring
fontSizenumber
fontStylestringe.g. "Bold", "Semi Bold".
letterSpacingPixels, or { value, unit: PIXELS | PERCENT }.
lineHeightPixels, { value, unit: PIXELS | PERCENT } or { unit: AUTO }.

set_style

Change a colour, text or effect style, grafta's or one the file already has (a kit's brand colour, changed once): rename it, or change its values (as create_style takes them for its type). Every node using it follows, in Figma and in read_node, instances are derived again, and a text style's texts are estimated again (texts_resized). Library styles are refused.

ParameterTypeDescription
handle *stringThe handle open_file returned.
id *stringA style's id, or its name when only one has it.
effectsarrayEFFECT: shadows and blurs, as set_properties takes them.
fillsarrayFILL: paints, as set_properties takes them.
fontFamilystring
fontSizenumber
fontStylestringe.g. "Bold", "Semi Bold".
letterSpacingPixels, or { value, unit: PIXELS | PERCENT }.
lineHeightPixels, { value, unit: PIXELS | PERCENT } or { unit: AUTO }.
namestring

get_image

An image the file embeds, by the imageHash a fill carries (read_node shows it). Returned as an image, up to 4 MB; a larger one is described instead.

ParameterTypeDescription
handle *stringThe handle open_file returned.
hash *stringThe fill's imageHash.

render_node

Draw a node (a board, frame, component, instance, shape or text) as a PNG you can look at, from the open file including unsaved edits. Use it to see a screen you read, or to check a change before save_as. Drawn offline: the caption's `notes` name everything drawn approximately or left out, and an empty list means nothing was.

ParameterTypeDescription
handle *stringThe handle open_file returned.
id *stringNode id, e.g. 12:345.
max_sizeintegerLargest side in pixels; a larger picture is scaled down to fit. Default 2048.
scalenumberPixels per unit. Default 1.

export_pdf

Write nodes (frames, boards, components) to a NEW .pdf file, a page each in the order given, each page the node's size in points: screens for review or handoff. Each page is the drawing render_node makes, unsaved edits and modes included, as vectors, with text grafta wrote kept as selectable text. The result's `pages` give each page's notes, as render_node's do; a shadow or blur makes what it covers an image. Never overwrites.

ParameterTypeDescription
handle *stringThe handle open_file returned.
ids *arrayNode ids, one page each, in order.
path *stringA new path ending in .pdf.

check_contrast

Check every visible text under a node (a screen, a frame, a component) against WCAG 2.2 AA: its colour against what is actually drawn behind it, as render_node draws it, in the frame's mode and with instances' overrides. 4.5:1 is required, 3:1 for large text (24 px, or 18.66 px bold). Lists the texts that fail, with colour, background, ratio and what is required, and those that cannot be measured, with why; `all: true` lists the passing ones too. Over a background of several colours, the lowest ratio is given. Paged.

ParameterTypeDescription
handle *stringThe handle open_file returned.
id *stringThe node whose texts are checked.
allbooleanList passing texts too. Default false.
budgetintegerMaximum result size in bytes. Default 32768.
cursorstringnext_cursor from the previous page.
limitintegerResults per page.

create_page

Create a page at the end of the file's page list. Returns its id. Nothing is written to disk until save_as.

ParameterTypeDescription
handle *stringThe handle open_file returned.
name *string

create_frame

Create an empty frame (no fill, no auto-layout) on a page or inside a frame, at x,y relative to the parent, with a width and height. Returns its id. Fills, strokes, auto-layout and text are not available yet: they have not been measured in Figma.

ParameterTypeDescription
handle *stringThe handle open_file returned.
height *number
name *string
parent *stringA page or frame id.
width *number
xnumber
ynumber

create_instance

Create an instance of a component this file defines, on a page or inside a frame, at x,y relative to the parent. It takes the component's own size. For a component set, pass one variant's id (the set's children, via read_node). Components from another file cannot be instantiated yet.

ParameterTypeDescription
component *stringA component (or variant) id.
handle *stringThe handle open_file returned.
parent *stringA page or frame id.
namestringDefault: the component's name.
xnumber
ynumber

create_component

Turn a frame into a component, in place, keeping its children, so it can be reused: then place copies with create_instance (component: its id) and change what each copy shows with override_instance. Build the frame first (create_frame, create_text, create_vector, set_properties), then make it a component. A frame inside a component or an instance cannot be one.

ParameterTypeDescription
handle *stringThe handle open_file returned.
id *stringThe frame to turn into a component.
namestringA new name, e.g. "Button/Primary".

create_variant_set

Group components into a variant set, as Figma's own sets: one component with properties, each component a variant of it. variants: [{ id, values: { "State": "Default" } }], every variant naming the same properties with a different combination. The components must share a parent; the set is placed around them. Then create_instance with any variant's id, and set_variant to switch an instance.

ParameterTypeDescription
handle *stringThe handle open_file returned.
name *stringThe set's name, e.g. "Product row".
variants *array

set_variant

Switch an instance of a variant to another variant of its set, by the values that change: { "State": "Substitute" }. The other properties keep their values. Its overrides stay; Figma matches them to the new variant's layers.

ParameterTypeDescription
handle *stringThe handle open_file returned.
id *stringAn instance of a variant.
values *objectProperty name → the value to switch to.

add_component_property

Give a component a property its instances set: TEXT (a label), BOOLEAN (show a part or not) or INSTANCE_SWAP (which icon), with its default. Then bind a layer inside the component with set_properties componentPropertyReferences ({ characters | visible | mainComponent: <property> }), and set each instance's value with set_properties componentProperties ({ "Label": "Guardar" }).

ParameterTypeDescription
component *stringA component's id.
default *A string, true or false, or a component's name or id.
handle *stringThe handle open_file returned.
name *stringe.g. "Label", "Show icon".
type *

create_text

Create a text layer on a page or in a frame. characters is the text (a line break starts a new paragraph). fontFamily and fontStyle name a font as Figma does (e.g. "Inter", "Semi Bold"); by default, the file's most used font. fontSize, fills (like set_properties: SOLID colour or a local colour variable; default black), x, y, textAlignHorizontal (LEFT, CENTER, RIGHT, JUSTIFIED), lineHeight (pixels, { value, unit: PIXELS | PERCENT } or { unit: AUTO }; default Auto, or the file's usual one at that size), letterSpacing (pixels or { value, unit: PIXELS | PERCENT }). Give width to wrap text inside a…

ParameterTypeDescription
handle *stringThe handle open_file returned.
parent *stringA page or frame id.
charactersstring
fillsarray
fontFamilystring
fontSizenumber
fontStylestring
heightnumber
letterSpacing
lineHeight
namestringLayer name. Default: the characters.
paragraphIndentnumber
paragraphSpacingnumber
paragraphsarray
runsarrayThe text as styled pieces; instead of characters.
textAlignHorizontal
textAlignVertical
textAutoResize
textCase
textDecoration
widthnumber
xnumber
ynumber

create_vector

Draw a vector from SVG path data (M L H V C S Q T A Z), as icon sets publish it: Lucide, Heroicons, Material Symbols. `path` is one path's d, or a list of them. `viewBox` is the box the data is drawn in ([0, 0, 24, 24] for Lucide), scaled to width and height; without it, the path's own bounds. For a line icon give strokes, strokeWeight (in the vector's pixels: Lucide's 2 at 24 px is 4 at 48 px), strokeCap and strokeJoin ROUND, and no fills. Figma draws the geometry itself.

ParameterTypeDescription
handle *stringThe handle open_file returned.
parent *stringA page or frame id.
path *SVG path data: a string, or a list of strings drawn together.
fillRule
fillsarray
heightnumber
namestring
strokeCap
strokeJoin
strokeWeightnumber
strokesarray
viewBoxarray[min x, min y, width, height] of the box the path is drawn in.
widthnumber
xnumber
ynumber

create_shape

Draw a shape as Figma's own layer type: RECTANGLE (cornerRadius), ELLIPSE (arcData { startingAngle, endingAngle, innerRadius } in radians: a ring, a pie, a half arc), LINE (width is its length; needs strokes), POLYGON (pointCount sides) or STAR (pointCount points, innerRadius 0-1). Fills and strokes as set_properties takes them; nothing is painted unless named. Style it further with set_properties.

ParameterTypeDescription
handle *stringThe handle open_file returned.
parent *stringA page or frame id.
type *
width *number
arcDataobject
cornerRadiusnumber
fillsarray
heightnumberNot for a LINE.
innerRadiusnumber
namestring
pointCountinteger
strokeWeightnumber
strokesarray
xnumber
ynumber

override_instance

Change what an instance shows, without changing its component: the colour of an icon, a button's label, a hidden part. properties: fills and strokes (paints, as in set_properties), characters (text layers), visible. layer names the component's layer by its id, as read_node on the component shows it; for a layer inside a nested instance, give a path of ids [nested instance, layer]. Without layer, fills and strokes recolour every vector layer of the component that already has fills (or strokes), and never add paint to a layer that had none. Many icons are drawn with strokes, not fills: read_node…

ParameterTypeDescription
handle *stringThe handle open_file returned.
id *stringAn instance you created.
properties *object
layerA layer id in the component, or a path of ids through nested instances.

fill_template

Place a component once per row of data, in a page or frame (an auto-layout frame flows them): product cards, list rows, localised screens. Rows are a JSON array of objects, or a CSV file whose first line names the keys. Each key of a row is, in this order: `name` (the instance's layer name); a variant property, when `component` is a variant set; a component property (TEXT, BOOLEAN, INSTANCE_SWAP); or the name of a layer in the component, whose text it sets, or whose image when the value is a .png or .jpg path. Any other key refuses the call before anything is written. One call, up to 1000 rows…

ParameterTypeDescription
component *stringA component, or a variant set.
handle *stringThe handle open_file returned.
parent *stringA page or frame id.
csvstringA CSV file instead of rows: its first line names the keys.
rowsarrayOne object per instance.

import_layout

Write a web page's layout as design layers: a layout snapshot (JSON from grafta's snapshot.js, https://n0ss4.github.io/grafta/snapshot.js, run in a browser on the page: graftaSnapshot('<css selector>')) becomes frames, text, images and auto-layout in a page or frame. Flexbox becomes auto-layout with fill, hug or fixed sizing as the browser measured it (layout: "auto", the default), or every box is placed where the browser put it ("absolute"). Backgrounds, uniform borders, radii, box shadows, opacity, fonts and local or data: images are written; what is not (a gradient, a transform, an inline S…

ParameterTypeDescription
handle *stringThe handle open_file returned.
parent *stringA page or frame id.
snapshot *stringThe snapshot's JSON file.
layoutstringFlexbox as auto-layout (default), or every box where the browser put it.
xnumber
ynumber

set_properties

Change a frame, instance or text layer you created, using read_node's names: x, y, width, height, name, visible, clipsContent (clip children to the frame), auto-layout (layoutMode NONE | HORIZONTAL | VERTICAL, itemSpacing, counterAxisSpacing, padding or paddingTop/Right/Bottom/Left, primaryAxisSizingMode and counterAxisSizingMode FIXED | AUTO (a frame given layoutMode alone hugs its children along that axis, as in Figma: give primaryAxisSizingMode FIXED to keep its size), primaryAxisAlignItems MIN | CENTER | MAX | SPACE_BETWEEN, counterAxisAlignItems MIN | CENTER | MAX, layoutWrap), a child's…

ParameterTypeDescription
handle *stringThe handle open_file returned.
id *stringA frame, instance or text layer you created.
properties *object

move_node

Move a frame, component or component set, instance, text layer, shape or vector: into another page or frame, or among its siblings. Siblings are drawn in order, the last on top; in an auto-layout frame the order is also the flow. Give `parent` (with `to`: "front", the default, or "back"), or `behind` / `in_front_of` a sibling to go right behind or in front of it, in that sibling's parent. x,y are relative to the new parent; by default the node keeps them.

ParameterTypeDescription
handle *stringThe handle open_file returned.
id *string
behindstringA node to go right behind, in its parent.
in_front_ofstringA node to go right in front of, in its parent.
parentstringA page or frame id.
tostringWith parent: the top of the stack (last, the default) or the bottom (first).
xnumber
ynumber

delete_node

Delete a node (a page, frame, text or instance) and everything inside it. Returns the ids removed. Refused when another node points at it or at something inside it (an instance of a component in it, a prototype link to it, an override of one of its layers), naming who. A layer inside a component goes from every instance of it, unless an instance overrides it. `also` deletes more nodes in the same call: what they point at among themselves does not count, so components that use each other can go together.

ParameterTypeDescription
handle *stringThe handle open_file returned.
id *string
alsoarrayMore nodes deleted with it, in one call.

group_nodes

Group layers that share a parent, as Figma's Group: the group sits at their bounds and each layer keeps its place on the canvas. Moving or resizing a grouped layer with set_properties fits the group again. ungroup undoes it.

ParameterTypeDescription
handle *stringThe handle open_file returned.
ids *array
namestringDefault "Group".

ungroup

Ungroup a group: its layers go to the group's parent, in its place and order, each where it was on the canvas, and the group is removed.

ParameterTypeDescription
handle *stringThe handle open_file returned.
id *stringA group's id.

create_section

Make a section on a page, to organise screens ("Onboarding", "Checkout"). Then move frames into it with move_node (parent: the section), or create them in it.

ParameterTypeDescription
handle *stringThe handle open_file returned.
height *number
parent *stringA page's id.
width *number
namestring
xnumber
ynumber

duplicate_node

Duplicate a node with everything in it: every layer copied with a new id, instances still instances of their components, bindings and styles kept. The copy goes in the same parent unless one is named, at x, y (by default the original's), in front of its new siblings; then change it. A component, or anything holding one, is not duplicated.

ParameterTypeDescription
handle *stringThe handle open_file returned.
id *string
namestring
parentstringWhere the copy goes; by default the original's parent.
xnumber
ynumber

save_as

Write the open file, with its edits, to a NEW path ending in its product's extension: .fig, or .deck for a Figma Slides file, .jam for FigJam, .site for Figma Sites. Never overwrites: a path that exists, or the source file, is refused. The written file is read back and compared before success is reported. Open the result in Figma to see it.

ParameterTypeDescription
handle *stringThe handle open_file returned.
path *stringA new path ending in .fig, or .deck, .jam or .site for a Figma Slides, FigJam or Figma Sites file.