Overview
Talk to Figma MCP uses a three-component pipeline architecture to enable seamless communication between AI agents (like Claude Code or Cursor) and Figma designs. This architecture ensures reliable, real-time interaction with Figma while maintaining the MCP protocol standard.Architecture Diagram
MCP Server
Protocol handler that exposes 50+ tools to AI agents
WebSocket Relay
Message router with channel-based isolation
Figma Plugin
In-canvas executor that modifies designs
MCP Server
The MCP server (src/talk_to_figma_mcp/server.ts) is the protocol adapter between AI agents and Figma. It implements the Model Context Protocol using @modelcontextprotocol/sdk.
Key Responsibilities
- Tool Registration: Exposes 50+ tools for creating shapes, modifying text, managing layouts, exporting images, and more
- Prompt Strategies: Provides AI prompts for design best practices and workflows
- Request Management: Tracks all outgoing requests with UUIDs in a
pendingRequestsMap - Timeout Handling: Manages 30-second timeouts with progress update support
- Protocol Translation: Converts MCP tool calls into WebSocket messages
Communication Flow
1
AI Agent sends tool request
The agent calls a tool like
create_frame() via stdio2
Server validates parameters
Zod schemas validate all input parameters
3
Server generates UUID
A unique request ID is created using
uuidv4()4
Server sends WebSocket message
The request is forwarded to the WebSocket relay
5
Server awaits response
The promise is stored in
pendingRequests with timeout callbacksCode Example: Request Lifecycle
server.ts
Transport Layer
The MCP server uses stdio transport to communicate with AI agents:server.ts
WebSocket Relay
The WebSocket relay (src/socket.ts) is a lightweight Bun-powered router that enables channel-based message isolation between multiple MCP servers and Figma plugins.
Why a Relay?
The relay solves a critical architectural challenge:- MCP servers communicate via stdio and need WebSocket connectivity
- Multiple users may run servers simultaneously on the same machine
- Channel isolation prevents messages from crossing between different sessions
Channel-Based Routing
Clients must join a channel before sending messages:socket.ts
socket.ts
Server Configuration
The relay runs on port 3055 by default (configurable viaPORT env):
socket.ts
Start the relay with
bun socket before connecting MCP servers or Figma plugins.Figma Plugin
The Figma plugin (src/cursor_mcp_plugin/) runs inside Figma and executes design modifications in response to commands from the MCP server.
Plugin Components
code.js - Main Thread
code.js - Main Thread
The plugin main thread handles 30+ commands via a dispatcher pattern. It processes requests like
create_frame, set_text_content, export_node_as_image, etc.No build step required — code.js is written directly as the runtime artifact.ui.html - Plugin UI
ui.html - Plugin UI
The plugin UI provides WebSocket connection management, allowing users to:
- Connect to the relay server
- Join channels
- Monitor connection status
manifest.json - Permissions
manifest.json - Permissions
Declares required permissions:
dynamic-pageaccess for document manipulationlocalhostnetwork access for WebSocket connections
Command Execution
The plugin receives commands via WebSocket and executes them using Figma’s Plugin API:code.js
Message Flow Example
Here’s how a complete request flows through the pipeline:1
AI Agent calls tool
2
MCP Server receives via stdio
Server validates parameters with Zod schema, generates UUID
abc-1233
MCP Server sends to relay
4
Relay broadcasts to channel
Relay forwards message to all clients in
my-channel except the sender5
Figma Plugin receives and executes
Plugin creates the frame using Figma API and sends response
6
Response flows back
7
MCP Server resolves promise
Server finds pending request by ID, clears timeout, resolves promise
8
AI Agent receives result
Key Design Patterns
Request Tracking
All requests are tracked in a Map with timeout and promise callbacks:server.ts
Progress Updates
For long-running operations (like scanning 100+ nodes), the plugin sends progress updates that reset the inactivity timer:server.ts
Auto-Reconnection
The MCP server automatically reconnects to the relay if the connection drops:server.ts
Next Steps
Channel Communication
Learn how channel-based isolation works
WebSocket Relay
Deep dive into relay server details