mcpField
F
Figma Vector MCP

Figma Vector MCP

本地服务
workingmodel.co媒体与设计01 周前更新

关于 Figma Vector MCP

Figma Vector MCP 将 MCP 客户端连接到 Figma 插件,以便在画布上创建可编辑矢量并操作文档。它提供路径、样式、布局、组件、页面和导出工具,通过本地 WebSocket 转发命令。

主要功能

  1. 01从 SVG 和路径创建可编辑矢量
  2. 02添加形状、文本、渐变和图像填充
  3. 03调整效果、描边和混合模式
  4. 04配置自动布局和组件
  5. 05搜索节点、样式和字体
  6. 06批量执行命令并导出 SVG 或 PNG

适用场景

  1. 01在 Figma 画布上制作矢量图
  2. 02设置画布节点样式与布局
  3. 03管理组件和文档页面
  4. 04导出选定节点或页面

MCP 相关

MCP 服务通过本地 WebSocket 中继与 Figma 插件通信,向 MCP 客户端提供创建、编辑画布节点和检查文档的工具。MCP 客户端通过 stdio 连接服务。

配置

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

mcp.json · 通用配置
{
"mcpServers": {
"workingmodel-figma-vector": {
"command": "npx",
"args": [
"-y",
"figma-vector-mcp"
],
"env": {
"FVMCP_CHANNEL": "<FVMCP_CHANNEL>",
"FVMCP_PORT": "<FVMCP_PORT>"
}
}
}
}
启动命令npx -y figma-vector-mcp
需要配置的环境变量
FVMCP_CHANNELChannel name the Figma plugin joins on the local socket relay (default: figma-vector-mcp)
FVMCP_PORTPort of the local socket relay (default: 3055)

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

安装包
npmfigma-vector-mcp0.3.3

工具

58

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

参数类型必填说明
channelstring是频道名称(必须与 Figma 插件匹配)

详细介绍

Figma Vector MCP

一款 Figma 插件 + MCP 服务,可通过本地 WebSocket 中继,让 Claude(或任何 MCP 客户端)在 Figma 画布上创建和操控完全可编辑的矢量节点,包括路径、形状、渐变、文本、效果、图像填充等。

由 Working Model Inc 开发

npm version npm downloads

版本 0.3.3 — 涵盖创建、样式、布局、组件、效果、页面和导出的 58 个工具。

为何开发此项目

cursor-talk-to-figma-mcp 非常适合读取 Figma 状态和创建基本图元,但它不具备矢量路径创建、渐变、效果或合成工具。此插件填补了这一空白:

功能cursor-talk-to-figma-mcpfigma-vector-mcp
创建矩形 / 椭圆 / 画框 / 文本✅✅
根据 SVG 字符串创建❌✅
根据路径 d 字符串创建❌✅
创建折线 / 多边形❌✅
渐变填充(线性、径向、角度、菱形)❌✅
图像填充(base64 → 画布)❌✅
效果(阴影、模糊)❌✅
混合模式❌✅
布尔运算(联合、减去等)❌✅
自动布局❌✅
组件 + 实例❌✅
字体发现❌✅
节点搜索❌✅
多页面管理❌✅
命名节点注册表❌✅
批量命令(单次往返)❌✅
自动重连 + 命令队列❌✅
导出 SVG + PNG❌✅

架构

Claude (MCP client)
  ↕ stdio (MCP protocol)
server.ts (MCP server)
  ↕ WebSocket (ws://localhost:3055)
socket.ts (relay — channel-based routing)
  ↕ WebSocket
Figma plugin (ui.html ↔ code.js)
  ↕ postMessage
Figma Plugin API → canvas

套接字中继在本地运行。Figma 插件连接并加入一个命名频道。MCP 服务加入同一频道并发送命令。结果沿相同路径返回。


AI Agent 快速入门

适用于 AI Agent(Claude Code、Cursor 等)——启动任何会话的推荐调用顺序:

1. health_check                    → confirm plugin is connected
2. get_document_info               → get page IDs, current page, top-level nodes
3. get_available_fonts             → discover loadable fonts before create_text
4. get_styles                      → load brand colours/text styles if available

颜色约定: 全程所有 RGB 值均为 0–1(与 Figma 的内部格式一致)。r: 1, g: 0, b: 0 = 红色。切勿使用 0–255。

渐变工作流:

1. create_frame({ width, height })          → get frameId
2. set_gradient_fill({ nodeId: frameId, type: "LINEAR", angle: 135,
     stops: [{ color: { r:0.2, g:0.1, b:0.9 }, position: 0 },
             { color: { r:0.9, g:0.2, b:0.4 }, position: 1 }] })

图像填充工作流(使用生成式 AI):

1. Generate image via Replicate/fal.ai → get base64 PNG
2. create_frame({ width: 512, height: 512 })
3. set_image_fill({ nodeId, base64, scaleMode: "FILL" })

批量合成——使用 $prev.id 串联命令,无需额外往返:

{ "commands": [
    { "command": "create_frame", "params": { "width": 400, "height": 300, "name": "Card" } },
    { "command": "set_gradient_fill", "params": { "nodeId": "$prev.id", "type": "LINEAR",
        "stops": [{"color":{"r":0.1,"g":0.1,"b":0.9},"position":0},
                  {"color":{"r":0.8,"g":0.2,"b":0.5},"position":1}] } },
    { "command": "create_text", "params": { "parentId": "$results.0.id",
        "text": "Hello", "fontSize": 32, "x": 24, "y": 24 } }
]}

已知 SVG 限制: figma.createNodeFromSvg() 会剥离 <defs>、渐变、滤镜、蒙版和动画。需要渐变时,请使用 set_gradient_fill,不要使用 SVG <linearGradient>。

重连: 如果插件断开连接,它会通过指数退避自动重连(1 秒→最长 30 秒),并重放排队的命令(最多保留 30 秒)。短暂中断无需手动干预。


设置

1 — 安装插件
  1. 克隆此仓库或下载源代码
  2. 在 Figma 桌面应用中:Plugins → Development → Import plugin from manifest
  3. 选择 src/figma-plugin/manifest.json
2 — 安装 MCP 服务
npm install -g figma-vector-mcp
# or use without installing via npx / bunx (see MCP config below)
3 — 启动套接字中继
bun run socket

监听地址为 ws://localhost:3055。登录时自动启动(macOS):

./scripts/setup.sh --launchd
4 — 配置 MCP 服务
# Auto-detect Claude Code / Cursor and write config:
./scripts/setup.sh

# Local build:
./scripts/setup.sh --local

# Install git pre-commit sandbox lint hook:
./scripts/setup.sh --hooks

手动配置(~/.claude/settings.json 或 ~/.cursor/mcp.json):

{
  "mcpServers": {
    "FigmaVectorMCP": {
      "command": "bunx",
      "args": ["figma-vector-mcp@latest"],
      "env": { "FVMCP_CHANNEL": "figma-vector-mcp" }
    }
  }
}
5 — 连接插件
  1. 打开你的 Figma 文件
  2. Plugins → Development → Figma Vector MCP
  3. 输入服务 URL(ws://localhost:3055)→ Connect
  4. 输入频道名称(figma-vector-mcp)→ Join

插件会保存上次使用的 URL 和频道,下次打开时自动预填。会话期间请保持插件面板打开——关闭面板会终止 WebSocket 连接。

6 — 验证
health_check → { "status": "ok", "version": "0.3.3", "currentPage": { ... } }

环境变量

变量默认值描述
FVMCP_PORT3055Socket 中继端口
FVMCP_CHANNELfigma-vector-mcp通道名称 — 必须与插件一致
FVMCP_TIMEOUT_MS10000默认命令超时时间(ms)

各工具的超时设置:health_check → 3s,export_node_as_png → 30s,export_node_as_svg → 15s,create_batch → 60s。


工具参考

连接与健康状况
工具描述关键参数
health_checkPing 插件;确认连接状态—
join_channel加入指定通道channel
矢量创建
工具描述关键参数
create_vector_from_svg根据 SVG 字符串放置可编辑矢量svg、x、y、name、parentId
create_path根据 SVG d 路径字符串创建矢量d、x、y、fillColor、strokeColor、strokeWeight
create_polyline根据 [x,y][] 点对创建矢量points、closed、strokeColor、strokeWeight
基本图形
工具描述关键参数
create_frame容器框架width、height、x、y、fillColor
create_rectangle矩形width、height、x、y、fillColor
create_ellipse椭圆 / 圆形width、height、x、y、fillColor
create_text文本节点,可选固定宽度列text、fontSize、fontFamily、fontStyle、fillColor、width、height、textAutoResize
填充与颜色
工具描述关键参数
set_fill_color纯色 RGBA 填充(0–1)nodeId、r、g、b、a
set_gradient_fill渐变填充 — LINEAR、RADIAL、ANGULAR、DIAMONDnodeId、type、stops、angle、center、gradientTransform
set_image_fill将 Base64 图像用作填充nodeId、base64、scaleMode、opacity
描边
工具描述关键参数
set_stroke完整描边控制nodeId、color、weight、position、dashPattern、lineCap、lineJoin
set_stroke_color快速设置描边颜色和粗细nodeId、r、g、b、a、weight
效果与合成
工具描述关键参数
set_effect投影、内阴影、模糊、背景模糊nodeId、effects[](type、color、offset、blur、spread)、mode(REPLACE | APPEND)
set_blend_mode图层混合模式nodeId、mode(NORMAL、MULTIPLY、SCREEN、OVERLAY…)
节点操作
工具描述关键参数
set_corner_radius圆角半径 — 统一设置或逐角设置nodeId、radius 或 topLeft、topRight、bottomLeft、bottomRight
set_opacity不透明度 0–1nodeId、opacity
set_text_style修改文本属性和文本框尺寸nodeId、fontSize、fontFamily、fontStyle、letterSpacing、lineHeight、textAlign、fillColor、width、height、textAutoResize
rename_node重命名节点nodeId、name
set_visibility显示或隐藏节点nodeId、visible
reorder_node更改父节点内的 Z 顺序nodeId、action(BRING_TO_FRONT / SEND_TO_BACK / BRING_FORWARD / SEND_BACKWARD)或 index
move_node重新定位nodeId、x、y
resize_node调整大小nodeId、width、height
delete_node从画布中移除nodeId
clone_node复制,可选重新定位nodeId、x、y、parentId
group_nodes将节点编组nodeIds[]、name、parentId
ungroup_nodes取消编组nodeId
boolean_operation联合、相减、相交、排除nodeIds[]、operation、name
create_mask剪切蒙版 — maskNode 剪切 targetNodemaskNodeId、targetNodeId、name
布局
工具描述关键参数
set_auto_layout启用/配置自动布局nodeId、direction、spacing、padding、primaryAxisAlign、counterAxisAlign、primaryAxisSizingMode、counterAxisSizingMode、wrap
set_layout_grid在画框上设置列/行/网格参考线nodeId、grids[](pattern、count、gutterSize、sectionSize、alignment、color)
batch_set_properties批量更新填充/描边/不透明度/位置/尺寸operations[](nodeId + 任意属性子集)
组件
工具描述关键参数
create_component将画框/组转换为组件nodeId、name
create_instance放置组件实例componentId、x、y、parentId
get_components列出所有本地组件—
get_library_components按名称搜索本地组件query
文档与页面
工具描述关键参数
get_document_info文档名称、页面及当前页面的子节点—
get_selection当前选中的节点—
get_node_info节点完整详情:填充、描边、布局、文本、约束nodeId
set_focus将视口滚动至节点并选中该节点nodeId
find_nodes按名称和/或类型搜索query、type、pageId、recursive
get_page_list所有页面—
switch_page激活某个页面pageId 或 pageName
create_page创建新页面name
duplicate_frame_to_page将节点复制到另一个页面nodeId、targetPageId、x、y
节点注册表
工具描述关键参数
register_node为节点 ID 保存命名别名(保存在文档中)alias、nodeId
resolve_node按别名查找节点 IDalias
颜色注册表
工具描述关键参数
register_color将命名颜色保存到文档调色板(0–1)alias、r、g、b、a
resolve_color按别名查找颜色alias
list_colors列出文档中注册的所有颜色—
样式与字体
工具描述关键参数
get_styles所有本地绘制样式和文本样式—
apply_style将文档样式应用到节点nodeId、styleId、styleType
get_available_fonts列出可加载字体;按名称筛选query
导出
工具描述关键参数
export_node_as_svg将节点导出为 SVG 字符串nodeId
export_node_as_png导出为 base64 PNGnodeId、scale(默认值为 2)
screenshot_current_page将整页导出为 base64 PNGscale
批处理
工具描述关键参数
create_batch在一次往返中运行多个命令。支持用于链式调用的 $prev.id 和 $results.N.field 令牌。commands[](command、params)

沙箱兼容性

插件主线程(code.js)在 Figma 受限的 QuickJS 沙箱中运行。UI(ui.html)是普通浏览器环境,不受影响。

构建前运行 bun run lint:plugin,检查 code.src.js 是否存在违规。可通过 ./scripts/install-hooks.sh 安装 pre-commit 钩子。

code.js 中禁止使用的内容
API / 语法安全替代方案
import / export将所有依赖内联
x ?? y(x != null) ? x : y
obj?.propobj && obj.prop
{ ...obj } / [ ...arr ]Object.assign({}, obj) / Array.from(arr)
localStoragefigma.clientStorage
TextDecoder分块使用 String.fromCharCode
fetch()主线程中不可用
figma.getNodeById()(同步)await figma.getNodeByIdAsync()
figma.currentPage = x(同步赋值)await figma.setCurrentPageAsync(x)
figma.getLocalPaintStyles()(同步)await figma.getLocalPaintStylesAsync()
figma.getLocalTextStyles()(同步)await figma.getLocalTextStylesAsync()
未加载页面就调用 figma.root.findAllWithCriteria()先调用 await figma.loadAllPagesAsync()
SVG 兼容性(create_vector_from_svg)
功能状态
<rect>、<polygon>、<polyline>、<path>、<circle>、<ellipse>✅
fill、stroke、stroke-width、stroke-linecap、stroke-linejoin✅
viewBox、width、height✅
<defs> 中的 <linearGradient> / <radialGradient>❌ 已剥离 — 请使用 set_gradient_fill
<filter>、<mask>、<pattern>❌ 已剥离
<animate>、<animateTransform>❌ 已剥离
<script>、<foreignObject>❌ 已剥离
fill="url(#...)" 引用❌ 已替换为 fill="none"

开发

bun install              # install deps
bun run socket           # start relay on :3055
bun run build            # build MCP server → dist/server.js
bun run build:plugin     # build plugin: code.src.js → code.js
bun run lint:plugin      # check code.src.js for sandbox violations
./scripts/install-hooks.sh  # install pre-commit lint hook
插件工作流
  1. 编辑 src/figma-plugin/code.src.js
  2. bun run lint:plugin — 在构建前检查沙箱违规
  3. bun run build:plugin — esbuild 输出 code.js(ES2017)
  4. 在 Figma 中关闭并重新打开插件面板,以加载新的 code.js

致谢

  • Socket 中继(src/socket.ts)改编自 cursor-talk-to-figma-mcp — Copyright (c) 2025 sonnylazuardi,MIT License
  • code.src.js 中的 setCharacters 辅助函数改编自同一项目 — Copyright (c) 2025 sonnylazuardi,MIT License

许可证

MIT © Working Model — 详见 LICENSE 和 THIRD_PARTY_NOTICES.md。


由 Working Model Inc 开发

评论

支持 Markdown

第一次接触 MCP?

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

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