Figma MCP服务器
模型上下文协议(MCP)服务器,提供对Figma API操作(文件、节点、图像、评论、团队、项目和组件)的访问。
认证
此服务器是 无状态和多租户每个面向租户的工具都接受 access_token 在每次调用时,根据请求进行身份验证——内存中不存储会话状态。
Figma支持两种代币类型:
| 类型 | 如何获取 |
|---|---|
| 个人访问令牌(PAT) | Figma→ 账户设置→ 个人访问令牌 |
| OAuth2承载令牌 | 标准OAuth2流 https://www.figma.com/oauth |
将任一令牌传递为 access_token 在每次工具调用中。服务器将其作为 X-Figma-Token 头到Figma REST API。
所需的Figma API作用域(OAuth2): file_read, file_comments:write
特性
| 工具 | 说明 |
|---|---|
health_check |
检查服务器就绪情况(无需身份验证) |
get_me |
获取经过身份验证的用户配置文件 |
get_file |
检索Figma文件文档树 |
get_file_nodes |
从文件中检索特定节点 |
get_file_components |
在文件中列出本地组件 |
get_file_styles |
在文件中列出本地样式 |
get_file_versions |
检索文件的版本历史记录 |
get_images |
将节点导出为渲染图像URL |
get_image_fills |
获取图像填充的下载URL |
get_comments |
列出文件上的所有评论 |
post_comment |
在文件上发表评论 |
get_team_projects |
列出团队中的项目 |
get_project_files |
列出项目中的文件 |
get_team_components |
列出团队库中已发布的组件 |
get_component |
获取特定已发布组件的元数据 |
设置```bash
pip install -r requirements.txt
## 运行服务器```bash
# stdio (default)
python server.py
# SSE
python server.py --transport sse --host 127.0.0.1 --port 8001
# Streamable HTTP
python server.py --transport streamable-http --host 127.0.0.1 --port 8001
工具调用示例
获取Figma文件:```json
{
"tool": "get_file",
"arguments": {
"access_token": "figd_...",
"file_key": "abc123XYZ"
}
}
**将节点导出为PNG图像:**```json
{
"tool": "get_images",
"arguments": {
"access_token": "figd_...",
"file_key": "abc123XYZ",
"node_ids": "1:2,3:4",
"format": "png",
"scale": 2
}
}
发表评论:```json
{
"tool": "post_comment",
"arguments": {
"access_token": "figd_...",
"file_key": "abc123XYZ",
"message": "Looks great — ready for dev handoff."
}
}
**列出团队项目:**```json
{
"tool": "get_team_projects",
"arguments": {
"access_token": "figd_...",
"team_id": "123456789"
}
}
项目结构```text
cl-mcp-figma/
|-- server.py
|-- requirements.txt
|-- README.md
|-- .gitignore
-- figma_mcp/
|-- __init__.py
|-- cli.py
|-- config.py
|-- schemas.py
|-- service.py-- tools.py
```
故障排除
- 401未经授权 --令牌无效、过期或缺少所需的作用域。
- 403禁止 --令牌无法访问请求的文件或团队。
- 404未找到 --文件密钥、节点ID、团队ID或组件密钥不存在。
- 429请求太多 --Figma速率限制命中;请后退并重试。
