使用说明
Figma MCP电桥<
Figma开发模式和设计系统之间通过MCP(模型上下文协议)服务器和Claude代理进行双向同步。
概述
Figma MCP桥实现了Figma和代码库之间设计令牌的无缝同步。它提供:
- 拉:从Figma文件中获取设计令牌
- 推:用本地令牌更改更新Figma
- 变换:在Figma和标准令牌格式之间转换
- 自动化:GitHub持续同步操作
快速开始
1.安装
# Clone the repository
git clone https://github.com/jgtolentino/figma-mcp-bridge.git
cd figma-mcp-bridge
# Install dependencies
pip install -r server/requirements.txt
2.配置
# Initialize configuration
python cli/figma_ds_sync.py init
# Or manually create .env file
cat > .env << EOF
FIGMA_PAT=your_figma_personal_access_token
FIGMA_FILE_ID=your_figma_file_id
EOF
3.基本用法
# Pull tokens from Figma
python cli/figma_ds_sync.py pull
# Push tokens to Figma
python cli/figma_ds_sync.py push
# Validate token structure
python cli/figma_ds_sync.py validate tokens/tokens.json
MCP服务器
启动MCP服务器以启用API访问:
# Start server
cd server
uvicorn main:app --reload
# Server will be available at http://localhost:8000
API终点
GET /-健康检查GET /figma/design-tokens-获取设计令牌POST /figma/push-将代币推送到FigmaGET /figma/components-获取组件定义
CLI命令
拉动命令
python cli/figma_ds_sync.py pull [OPTIONS]
Options:
-o, --output PATH Output file path [default: tokens/tokens.json]
-f, --file-id TEXT Figma file ID (overrides env)
-p, --pretty Pretty print JSON [default: True]
推送命令
python cli/figma_ds_sync.py push [OPTIONS]
Options:
-i, --input PATH Input file path [default: tokens/tokens.json]
-f, --file-id TEXT Figma file ID (overrides env)
-m, --merge Merge with existing tokens [default: True]
-d, --dry-run Preview changes without applying
构建命令(样式词典)
python cli/figma_ds_sync.py build [OPTIONS]
Options:
-c, --config PATH Style Dictionary config [default: style-dictionary.config.js]
-p, --platform TEXT Build specific platform only
变换命令
python cli/figma_ds_sync.py transform INPUT OUTPUT [OPTIONS]
Options:
-d, --direction TEXT Transform direction: figma-to-sd or sd-to-figma
-p, --platform TEXT Target platform for transformation
推送组件命令
python cli/figma_ds_sync.py push-component COMPONENT_PATH [OPTIONS]
Options:
-f, --file-id TEXT Figma file ID (overrides env)
-s, --as-set Create as component set
-d, --dry-run Preview without pushing
merge命令
python cli/figma_ds_sync.py merge INPUT_FILES... [OPTIONS]
Options:
-o, --output PATH Output file for merged tokens [default: tokens/merged.json]
代币结构
令牌应遵循以下结构:
{
"colors": {
"primary": {
"value": "#1E40AF",
"type": "color"
}
},
"spacing": {
"sm": {
"value": "8px",
"type": "dimension"
}
},
"typography": {
"heading": {
"value": {
"fontFamily": "Inter",
"fontSize": 24,
"fontWeight": 700
},
"type": "typography"
}
}
}
GitHub操作
推送时自动同步令牌:
-
将机密添加到GitHub存储库:
FIGMA_PAT-您的Figma个人访问令牌FIGMA_FILE_ID-您的Figma文件ID
-
当您向推送更改时,令牌将自动同步
tokens/目录
脉冲器集成
在Pulser CLI中注册:
# In your main repository
:clodrep run figma-agent.yaml
# Use Pulser commands
pulser figma:pull
pulser figma:push
pulser figma:build
pulser figma:transform
样式词典集成
该桥包括对多平台令牌生成的完整样式字典支持:
支持的平台
- 网络:CSS变量、SCSS、JavaScript/TypeScript
- iOS:Swift、Objective-C颜色/字体定义
- 安卓:颜色、尺寸、字体的XML资源
工作流示例
# 1. Pull tokens from Figma
python cli/figma_ds_sync.py pull
# 2. Transform to Style Dictionary format
python cli/figma_ds_sync.py transform tokens/tokens.json tokens/sd-tokens.json
# 3. Build for all platforms
python cli/figma_ds_sync.py build
# 4. Or build for specific platform
python cli/figma_ds_sync.py build --platform css
组件推送(测试版)
将React组件作为原生组件推回Figma:
# Push single component
python cli/figma_ds_sync.py push-component src/components/Button.tsx
# Push directory of components
python cli/figma_ds_sync.py push-component src/components/
# Create component set from variants
python cli/figma_ds_sync.py push-component src/components/Button/ --as-set
支持的组件功能
- TypeScript道具提取
- 从联合类型中检测变量
- 默认道具值
- 组件文档
发展
项目结构
figma-mcp-bridge/
�� server/ # FastAPI MCP server
�� main.py # API endpoints
�� figma_client.py # Figma API client
�� design_token_utils.py # Token utilities
�� cli/ # CLI tool
�� figma_ds_sync.py # Typer CLI app
�� tokens/ # Token files
�� .github/workflows/ # GitHub Actions
�� figma-agent.yaml # Claude agent config
运行测试
# Install dev dependencies
pip install pytest pytest-asyncio
# Run tests
pytest tests/
Figma设置
-
生成个人访问令牌:
- 前往Figma� 设置� 个人访问令牌
- 创建具有文件读/写权限的新令牌
-
获取您的文件ID:
- 在浏览器中打开Figma文件
- 从URL复制ID:
figma.com/file/[FILE_ID]/...
-
启用开发模式:
- 在Figma中打开文件
- 在工具栏中切换开发模式
故障排除
常见问题
-
认证错误
Error: FIGMA_PAT environment variable not set解决方案:确保
.env文件存在有效令牌 -
找不到文件
Error: Failed to fetch Figma file解决方案:验证文件ID和令牌权限
-
令牌验证失败
Error: Token 'primary' missing 'value' field解决方案:确保令牌遵循所需的结构
贡献
- 分叉存储库
- 创建特征分支(
git checkout -b feature/amazing-feature) - 提交更改(
git commit -m 'Add amazing feature') - 推送到分支(
git push origin feature/amazing-feature) - 打开拉取请求
许可证
MIT许可证-请参阅 许可证 详细信息文件
作者
杰克A(@jgtoletino)
Built with d for the design-to-code community
