How sonnylazuardi/cursor-talk-to-figma-mcp works
Project Overview and Purpose
• This project integrates Cursor AI with Figma using a Model Context Protocol (MCP). It consists of a Figma plugin, an MCP server (written in TypeScript) that handles Figma-related API calls and commands, and a WebSocket server that acts as a communication bridge between the MCP server and the Figma plugin.
• The primary goal is to enable programmatic design modifications and information retrieval from Figma directly through Cursor’s tools.
Main Components
• Figma Plugin:
• Located in the folder src/cursor_mcp_plugin.
• Contains files like code.js, manifest.json, ui.html, and setcharacters.js.
• Installed and executed within Figma’s development environment.
• MCP Server:
• Found in src/talk_to_figma_mcp.
• Implements the server-side logic (server.ts, configuration files like tsconfig.json, and its own package.json).
• Acts as the command processor for various design manipulation tasks, like creating, modifying, and querying nodes.
• WebSocket Server:
• The src/socket.ts file serves as the intermediary communication layer.
• Its role is to facilitate real-time, bidirectional communication between the Figma plugin and the MCP server.
• Supporting Infrastructure:
• Additional configuration and setup files (e.g., Dockerfile, scripts/setup.sh, tsup.config.ts) support deployment, builds, and environment setups.
• Package management with Bun (bun.lock and package.json files).
Relationships and Interactions
• The Figma plugin is loaded inside Figma and, once activated, connects to the WebSocket server.
• The WebSocket server (src/socket.ts) acts as the “messenger” channel for sending commands and responses between the plugin and the MCP server.
• The MCP server (src/talk_to_figma_mcp/server.ts) receives requests (commands) via the WebSocket connection, processes them, and then sends back instructions or data related to the Figma design document.
• The communication flow is typically:
Figma Plugin → WebSocket Server → MCP Server and, conversely, MCP Server → WebSocket Server → Figma Plugin.
Architectural Patterns and Important Technical Aspects
• Separation of Concerns – Each component has a specific responsibility (UI in Figma, logic in the MCP server, and communication in the WebSocket server).
• Real-time Communication – Utilizing a WebSocket server to enable asynchronous, bidirectional message passing.
• Extensibility – The plugin and MCP server are designed to support multiple commands (e.g., get_document_info, create_rectangle, etc.) that facilitate rich interactions with Figma.
• Dependency Integration – The project uses Bun for package management and possibly containerization (Dockerfile) for the deployment environment.