Figma转React Native工具箱
将Figma设计转换为React Native组件,允许用户从Figma设计中提取组件,并生成具有适当类型和样式的对应React Native组件。
MCP 服务配置
复制以下 JSON 到 OPClaw 或其他 MCP 客户端的配置文件中即可使用
{
"mcpServers": {
"figma-to-code": {
"args": [
"PATH_TO_REPO/build/index.js"
],
"command": "node",
"env": {
"FIGMA_FILE": "your_figma_file_id",
"FIGMA_TOKEN": "your_figma_token",
"PROJECT_DIR": "your_project_directory"
}
}
}
}
该服务需要配置环境变量:FIGMA_FILE、FIGMA_TOKEN、PROJECT_DIR
服务介绍
Figma 到 React Native MCP
使用 Cursor 的 MCP 将 Figma 设计转换为 React Native 组件。此工具从您的 Figma 设计中提取组件,并生成具有适当类型和样式的相应 React Native 组件。
安装
开发环境
在您的 eas.json 中添加:
{
"mcpServers": {
"figma-to-code": {
"command": "node",
"args": ["PATH_TO_REPO/build/index.js"],
"env": {
"FIGMA_TOKEN": "your_figma_token",
"FIGMA_FILE": "your_figma_file_id",
"PROJECT_DIR": "your_project_directory"
}
}
}
}
最终用户
在您的 Cursor IDE 中安装 MCP 服务器:
npx -y @smithery/cli@latest install @kailashg101/mcp-figma-to-code --client claude --config "{
\"figmaToken\": \"YOUR_FIGMA_TOKEN\",
\"figmaFile\": \"YOUR_FIGMA_FILE_ID\",
\"projectDir\": \"YOUR_PROJECT_DIRECTORY\"
}"
使用
安装后,您可以在 Cursor 中使用以下提示:
提取所有组件
using the extract_components mcp tool get all components from figma and generate their corresponding react native components in components folder
提取特定组件
using the extract_components mcp tool get the [ComponentName] component from figma and generate its corresponding react native component in components folder
配置
配置对象接受以下参数:
{
"figmaToken": string, // Your Figma access token
"figmaFile": string, // Your Figma file ID (from the URL)
"projectDir": string // Where to generate the components
}
功能
当前功能:
- ✅ 从 Figma 中提取组件
- ✅ 生成 React Native 组件
- ✅ 保持组件层次结构
- ✅ 处理组件属性和类型
- ✅ 支持嵌套组件
即将推出的功能:
- 🚧 GraphQL 模式生成
开发
要贡献或修改:
- 克隆仓库
- 安装依赖项:
npm install
- 构建:
npm run build
- 本地运行:
npm start
环境变量
在本地运行时,您需要在 .env 文件中设置这些变量:
FIGMA_TOKEN=your_figma_token
FIGMA_FILE=your_figma_file_id
PROJECT_DIR=your_project_directory
错误处理
常见错误及其解决方案:
- "Failed to create client":检查是否已正确设置所有环境变量
- "Components page not found":确保您的 Figma 文件有一个名为 "Components" 的页面
- "Failed to fetch Figma file":验证您的 Figma 令牌和文件 ID
许可证
MIT
对于问题和功能请求,请在 GitHub 上提出 issue。