Skip to main content
Glama
openfig-mcp

openfig-mcp

by AmirShokry
README.md
# openfig-mcp

**Figma `.fig` files → LLM-ready design data, over MCP.** No Figma account, API token or plugin: point it
at a downloaded `.fig` file and your coding agent (GitHub Copilot, Claude, Cursor, …) can list the
screens, pull any frame as HTML + CSS, see it as an image, and get the design tokens, components,
hover/press states, animations, prototype links, icons (SVG), images and fonts.

Built on [OpenFig](https://github.com/OpenFig-org)'s `.fig` parser ([openfig-core](https://github.com/OpenFig-org/openfig-core)) and SVG renderer.

## Quick start — VS Code + GitHub Copilot

1. Save your Figma file into the project as `design.fig`
   (Figma: *Main menu → File → Save local copy…*, or *Download* on a Community file).
2. Add `.vscode/mcp.json`:

```json
{
  "servers": {
    "openfig": {
      "type": "stdio",
      "command": "npx",
      "args": ["-y", "openfig-mcp", "${workspaceFolder}/design.fig"]
    }
  }
}
```

3. Open Copilot Chat in **Agent** mode and ask:

> Implement the "Login" screen from the design in React + Tailwind.

> Use openfig to build `https://www.figma.com/design/…?node-id=12-345` as a Vue component.

The file given in `args` is the default for every tool. Frames can be referenced by **name** (`"Login"`),
**id** (`"12:345"`) or a **Figma URL** with `node-id`. Working with several files? Pass a folder
(`"${workspaceFolder}/designs"`) instead, and name the file in the prompt ("…from `designs/app.fig`").

### Other clients

<details><summary>Claude Desktop / Claude Code / Cursor / Windsurf</summary>

```json
{ "mcpServers": { "openfig": { "command": "npx", "args": ["-y", "openfig-mcp", "/absolute/path/to/design.fig"] } } }
```
Claude Code: `claude mcp add openfig -- npx -y openfig-mcp ./design.fig`
</details>

## Tools

| Tool | What the agent gets |
|---|---|
| `list_fig_files` | `.fig` files in the workspace |
| `list_frames` | pages → sections → screens / frames / component sets, with ids, sizes, prototype start points |
| `get_frame` | **the main tool.** Summary (fonts, components + variants, tokens, `:hover`/`:active` states, auto-playing animations, navigation & modals) **plus** an HTML + CSS reproduction. Writes an export folder (below) |
| `render_frame` | PNG image of any frame/node so the model can *see* it |
| `get_design_tokens` | color / text / effect styles **and Figma Variables (all modes, e.g. light/dark)** as CSS custom properties + typography classes, or JSON |
| `list_components` | components & variant sets with their properties (`State=Hover`, `Size=lg`…) and usage counts |
| `get_component` | every variant, the CSS diff between interactive states, HTML/CSS of the set |
| `search_nodes` | find layers by name or text ("Sign in", "price") |
| `get_prototype_flows` | flows and every click/hover/timer link between screens, overlays (modals), URLs |
| `export_svg` | any icon / logo / vector as SVG |

Plus an MCP prompt **`implement_frame`** (in VS Code: `/mcp.openfig.implement_frame`).

### What `get_frame` writes

```
figma-export/<frame>-<id>/
  DESIGN.md      summary: fonts, components, states, animations, links, modals
  index.html     HTML reproduction (flex where Figma used auto-layout, absolute elsewhere)
  styles.css     one class per unique style + :hover / :active rules from variant interactions
  tokens.css     CSS variables for the tokens this frame uses (styles + variables, per mode)
  spec.json      full tree: box, style, text runs, constraints, component/variant info, interactions
  preview.png    rendering of the frame
  assets/        SVG icons & vectors, images (png/jpg/gif/webp), masked groups as PNG
```

The inline response is budgeted (`maxChars`, default 40k): deep subtrees are collapsed with a pointer
to drill in (`get_frame` on a section id), and the full files are always on disk.

## What is extracted

| Figma | Output |
|---|---|
| Auto layout (direction, gap, padding, alignment, wrap, hug / fill / fixed, absolute children, margins) | `display:flex`, `gap`, `padding`, `justify-content`, `align-items`, `flex: 1`, `align-self`, `fit-content` |
| Frames without auto layout, constraints | absolute positioning (+ constraints in `spec.json`) |
| Fills: solid, linear/radial/angular gradients, images (fill/fit/tile/crop), multiple layers | `background` (stacked), `<img object-fit>` |
| Strokes (inside/center/outside, per-side, dashed), corner radii (per corner) | `outline`/`border-*`, `border-radius` |
| Effects: drop/inner shadow, layer & background blur | `box-shadow`, `text-shadow`, `filter`, `backdrop-filter` |
| Opacity, blend modes, clip content, scrolling frames | `opacity`, `mix-blend-mode`, `overflow` |
| Text: font, weight, size, line height, letter spacing, case, decoration, alignment, truncation, mixed-style runs, links | full typography, `<span>` runs, `<a>` |
| Color / text / effect styles, Figma Variables + modes | `var(--color-primary-600)`, `.ts-text-md-semibold`, `[data-theme="dark"]` blocks |
| Components, variants, instance overrides, component properties (text / boolean / instance swap) | resolved per instance; `data-component` / `data-variant` attributes |
| Prototype interactions, variants, states | see [Interactivity](#interactivity) |
| Vectors, icons, boolean ops, masks | SVG files (icons deduplicated), masked groups → PNG |
| Fonts | reported, not bundled: family, weights and styles of every font used, with a warning to add them to the project (and whether each is installed locally) |

Ids of nodes inside component instances use Figma's own format (`I<instance>;<child>`).

## Interactivity

Everything Figma's prototype model can express is extracted, and turned into CSS where CSS can express it:

| Figma | Output |
|---|---|
| **Triggers**: on click, while hovering, while pressing, mouse enter / leave / down / up, after delay, key press (key names, e.g. `Escape`), drag, video events | per element in `spec.json`, `data-on-click="…"` / `data-on-hover="…"` / `data-on-key="…"` attributes, and a plain-English list in the summary |
| **Navigate to** another frame, **back**, **scroll to** a layer (+ offset), **open URL** (new tab or not) | "click → navigates to "Checkout" (12:34) [smart animate 300ms ease-out]" |
| **Overlays / modals**: open, swap, close; position, backdrop color, close-on-outside-click | "click → opens overlay/modal "Share" — position center, closes on outside click, backdrop rgba(0,0,0,0.5)" |
| **Variant swaps** ("change to") | CSS diff between the two variants, plus exactly **which layers appear and disappear** (`shows "Dropdown menu"`, `hides "Badge"`) |
| **Variables**: set variable (with expressions like `!menuOpen`), set mode (theme / language), **conditionals** (if / else) | "click → sets menuOpen = !menuOpen → toggles visibility of "Dropdown menu" (hidden by default)" (layers whose visibility is bound to the variable are resolved) |
| **Pseudo-classes** | `:hover`, `:active` (from hover / press interactions, chains like Default → Hover → Pressed included) and, from variant naming (`State=Hover / Pressed / Focused / Disabled`, `Selected / Checked / Open = True`, `State=Error / Loading`): `:hover`, `:active`, `:focus-visible`, `:disabled` + `[aria-disabled]`, `[aria-selected]`, `:checked` + `[aria-checked]`, `[aria-expanded]`, `[aria-invalid]`, `[aria-busy]`. Layers hidden in the target state get `display: none`; layers that only exist in the target state are listed so they can be rendered conditionally |
| **Timers** (after delay → change variant) | grouped into auto-playing animations (carousels, marquees, loaders) with each step's delay, transition and easing |
| **Transitions** | type (instant, dissolve, slide/push/move in/out, smart animate), duration, easing as `cubic-bezier()` |
| **Scrolling**: scroll direction, fixed and sticky layers | `overflow`, `data-scroll="fixed|sticky"`, listed in the summary |
| **Prototype flows** | `get_prototype_flows`: starting points and every link between screens |

Hover and press states become CSS rules. Click toggles, key handlers, variables and conditionals are
described precisely (trigger, effect, timing) for the agent to implement in the app's framework.

## Fidelity

`npm run fidelity -- <file.fig>` lays every generated `index.html` out in a real browser and compares
each element's box with the layout **Figma stored in the file**, checks every text string and asset,
and computes SSIM against the rendered preview. Results on the 33 non-empty screens of a 134 MB
community file (8 interactive UI designs, 23k layers; 4,797 elements compared):

| Metric | Fonts as-is | Text boxes at Figma's size (`--pin-text`) |
|---|---|---|
| Elements within 8 px of Figma's position & size | 93.2 % (median screen 97.8 %) | **99.5 %** (median screen 100 %) |
| Elements within 2 px | 87.9 % | 99.5 % |
| Text strings present | 100 % | 100 % |
| Broken asset references (2,337 images / SVGs) | 0 | 0 |

**Why not 100 %?** The design uses fonts the test browser doesn't have (*Satoshi*, *Clash Display*,
*Zen Dots*). The fallback font has different glyph widths and line heights, so every text box that
hugs its content gets a different size, and that shifts its containers and siblings in auto-layout.
Pin the text boxes to the sizes Figma measured (`--pin-text`) and that whole category disappears:
99.5 % of elements land within 2 px. The remaining 0.5 % are a handful of rotated/skewed mockup layers
and masked decorative groups. With the design's real fonts installed in your app, you get the
right-hand column.

The metric is strict: an element counts as wrong if *any* of x, y, width or height is off, and one
mis-sized parent marks all its descendants as wrong too. See `examples/fidelity-report.md`.

## CLI

The same package is a CLI (handy for CI or a quick look):

```bash
npx -y openfig-mcp frames  design.fig                 # list frames
npx -y openfig-mcp export  design.fig "Login" -o out/  # export bundle
npx -y openfig-mcp render  design.fig 12:345 -o login.png
npx -y openfig-mcp tokens  design.fig [--json]
npx -y openfig-mcp components design.fig [query]
npx -y openfig-mcp search  design.fig "Sign in"
npx -y openfig-mcp flows   design.fig
```

## Library

```js
import { FigFile } from 'openfig-mcp';
const fig = await FigFile.open('design.fig');
fig.listFrames();                       // [{ id, name, kind, page, size, ... }]
const r = await fig.getFrame('Login', { outDir: 'out/login' });
r.summary; r.fullHtml; r.fullCss; r.spec; r.meta.states;
const { png } = await fig.render('12:345');
fig.tokens().css;
```

## Configuration

| Env var | |
|---|---|
| `OPENFIG_MCP_FONT_DIRS=dir1;dir2` | optional extra local font folders used for preview renders (`render_frame`, `preview.png`). Otherwise installed system fonts are used, with a common UI font as fallback |

## Fonts

openfig-mcp never downloads or bundles fonts. Providing them is the project's job. Every `get_frame` /
`render_frame` response lists the fonts the design needs (family, weights, styles) with a warning, and
says which ones aren't installed on the machine. Generated CSS uses `font-family: 'Family', sans-serif`.

## Limitations

- `.fig` is Figma's private format. openfig follows it closely, but a new Figma release can add fields
  before the parser knows them. Everything unknown is passed through to `spec.json` as-is.
- `render_frame` / `preview.png` come from openfig's renderer, not Figma: good for layout and color,
  but text uses installed fonts (or a fallback), and complex blend modes and some effects (noise, glass,
  progressive blur) are approximate.
- Components from **unpublished external libraries** only exist in the file as the copies Figma
  embeds (that is usually all that is needed).
- Smart-animate transitions are described (from/to state, duration, easing). The generated CSS
  covers hover/press states. Click toggles, carousels and page transitions are listed for the agent
  to implement in JS.
- Figma Variables support follows the file schema and is covered by tests with synthetic data. The
  sample community file uses styles, not variables.

## Development

```bash
npm install
npm test                                   # unit + end-to-end MCP tests (FIG_SAMPLE=/path/to.fig for the big ones)
npm run fidelity -- design.fig [frameId…]  # browser-based fidelity report (needs Edge/Chrome or CHROME_PATH)
```


## Releasing

CI (`.github/workflows/ci.yml`) runs the tests on Linux, Windows and macOS for every push and PR.
Publishing is tag-driven (`.github/workflows/release.yml`):

```bash
npm version patch        # or minor / major: bumps package.json, commits, creates tag vX.Y.Z
git push --follow-tags   # pushes main + the tag → CI tests, publishes to npm (with provenance), creates a GitHub release
```

The release job only publishes if the tag points at a commit on `main` and matches `package.json`'s version.
It authenticates with the `NPM_TOKEN` repository secret (an npm *granular access token* with
read/write access to `openfig-mcp`).

MIT. Figma is a trademark of Figma, Inc. This project is not affiliated with Figma.