mcpField
F
figma-ui-mcp

figma-ui-mcp

本地服务
github.com/TranHoaiHung媒体与设计2642 天前更新

关于 figma-ui-mcp

figma-ui-mcp 是双向的 Figma MCP 桥接工具,让 Claude Code、Cursor 等支持 MCP 的 AI 助手直接在 Figma 画布上绘制界面,并将现有设计读取为结构化数据、截图或代码可用的样式令牌。通过 localhost 通信,无需 Figma API 密钥,需要 Figma 桌面版。

主要功能

  1. 01在 Figma 画布上绘制界面
  2. 02读取节点树、颜色与字体排版
  3. 03获取截图与 CSS 输出
  4. 04生成设计系统规则表
  5. 05支持多个 Figma 文件同时连接

适用场景

  1. 01根据自然语言描述生成界面草稿
  2. 02读取现有设计并转换为代码
  3. 03为会话生成设计令牌与组件规则

MCP 相关

该项目是一个 MCP 服务,向 MCP 客户端提供 figma_write、figma_read、figma_status、figma_docs 和 figma_rules 等工具。

配置

本地服务的配置在各客户端中通用,复制后粘贴到客户端的 MCP 配置文件即可。

mcp.json · 通用配置
{
"mcpServers": {
"tranhoaihung-figma-ui": {
"command": "npx",
"args": [
"-y",
"figma-ui-mcp"
]
}
}
}
启动命令npx -y figma-ui-mcp

本地服务需要在你的电脑上安装运行环境(如 Node.js 18+)。各客户端的配置文件位置不同,请参考客户端文档。

安装包
npmfigma-ui-mcp2.5.30

工具

5

收录的工具列表 · 更新于 2 天前

此工具无需参数。

详细介绍

figma-ui-mcp

figma-ui-mcp — Claude Code 到 Figma,AI 到 Figma,MCP Figma Bridge

npm 版本 MCP 注册表 许可证:MIT GitHub 星标 MCPVault:已认领

Claude Code 到 Figma · Antigravity 到 Figma · Cursor 到 Figma · 任意 MCP IDE 到 Figma

✅ 已测试:Claude Code、Antigravity  |  🔧 兼容:Cursor、VS Code、Windsurf、Zed(任意 MCP stdio 客户端)

双向 Figma MCP 桥接工具——让 AI 助手(Claude Code、Cursor、Windsurf、Antigravity、VS Code Copilot,或任意兼容 MCP 的 IDE)直接在 Figma 画布上绘制 UI,并将现有设计读取为结构化数据、屏幕截图或可直接用于代码的令牌。无需 Figma API 密钥——完全通过 localhost 运行。

需要 Figma Desktop——插件通过 localhost HTTP 轮询与 MCP 服务通信。Figma 网页应用不允许访问 localhost 网络,因此必须使用 Figma Desktop。

Claude ──figma_write──▶ MCP Server ──HTTP (localhost:38451)──▶ Figma Plugin ──▶ Figma Document
Claude ◀─figma_read──── MCP Server ◀──HTTP (localhost:38451)── Figma Plugin ◀── Figma Document
localhost 桥接的工作原理

MCP 服务会启动一个绑定到 localhost:38451 的小型 HTTP 服务。Figma 插件(在 Figma Desktop 内运行)使用长轮询——服务会将请求保持最多 8s,直到有任务到达;新操作进入队列时会立即刷新(近实时延迟 <100ms)。所有流量都留在你的计算机上——不会发送到任何外部服务。

**多实例支持(v2.3.0+):**多个 Figma 文件/标签页可以同时连接。每个插件实例都会发送一个 sessionId,桥接工具会将操作路由到正确的会话。在 figma_write/figma_read 中使用可选的 sessionId 参数即可指定目标文件。


功能

方向工具功能
写入figma_write通过 JS 代码绘制画框、形状、文本和原型
读取figma_read提取节点树、颜色、字体排版和屏幕截图
信息figma_status检查插件连接状态和活动会话
文档figma_docs获取完整的 API 参考和示例
规则figma_rules生成设计系统规则表——令牌、字体排版和组件
v2.5 新特性
功能描述
get_design_context节点的 AI 优化负载——弹性布局、解析令牌后的颜色(var(--name))、带样式名称的排版,以及带变体属性的组件实例。设计转为 React/Vue/Swift 代码的最佳单次调用。
get_component_map列出一个画框中的所有组件实例,包含 componentSetName、variantLabel、属性和 suggestedImport 路径。一次调用即可搭建导入语句。
get_unmapped_components查找在 Figma 中没有描述的组件实例(尚无代码映射)。提示 AI 询问用户正确的导入路径。
figma_rules 工具新增的顶层 MCP 工具——将颜色令牌、排版样式、变量(所有模式)和组件目录汇总为单个 Markdown 规则表。相当于官方 Figma MCP 的 create_design_system_rules。在会话开始时调用一次。
get_css 操作figma_read get_css { nodeId } → 可直接使用的 CSS 字符串(弹性布局、排版、填充、边框、阴影、不透明度、变换)。一次调用,粘贴到代码中即可。
已解析的变量get_node_detail 现在会将 boundVariables ID 解析为 { name, resolvedType, value }。无需再手动查找 ID。
已解析的样式引用fillStyleId / textStyleId 现在包含 fillStyle: { name, hex } 和 textStyle: { name, fontSize, fontFamily }。
实例覆盖详情overrides: [{ id, overriddenFields: ["fills","characters",...] }]——提供相对于 mainComponent 的完整差异,而不只是数量。
componentSetName + variantLabelINSTANCE 节点现在会分别公开集合名称("Button")和变体标签("State=Primary, Size=Large")。
用于创建的 insertIndexfigma.create({ ..., insertIndex: 2 })——在父节点中的确切位置插入节点,而不总是追加到末尾。
排版令牌setupDesignTokens({ fontSizes, fonts, textStyles })——一次调用即可引导完整的排版系统,并创建绑定变量的文本样式。支持多模式(Compact/Comfortable/Large)。
applyTextStyle一次调用即可按名称将本地文本样式应用于 TEXT 节点——自动加载字体。
用于字体的 STRING 变量applyVariable 现在可以绑定 fontFamily、fontStyle、characters(通过一个变量将 Inter 替换为 SF Pro)。
效果任意节点均可使用 effects: [{ type: "DROP_SHADOW" | "INNER_SHADOW" | "LAYER_BLUR" | "BACKGROUND_BLUR", ... }]。
渐变填充在 create/modify 中使用 fill: { type: "LINEAR_GRADIENT" | "RADIAL_GRADIENT", angle, stops }。
单独设置圆角半径FRAME/RECT 支持 topLeftRadius、topRightRadius、bottomLeftRadius、bottomRightRadius。
8 位十六进制颜色 + rgba alphafill: "#FFFFFF80" 或 "rgba(255,255,255,0.5)"——透明度会自动应用于绘制不透明度。
SVG 弧线(A)+ 逗号VECTOR d 路径接受 A 弧线命令(自动转换为三次贝塞尔曲线)和逗号。
图标库7 个免费的开源图标库,优先使用 iOS 填充样式:Ionicons → Fluent → Bootstrap → Phosphor → Tabler Filled → Tabler Outline → Lucide。
实例覆盖figma.instantiate({ overrides: { "LayerName": { text, fill, fontSize } } })——按图层覆盖属性。
批量删除figma.delete({ ids: [...] })——一次往返即可删除多个节点。
原型交互setReactions——点击/悬停/按下 → 使用 Smart Animate 进行跳转/叠加/替换。
滚动行为setScrollBehavior——HORIZONTAL / VERTICAL / BOTH 溢出行为。
变体与实例替换setComponentProperties / swapComponent——变体 + 实例替换。
组件属性定义 (v2.5.24)addComponentProperty + bindComponentProperty——在主组件上创建 TEXT / BOOLEAN / INSTANCE_SWAP 属性。实例文本覆盖现在会实际重新计算自动布局(按钮会扩展以适应更长的标签)。
多实例可通过会话同时连接多个 Figma 标签页。

完整版本历史:参见 CHANGELOG.md。


快速入门

步骤 1 — 将 MCP 服务添加到你的 AI 客户端

选择你的平台:

Claude Code(CLI)
# Project scope (default)
claude mcp add figma-ui-mcp -- npx figma-ui-mcp

# Global scope (all projects)
claude mcp add --scope user figma-ui-mcp -- npx figma-ui-mcp
Claude Desktop

编辑配置文件:

  • macOS:~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows:%APPDATA%\Claude\claude_desktop_config.json
{
  "mcpServers": {
    "figma": {
      "command": "npx",
      "args": ["-y", "figma-ui-mcp"]
    }
  }
}
Cursor

编辑 .cursor/mcp.json(项目级)或 ~/.cursor/mcp.json(全局):

{
  "mcpServers": {
    "figma": {
      "command": "npx",
      "args": ["-y", "figma-ui-mcp"]
    }
  }
}
VS Code / GitHub Copilot

编辑 .vscode/mcp.json(项目级)或添加到 settings.json(全局):

{
  "mcp": {
    "servers": {
      "figma": {
        "command": "npx",
        "args": ["-y", "figma-ui-mcp"]
      }
    }
  }
}
Windsurf

编辑 ~/.codeium/windsurf/mcp_config.json:

{
  "mcpServers": {
    "figma": {
      "command": "npx",
      "args": ["-y", "figma-ui-mcp"]
    }
  }
}
Antigravity(Google)
  1. 打开 Agent 面板顶部的 “...”下拉菜单
  2. 点击 “Manage MCP Servers” → “View raw config”
  3. 添加到 mcp_config.json:
{
  "mcpServers": {
    "figma": {
      "command": "npx",
      "args": ["-y", "figma-ui-mcp"]
    }
  }
}
从源代码安装(任意客户端)
git clone https://github.com/TranHoaiHung/figma-ui-mcp
cd figma-ui-mcp
npm install
# Then point your MCP client to: node /path/to/figma-ui-mcp/server/index.js

⚠️ 重要:添加 MCP 服务后,必须重启 IDE / AI 客户端(退出并重新打开)。 MCP 服务仅在启动时加载——仅保存配置文件是不够的。此要求适用于 Claude Code、Cursor、VS Code、Windsurf 和 Antigravity。

步骤 2 — 安装 Figma 插件

⬇ 下载 plugin.zip — 无需克隆 Git 仓库

  1. 下载并将 plugin.zip 解压到你电脑上的任意位置
  2. 打开 Figma Desktop(必需——Web 应用无法访问 localhost)
  3. 前往 Plugins → Development → Import plugin from manifest...
  4. 从解压后的文件夹中选择 manifest.json
  5. 运行 Plugins → Development → Figma UI MCP Bridge

连接 MCP 服务后,插件界面会显示一个绿色圆点。

更新到较新版本
# Step 1 — get the new version + plugin path
npx figma-ui-mcp@latest --version
# figma-ui-mcp v2.5.12  —  plugin: /.../.npm/_npx/.../figma-ui-mcp/plugin

# Step 2 — restart Claude / your IDE so the MCP server reloads

# Step 3 — re-link the Figma plugin (manual, one-time per update)
#   Figma Desktop → Plugins → Development → Manage plugins in development
#   Remove old "Figma UI MCP Bridge" → "+" → Import plugin from manifest...
#   Select manifest.json from the plugin path printed in Step 1

# Step 4 — verify
#   Ask your AI: "figma_status"
#   pluginVersion in the response should match the npm version above

Figma 插件不会自动更新——每次插件变更后,都需要重新关联(步骤 3)。

步骤 3 — 将 AI 连接到 Figma

让你的 AI 助手连接:

"Connect to figma-ui-mcp"

AI 将调用 figma_status 并确认:

✅ Connected — File: "My Project", Page: "Page 1", Plugin v2.5.5

如果看到“Plugin not connected”,请确保 Figma 插件正在运行(步骤 2)。

步骤 4 — 使用提示词开始设计

连接后,只需用自然语言描述你的需求:

"Use figma-ui-mcp to draw a login screen for mobile"

AI 将自动:

  1. 调用 figma_docs 加载 API 参考和设计规则
  2. 调用 figma_read get_page_nodes 了解当前画布
  3. 调用 figma_write 在 Figma 画布上创建设计
  4. 调用 figma_read screenshot 验证结果
提示词示例
提示词执行结果
"Draw a mobile login screen with social login buttons"创建一个 390×844 的画框,包含电子邮件/密码输入框、Apple/Google 按钮
"Read the selected frame and describe the design"提取所选内容的颜色、字体排印和间距信息
"Take a screenshot of the current frame"返回一张可供 AI 分析的内嵌图片
"Create a dark theme dashboard with KPI cards"绘制完整的仪表盘布局,包含图表和统计信息
"Design an e-commerce product card"创建包含图片、价格、评分和 CTA 的商品卡片
"Draw a settings page with toggle switches"创建分组设置,包含图标和切换开关
提升效果的小技巧
  • 明确风格:"dark theme"、"glassmorphism"、"minimal white" 能为 AI 指明清晰的方向
  • 提及平台:"mobile"(390×844)、"tablet"(768×1024)、"desktop"(1440×900)
  • 迭代优化:第一次绘制完成后,说 "fix the spacing" 或 "make the buttons bigger"——AI 会读取并修改现有节点
  • 使用选择:在 Figma 中选择一个画框,然后询问 "improve this design"——AI 会先读取你的选择
  • 多屏流程:"Now draw the signup screen next to the login screen"——AI 会将画框并排放置
工作流摘要
You: "Connect to figma-ui-mcp"
AI:  ✅ Connected to Figma

You: "Draw a mobile onboarding screen with 3 steps"
AI:  [calls figma_docs → figma_write → figma_read screenshot]
AI:  ✅ Done — here's what I created: [inline screenshot]

You: "The title text is not centered"
AI:  [calls figma_read get_selection → figma_write modify → screenshot]
AI:  ✅ Fixed — text is now centered

You: "Now draw the next onboarding screen beside it"
AI:  [reads page_nodes to find position → draws at x+440]
AI:  ✅ Done — 2 screens side by side
figma_status     — check connection (always call first)
figma_docs       — load API reference (call before drawing)
figma_write      — draw / modify UI on canvas
figma_read       — extract design data, screenshots, SVG

使用示例

绘制一个屏幕

向 Claude 提问:"Draw a dark dashboard with a sidebar, header, and 4 KPI cards"

Claude 会调用 figma_write,并使用类似这样的代码:

await figma.createPage({ name: "Dashboard" });
await figma.setPage({ name: "Dashboard" });

const root = await figma.create({
  type: "FRAME", name: "Dashboard",
  x: 0, y: 0, width: 1440, height: 900,
  fill: "#0f172a",
});

const sidebar = await figma.create({
  type: "FRAME", name: "Sidebar",
  parentId: root.id,
  x: 0, y: 0, width: 240, height: 900,
  fill: "#1e293b", stroke: "#334155", strokeWeight: 1,
});

await figma.create({
  type: "TEXT", name: "App Name",
  parentId: sidebar.id,
  x: 20, y: 24, content: "My App",
  fontSize: 16, fontWeight: "SemiBold", fill: "#f8fafc",
});
// ... continue
读取设计

向 Claude 提问:"Read my selected frame and convert it to Tailwind CSS"

Claude 会使用 operation: "get_selection" 调用 figma_read,接收完整的节点树, 然后生成相应的代码。

截取画框
figma_read  →  operation: "screenshot"  →  nodeId: "123:456"

返回一个 base64 PNG,Claude 可以对其进行分析和描述。


架构

figma-ui-mcp/
├── server/
│   ├── index.js            MCP server (stdio transport)
│   ├── bridge-server.js    HTTP bridge on localhost:38451 (long-poll, multi-session)
│   ├── code-executor.js    VM sandbox — safe JS execution + 7-lib icon fetcher
│   ├── tool-definitions.js MCP tool schemas (figma_status / _write / _read / _docs)
│   └── api-docs.js         API reference text (served to AI via figma_docs)
├── src/plugin/             Plugin source (concat-built into plugin/code.js)
│   ├── utils.js, svg-path-helpers.js, paint-and-effects.js, read-helpers.js
│   ├── handlers-write.js, handlers-read.js, handlers-read-detail.js,
│   │   handlers-library.js, handlers-tokens.js, handlers-write-ops.js
│   └── main.js
└── plugin/
    ├── manifest.json       Figma plugin manifest
    ├── code.js             Plugin main (auto-generated — 3600+ LOC)
    └── ui.html             Plugin UI — long-poll client + status dot
安全性
层防护措施
VM 沙箱vm.runInContext() — 阻止 require、process、fs、fetch
仅限本地主机桥接服务绑定到 localhost:38451,绝不暴露给网络
操作允许列表接受 56 个预定义操作(WRITE_OPS + READ_OPS)
超时VM 执行 30s + 每个插件操作 60-90s(根据操作类型自适应)
请求体大小限制每个请求最大 5 MB
会话隔离多实例会话按 Figma 文件 ID 进行隔离

可用的写入操作(figma_write)

核心 CRUD
操作描述
figma.create({ type, ... })创建 FRAME / RECTANGLE / ELLIPSE / LINE / TEXT / SVG / VECTOR / IMAGE
figma.modify({ id, ... })更新节点属性(填充、大小、文本、布局等)
figma.delete({ id })移除单个节点
figma.delete({ ids: [...] })批量删除,一次调用即可删除多个节点
figma.query({ type?, name?, id? })按类型、名称或 ID 查找节点
figma.append({ parentId, childId })将节点移入父节点

create / modify — 任何节点都可使用的高级属性:

属性示例说明
fill (纯色)"#6C5CE7" 或 "#6C5CE780"(带 alpha 的 8 位十六进制)或 "rgba(108,92,231,0.5)"Alpha 会自动提取为填充的不透明度
fill (渐变){ type: "LINEAR_GRADIENT", angle: 135, stops: [{ pos: 0, color: "#7C3AED" }, { pos: 1, color: "#EC4899" }] }也支持 RADIAL_GRADIENT
stroke、strokeWeight、strokeOpacity遵循相同的十六进制/rgba 规则
cornerRadius(统一)12适用于全部 4 个圆角
单独设置圆角topLeftRadius: 20, topRightRadius: 20, bottomLeftRadius: 0, bottomRightRadius: 0圆角顶部面板样式
effects 数组[{ type: "DROP_SHADOW", color: "#00000026", offset: {x:0,y:8}, radius: 24, spread: 0 }]类型:DROP_SHADOW、INNER_SHADOW、LAYER_BLUR、BACKGROUND_BLUR
TEXT 居中使用显式的 width,并设置 textAlign: "CENTER"会自动推断 textAutoResize: "NONE",以确保居中生效
VECTOR 路径d: "M 150 7 A 143 143 0 1 1 29.26 226.62"SVG A 弧线会自动转换为三次贝塞尔曲线;支持逗号
页面管理
操作描述
figma.status()当前 Figma 上下文信息
figma.listPages()列出所有页面
figma.setPage({ name })切换当前页面
figma.createPage({ name })添加新页面
节点操作
操作描述
figma.clone({ id, x?, y?, parentId? })复制节点,可选择重新定位
figma.group({ nodeIds, name? })将多个节点编组
figma.ungroup({ id })取消 GROUP/FRAME 的编组
figma.flatten({ id })将矢量图形扁平化/合并为单一路径
figma.resize({ id, width, height })调整任意节点的大小
figma.set_selection({ ids })以编程方式选择节点
figma.set_viewport({ nodeId?, x?, y?, zoom? })导航视口
figma.batch({ operations })在一次调用中执行最多 50 项操作(快 10–25 倍)
组件
操作描述
figma.listComponents()列出文档中的所有组件
figma.createComponent({ nodeId, name? })将 FRAME/GROUP 转换为可复用组件
figma.instantiate({ componentId/Name, parentId, x, y })创建组件实例
figma.instantiate({ ..., overrides: { "LayerName": { text, fill, fontSize, visible, ... } } })使用各图层覆盖值创建实例
设计令牌与样式
操作描述
figma.setupDesignTokens({ colors, numbers, fontSizes, fonts, textStyles, modes })初始化完整的令牌系统(幂等)——在一次调用中设置颜色、间距、排版、文本样式和多模式
figma.createVariableCollection({ name })创建变量集合(“Colors”“Spacing”)
figma.createVariable({ name, collectionId, resolvedType, value })创建 COLOR/FLOAT/STRING/BOOLEAN 变量
figma.addVariableMode({ collectionId, modeName })添加模式(例如“dark”“compact”)
figma.renameVariableMode({ collectionId, modeId, newName })重命名模式
figma.removeVariableMode({ collectionId, modeId })移除模式
figma.setVariableValue({ variableId/Name, modeId/Name, value })设置各模式的值
figma.modifyVariable({ variableName, value })更改变量值——所有绑定的节点都会更新
figma.applyVariable({ nodeId, field, variableId/Name })将变量绑定到节点属性
figma.applyTextStyle({ nodeId, styleName })按名称将本地文本样式应用到 TEXT 节点(自动加载字体)
figma.setFrameVariableMode({ nodeId, collectionId, modeName })将画框固定为某个变量模式(Light/Dark、Compact/Large)
figma.clearFrameVariableMode({ nodeId, collectionId })将画框重置为文档默认模式
figma.createPaintStyle({ name, color })创建可复用的绘制样式
figma.createTextStyle({ name, fontFamily, fontSize, ... })创建可复用的文本样式(手动创建——建议使用 setupDesignTokens.textStyles)
figma.ensure_library()创建/获取 Design Library 画框
figma.get_library_tokens()读取库中的颜色和文本令牌

applyVariable 支持的字段——将 FLOAT/COLOR/STRING/BOOLEAN 变量绑定到:

  • 颜色:fill、stroke
  • 几何属性:opacity、width、height、strokeWeight
  • 圆角半径:cornerRadius 和单独的 topLeftRadius/topRightRadius/bottomLeftRadius/bottomRightRadius
  • 间距(自动布局):paddingTop、paddingBottom、paddingLeft、paddingRight、itemSpacing、counterAxisSpacing
  • 排版(TEXT 节点):fontSize、letterSpacing、lineHeight、paragraphSpacing、paragraphIndent
  • 字体替换(STRING):fontFamily、fontStyle、characters——通过一个变量即可将 Inter 替换为 SF Pro
  • 可见性(BOOLEAN):visible
图像与图标辅助工具(服务端)
操作描述
figma.loadImage(url, opts)下载图像 → 放置到画布上
figma.loadIcon(name, opts)获取 SVG 图标,支持 7 个图标库回退(优先使用 iOS 填充样式)
figma.loadIconIn(name, opts)将图标置于居中的圆形背景中

loadIcon 回退优先级(优先填充样式,首选 iOS 风格): Ionicons(iOS 填充) → Fluent UI(Win11 填充) → Bootstrap(填充) → Phosphor(填充) → Tabler Filled(4,500+) → Tabler Outline → Lucide(轮廓样式回退)

可免费替代付费的 Icons8 ios-filled。Ionicons 命名注意事项:Bell→notifications、Back→chevron-back、Clock→time、Fire→flame、Lightning→flash、Lock→lock-closed。

原型与交互
操作描述
figma.setReactions({ id, reactions })添加原型交互(ON_CLICK/ON_HOVER/ON_PRESS → NAVIGATE/OVERLAY/SWAP)
figma.getReactions({ id })读取节点的所有原型交互
figma.removeReactions({ id })清除节点的所有交互

支持的过渡效果:SMART_ANIMATE、DISSOLVE、MOVE_IN、MOVE_OUT、PUSH、SLIDE_IN、SLIDE_OUT、INSTANT 支持的缓动效果:LINEAR、EASE_IN、EASE_OUT、EASE_IN_AND_OUT、CUSTOM_BEZIER

滚动行为
操作描述
figma.setScrollBehavior({ id, overflowDirection })设置溢出滚动:NONE / HORIZONTAL / VERTICAL / BOTH
变体与组件替换
操作描述
figma.setComponentProperties({ id, properties })在 INSTANCE 上设置变体、布尔值、文本或实例替换属性
figma.swapComponent({ id, componentId })替换实例的主组件
figma.getComponentProperties({ id })读取组件/实例的所有属性和定义

可用的读取操作(figma_read)

操作描述
get_selection所选节点的完整设计树 + 设计令牌
get_design帧/页面的完整节点树(深度参数:默认值为 10,或 "full")
get_page_nodes当前页面上的顶层帧
screenshot将节点导出为 PNG — 在 Claude Code 中内嵌显示
export_svg将节点导出为 SVG 标记
export_image将节点导出为 base64 PNG/JPG — 用于保存到磁盘(format、scale 参数)
get_design_context经过 AI 优化的设计→代码载荷 — flex 布局、解析为 var(--name) 的令牌填充、带样式名称的排版、带变体属性的组件实例,以及 componentsUsed / tokensUsed 摘要。生成 React/Vue/Swift 代码时的最佳单次调用。
get_component_map组件实例映射 — 帧中的每个 INSTANCE 都包含 componentSetName、variantLabel、properties 和 suggestedImport 路径。通过 uniqueComponents[] 去重,并附带使用次数。
get_unmapped_components代码映射审计 — 列出在 Figma 中没有描述的实例(unmapped[])。生成代码前,可据此询问用户正确的导入路径。
get_node_detail单个节点的结构化属性 — 填充、布局、排版、效果、绑定变量**(解析为名称+值)、样式引用(解析为名称+十六进制值)、实例覆盖(完整字段列表)**、componentSetName + variantLabel
get_css节点的可直接使用的 CSS 字符串 — 背景、flex、边框、圆角、阴影、排版、不透明度、变换。最适合设计转代码。
get_styles所有本地绘制、文本、效果和网格样式
get_local_components带描述和变体属性的组件列表
get_viewport当前视口的位置、缩放和边界
get_variables本地变量(设计令牌)— 集合、模式和值
search_nodes按类型、名称、填充颜色、字体、大小查找节点 — 支持 includeHidden
scan_design大型文件的渐进式扫描 — 所有文本、颜色、字体、图像和图标

includeHidden 参数(布尔值,默认值为 false)— 适用于 get_selection、get_design、search_nodes、scan_design。当值为 false(默认值)时,会跳过 visible: false 的节点。传入 true 可包含隐藏图层。


使用现有项目

打开已有设计系统的 Figma 文件时,始终先读取,再绘制。

步骤 1 — 读取现有内容
figma_read get_variables      → load variable IDs (Design Tokens)
figma_read get_styles         → load paint/text style IDs and hex values
figma_read get_local_components → load component IDs
figma_read get_page_nodes     → load top-level frame IDs
步骤 2 — 在 figma_write 中构建查找映射
// Load variables → build varMap: name → id
var vars = await figma.get_variables();
var varMap = {};
for (var ci = 0; ci < vars.collections.length; ci++) {
  var col = vars.collections[ci];
  for (var vi = 0; vi < col.variables.length; vi++) {
    var v = col.variables[vi];
    varMap[v.name] = v.id;
  }
}

// Load styles → build colorMap: name → hex, textMap: name → {fontSize, fontWeight}
var styles = await figma.get_styles();
var colorMap = {}, textMap = {};
styles.paintStyles.forEach(function(s) { colorMap[s.name] = s.hex; });
styles.textStyles.forEach(function(s)  { textMap[s.name]  = s; });

// Load components → build compMap: name → id
var comps = await figma.get_local_components();
var compMap = {};
comps.components.forEach(function(c) { compMap[c.name] = c.id; });
步骤 3 — 使用发现的值创建节点
// Use colorMap for fill (hex from existing styles)
var card = await figma.create({
  type: "FRAME", name: "Card",
  fill: colorMap["color/bg-surface"] || "#FFFFFF",
  width: 360, height: 200,
  layoutMode: "VERTICAL", paddingTop: 16, paddingLeft: 16,
  paddingBottom: 16, paddingRight: 16, itemSpacing: 12,
});

// Then bind variables so light/dark mode switches propagate
if (varMap["bg-surface"])
  await figma.applyVariable({ nodeId: card.id, field: "fill",        variableId: varMap["bg-surface"] });
if (varMap["radius-md"])
  await figma.applyVariable({ nodeId: card.id, field: "cornerRadius",variableId: varMap["radius-md"] });
if (varMap["spacing-md"])
  await figma.applyVariable({ nodeId: card.id, field: "paddingTop",  variableId: varMap["spacing-md"] });
步骤 4 — 使用覆盖属性实例化组件
// Prefer existing components over drawing from scratch
if (compMap["btn/primary"]) {
  await figma.instantiate({
    componentId: compMap["btn/primary"],
    parentId: card.id,
    overrides: { "Label": { text: "Confirm", fill: "#FFFFFF" } }
  });
}
步骤 5 — 将帧固定为 Light / Dark 模式
var collection = vars.collections.find(function(c) { return c.name === "Design Tokens"; });

// Duplicate frame and preview both modes side by side
var frames = await figma.get_page_nodes();
var homeId  = frames.find(function(f) { return f.name === "Home"; }).id;
var light   = await figma.clone({ id: homeId, x: 0,    name: "Preview/Light" });
var dark    = await figma.clone({ id: homeId, x: 1540, name: "Preview/Dark"  });
await figma.setFrameVariableMode({ nodeId: light.id, collectionId: collection.id, modeName: "light" });
await figma.setFrameVariableMode({ nodeId: dark.id,  collectionId: collection.id, modeName: "dark"  });

完整 API 参考和所有设计规则:在 AI 客户端中运行 figma_docs。


Star History

如果 figma-ui-mcp 对你有帮助,请给它点个星 — 这有助于其他人发现这个项目!

GitHub stars

Star History Chart


许可证

License: MIT

MIT © TranHoaiHung — 可免费使用、修改和分发。详情请参阅 LICENSE。


关键词

Figma MCP、Claude Code 转 Figma、Cursor 转 Figma、AI 转 Figma、Figma AI 插件、Figma MCP 桥接器、Figma MCP 服务、Figma 设计转代码、代码转 Figma 设计、AI UI 设计、Figma 自动化、Figma AI 插件、Model Context Protocol Figma、Claude Figma、Windsurf Figma、VS Code Figma、Antigravity Figma、AI 设计工具、Figma API 替代方案、Figma 本地主机插件、用 AI 绘制 UI、AI 生成 Figma 设计、Figma AI 设计系统、Figma MCP 服务、读取 Figma 设计、写入 Figma 设计、双向 Figma、Figma 桌面插件、npx figma-ui-mcp

评论

支持 Markdown

第一次接触 MCP?

从协议是什么,到在客户端里装上第一个服务,这几条回答覆盖了大多数入门问题。

一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。