# sonnylazuardi/cursor-talk-to-figma-mcp architecture

> Architecture diagram of the GitHub repository sonnylazuardi/cursor-talk-to-figma-mcp, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sonnylazuardi/cursor-talk-to-figma-mcp
- Repository: https://github.com/sonnylazuardi/cursor-talk-to-figma-mcp

## Overview

##### 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.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Figma Environment
    subgraph "Figma Environment"
        FP["Figma Plugin"]:::frontend
    end

    %% Communication Layer
    subgraph "Communication Layer"
        WS["WebSocket Server"]:::ws
    end

    %% Backend Services
    subgraph "Backend Services"
        MCP["MCP Server (TypeScript)"]:::server
    end

    %% Deployment & Configurations
    subgraph "Deployment & Configurations"
        DF["Dockerfile"]:::infra
        SS["Setup Script"]:::infra
        TC["Tsup Config"]:::infra
        RP["Root package.json"]:::infra
        MP["MCP package.json"]:::infra
        Bun["Bun (Runtime/Build Tool)"]:::infra
    end

    %% Data Flow Connections
    FP -->|"sends_command"| WS
    WS -->|"forwards_to"| MCP
    MCP -->|"sends_response"| WS
    WS -->|"returns_to"| FP

    %% Infrastructure relation (optional build dependency)
    Bun ---|"build_tool"| MCP
    Bun ---|"build_tool"| FP

    %% Click Events
    click FP "https://github.com/sonnylazuardi/cursor-talk-to-figma-mcp/tree/main/src/cursor_mcp_plugin"
    click MCP "https://github.com/sonnylazuardi/cursor-talk-to-figma-mcp/tree/main/src/talk_to_figma_mcp"
    click WS "https://github.com/sonnylazuardi/cursor-talk-to-figma-mcp/blob/main/src/socket.ts"
    click DF "https://github.com/sonnylazuardi/cursor-talk-to-figma-mcp/tree/main/Dockerfile"
    click SS "https://github.com/sonnylazuardi/cursor-talk-to-figma-mcp/blob/main/scripts/setup.sh"
    click TC "https://github.com/sonnylazuardi/cursor-talk-to-figma-mcp/blob/main/tsup.config.ts"
    click RP "https://github.com/sonnylazuardi/cursor-talk-to-figma-mcp/blob/main/package.json"
    click MP "https://github.com/sonnylazuardi/cursor-talk-to-figma-mcp/blob/main/src/talk_to_figma_mcp/package.json"

    %% Styles
    classDef frontend fill:#ADD8E6,stroke:#333,stroke-width:2px;
    classDef server fill:#FFB6C1,stroke:#333,stroke-width:2px;
    classDef ws fill:#FFFACD,stroke:#333,stroke-width:2px;
    classDef infra fill:#90EE90,stroke:#333,stroke-width:2px;
```
