使用FastMCP实现的Python版Figma模型上下文协议(MCP)服务器。该服务器允许AI助手通过WebSocket连接读取数据并分析设计。
出于安全考虑,此服务器不支持:
set_*)join_channel - 加入通道以与Figma通信get_document_info - 获取当前Figma文档的信息get_selection - 获取当前选择的信息read_my_design - 获取分配的详细信息,包括所有节点的细节get_node_info - 根据ID获取特定节点的信息get_nodes_info - 获取多个节点的信息get_node_children - 获取所有子节点的ID,完全递归投资get_styles - 获取文档中的所有样式get_local_components - 获取所有本地组件get_instance_overrides - 获取组件实例重新定义scan_text_nodes - 扫描指定节点内的文本节点scan_nodes_by_types - 扫描特定类型的节点(TEXT, RECTANGLE, FRAME)export_node_as_image - 将节点导出为图像(PNG, JPG, SVG, PDF)get_annotations - 获取节点或整个文档的注释get_reactions - 获取节点的反应(交互连接)AI客户端(Cursor) ←→ MCP服务器 ←→ WebSocket服务器 ←→ Figma插件
cd python-version
python -m venv venv
source venv/bin/activate # Linux/Mac
# 或者 venv\Scripts\activate # Windows
pip install -r requirements.txt
python websocket_proxy.py --port 3055 --debug
src/cursor_mcp_plugin/manifest.jsonabc1123xyz)在MCP Cursor设置(.cursor/mcp.json)中添加以下配置:
{
"mcpServers": {
"figma-mcp": {
"command": "python",
"args": ["-m", "src.figma_mcp.server", "--server", "localhost:3055"],
"cwd": "/path/to/your/figma_mcp"
}
}
}
替代方法(使用虚拟环境):
{
"mcpServers": {
"figma-mcp": {
"command": "/path/to/your/figma_mcp/venv/bin/python",
"args": ["/path/to/your/figma_mcp/src/figma_mcp/server.py", "--server", "localhost:3055"]
}
}
}
注意:将
/path/to/your/figma_mcp替换为项目的实际路径。
python -m src.figma_mcp.server --server localhost:3055
使用接收到的频道ID使用工具 join_channel:
{
"tool": "join_channel",
"arguments": {
"channel": "abc123xyz"
}
}
{
"tool": "get_document_info",
"arguments": {}
}
{
"tool": "get_node_info",
"arguments": {
"node_id": "4472:98013"
}
}
{
"tool": "get_node_children",
"arguments": {
"node_id": "4472:98012"
}
}
{
"tool": "scan_text_nodes",
"arguments": {
"node_id": "4472:98012",
"use_chunking": true,
"chunk_size": 50
}
}
{
"tool": "export_node_as_image",
"arguments": {
"node_id": "4472:98013",
"format": "PNG",
"scale": 2.0
}
}
--debug在项目根目录或家目录创建文件 .cursor/mcp.json:
{
"$schema": "https://schema.cursor.com/mcp.json",
"mcpServers": {
"figma-mcp": {
"command": "python",
"args": ["-m", "src.figma_mcp.server", "--server", "localhost:3055"],
"cwd": "/absolute/path/to/figma_mcp",
"env": {
"PYTHONPATH": "/absolute/path/to/figma_mcp"
}
}
}
}
主要参数:
command:运行Python的命令args:启动MCP服务器的参数cwd:工作目录(项目的绝对路径)env:环境变量(可选)python-version/
├── src/figma_mcp/
│ ├── __init__.py
│ ├── server.py # 主要的MCP服务器
│ ├── websocket_client.py # WebSocket客户端
│ ├── types.py # Pydantic类型
│ └── utils.py # 工具
├── tests/ # 测试(41个测试)
├── websocket_proxy.py # WebSocket服务器
├── requirements.txt # 依赖项
└── README.md # 文档
运行所有测试:
python -m pytest tests/ -v
连接测试:
python test_mcp.py
MIT许可证