该项目实现了Cursor AI与Figma之间的Model Context Protocol (MCP)集成,使Cursor能够与Figma进行通信,以读取设计并对其进行编程修改。
https://github.com/user-attachments/assets/129a14d2-ed73-470f-9a4c-2240b2a4885c
src/talk_to_figma_mcp/ - 用于Figma集成的TypeScript MCP服务器src/cursor_mcp_plugin/ - 用于与Cursor通信的Figma插件src/socket.ts - 促进MCP服务器与Figma插件之间通信的WebSocket服务器curl -fsSL https://bun.sh/install | bash
bun setup
bun start
在~/.cursor/mcp.json中将服务器添加到Cursor MCP配置中:
{
"mcpServers": {
"TalkToFigma": {
"command": "bun",
"args": [
"/path/to/cursor-talk-to-figma-mcp/src/talk_to_figma_mcp/server.ts"
]
}
}
}
启动WebSocket服务器:
bun run src/socket.ts
src/cursor_mcp_plugin/manifest.json文件join_channel加入一个频道来连接插件和WebSocket服务器MCP服务器提供了以下工具与Figma进行交互:
get_document_info - 获取当前Figma文档的信息get_selection - 获取当前选区的信息get_node_info - 获取特定节点的详细信息create_rectangle - 创建一个新的矩形,包括位置、大小和可选名称create_frame - 创建一个新的框架,包括位置、大小和可选名称create_text - 创建一个新的文本节点,具有可定制的字体属性set_fill_color - 设置节点的填充颜色(RGBA)set_stroke_color - 设置节点的描边颜色和权重set_corner_radius - 设置节点的圆角半径,可选每个角的控制move_node - 将节点移动到新位置resize_node - 调整节点的新尺寸delete_node - 删除节点get_styles - 获取本地样式的信息get_local_components - 获取本地组件的信息get_team_components - 获取团队组件的信息create_component_instance - 创建组件实例export_node_as_image - 将节点导出为图像(PNG、JPG、SVG或PDF)execute_figma_code - 在Figma中执行任意JavaScript代码(谨慎使用)join_channel - 加入特定频道以与Figma进行通信导航至Figma插件目录:
cd src/cursor_mcp_plugin
编辑code.js和ui.html
在使用Figma MCP时:
get_document_info获取文档概览get_selection检查当前选区create_frame用于容器create_rectangle用于基本形状create_text用于文本元素get_node_info验证更改MIT