Architecture
This document explains how Figma Agent Kit is structured: packages, runtime roles, data paths, and design principles.
Goals
- Let AI agents (Cursor, Claude Code, Codex, …) read and write the Figma file currently open in Figma Desktop
- Keep canvas traffic on localhost — no Figma REST upload of the document for bridge tools
- Support multiple MCP clients at once via Leader / Follower election on a single bridge port
- Ship an optional in-plugin AI path (rename / group) that is independent of MCP credentials
Monorepo layout
Versions are kept in lockstep (0.1.x). Prefer pnpm release:kit:* over releasing only one side.
System overview
End-to-end:
- The agent talks MCP over stdio to a
figma-agent-mcpprocess. - That process is either the Leader (binds
localhost:PORT) or a Follower (forwards to the Leader). - The plugin UI iframe opens a WebSocket to the Leader and speaks MessagePack.
- The UI forwards RPC to the plugin main thread, which calls the Figma Plugin API (
documentAccess: dynamic-page).
Tech stack
Module map (MCP)
Module map (plugin)
Leader / Follower election
Multiple agent windows often spawn multiple MCP processes. Only one process may bind the bridge port.
- Leader: binds port, accepts plugin sockets, serves discovery + RPC.
- Follower: every tool call →
POST /rpc(MsgPack) on the Leader;list_files→GET /files. - Health poll (~3–5s): if Leader dies, a Follower retries election and may take over.
RPC path (tool call)
Important details:
- Wire tool name may appear as
typeortool. - Screenshot
datais raw PNG bytes on the bridge (MsgPackbin), not base64. - Logs go to stderr only — stdout is reserved for MCP stdio.
Screenshot & slice export paths
Two AI paths
MCP bridge tools never need an LLM API key. Optional rename/group AI runs only inside the plugin UI.
Port configuration
- Edit root
bridge.config.json(defaultPort). - Run
pnpm sync:bridge(also runs onpredev/prebuild). - Rebuild the plugin and restart MCP.
Runtime override for MCP only: FIGMA_AGENT_MCP_PORT — must match the port baked into the plugin manifest / UI.
Principles
- Local-first — bridge traffic stays on
localhost; design data is not uploaded for MCP tools. - MsgPack on the hot path — WS + follower RPC; small discovery endpoints stay JSON.
- Stdout purity — never print diagnostics on stdout in the MCP process.
- Async node lookup —
dynamic-pageplugins usefigma.getNodeByIdAsync. - Co-versioned releases — upgrade plugin + MCP together after protocol changes.
- Capability honesty — Motion tools require a Figma build that exposes motion APIs; otherwise return a clear error.
Further reading
- Bridge protocol — wire formats and endpoints
- MCP tools — full tool catalog
- Getting started — install and connect
- FAQ — common failure modes
