figma-ui-mcp-bridge

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Figma UI MCP Bridge

Figma UI MCP Bridge

Skill by ara.so — Design Skills collection
Bidirectional MCP bridge between AI assistants and Figma Desktop. Let Claude Code, Cursor, Windsurf, VS Code Copilot, or any MCP-compatible IDE draw UI directly on Figma canvas via JavaScript and read existing designs back as structured data, screenshots, or code-ready tokens. Works entirely over localhost — no Figma API key required.
Requires Figma Desktop (web app cannot access localhost).
ara.so开发的Skill——设计技能合集
AI助手与Figma Desktop之间的双向MCP桥接工具。让Claude Code、Cursor、Windsurf、VS Code Copilot或任何兼容MCP的IDE,通过JavaScript直接在Figma画布上绘制UI,并将现有设计以结构化数据、截图或可直接用于代码的设计令牌形式读取返回。全程通过localhost运行——无需Figma API密钥。
需使用Figma Desktop(网页版无法访问localhost)。

Architecture

架构

AI Agent ─figma_write─▶ MCP Server ─HTTP (localhost:38451)─▶ Figma Plugin ─▶ Figma Document
AI Agent ◀figma_read──── MCP Server ◀HTTP (localhost:38451)─ Figma Plugin ◀─ Figma Document
The MCP server starts an HTTP server on
localhost:38451
. The Figma plugin uses long polling (8s hold, <100ms latency). Multi-instance support — multiple Figma files can connect simultaneously via
sessionId
.
AI Agent ─figma_write─▶ MCP Server ─HTTP (localhost:38451)─▶ Figma Plugin ─▶ Figma Document
AI Agent ◀figma_read──── MCP Server ◀HTTP (localhost:38451)─ Figma Plugin ◀─ Figma Document
MCP服务器会在
localhost:38451
启动HTTP服务。Figma插件使用长轮询机制(8秒保持,延迟<100ms)。支持多实例——多个Figma文件可通过
sessionId
同时连接。

Installation

安装

Step 1: Add MCP Server

步骤1:添加MCP Server

Claude Code (CLI):
bash
undefined
Claude Code(CLI):
bash
undefined

Project scope

项目范围

claude mcp add figma-ui-mcp -- npx figma-ui-mcp
claude mcp add figma-ui-mcp -- npx figma-ui-mcp

Global scope

全局范围

claude mcp add --scope user figma-ui-mcp -- npx figma-ui-mcp

**Claude Desktop:**
Edit `~/Library/Application Support/Claude/claude_desktop_config.json` (macOS) or `%APPDATA%\Claude\claude_desktop_config.json` (Windows):
```json
{
  "mcpServers": {
    "figma": {
      "command": "npx",
      "args": ["-y", "figma-ui-mcp"]
    }
  }
}
Cursor: Edit
.cursor/mcp.json
(project) or
~/.cursor/mcp.json
(global):
json
{
  "mcpServers": {
    "figma": {
      "command": "npx",
      "args": ["-y", "figma-ui-mcp"]
    }
  }
}
VS Code / Copilot: Edit
.vscode/mcp.json
:
json
{
  "mcp": {
    "servers": {
      "figma": {
        "command": "npx",
        "args": ["-y", "figma-ui-mcp"]
      }
    }
  }
}
Windsurf: Edit
~/.codeium/windsurf/mcp_config.json
:
json
{
  "mcpServers": {
    "figma": {
      "command": "npx",
      "args": ["-y", "figma-ui-mcp"]
    }
  }
}
⚠️ MUST restart IDE/AI client after adding MCP server (quit and reopen — saving config is not enough).
claude mcp add --scope user figma-ui-mcp -- npx figma-ui-mcp

**Claude Desktop:**
编辑`~/Library/Application Support/Claude/claude_desktop_config.json`(macOS)或`%APPDATA%\Claude\claude_desktop_config.json`(Windows):
```json
{
  "mcpServers": {
    "figma": {
      "command": "npx",
      "args": ["-y", "figma-ui-mcp"]
    }
  }
}
Cursor: 编辑
.cursor/mcp.json
(项目级)或
~/.cursor/mcp.json
(全局级):
json
{
  "mcpServers": {
    "figma": {
      "command": "npx",
      "args": ["-y", "figma-ui-mcp"]
    }
  }
}
VS Code / Copilot: 编辑
.vscode/mcp.json
json
{
  "mcp": {
    "servers": {
      "figma": {
        "command": "npx",
        "args": ["-y", "figma-ui-mcp"]
      }
    }
  }
}
Windsurf: 编辑
~/.codeium/windsurf/mcp_config.json
json
{
  "mcpServers": {
    "figma": {
      "command": "npx",
      "args": ["-y", "figma-ui-mcp"]
    }
  }
}
⚠️ 添加MCP服务器后必须重启IDE/AI客户端(退出并重新打开——仅保存配置无效)。

Step 2: Install Figma Plugin

步骤2:安装Figma插件

  1. Download
    plugin.zip
    from https://github.com/TranHoaiHung/figma-ui-mcp/raw/main/plugin.zip
  2. Unzip anywhere on your machine
  3. Open Figma Desktop (required)
  4. Plugins → Development → Import plugin from manifest...
  5. Select
    manifest.json
    from unzipped folder
  6. Run Plugins → Development → Figma UI MCP Bridge
Green dot = connected. Orange = server not reachable.
  1. https://github.com/TranHoaiHung/figma-ui-mcp/raw/main/plugin.zip下载`plugin.zip`
  2. 将压缩包解压到任意位置
  3. 打开Figma Desktop(必须使用桌面版)
  4. 依次点击插件 → 开发 → 从清单导入插件...
  5. 选择解压文件夹中的
    manifest.json
  6. 运行插件 → 开发 → Figma UI MCP Bridge
绿色圆点表示已连接,橙色圆点表示无法连接到服务器。

Step 3: Verify Connection

步骤3:验证连接

javascript
// AI will call this automatically when you say "connect to Figma"
figma_status()
// Returns: { status: "ok", fileName, pageName, pluginVersion, sessions: [...] }
javascript
// 当你说"连接到Figma"时,AI会自动调用此函数
figma_status()
// 返回结果: { status: "ok", fileName, pageName, pluginVersion, sessions: [...] }

Core MCP Tools

核心MCP工具

figma_status

figma_status

Check connection status and list active sessions.
javascript
figma_status()
// Response:
// {
//   status: "ok",
//   fileName: "My Project",
//   pageName: "Page 1",
//   pluginVersion: "2.5.12",
//   sessions: [
//     { sessionId: "abc123", fileName: "My Project", pageName: "Page 1" }
//   ]
// }
检查连接状态并列出活跃会话。
javascript
figma_status()
// 响应:
// {
//   status: "ok",
//   fileName: "My Project",
//   pageName: "Page 1",
//   pluginVersion: "2.5.12",
//   sessions: [
//     { sessionId: "abc123", fileName: "My Project", pageName: "Page 1" }
//   ]
// }

figma_docs

figma_docs

Get full API reference and examples. Call once at session start to load capabilities.
javascript
figma_docs()
// Returns: markdown reference with all operations, params, examples
获取完整API参考和示例。会话开始时调用一次,以加载功能说明。
javascript
figma_docs()
// 返回结果: 包含所有操作、参数和示例的markdown参考文档

figma_rules

figma_rules

Generate design system rule sheet — color tokens, typography styles, variables (all modes), component catalog. Equivalent to official Figma MCP's
create_design_system_rules
. Call once per file.
javascript
figma_rules({ sessionId: "abc123" }) // optional sessionId
// Returns: markdown rule sheet with all design tokens
生成设计系统规则表——包含颜色令牌、排版样式、变量(所有模式)、组件目录。等效于官方Figma MCP的
create_design_system_rules
。每个文件调用一次。
javascript
figma_rules({ sessionId: "abc123" }) // sessionId为可选参数
// 返回结果: 包含所有设计令牌的markdown规则表

figma_write

figma_write

Execute JavaScript operations on Figma canvas. Takes
operation
(string) and
params
(object).
Single operation:
javascript
figma_write({
  operation: "create",
  params: {
    type: "FRAME",
    name: "Login Screen",
    width: 390,
    height: 844,
    fill: "#FFFFFF",
    children: [
      {
        type: "TEXT",
        name: "Title",
        characters: "Welcome Back",
        fontSize: 32,
        fontFamily: "Inter",
        fontWeight: 700,
        fill: "#000000",
        x: 40,
        y: 100
      }
    ]
  }
})
Batch operations:
javascript
figma_write({
  operations: [
    {
      operation: "create",
      params: { type: "FRAME", name: "Container", width: 800, height: 600 }
    },
    {
      operation: "modify",
      params: { id: "result[0]", fill: "#F5F5F5" }
    }
  ]
})
Use
result[0]
,
result[1]
to reference previous operation results.
在Figma画布上执行JavaScript操作。接收
operation
(字符串)和
params
(对象)参数。
单次操作:
javascript
figma_write({
  operation: "create",
  params: {
    type: "FRAME",
    name: "Login Screen",
    width: 390,
    height: 844,
    fill: "#FFFFFF",
    children: [
      {
        type: "TEXT",
        name: "Title",
        characters: "Welcome Back",
        fontSize: 32,
        fontFamily: "Inter",
        fontWeight: 700,
        fill: "#000000",
        x: 40,
        y: 100
      }
    ]
  }
})
批量操作:
javascript
figma_write({
  operations: [
    {
      operation: "create",
      params: { type: "FRAME", name: "Container", width: 800, height: 600 }
    },
    {
      operation: "modify",
      params: { id: "result[0]", fill: "#F5F5F5" }
    }
  ]
})
使用
result[0]
result[1]
引用之前操作的结果。

figma_read

figma_read

Read data from Figma. Takes
operation
and
params
.
Get page structure:
javascript
figma_read({
  operation: "get_page_nodes",
  params: {}
})
// Returns: { nodes: [...], totalNodes: 42 }
Get selection:
javascript
figma_read({
  operation: "get_selection",
  params: {}
})
// Returns: [{ id, name, type, x, y, width, height, ... }]
Take screenshot:
javascript
figma_read({
  operation: "screenshot",
  params: { nodeId: "123:456", scale: 2 }
})
// Returns: { base64: "data:image/png;base64,..." }
Get design context (AI-optimized):
javascript
figma_read({
  operation: "get_design_context",
  params: { nodeId: "123:456" }
})
// Returns: flex layout, token-resolved colors, typography with style names,
// component instances with variant properties — best for code generation
Get component map:
javascript
figma_read({
  operation: "get_component_map",
  params: { frameId: "123:456" }
})
// Returns: { instances: [{ componentSetName, variantLabel, properties, suggestedImport }] }
Get CSS:
javascript
figma_read({
  operation: "get_css",
  params: { nodeId: "123:456" }
})
// Returns: { css: "display: flex; flex-direction: column; ..." }
从Figma读取数据。接收
operation
params
参数。
获取页面结构:
javascript
figma_read({
  operation: "get_page_nodes",
  params: {}
})
// 返回结果: { nodes: [...], totalNodes: 42 }
获取选中内容:
javascript
figma_read({
  operation: "get_selection",
  params: {}
})
// 返回结果: [{ id, name, type, x, y, width, height, ... }]
截取截图:
javascript
figma_read({
  operation: "screenshot",
  params: { nodeId: "123:456", scale: 2 }
})
// 返回结果: { base64: "data:image/png;base64,..." }
获取设计上下文(AI优化):
javascript
figma_read({
  operation: "get_design_context",
  params: { nodeId: "123:456" }
})
// 返回结果: 弹性布局、已解析令牌的颜色、带样式名称的排版、
// 包含变体属性的组件实例——最适合代码生成
获取组件映射:
javascript
figma_read({
  operation: "get_component_map",
  params: { frameId: "123:456" }
})
// 返回结果: { instances: [{ componentSetName, variantLabel, properties, suggestedImport }] }
获取CSS:
javascript
figma_read({
  operation: "get_css",
  params: { nodeId: "123:456" }
})
// 返回结果: { css: "display: flex; flex-direction: column; ..." }

Common Operations

常见操作

Create Nodes

创建节点

Frame with auto-layout:
javascript
figma_write({
  operation: "create",
  params: {
    type: "FRAME",
    name: "Card",
    width: 320,
    height: 240,
    fill: "#FFFFFF",
    cornerRadius: 16,
    layoutMode: "VERTICAL",
    paddingTop: 24,
    paddingRight: 24,
    paddingBottom: 24,
    paddingLeft: 24,
    itemSpacing: 16,
    effects: [
      {
        type: "DROP_SHADOW",
        color: "rgba(0,0,0,0.1)",
        offsetX: 0,
        offsetY: 4,
        blur: 12
      }
    ]
  }
})
Text with typography:
javascript
figma_write({
  operation: "create",
  params: {
    type: "TEXT",
    name: "Heading",
    characters: "Design System",
    fontSize: 48,
    fontFamily: "Inter",
    fontWeight: 700,
    lineHeight: { value: 120, unit: "PERCENT" },
    letterSpacing: { value: -2, unit: "PERCENT" },
    fill: "#1A1A1A"
  }
})
Rectangle with gradient:
javascript
figma_write({
  operation: "create",
  params: {
    type: "RECTANGLE",
    name: "Gradient BG",
    width: 800,
    height: 600,
    fill: {
      type: "LINEAR_GRADIENT",
      angle: 135,
      stops: [
        { position: 0, color: "#667EEA" },
        { position: 1, color: "#764BA2" }
      ]
    }
  }
})
Icon from library:
javascript
figma_write({
  operation: "createIcon",
  params: {
    name: "home",
    library: "ionicons", // ionicons | fluent | bootstrap | phosphor | tabler-filled | tabler-outline | lucide
    size: 24,
    fill: "#000000",
    x: 100,
    y: 100
  }
})
Component instance with overrides:
javascript
figma_write({
  operation: "instantiate",
  params: {
    componentKey: "abc123",
    overrides: {
      "ButtonLabel": { text: "Submit", fill: "#FFFFFF" },
      "Icon": { visible: false }
    }
  }
})
带自动布局的Frame:
javascript
figma_write({
  operation: "create",
  params: {
    type: "FRAME",
    name: "Card",
    width: 320,
    height: 240,
    fill: "#FFFFFF",
    cornerRadius: 16,
    layoutMode: "VERTICAL",
    paddingTop: 24,
    paddingRight: 24,
    paddingBottom: 24,
    paddingLeft: 24,
    itemSpacing: 16,
    effects: [
      {
        type: "DROP_SHADOW",
        color: "rgba(0,0,0,0.1)",
        offsetX: 0,
        offsetY: 4,
        blur: 12
      }
    ]
  }
})
带排版样式的文本:
javascript
figma_write({
  operation: "create",
  params: {
    type: "TEXT",
    name: "Heading",
    characters: "Design System",
    fontSize: 48,
    fontFamily: "Inter",
    fontWeight: 700,
    lineHeight: { value: 120, unit: "PERCENT" },
    letterSpacing: { value: -2, unit: "PERCENT" },
    fill: "#1A1A1A"
  }
})
带渐变的矩形:
javascript
figma_write({
  operation: "create",
  params: {
    type: "RECTANGLE",
    name: "Gradient BG",
    width: 800,
    height: 600,
    fill: {
      type: "LINEAR_GRADIENT",
      angle: 135,
      stops: [
        { position: 0, color: "#667EEA" },
        { position: 1, color: "#764BA2" }
      ]
    }
  }
})
从图标库创建图标:
javascript
figma_write({
  operation: "createIcon",
  params: {
    name: "home",
    library: "ionicons", // ionicons | fluent | bootstrap | phosphor | tabler-filled | tabler-outline | lucide
    size: 24,
    fill: "#000000",
    x: 100,
    y: 100
  }
})
带覆盖属性的组件实例:
javascript
figma_write({
  operation: "instantiate",
  params: {
    componentKey: "abc123",
    overrides: {
      "ButtonLabel": { text: "Submit", fill: "#FFFFFF" },
      "Icon": { visible: false }
    }
  }
})

Modify Nodes

修改节点

Change properties:
javascript
figma_write({
  operation: "modify",
  params: {
    id: "123:456",
    fill: "#FF5733",
    width: 400,
    opacity: 0.8
  }
})
Apply design tokens:
javascript
figma_write({
  operation: "applyVariable",
  params: {
    nodeId: "123:456",
    field: "fills", // fills | strokes | width | height | cornerRadius | paddingTop | etc.
    variableName: "color/primary"
  }
})
Apply text style:
javascript
figma_write({
  operation: "applyTextStyle",
  params: {
    nodeId: "123:456",
    styleName: "Heading/H1"
  }
})
修改属性:
javascript
figma_write({
  operation: "modify",
  params: {
    id: "123:456",
    fill: "#FF5733",
    width: 400,
    opacity: 0.8
  }
})
应用设计令牌:
javascript
figma_write({
  operation: "applyVariable",
  params: {
    nodeId: "123:456",
    field: "fills", // fills | strokes | width | height | cornerRadius | paddingTop | etc.
    variableName: "color/primary"
  }
})
应用文本样式:
javascript
figma_write({
  operation: "applyTextStyle",
  params: {
    nodeId: "123:456",
    styleName: "Heading/H1"
  }
})

Setup Design Tokens

设置设计令牌

Color tokens (all modes):
javascript
figma_write({
  operation: "setupDesignTokens",
  params: {
    colors: {
      "color/primary": {
        Light: "#667EEA",
        Dark: "#A5B4FC"
      },
      "color/background": {
        Light: "#FFFFFF",
        Dark: "#1A1A1A"
      }
    }
  }
})
Typography tokens:
javascript
figma_write({
  operation: "setupDesignTokens",
  params: {
    fontSizes: {
      "size/xs": { Compact: 12, Comfortable: 14, Large: 16 },
      "size/sm": { Compact: 14, Comfortable: 16, Large: 18 },
      "size/md": { Compact: 16, Comfortable: 18, Large: 20 }
    },
    fonts: {
      "font/primary": { Compact: "Inter", Comfortable: "Inter", Large: "SF Pro" }
    },
    textStyles: [
      {
        name: "Heading/H1",
        fontFamily: "font/primary",
        fontSize: "size/md",
        fontWeight: 700,
        lineHeightPercent: 120
      }
    ]
  }
})
颜色令牌(所有模式):
javascript
figma_write({
  operation: "setupDesignTokens",
  params: {
    colors: {
      "color/primary": {
        Light: "#667EEA",
        Dark: "#A5B4FC"
      },
      "color/background": {
        Light: "#FFFFFF",
        Dark: "#1A1A1A"
      }
    }
  }
})
排版令牌:
javascript
figma_write({
  operation: "setupDesignTokens",
  params: {
    fontSizes: {
      "size/xs": { Compact: 12, Comfortable: 14, Large: 16 },
      "size/sm": { Compact: 14, Comfortable: 16, Large: 18 },
      "size/md": { Compact: 16, Comfortable: 18, Large: 20 }
    },
    fonts: {
      "font/primary": { Compact: "Inter", Comfortable: "Inter", Large: "SF Pro" }
    },
    textStyles: [
      {
        name: "Heading/H1",
        fontFamily: "font/primary",
        fontSize: "size/md",
        fontWeight: 700,
        lineHeightPercent: 120
      }
    ]
  }
})

Prototyping

原型设计

Add click interaction:
javascript
figma_write({
  operation: "setReactions",
  params: {
    nodeId: "123:456",
    reactions: [
      {
        trigger: "ON_CLICK", // ON_CLICK | ON_HOVER | ON_PRESS | ON_DRAG
        action: "NAVIGATE", // NAVIGATE | OVERLAY | SWAP | SCROLL_TO | CLOSE
        destinationId: "789:012",
        transition: "SMART_ANIMATE", // SMART_ANIMATE | DISSOLVE | SLIDE_IN | PUSH | etc.
        duration: 300,
        easing: "EASE_OUT"
      }
    ]
  }
})
Set scroll behavior:
javascript
figma_write({
  operation: "setScrollBehavior",
  params: {
    nodeId: "123:456",
    overflow: "VERTICAL" // HORIZONTAL | VERTICAL | BOTH | NONE
  }
})
添加点击交互:
javascript
figma_write({
  operation: "setReactions",
  params: {
    nodeId: "123:456",
    reactions: [
      {
        trigger: "ON_CLICK", // ON_CLICK | ON_HOVER | ON_PRESS | ON_DRAG
        action: "NAVIGATE", // NAVIGATE | OVERLAY | SWAP | SCROLL_TO | CLOSE
        destinationId: "789:012",
        transition: "SMART_ANIMATE", // SMART_ANIMATE | DISSOLVE | SLIDE_IN | PUSH | etc.
        duration: 300,
        easing: "EASE_OUT"
      }
    ]
  }
})
设置滚动行为:
javascript
figma_write({
  operation: "setScrollBehavior",
  params: {
    nodeId: "123:456",
    overflow: "VERTICAL" // HORIZONTAL | VERTICAL | BOTH | NONE
  }
})

Component Variants

组件变体

Set variant properties:
javascript
figma_write({
  operation: "setComponentProperties",
  params: {
    instanceId: "123:456",
    properties: {
      "State": "Primary",
      "Size": "Large"
    }
  }
})
Swap component:
javascript
figma_write({
  operation: "swapComponent",
  params: {
    instanceId: "123:456",
    newComponentKey: "def789"
  }
})
设置变体属性:
javascript
figma_write({
  operation: "setComponentProperties",
  params: {
    instanceId: "123:456",
    properties: {
      "State": "Primary",
      "Size": "Large"
    }
  }
})
替换组件:
javascript
figma_write({
  operation: "swapComponent",
  params: {
    instanceId: "123:456",
    newComponentKey: "def789"
  }
})

Read Operations Reference

读取操作参考

OperationPurposeKey Params
get_page_nodes
List all top-level nodes
{ maxDepth }
get_selection
Get selected nodes
{}
get_node_detail
Full node data with resolved variables/styles
{ nodeId }
get_design_context
AI-optimized payload for code generation
{ nodeId }
get_component_map
List component instances with variants
{ frameId }
get_unmapped_components
Find components missing code mapping
{ frameId }
get_css
Generate CSS from node
{ nodeId }
screenshot
Capture PNG
{ nodeId, scale }
get_variables
All variables (all modes)
{}
get_styles
All color/text/effect styles
{}
操作用途关键参数
get_page_nodes
列出所有顶级节点
{ maxDepth }
get_selection
获取选中节点
{}
get_node_detail
获取包含已解析变量/样式的完整节点数据
{ nodeId }
get_design_context
为代码生成优化的AI负载
{ nodeId }
get_component_map
列出包含变体的组件实例
{ frameId }
get_unmapped_components
查找缺少代码映射的组件
{ frameId }
get_css
从节点生成CSS
{ nodeId }
screenshot
捕获PNG截图
{ nodeId, scale }
get_variables
获取所有变量(所有模式)
{}
get_styles
获取所有颜色/文本/效果样式
{}

Multi-Instance Sessions

多实例会话

When multiple Figma files are open, each plugin instance has a unique
sessionId
. Target specific files:
javascript
// List all sessions
figma_status()
// { sessions: [{ sessionId: "abc123", fileName: "App Design" }, ...] }

// Write to specific session
figma_write({
  operation: "create",
  params: { type: "FRAME", name: "Test" },
  sessionId: "abc123"
})

// Read from specific session
figma_read({
  operation: "get_page_nodes",
  params: {},
  sessionId: "abc123"
})
Omit
sessionId
to use the first connected session.
当打开多个Figma文件时,每个插件实例都有唯一的
sessionId
。可指定目标文件:
javascript
// 列出所有会话
figma_status()
// { sessions: [{ sessionId: "abc123", fileName: "App Design" }, ...] }

// 向指定会话写入
figma_write({
  operation: "create",
  params: { type: "FRAME", name: "Test" },
  sessionId: "abc123"
})

// 从指定会话读取
figma_read({
  operation: "get_page_nodes",
  params: {},
  sessionId: "abc123"
})
省略
sessionId
将使用第一个已连接的会话。

Common Patterns

常见模式

Design System Bootstrap

设计系统初始化

javascript
// Step 1: Generate rule sheet
figma_rules()

// Step 2: Setup color tokens
figma_write({
  operation: "setupDesignTokens",
  params: {
    colors: {
      "color/primary": { Light: "#667EEA", Dark: "#A5B4FC" },
      "color/text": { Light: "#1A1A1A", Dark: "#F5F5F5" }
    }
  }
})

// Step 3: Setup typography
figma_write({
  operation: "setupDesignTokens",
  params: {
    fontSizes: {
      "size/h1": { Compact: 32, Comfortable: 40, Large: 48 }
    },
    textStyles: [
      {
        name: "Heading/H1",
        fontSize: "size/h1",
        fontWeight: 700
      }
    ]
  }
})
javascript
// 步骤1:生成规则表
figma_rules()

// 步骤2:设置颜色令牌
figma_write({
  operation: "setupDesignTokens",
  params: {
    colors: {
      "color/primary": { Light: "#667EEA", Dark: "#A5B4FC" },
      "color/text": { Light: "#1A1A1A", Dark: "#F5F5F5" }
    }
  }
})

// 步骤3:设置排版
figma_write({
  operation: "setupDesignTokens",
  params: {
    fontSizes: {
      "size/h1": { Compact: 32, Comfortable: 40, Large: 48 }
    },
    textStyles: [
      {
        name: "Heading/H1",
        fontSize: "size/h1",
        fontWeight: 700
      }
    ]
  }
})

Design-to-Code Workflow

设计转代码工作流

javascript
// Step 1: Get design context
const context = await figma_read({
  operation: "get_design_context",
  params: { nodeId: "123:456" }
})
// Returns: flex layout, resolved color tokens, typography with style names

// Step 2: Get component map
const components = await figma_read({
  operation: "get_component_map",
  params: { frameId: "123:456" }
})
// Returns: { instances: [{ componentSetName: "Button", variantLabel: "State=Primary", suggestedImport: "@/components/Button" }] }

// Step 3: Get CSS
const css = await figma_read({
  operation: "get_css",
  params: { nodeId: "123:456" }
})
// Returns: { css: "display: flex; ..." }
javascript
// 步骤1:获取设计上下文
const context = await figma_read({
  operation: "get_design_context",
  params: { nodeId: "123:456" }
})
// 返回结果: 弹性布局、已解析颜色令牌、带样式名称的排版

// 步骤2:获取组件映射
const components = await figma_read({
  operation: "get_component_map",
  params: { frameId: "123:456" }
})
// 返回结果: { instances: [{ componentSetName: "Button", variantLabel: "State=Primary", suggestedImport: "@/components/Button" }] }

// 步骤3:获取CSS
const css = await figma_read({
  operation: "get_css",
  params: { nodeId: "123:456" }
})
// 返回结果: { css: "display: flex; ..." }

Batch Create + Reference

批量创建+引用

javascript
figma_write({
  operations: [
    // Create container
    {
      operation: "create",
      params: {
        type: "FRAME",
        name: "Container",
        width: 800,
        height: 600,
        layoutMode: "VERTICAL",
        itemSpacing: 24
      }
    },
    // Create child, insert into container
    {
      operation: "create",
      params: {
        type: "RECTANGLE",
        name: "Header",
        width: 800,
        height: 80,
        fill: "#667EEA",
        parentId: "result[0]" // Reference first operation's result
      }
    }
  ]
})
javascript
figma_write({
  operations: [
    // 创建容器
    {
      operation: "create",
      params: {
        type: "FRAME",
        name: "Container",
        width: 800,
        height: 600,
        layoutMode: "VERTICAL",
        itemSpacing: 24
      }
    },
    // 创建子节点并插入容器
    {
      operation: "create",
      params: {
        type: "RECTANGLE",
        name: "Header",
        width: 800,
        height: 80,
        fill: "#667EEA",
        parentId: "result[0]" // 引用第一个操作的结果
      }
    }
  ]
})

Troubleshooting

故障排除

Plugin shows orange dot

插件显示橙色圆点

  • Cause: MCP server not running or wrong port
  • Fix: Restart IDE/AI client (MCP server loads on startup). Check server logs for port conflicts.
  • 原因: MCP服务器未运行或端口错误
  • 解决方法: 重启IDE/AI客户端(MCP服务器在启动时加载)。检查服务器日志是否存在端口冲突。

"Plugin not connected" error

出现“插件未连接”错误

  • Cause: Plugin not running in Figma Desktop
  • Fix: Figma Desktop → Plugins → Development → Figma UI MCP Bridge. Must be Figma Desktop (web app cannot access localhost).
  • 原因: Figma Desktop中未运行插件
  • 解决方法: 在Figma Desktop中依次点击插件 → 开发 → Figma UI MCP Bridge。必须使用Figma Desktop(网页版无法访问localhost)。

Operations fail silently

操作无响应

  • Cause: Invalid node ID or operation params
  • Fix: Call
    figma_read get_page_nodes
    first to get valid node IDs. Check
    figma_docs
    for param schema.
  • 原因: 节点ID无效或操作参数错误
  • 解决方法: 先调用
    figma_read get_page_nodes
    获取有效的节点ID。查看
    figma_docs
    获取参数格式说明。

Font not found

字体未找到

  • Cause: Font not installed on system
  • Fix: Use
    fontFamily: "Inter"
    (ships with Figma) or install custom fonts locally.
  • 原因: 系统未安装该字体
  • 解决方法: 使用
    fontFamily: "Inter"
    (Figma内置字体)或在本地安装自定义字体。

Multi-instance targeting wrong file

多实例指向错误文件

  • Cause: No
    sessionId
    specified with multiple files open
  • Fix: Call
    figma_status
    to list sessions, then pass
    sessionId
    to
    figma_write
    /
    figma_read
    .
  • 原因: 打开多个文件时未指定
    sessionId
  • 解决方法: 调用
    figma_status
    列出会话,然后将
    sessionId
    传递给
    figma_write
    /
    figma_read

Variable binding fails

变量绑定失败

  • Cause: Variable doesn't exist or wrong type
  • Fix: Call
    figma_read get_variables
    first. Ensure
    FLOAT
    variables for dimensions,
    COLOR
    for fills.
  • 原因: 变量不存在或类型错误
  • 解决方法: 先调用
    figma_read get_variables
    。确保尺寸使用
    FLOAT
    变量,填充使用
    COLOR
    变量。

Best Practices

最佳实践

  1. Always call
    figma_docs
    at session start
    to load API reference into AI context
  2. Call
    figma_rules
    once per file
    to get design system tokens before generating code
  3. Use
    get_design_context
    for code generation
    — single call returns all layout/color/typography data
  4. Use
    get_component_map
    for import statements
    — returns
    suggestedImport
    paths
  5. Batch operations when possible — reduces round-trips (single
    figma_write
    with
    operations
    array)
  6. Reference previous results with
    result[0]
    ,
    result[1]
    in batch operations
  7. Use design tokens (
    applyVariable
    ) instead of hardcoded colors for maintainability
  8. Check
    figma_status
    first
    to verify connection and list sessions
  9. Use
    sessionId
    when multiple Figma files are open to avoid ambiguity
  10. Take screenshots to verify AI-generated designs match intent
  1. 会话开始时始终调用
    figma_docs
    ,将API参考加载到AI上下文
  2. 每个文件调用一次
    figma_rules
    ,在生成代码前获取设计系统令牌
  3. 使用
    get_design_context
    进行代码生成
    ——单次调用即可获取所有布局/颜色/排版数据
  4. 使用
    get_component_map
    获取导入语句
    ——返回
    suggestedImport
    路径
  5. 尽可能批量操作——减少往返次数(单次
    figma_write
    传入
    operations
    数组)
  6. 在批量操作中使用
    result[0]
    result[1]
    引用之前的结果
  7. 使用设计令牌
    applyVariable
    )而非硬编码颜色,提升可维护性
  8. **先调用
    figma_status
    **验证连接并列出会话
  9. **打开多个Figma文件时使用
    sessionId
    **避免歧义
  10. 截取截图验证AI生成的设计是否符合预期

Version Updates

版本更新

bash
undefined
bash
undefined

Get latest version + plugin path

获取最新版本和插件路径

npx figma-ui-mcp@latest --version
npx figma-ui-mcp@latest --version

Re-link Figma plugin (manual step required)

重新关联Figma插件(需手动操作)

Figma Desktop → Plugins → Development → Manage plugins in development

Figma Desktop → 插件 → 开发 → 管理开发中的插件

Remove old → Import from manifest → Select new plugin path

删除旧插件 → 从清单导入 → 选择新插件路径


Plugin does **not** auto-update — must re-link after npm update.

插件**不会自动更新**——npm更新后必须重新关联。