figma-files-mcp
by AmirShokry
README.md
# figma-files-mcp
A **read-only** local MCP server (and Node library) that gives Copilot, Claude, Cursor, or any MCP-capable agent
the design *as it is* in a Figma file. It uses only a **personal access token** and the public Figma REST API,
so no Dev seat or official Figma MCP is needed.
What an agent gets:
| Need | Tool | Cost |
|---|---|---|
| Pages, screens, sizes, flows at a glance | `figma_get_file_overview` | 1× Tier 1 the first time, then cached |
| Find layers by name / type / text | `figma_search_nodes` | free |
| Node tree + computed CSS per layer (+ raw Figma JSON) | `figma_get_node` | free |
| Exact CSS: flex/grid auto layout, sizing, constraints, gradients, borders, radius, shadows, blurs, blend modes, typography, truncation, scroll/sticky | `figma_get_css` | free |
| HTML + CSS for a whole screen or component (icons inlined as SVG, interactions as `data-on-*`) | `figma_get_code` | free |
| Text content with per-run styles, links, lists | `figma_get_text` | free |
| SVG for icons/vectors from Figma's own geometry | `figma_get_svg` | free |
| Color / text / effect / grid styles with resolved values | `figma_get_styles` | free |
| Design tokens (JSON or `:root` CSS vars, themes via variable modes) | `figma_get_design_tokens`, `figma_get_variables` | free + 1× Tier 2 per version |
| Fonts (families, weights, sizes, Google Fonts URLs), color palette | `figma_get_fonts`, `figma_get_colors` | free |
| Components, variants and properties | `figma_get_components` | free |
| **Hover / pressed / focus / disabled CSS from variants + transitions** | `figma_get_component_states` | free |
| **Prototype flows**: what happens on click/hover/…, destinations, overlays, animations (duration, easing, springs → CSS `linear()`) | `figma_get_prototype_flows`, `figma_get_interactions` | free |
| Original bitmap assets (photos) | `figma_get_image_fills` | 1× Tier 2 per version |
| Pixel renders PNG/JPG/SVG/PDF | `figma_export_images` | **1× Tier 1 per call** (batch ids) |
| Comments, Dev Mode links | `figma_get_comments`, `figma_get_dev_resources` | 1× Tier 2 per version |
| Quota usage + cache status | `figma_rate_limit_status` | free |
## Quick start (VS Code + GitHub Copilot, about 2 minutes)
You need [Node.js](https://nodejs.org) 20 or newer. Nothing to install: VS Code downloads the server with `npx` the first time it starts.
**1. Get a Figma access token** (works with a free View seat)
1. Open [figma.com](https://www.figma.com) → click your **avatar / name** (top-left) → **Settings** → **Security** tab.
2. Under **Personal access tokens**, click **Generate new token**.
3. Name it (e.g. `vscode-mcp`), pick an expiration, and under **Scopes** set **File content → Read-only**.
Optionally add **Comments → Read** and **Dev resources → Read**.
4. Click **Generate token** and **copy it now**. Figma shows it only once. It starts with `figd_`.
**2. Add the server to VS Code**
1. Press **Ctrl + Shift + P** (macOS: **Cmd + Shift + P**) and run **`MCP: Open User Configuration`**
(all your projects), or **`MCP: Open Workspace Folder Configuration`** (this project only, saved as `.vscode/mcp.json`).
2. Paste this, replacing `figd_your_token_here` with your token:
```json
{
"servers": {
"figma": {
"type": "stdio",
"command": "npx",
"args": ["-y", "figma-files-mcp"],
"env": { "FIGMA_TOKEN": "figd_your_token_here" }
}
}
}
```
If the file already has a `"servers"` block, add just the `"figma": { … }` entry inside it.
3. Save. Click **Start** above `"figma"` in the file, or run **`MCP: List Servers`** → **figma** → **Start Server**.
**3. Use it**
> **Keep the token private.** If you used the workspace configuration, add `.vscode/mcp.json` to `.gitignore`.
> Alternatively, keep the token out of the file entirely: let VS Code prompt for it
> (`"env": { "FIGMA_TOKEN": "${input:figma-token}" }`, see [Setup](#setup-2-steps)), or run `npx -y figma-files-mcp login` once and drop the `env` line.
Other editors (Cursor, Claude Code, Claude Desktop, Windsurf) are covered in [Setup](#setup-2-steps).
## Why it's built this way: Figma's rate limits
Since Nov 2025 Figma meters REST calls per token owner and plan.
On **View/Collab seats, Tier 1 endpoints (GET file, GET nodes, GET image renders) allow only "up to 20 per month"**
(6 on Starter-plan files). Dev/Full seats get 10–20/min. Tier 2: 5/min vs 25–100/min. Tier 3: 10/min vs 50–150/min.
So this server:
1. Downloads each file **once per version** (`GET /v1/files/:key?geometry=paths`, 1 Tier 1 call) and keeps it on disk
(`~/.figma-files-mcp/cache`). Every process and session shares the cache.
2. Derives **everything else locally** from that JSON: CSS, HTML, SVG (from vector geometry), tokens, states, flows.
3. Checks freshness with the cheap Tier 3 `/meta` endpoint (at most every `FIGMA_FRESHNESS_TTL_SEC`, default 600 s)
and re-downloads only when the version changed. Concurrent requests share one download.
4. Throttles client-side per tier (sliding window), honours `Retry-After` on 429s up to `FIGMA_MAX_RETRY_WAIT_SEC`,
and **fails fast** with an actionable message (Retry-After in days, plan tier, seat type, upgrade link) instead of looping.
5. Persists a **usage ledger** of every real API call, so agents and you can see what was spent (`figma_rate_limit_status`).
6. Caches Tier 2 results (image fill URLs, variables, comments) and Tier 1 renders per file version.
7. Optional hard cap: `FIGMA_TIER1_MONTHLY_BUDGET=15` refuses Tier 1 calls past that count in a rolling 30 days.
Agents are told all of this through the MCP server `instructions`, each tool's description (which states its cost),
and [AGENTS.md](AGENTS.md).
## Setup (2 steps)
This is **not a Figma plugin**: nothing is installed inside Figma. Figma only issues the access token, and the server
runs on your machine, launched by your editor.
**1. Get a token.** In Figma: avatar menu → **Settings → Security → Personal access tokens → Generate new token**,
with scope **File content: Read** (optionally *Comments: Read*, *Dev resources: Read*). Copy it (it starts with `figd_`).
**2. Save it once** (validated against Figma, stored in `~/.figma-files-mcp/config.json`, readable only by you):
```bash
npx -y figma-files-mcp login # prompts for the token
# or: npm i -g figma-files-mcp && figma-files-mcp login
figma-files-mcp status # shows account, token source, cache and API usage
```
Then add the server to your editor. **No path, args or token are needed:**
**VS Code / GitHub Copilot**: `.vscode/mcp.json` (workspace) or the user-level `mcp.json`:
```json
{ "servers": { "figma": { "type": "stdio", "command": "npx", "args": ["-y", "figma-files-mcp"] } } }
```
or, after `npm i -g figma-files-mcp`, simply `{ "servers": { "figma": { "type": "stdio", "command": "figma-files-mcp" } } }`.
**Claude Code**
```bash
claude mcp add figma -- npx -y figma-files-mcp # Windows: claude mcp add figma -- cmd /c npx -y figma-files-mcp
```
**Cursor / Windsurf / Claude Desktop** (`mcp.json` / `claude_desktop_config.json`)
```json
{ "mcpServers": { "figma": { "command": "npx", "args": ["-y", "figma-files-mcp"] } } }
```
### Where the token can come from (first match wins)
1. `--token figd_…` in the server args (optional)
2. `FIGMA_TOKEN` env var, e.g. in the editor config's `"env": { "FIGMA_TOKEN": "…" }`. Useful for per-project
tokens or CI. VS Code can prompt for it securely:
```json
{ "inputs": [{ "type": "promptString", "id": "figma-token", "description": "Figma token", "password": true }],
"servers": { "figma": { "type": "stdio", "command": "npx", "args": ["-y", "figma-files-mcp"], "env": { "FIGMA_TOKEN": "${input:figma-token}" } } } }
```
3. The saved login (`figma-files-mcp login`). It is re-read on every request, so logging in, switching accounts, or
`figma-files-mcp logout` takes effect without restarting the editor.
Without any token the server still starts, and every tool answers with these setup instructions.
### Environment variables
| Variable | Default | Meaning |
|---|---|---|
| `FIGMA_TOKEN` (or `FIGMA_ACCESS_TOKEN`) | – | Personal access token (optional if you ran `login`) |
| `FIGMA_MCP_HOME` | `~/.figma-files-mcp` | Config, cache and assets root |
| `FIGMA_SEAT_TYPE` | `low` | `low` = View/Collab limits, `high` = Dev/Full limits (sets client throttling defaults) |
| `FIGMA_RATE_TIER{1,2,3}_PER_MIN` | 3 / 5 / 10 (low), 10 / 25 / 50 (high) | Client-side per-minute caps |
| `FIGMA_TIER1_MONTHLY_BUDGET` | `0` (off) | Hard cap on Tier 1 calls per rolling 30 days |
| `FIGMA_MAX_RETRY_WAIT_SEC` | `90` | Longest Retry-After the server will sleep through; longer means fail fast |
| `FIGMA_MAX_RETRIES` | `4` | Retries for 429 / 5xx / network errors |
| `FIGMA_FRESHNESS_TTL_SEC` | `600` | How often a cached file's version is re-checked (Tier 3) |
| `FIGMA_CACHE_DIR` | `~/.figma-files-mcp/cache` | File JSON + ledger + Tier 2 caches |
| `FIGMA_ASSETS_DIR` | `~/.figma-files-mcp/assets` | Downloaded image fills and renders |
| `FIGMA_MCP_MAX_OUTPUT_CHARS` | `120000` | Hard cap per tool response (tools also budget themselves) |
| `FIGMA_MCP_QUIET` | – | `1` silences the stderr request log |
## Library use
```ts
import { FigmaDesign } from "figma-files-mcp";
const figma = new FigmaDesign(); // token: FIGMA_TOKEN env or saved login; or pass { token }
const url = "https://www.figma.com/design/KEY/Name?node-id=12-345";
const { html, css } = await figma.code(url, "12:345");
const tokensCss = (await figma.tokens(url, "css")).css;
const states = await figma.componentStates(url, "1:10");
const flows = await figma.flows(url);
```
Lower-level pieces are exported too: `nodeToCss`, `nodeToSvg`, `generateCode`, `prototypeFlows`, `componentStates`,
`resolveStyles`, `FigmaApi` (rate-limited client), `FileStore`, `UsageLedger`, ...
## Fidelity: how it was verified
The data itself is exact: tools return Figma's own values (and `figma_get_node format: "raw"` returns the untouched
JSON). What is measured here is the *translation* of that data into SVG and HTML/CSS.
`test/visual/compare.mjs` renders nodes three ways and diffs them pixel by pixel at 2×: Figma's own renderer
(`/v1/images`), this server's local SVG, and its generated HTML/CSS in headless Chrome. Text areas are reported
separately: glyph rasterisation differs between any browser and Figma (different font engines and font builds),
so text can match in every value but never in every antialiased pixel. Everything else (geometry, layout, colors,
gradients, strokes, masks, effects) should be exact.
| file | output | mismatch outside text (mean) | nodes at 0 px |
|---|---|---|---|
| Pomo prototype (846 auto-layout frames, variants, flows) | local SVG | **0.001 %** (≤ 5 px per node) | 11 / 14 |
| | HTML/CSS | **0.45 %** | 7 / 14 |
| Figma "UI2" design system (vectors, booleans, masks, tiled images, blend modes) | local SVG | **0.24 %** | 15 / 20 |
| | HTML/CSS | **0.17 %** | 16 / 20 |
Full 1512×982 screens: 0 px outside text as SVG, 0.012 % as HTML. The remaining HTML differences come from
hug-sized boxes around text: when the browser's font renders a word 1–2 px wider than Figma's, the box grows by the
same amount. Open `test/fixtures/visual-report*/report.html` after a run for side-by-side images and diffs.
Run the suites:
```bash
npm test # unit tests (synthetic Figma JSON + mock API)
FIGMA_TOKEN=... node test/mcp-e2e.mjs <file-url> # every MCP tool over stdio (uses the cache)
# visual: Figma's reference renders aren't committed (they're renders of third-party files);
# fetch them once (1 Tier 1 call per fixture file), then compare as often as you like (free)
FIGMA_TOKEN=... node test/visual/render-fixtures.mjs test/fixtures/ui2-nodes.json test/fixtures/ui2-renders
FIGMA_TOKEN=... node test/visual/compare.mjs test/fixtures/ui2-nodes.json test/fixtures/ui2-renders
```
The visual compare needs `npm i` (dev deps: puppeteer-core, pngjs, pixelmatch) and a local Chrome or Edge.
## Known limitations (REST API / web platform)
* **Variables** (names, collections, modes) are REST-accessible only on Enterprise plans. Elsewhere you get each
binding with the value Figma resolved, plus the frames that switch modes, but not variable names.
* **Text in SVG** is emitted as `<text>`, because REST geometry has no glyph outlines. Use `figma_export_images` with
`format: "svg", svgOutlineText: true` (Tier 1) for outlined text.
* CSS has no equivalent for diamond gradients, corner smoothing (squircles), noise/texture/glass effects, progressive
blur or Figma image filters. These are flagged in `notes`, and the SVG path covers most of them.
* Dev Mode annotations and measurements are not exposed by the REST API.
* Smart Animate is described as transition type + duration + easing + "match layers". Implementing the layer
matching (e.g. FLIP) is up to the app.
* Main components of **remote library** instances live in the library file. Pass that file to analyse its variants.
## Releasing
Releases are automated by `.github/workflows/release.yml`. From an up-to-date `master`:
```bash
npm version patch # or minor / major: bumps package.json, commits, creates tag vX.Y.Z
git push --follow-tags # pushes master + the tag; GitHub Actions builds, tests and publishes to npm
```
The workflow refuses tags that aren't on `master` or don't match `package.json`, skips versions already on npm,
publishes with provenance, and creates a GitHub Release with generated notes. CI (`ci.yml`) runs the build and
tests on Linux and Windows for Node 20/22/24 on every push and pull request.
npm authentication uses **Trusted Publishing** (OIDC, no stored token). It is a one-time setup by the package owner,
either from the CLI (npm ≥ 11.10; it asks you to approve in the browser):
```bash
npx -y npm@latest trust github figma-files-mcp --file release.yml --repo AmirShokry/figma-files-mcp --env npm --allow-publish --yes
```
or on npmjs.com → package **figma-files-mcp** → **Settings** → **Trusted Publisher** → **GitHub Actions**: owner
`AmirShokry`, repository `figma-files-mcp`, workflow `release.yml`, environment `npm`.
npm is phasing out "bypass 2FA" tokens for publishing, so prefer Trusted Publishing over an `NPM_TOKEN` secret.
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessNo recent community issues