
Localfig
io.github.LucasGorgal由 GitHub 账号 LucasGorgal 发布v0.4.1更新于 Oct 24, 2026
The Figma desktop app as an MCP server: full Plugin API for AI agents. Local, no token, no quota.
概览
Localfig 通过本地插件桥接把 Figma 桌面应用开放给 AI 助手,可对当前打开的文件进行完整的 Plugin API 读写操作。
- 可以做什么
- 检查插件连接状态、当前文件、页面、选区与顶层画框,并通过文本、自动布局、令牌和组件等辅助函数在打开的文件中执行任意 Plugin API JavaScript。查看结构:带样式、绑定变量和计算 CSS 的元数据导出,以及变量集合、颜色、文本和效果样式。跨页面按类型、图层名和文本搜索,查看自上次调用以来的变更,保存命名快照并撤销上一次工具调用。使用团队库:列出变量、导入组件、样式和变量并放置实例。将节点导出为 PNG、JPG、SVG、PDF 或 JSON,并把本地图片放入填充。
- 适用场景
- 适合需要助手在桌面应用中读取、编辑或生成真实 Figma 设计的场景,且不想使用云端令牌,例如基于现有设计系统构建、提取令牌和元数据用于代码交付,或导出渲染图和素材。
- 运行要求
- 需要 Node.js 18 或更高版本、Figma 桌面应用(浏览器中无法导入开发插件),以及能启动 stdio 服务器的 MCP 客户端。安装会把插件写入本地文件夹,需在 Figma 中导入一次;每次会话都要运行插件并保持面板打开。可选环境变量可设置主目录、桥接端口和导出目录。
安装
在 SourceWeft 中
- 打开 控制台中的 Localfig,将其添加到工作区。
- 为需要使用其工具的对话启用该服务。
Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。
其他 MCP 客户端
参照 仓库 中的启动说明。
README
localfig
The Figma desktop app as an MCP server. localfig gives an AI agent the full Figma Plugin API on the file you have open — through a tiny dev plugin and a loopback HTTP bridge, entirely on your machine.
- Reads and writes. Frames, text, auto-layout, variables, components, image fills, exports, undo — anything the Plugin API can do, the agent can do.
- No Figma cloud API, no personal access token, no per-account quota.
- Zero dependencies. Node built-ins only. Nothing leaves your machine.
- Works with any MCP client that can launch a stdio server: Claude Code, Cursor, Windsurf, Cline, Claude Desktop and more.
Why localfig
Requirements
- Node.js 18 or newer
- The Figma desktop app — dev plugins cannot be imported in the browser
- An MCP client: Claude Code, Cursor, Windsurf, Cline, Claude Desktop, …
Install (once)
That generates your local secret, writes the plugin to ~/.localfig/plugin/, registers localfig with every MCP client it finds on your machine, and prints the manifest path for the next step. --dry-run shows what it would do without touching anything, and --clients=cursor,vscode limits it to the clients you name. Prefer a clone? git clone https://github.com/LucasGorgal/localfig.git && cd localfig && node server.mjs --setup does the same.
A client counts as installed when its config folder exists. Setup merges into existing files instead of replacing them: other servers and settings stay, an existing localfig entry keeps its env, and a .localfig.bak copy is written before any change. Files it cannot safely rewrite, such as a settings.json with comments, are left untouched and reported with the entry to paste. Restart any client that was already open.
For a client that is not in the list, add this to its MCP configuration:
On Windows, use "command": "cmd", "args": ["/c", "npx", "-y", "localfig"] instead: most clients start servers without a shell, and npx is a .cmd script there.
Then import the plugin into Figma (once):
- Open any design file in the desktop app. The Plugins menu only exists inside a file, not on the home screen.
- Figma menu (the logo, top-left) → Plugins → Development → Import plugin from manifest… — or press
Ctrl/(Cmd/) and type import plugin from manifest. - Pick
~/.localfig/plugin/manifest.json(the setup output prints the full path).
The manifest asks for two permissions — teamlibrary (library components and tokens) and currentuser (who is driving) — and registers a relaunch button.
Use (every session)
- Open the file you want to work on.
- Run the plugin:
Ctrl/→ localfig — orCtrlAltP(CmdOptP) to re-run the last plugin, or the Reconnect localfig button in the properties panel of a file it has run in. A small panel appears and says Connected to localfig once the MCP server is up. Leave it open. - Ask your agent to do Figma work. Every tool acts on the file where the plugin is running — there is no file key, which is why nothing touches the cloud.
Closing the panel (or the file) disconnects; re-run the plugin to reconnect. This is the one manual step: Figma provides no way to launch a plugin from outside.
Tools
figma_eval environment
Code runs inside the plugin sandbox, wrapped in an async function: top-level await and return both work.
Globals: figma and helpers.
helpers.createText({characters, font: {family, style}, fontSize, color: '#hex', width, lineHeight, letterSpacing, textCase, textAlign, name, parent, x, y})— loads the font and ordersresize()beforetextAutoResize.helpers.setText(node, chars)— loads the node's real fonts, then sets characters.helpers.loadNodeFonts(node).helpers.set(node, props)— batch assign;layoutModefirst,width/heightviaresize, sizing modes after.helpers.rgb('#rrggbb'),helpers.rgba('#rrggbbaa')— hex to the{r, g, b[, a]}fills want.helpers.reveal(nodes)— scroll and zoom the viewport to what you just made.helpers.notify(msg)— a toast.helpers.collection(name, [modes]),helpers.token(collection, name, type, value | {mode: value}),helpers.bind(node, 'fills' | 'strokes' | prop, variable)— create design tokens and bind properties to them, one line each.helpers.importComponent(key),helpers.instance(key, parent, props)— team-library components.helpers.query(root, sel)— minimal selectors:TEXT,[name=X],[name*=X],A B,a, b.helpers.createAutoLayout(dir, props).helpers.command(kind, payload)— run any typed command (tokens,metadata,find,changes,export…) from inside a script:(await helpers.command('tokens', { collection: 'Brand' })).result.
Plugin API gotchas the helpers protect you from
resize()on a TEXT node resetstextAutoResizetoNONE; on an auto-layout frame it sets both sizing modes toFIXED. Resize first, then set the sizing.- Return plain data from
figma_eval. Real Figma nodes are collapsed to{id, name, type}so a stray node reference cannot flood the result — usefigma_metadatato inspect a subtree. - Load fonts before any text mutation.
figma.notify()works here (the cloud MCP blocks it).
Design-system awareness
figma_tokens returns the file's variables the way a design system thinks about them:
figma_metadata with styles: true then reports, per node, boundVariables (which token drives each property), fillStyle / textStyle / effectStyle names, and for instances the main component and its componentProperties; css: true adds the CSS Figma computes for each node. Together they let an agent build on a design system instead of hard-coding values — and hand code off from a real file.
Images
- In:
figma_place_imagesends the file's bytes to the plugin UI, which is a full Chromium iframe. It decodes any browser-supported format, downscales tomaxSide(default 4096, Figma's hard limit) with high-quality smoothing, converts non-native formats to PNG, and hands the result to the main thread. The tool result reports what happened (prepared). - Out:
figma_exportwrites files to~/.localfig/exports/and attaches PNG/JPG (≤ 2 MB each) to the result as images, so the agent sees the render without another call.JSONexports the subtree in Figma REST API shape.
Undo, versions and change tracking
Every mutating tool call is checkpointed with figma.commitUndo, so it lands in the file's undo history as one step a person can Ctrl+Z (the most recent call is committed 60 s after it finishes, or at the next call). Within that window figma_history {action: "undo"} reverts the last call from the agent side — triggerUndo reverts to the last checkpoint — and {action: "snapshot"} saves a named version before risky edits. The plugin also records node changes on every page it has seen (Figma delivers them batched, after the fact): figma_changes returns what changed since a seq, with edits caused by tool calls tagged byPlugin by a time-window heuristic and hidden by default — the agent can notice what the person changed in Figma between calls instead of overwriting it.
Multiple sessions
The first localfig process owns the bridge port; later ones detect it via /health, run as clients, and proxy through it — same tools either way. If the owner dies, the next tool call on a client re-binds the port and takes over ("re-election" in the log); the plugin re-registers when it reconnects.
Files and configuration
node server.mjs --help lists the flags.
Security
The bridge binds loopback only (127.0.0.1 and ::1). Every endpoint except /health requires a 32-hex secret generated on first run into ~/.localfig/token and baked into ~/.localfig/plugin/ui.html. Edit plugin/ui.template.html in the package, never the generated ui.html. Nothing is sent to any server.
Design notes
- Why a plugin? It is the only local surface with full read/write access to an open Figma document. The REST API is cloud, needs a token, and cannot write nodes.
- Why HTTP long-poll and not WebSocket? The plugin main thread has no network at all; only the UI iframe does. Long-poll needs no dependency and no framing code, and
http://localhostis exempt from mixed-content blocking. Figma's manifest validator rejects raw IPs innetworkAccess, hencelocalhost— and the IPv6 mirror listener, because Windows resolveslocalhostto::1first. - Binary stays binary on the plugin channel. Exports leave as
POST /blob; images enter viaGET /assetinto aUint8Array. Only JSON goes through the command channel. (Renders are base64-encoded once, in the MCP result, where the protocol requires it.) - Why a home directory? The package may live in the npx cache or a read-only global install; the plugin folder you import must not move when the package updates, and per-user state must not live in a package.
Platform notes
Developed and tested on Windows 11 with the Figma desktop app. macOS and Linux should work unchanged — Node built-ins only, no native code — but have not been exercised yet. Reports and fixes welcome.
Test
Spawns the server in an isolated home, speaks MCP over stdio, and impersonates the plugin over HTTP — covering the handshake, all ten tools, file round-trips, inline images, owner re-election, and setup against sandboxed MCP client configs, without Figma running. 55 assertions.
Layout
License
MIT — see LICENSE.
来源:README.md,提交 0242238
工具
0版本历史
1- v0.4.1最新Sep 16, 2026
评分
已满足适用检查项的 50%
该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。
- 近 30 天内可连通25 分
请保持端点能够响应 MCP 握手;SourceWeft 每 30 天探测一次。
- 已声明认证方式10 分
请在注册中心条目中声明凭据请求头,或保持端点能够响应探测,以便判定其认证方式。
- 已列出工具15 分
请让服务器在无凭据时响应 tools/list,或发布可在沙箱中无凭据启动的软件包。
- 描述必需15 分
- 图标10 分
- 文档15 分
- 许可证10 分