figma-mcp-server

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Figma MCP Server

Figma MCP Server

Skill by ara.so — MCP Skills collection.
The Figma MCP server connects AI coding agents directly to Figma, enabling you to generate code from designs, extract design tokens, leverage Code Connect mappings, and write native Figma content back to the canvas. This skill teaches agents how to work with Figma files through the Model Context Protocol.
ara.so 提供的Skill — MCP Skills合集。
Figma MCP服务器将AI编码Agent直接与Figma连接,使你能够从设计生成代码、提取设计令牌、利用Code Connect映射,并将原生Figma内容写回画布。本Skill教Agent如何通过Model Context Protocol处理Figma文件。

What It Does

功能介绍

  • Generate code from Figma frames — Select any frame and get structured code (React + Tailwind by default, adaptable to any framework)
  • Extract design context — Pull variables, components, styles, and layout data
  • Code Connect integration — Reference actual component implementations from your codebase
  • Write to canvas (beta) — Create and modify frames, components, variables, and auto layout directly in Figma
  • Import from web (rolling out) — Convert web pages into Figma designs
  • 从Figma帧生成代码 — 选择任意帧,获取结构化代码(默认是React + Tailwind,可适配任意框架)
  • 提取设计上下文 — 获取变量、组件、样式和布局数据
  • Code Connect集成 — 引用代码库中的实际组件实现
  • 写入画布(测试版)— 在Figma中直接创建和修改帧、组件、变量及自动布局
  • 从网页导入(逐步推出)— 将网页转换为Figma设计

Installation

安装步骤

VS Code (requires GitHub Copilot)

VS Code(需安装GitHub Copilot)

  1. Press
    ⌘ Shift P
    → search
    MCP:Add Server
  2. Select
    HTTP
  3. Enter URL:
    https://mcp.figma.com/mcp
  4. Enter server ID:
    figma
  5. Choose global or workspace scope
Verify in
mcp.json
:
json
{
  "servers": {
    "figma": {
      "type": "http",
      "url": "https://mcp.figma.com/mcp"
    }
  }
}
Test: Open agent mode (
⌥⌘B
or
⌃⌘I
) and type
#get_design_context
  1. 按下
    ⌘ Shift P
    → 搜索
    MCP:Add Server
  2. 选择
    HTTP
  3. 输入URL:
    https://mcp.figma.com/mcp
  4. 输入服务器ID:
    figma
  5. 选择全局或工作区作用域
mcp.json
中验证:
json
{
  "servers": {
    "figma": {
      "type": "http",
      "url": "https://mcp.figma.com/mcp"
    }
  }
}
测试:打开Agent模式(
⌥⌘B
⌃⌘I
)并输入
#get_design_context

Cursor

Cursor

Recommended: Install the Figma plugin (includes MCP + skills):
/add-plugin figma
Manual:
  1. Open Cursor → Settings → Cursor Settings → MCP
  2. Click + Add new global MCP server
  3. Add:
json
{
  "mcpServers": {
    "figma": {
      "url": "https://mcp.figma.com/mcp"
    }
  }
}
推荐方式:安装Figma插件(包含MCP + Skills):
/add-plugin figma
手动安装
  1. 打开 Cursor → 设置 → Cursor Settings → MCP
  2. 点击 + 添加新的全局MCP服务器
  3. 添加如下配置:
json
{
  "mcpServers": {
    "figma": {
      "url": "https://mcp.figma.com/mcp"
    }
  }
}

Claude Code

Claude Code

Recommended: Install official plugin:
bash
claude plugin install figma@claude-plugins-official
Manual:
bash
claude mcp add --transport http figma https://mcp.figma.com/mcp
Authenticate:
bash
undefined
推荐方式:安装官方插件:
bash
claude plugin install figma@claude-plugins-official
手动安装
bash
claude mcp add --transport http figma https://mcp.figma.com/mcp
身份验证:
bash
undefined

Inside claude CLI

在claude CLI内执行

/mcp auth figma
undefined
/mcp auth figma
undefined

Gemini CLI

Gemini CLI

bash
gemini extensions install https://github.com/figma/mcp-server-guide
Authenticate:
bash
gemini
bash
gemini extensions install https://github.com/figma/mcp-server-guide
身份验证:
bash
gemini

Then inside CLI:

然后在CLI内执行:

/mcp auth figma
undefined
/mcp auth figma
undefined

Other Editors

其他编辑器

Any tool supporting Streamable HTTP can connect using:
json
{
  "mcpServers": {
    "figma": {
      "url": "https://mcp.figma.com/mcp"
    }
  }
}
任何支持Streamable HTTP的工具都可通过以下配置连接:
json
{
  "mcpServers": {
    "figma": {
      "url": "https://mcp.figma.com/mcp"
    }
  }
}

Rate Limits

速率限制

  • Starter/View/Collab seats: 6 tool calls per month
  • Dev/Full seats (Pro/Org/Enterprise): Per-minute limits (same as Tier 1 Figma REST API)
  • Write operations: Exempt from rate limits during beta
  • 入门/查看/协作席位:每月6次工具调用
  • 开发/完整席位(专业版/组织版/企业版):每分钟调用限制(与Figma REST API的Tier 1相同)
  • 写入操作:测试版期间不受速率限制

Core Tools

核心工具

get_design_context

get_design_context

Fetches structured design data (React + Tailwind representation) from a Figma node.
Usage:
Copy Figma frame URL → paste in prompt:
"Implement this design: https://www.figma.com/design/FILE_ID?node-id=123-456"
The agent extracts the
node-id
and calls the tool automatically.
Explicit trigger:
"Use get_design_context to fetch the design at this URL"
从Figma节点获取结构化设计数据(React + Tailwind格式)。
使用方式
复制Figma帧URL → 粘贴到提示词中:
"实现这个设计:https://www.figma.com/design/FILE_ID?node-id=123-456"
Agent会自动提取
node-id
并调用该工具。
显式触发
"使用get_design_context获取该URL对应的设计内容"

get_screenshot

get_screenshot

Returns a visual snapshot of the selected node.
Usage:
"Get a screenshot of this Figma component"
Always pair with
get_design_context
for complete context.
返回所选节点的可视化截图。
使用方式
"获取这个Figma组件的截图"
建议始终与
get_design_context
配合使用,以获取完整上下文。

get_variable_defs

get_variable_defs

Extracts design tokens (colors, spacing, typography) from a selection.
Usage:
"Get the variable names and values used in this frame"
"Extract design tokens from this Figma file"
Example output structure:
javascript
{
  "colors": {
    "primary": "#3B82F6",
    "secondary": "#10B981"
  },
  "spacing": {
    "sm": "8px",
    "md": "16px",
    "lg": "24px"
  },
  "typography": {
    "headingLarge": {
      "fontFamily": "Inter",
      "fontSize": "32px",
      "fontWeight": "700"
    }
  }
}
从选中内容中提取设计令牌(颜色、间距、排版)。
使用方式
"获取这个帧中使用的变量名称和值"
"从这个Figma文件中提取设计令牌"
示例输出结构
javascript
{
  "colors": {
    "primary": "#3B82F6",
    "secondary": "#10B981"
  },
  "spacing": {
    "sm": "8px",
    "md": "16px",
    "lg": "24px"
  },
  "typography": {
    "headingLarge": {
      "fontFamily": "Inter",
      "fontSize": "32px",
      "fontWeight": "700"
    }
  }
}

get_metadata

get_metadata

Fetches high-level node structure without full content (useful when responses are truncated).
Usage:
"Get the metadata for this Figma file"
"Show me the node structure"
Use to discover node IDs, then fetch specific nodes with
get_design_context
.
获取节点的高层结构信息(不包含完整内容,适用于响应被截断的场景)。
使用方式
"获取这个Figma文件的元数据"
"展示节点结构"
可用于发现节点ID,然后使用
get_design_context
获取特定节点的详细内容。

Write Tools (beta, remote server only)

写入工具(测试版,仅远程服务器可用)

  • create_frame
    — Create new frames
  • create_component
    — Define reusable components
  • update_auto_layout
    — Modify layout properties
  • create_variable
    — Add design tokens
Example flow:
"Create a component in Figma for a primary button with our design system tokens"
Agent will:
  1. Fetch variables with
    get_variable_defs
  2. Use
    create_component
    to build the button
  3. Apply tokens via
    create_variable
    if needed
  • create_frame
    — 创建新帧
  • create_component
    — 定义可复用组件
  • update_auto_layout
    — 修改布局属性
  • create_variable
    — 添加设计令牌
示例流程
"在Figma中使用我们的设计系统令牌创建一个主按钮组件"
Agent会执行以下操作:
  1. 使用
    get_variable_defs
    获取变量
  2. 使用
    create_component
    构建按钮
  3. 必要时通过
    create_variable
    应用令牌

Working With Figma URLs

Figma URL使用说明

Figma URLs contain the node identifier. Agents parse this automatically:
Frame URL format:
https://www.figma.com/design/abc123?node-id=45-678
The agent extracts:
  • file_id
    :
    abc123
  • node_id
    :
    45-678
Prompt patterns:
"Implement this design: [paste URL]"
"Generate code for https://www.figma.com/design/..."
"Use Code Connect for this component: [URL]"
Figma URL包含节点标识符,Agent会自动解析:
帧URL格式
https://www.figma.com/design/abc123?node-id=45-678
Agent会提取
  • file_id
    :
    abc123
  • node_id
    :
    45-678
提示词模板
"实现这个设计:[粘贴URL]"
"为https://www.figma.com/design/...生成代码"
"为这个组件使用Code Connect:[URL]"

Code Connect Integration

Code Connect集成

Code Connect maps Figma components to your actual component implementations. When configured, agents generate code using your real components instead of generic markup.
Setup:
  1. Install Code Connect in your repo
  2. Link components to Figma in your codebase
  3. Figma MCP automatically detects and uses mappings
Example mapping (React):
javascript
// Button.figma.tsx
import figma from '@figma/code-connect';
import { Button } from './Button';

figma.connect(Button, 
  'https://www.figma.com/design/abc123?node-id=12-34', 
  {
    props: {
      variant: figma.enum('Variant', {
        Primary: 'primary',
        Secondary: 'secondary'
      }),
      size: figma.enum('Size', {
        Small: 'sm',
        Large: 'lg'
      })
    },
    example: ({ variant, size }) => (
      <Button variant={variant} size={size}>
        Click me
      </Button>
    )
  }
);
Agent behavior with Code Connect:
Without:
jsx
<button className="bg-blue-500 px-4 py-2 rounded">
  Click me
</button>
With:
jsx
import { Button } from '@/components/ui/Button';

<Button variant="primary" size="md">
  Click me
</Button>
Prompt:
"Use Code Connect to implement this button component"
"Generate code using our actual component library"
Code Connect将Figma组件映射到你实际的组件实现。配置完成后,Agent会使用你真实的组件生成代码,而非通用标记。
设置步骤
  1. 在代码库中安装Code Connect
  2. 在代码库中将组件与Figma关联
  3. Figma MCP会自动检测并使用映射关系
示例映射(React)
javascript
// Button.figma.tsx
import figma from '@figma/code-connect';
import { Button } from './Button';

figma.connect(Button, 
  'https://www.figma.com/design/abc123?node-id=12-34', 
  {
    props: {
      variant: figma.enum('Variant', {
        Primary: 'primary',
        Secondary: 'secondary'
      }),
      size: figma.enum('Size', {
        Small: 'sm',
        Large: 'lg'
      })
    },
    example: ({ variant, size }) => (
      <Button variant={variant} size={size}>
        Click me
      </Button>
    )
  }
);
启用Code Connect后的Agent行为
未启用时:
jsx
<button className="bg-blue-500 px-4 py-2 rounded">
  Click me
</button>
启用后:
jsx
import { Button } from '@/components/ui/Button';

<Button variant="primary" size="md">
  Click me
</Button>
提示词
"使用Code Connect实现这个按钮组件"
"使用我们实际的组件库生成代码"

Real-World Workflows

实际工作流

Implement a Feature Flow

功能实现流程

"Implement this checkout flow using our existing components: 
https://www.figma.com/design/xyz?node-id=100-200

Use components from src/components/checkout
Follow our Next.js page structure
Use our design tokens for spacing and colors"
Agent will:
  1. Call
    get_design_context
    for the frame
  2. Call
    get_variable_defs
    for tokens
  3. Call
    get_screenshot
    for visual reference
  4. Check Code Connect for component mappings
  5. Generate code using your conventions
"使用我们现有的组件实现这个结账流程:
https://www.figma.com/design/xyz?node-id=100-200

使用src/components/checkout中的组件
遵循我们的Next.js页面结构
使用我们的设计令牌设置间距和颜色"
Agent会:
  1. 调用
    get_design_context
    获取帧内容
  2. 调用
    get_variable_defs
    获取令牌
  3. 调用
    get_screenshot
    获取可视化参考
  4. 检查Code Connect的组件映射
  5. 按照你的规范生成代码

Extract Design System Tokens

提取设计系统令牌

"Extract all color, spacing, and typography variables from this design system:
https://www.figma.com/design/tokens?node-id=1-1

Generate a TypeScript tokens file for Tailwind config"
Agent response:
typescript
// tokens.ts
export const tokens = {
  colors: {
    primary: {
      50: '#eff6ff',
      500: '#3b82f6',
      900: '#1e3a8a'
    },
    secondary: {
      500: '#10b981'
    }
  },
  spacing: {
    xs: '4px',
    sm: '8px',
    md: '16px',
    lg: '24px',
    xl: '32px'
  },
  typography: {
    display: {
      fontFamily: 'Inter',
      fontSize: '48px',
      fontWeight: '700',
      lineHeight: '1.2'
    },
    body: {
      fontFamily: 'Inter',
      fontSize: '16px',
      fontWeight: '400',
      lineHeight: '1.5'
    }
  }
} as const;
"从这个设计系统中提取所有颜色、间距和排版变量:
https://www.figma.com/design/tokens?node-id=1-1

为Tailwind配置生成TypeScript令牌文件"
Agent响应示例
typescript
// tokens.ts
export const tokens = {
  colors: {
    primary: {
      50: '#eff6ff',
      500: '#3b82f6',
      900: '#1e3a8a'
    },
    secondary: {
      500: '#10b981'
    }
  },
  spacing: {
    xs: '4px',
    sm: '8px',
    md: '16px',
    lg: '24px',
    xl: '32px'
  },
  typography: {
    display: {
      fontFamily: 'Inter',
      fontSize: '48px',
      fontWeight: '700',
      lineHeight: '1.2'
    },
    body: {
      fontFamily: 'Inter',
      fontSize: '16px',
      fontWeight: '400',
      lineHeight: '1.5'
    }
  }
} as const;

Create Components in Figma (Write to Canvas)

在Figma中创建组件(写入画布)

"Create a primary button component in Figma using our design system tokens.
Should have three variants: small, medium, large.
Use our primary blue and standard corner radius."
Agent will:
  1. Fetch existing variables
  2. Call
    create_component
    with proper structure
  3. Apply auto layout
  4. Link to variables
"使用我们的设计系统令牌在Figma中创建一个主按钮组件。
需要三个变体:小、中、大尺寸。
使用我们的主蓝色和标准圆角。"
Agent会:
  1. 获取现有变量
  2. 使用
    create_component
    创建正确结构的组件
  3. 应用自动布局
  4. 关联变量

Sync Design and Code

同步设计与代码

"This Card component has been updated in code (src/components/Card.tsx).
Update the Figma component to match:
- Add elevation prop
- Support optional image
- Update spacing to use 16px instead of 12px"
Agent reads your code, then calls write tools to update Figma.
"这个Card组件已在代码中更新(src/components/Card.tsx)。
更新Figma组件以匹配:
- 添加elevation属性
- 支持可选图片
- 将间距从12px改为16px"
Agent会读取你的代码,然后调用写入工具更新Figma。

Configuration and Rules

配置与规则

Project-Level Instructions

项目级指令

Add to your project's agent instructions file (
.cursorrules
,
.clinerules
, etc.):
yaml
undefined
添加到项目的Agent指令文件(
.cursorrules
,
.clinerules
等):
yaml
undefined

Figma MCP Integration

Figma MCP集成

Required workflow

必选工作流

  1. Always run get_design_context first for the exact node
  2. If truncated, use get_metadata → then re-fetch specific nodes
  3. Run get_screenshot for visual reference
  4. Download assets as needed
  5. Translate React + Tailwind output to our framework
  1. 始终先为指定节点运行get_design_context
  2. 如果响应被截断,使用get_metadata → 然后重新获取特定节点
  3. 运行get_screenshot获取可视化参考
  4. 按需下载资源
  5. 将React + Tailwind输出转换为我们的框架格式

Framework conventions

框架规范

  • Use Next.js App Router structure
  • Components go in src/components/ui/
  • Use our Stack and Box layout primitives
  • Import design tokens from @/lib/tokens
  • 使用Next.js App Router结构
  • 组件放在src/components/ui/
  • 使用我们的Stack和Box布局原语
  • 从@/lib/tokens导入设计令牌

Styling

样式规范

  • Use Tailwind classes via className
  • Reference design tokens: colors.primary.500
  • Never hardcode spacing — use token variables
  • 通过className使用Tailwind类
  • 引用设计令牌:colors.primary.500
  • 绝不硬编码间距 — 使用令牌变量

Code Connect

Code Connect

  • Always check for Code Connect mappings
  • Reuse existing components from src/components/
  • Match prop names to our component API
  • 始终检查Code Connect映射
  • 复用src/components/中的现有组件
  • 匹配我们组件API的属性名称

File organization

文件组织

  • One component per file
  • Export as named export
  • Include TypeScript types
  • Add JSDoc for complex props
  • 一个文件对应一个组件
  • 使用命名导出
  • 包含TypeScript类型
  • 为复杂属性添加JSDoc注释

Never hardcode

禁止硬编码

  • Colors → use tokens.colors.*
  • Spacing → use tokens.spacing.*
  • Typography → use tokens.typography.*
undefined
  • 颜色 → 使用tokens.colors.*
  • 间距 → 使用tokens.spacing.*
  • 排版 → 使用tokens.typography.*
undefined

Asset Handling

资源处理

Images returned by
get_design_context
are base64-encoded:
javascript
// Agent pattern for assets
const assetData = designContext.images[0];
if (assetData.startsWith('data:image')) {
  // Write to file
  fs.writeFileSync(
    `public/assets/${nodeName}.png`,
    Buffer.from(assetData.split(',')[1], 'base64')
  );
}
Rule for agents:
When Figma MCP returns images:
1. Decode base64 data
2. Save to public/assets/ with semantic names
3. Reference via relative path in code
4. Use Next.js Image component with proper sizing
get_design_context
返回的图片为base64编码:
javascript
// Agent处理资源的模板
const assetData = designContext.images[0];
if (assetData.startsWith('data:image')) {
  // 写入文件
  fs.writeFileSync(
    `public/assets/${nodeName}.png`,
    Buffer.from(assetData.split(',')[1], 'base64')
  );
}
Agent规则
当Figma MCP返回图片时:
1. 解码base64数据
2. 保存到public/assets/目录,使用语义化名称
3. 在代码中通过相对路径引用
4. 使用Next.js Image组件并设置正确尺寸

Framework Translation

框架转换

Default output is React + Tailwind. Translate to your stack in the prompt:
SwiftUI:
"Generate SwiftUI code from this Figma frame"
Vue + Tailwind:
"Convert this to Vue 3 composition API with Tailwind"
React Native:
"Generate React Native StyleSheet code for this design"
Chakra UI:
"Use Chakra UI components for this layout"
Custom design system:
"Use our design system components from @company/ui-kit
Available components: Button, Card, Stack, Text, Input
Import from @company/ui-kit"
默认输出为React + Tailwind,可在提示词中指定转换为你的技术栈:
SwiftUI
"从这个Figma帧生成SwiftUI代码"
Vue + Tailwind
"将这个设计转换为Vue 3组合API + Tailwind格式"
React Native
"为这个设计生成React Native StyleSheet代码"
Chakra UI
"使用Chakra UI组件实现这个布局"
自定义设计系统
"使用我们@company/ui-kit中的设计系统组件
可用组件:Button, Card, Stack, Text, Input
从@company/ui-kit导入"

Troubleshooting

故障排查

Agent not picking right tool

Agent未调用正确工具

Problem: Generic code generated instead of using variables.
Solution:
"Use get_variable_defs to extract design tokens first, 
then generate code referencing those tokens"
问题:生成了通用代码,未使用变量。
解决方案
"先使用get_variable_defs提取设计令牌,
然后生成引用这些令牌的代码"

Truncated responses

响应被截断

Problem:
get_design_context
returns incomplete data.
Solution:
"Use get_metadata to see the node structure, 
then fetch only the specific child nodes I need"
问题
get_design_context
返回的数据不完整。
解决方案
"使用get_metadata查看节点结构,
然后仅获取我需要的特定子节点"

Missing Code Connect mappings

Code Connect映射缺失

Problem: Components not reused even though Code Connect is set up.
Solution:
  1. Verify Code Connect files are in repo
  2. Check figma.connect() URLs match exact node IDs
  3. Prompt: "Check for Code Connect mappings before generating code"
问题:已设置Code Connect,但未复用组件。
解决方案
  1. 验证Code Connect文件已在代码库中
  2. 检查figma.connect()的URL是否匹配精确节点ID
  3. 提示词:"生成代码前检查Code Connect映射"

Wrong component structure

组件结构错误

Problem: Auto layout not translating correctly.
Fix in Figma:
  1. Use Auto Layout with clear direction (horizontal/vertical)
  2. Set explicit padding and gap values
  3. Use fixed sizes or fill container intent
  4. Add dev notes if layout is complex
Prompt:
"This frame uses auto layout. 
Generate a flex container with proper gap and padding.
Check the Figma auto layout settings before coding."
问题:自动布局未正确转换。
Figma端修复
  1. 使用自动布局并明确方向(水平/垂直)
  2. 设置明确的内边距和间距值
  3. 使用固定尺寸或填充容器属性
  4. 若布局复杂,添加开发注释
提示词
"这个帧使用了自动布局。
生成带有正确间距和内边距的flex容器。
编码前检查Figma的自动布局设置。"

Rate limit hit

触发速率限制

Problem: "Rate limit exceeded" error.
Solution:
  • Upgrade to Dev or Full seat
  • Batch requests (use get_metadata → fetch specific nodes)
  • Cache design context for repeated work
问题:出现“Rate limit exceeded”错误。
解决方案
  • 升级到开发或完整席位
  • 批量请求(使用get_metadata → 获取特定节点)
  • 为重复工作缓存设计上下文

Environment Variables

环境变量

Figma MCP uses authentication automatically through the MCP client. No manual API keys required.
For custom implementations using Figma REST API directly:
bash
undefined
Figma MCP通过MCP客户端自动处理身份验证,无需手动配置API密钥。
若直接使用Figma REST API进行自定义实现:
bash
undefined

.env

.env

FIGMA_ACCESS_TOKEN=your_personal_access_token

Get token: Figma → Settings → Account → Personal access tokens
FIGMA_ACCESS_TOKEN=your_personal_access_token

获取令牌:Figma → 设置 → 账户 → 个人访问令牌

Best Practices

最佳实践

Structure Figma Files for Better Code

优化Figma文件结构以提升代码质量

  • Use components for reusable elements
  • Link via Code Connect for accurate component reuse
  • Use variables for colors, spacing, typography
  • Name layers semantically (CardContainer, not Group 5)
  • Use Auto Layout to communicate responsive behavior
  • Add dev notes for complex interactions
  • 使用组件实现可复用元素
  • 通过Code Connect关联以确保组件准确复用
  • 使用变量管理颜色、间距、排版
  • 语义化命名图层(如CardContainer,而非Group 5)
  • 使用自动布局传达响应式行为
  • 添加开发注释说明复杂交互

Write Effective Prompts

编写有效的提示词

❌ "Make this into code"
✅ "Generate Next.js code for this dashboard layout.
   Use components from src/components/dashboard.
   Apply our design tokens from @/lib/tokens.
   Follow the App Router structure."
❌ "把这个转成代码"
✅ "为这个仪表板布局生成Next.js代码。
   使用src/components/dashboard中的组件。
   应用@/lib/tokens中的设计令牌。
   遵循App Router结构。"

Verify Design Intent

验证设计意图

Before generating code:
"Show me the auto layout settings and variables used in this frame"
"Get a screenshot and design context for this component"
生成代码前:
"展示这个帧的自动布局设置和使用的变量"
"获取这个组件的截图和设计上下文"

Keep Designs in Sync

保持设计与代码同步

When code changes:
"I updated the Button component in src/components/Button.tsx.
Update the Figma component to match:
[paste code]"
代码变更时:
"我已更新src/components/Button.tsx中的Button组件。
更新Figma组件以匹配:
[粘贴代码]"

Integration Patterns

集成模式

CI/CD Design Checks

CI/CD设计检查

javascript
// scripts/check-design-sync.js
import { exec } from 'child_process';

const figmaNodeId = process.env.FIGMA_COMPONENT_NODE;
const prompt = `
Compare the Figma component at node ${figmaNodeId}
with src/components/Button.tsx.
Report any mismatches in props, variants, or styling.
`;

exec(`claude code "${prompt}"`, (error, stdout) => {
  if (stdout.includes('mismatch')) {
    process.exit(1);
  }
});
javascript
// scripts/check-design-sync.js
import { exec } from 'child_process';

const figmaNodeId = process.env.FIGMA_COMPONENT_NODE;
const prompt = `
对比节点${figmaNodeId}对应的Figma组件
与src/components/Button.tsx。
报告属性、变体或样式中的任何不匹配。
`;

exec(`claude code "${prompt}"`, (error, stdout) => {
  if (stdout.includes('mismatch')) {
    process.exit(1);
  }
});

Design System Documentation

设计系统文档

"Generate Storybook stories from all button variants in this Figma frame.
Include controls for each variant and size.
Use our actual Button component from @/components/ui/Button."
"从这个Figma帧中的所有按钮变体生成Storybook故事。
为每个变体和尺寸添加控件。
使用我们@/components/ui/Button中的实际Button组件。"

Automated Handoff

自动化交付

"Create a PR that:
1. Extracts design tokens from this Figma file
2. Updates src/theme/tokens.ts
3. Regenerates Tailwind config
4. Shows a preview of changed colors in Storybook"
"创建一个PR,完成以下操作:
1. 从这个Figma文件中提取设计令牌
2. 更新src/theme/tokens.ts
3. 重新生成Tailwind配置
4. 在Storybook中展示颜色变更的预览"

Advanced Usage

高级用法

Multi-Frame Workflows

多帧工作流

"Implement these three screens as Next.js pages:
1. Login: https://figma.com/design/x?node-id=1-1
2. Dashboard: https://figma.com/design/x?node-id=1-2
3. Profile: https://figma.com/design/x?node-id=1-3

Share components between pages.
Use the same header and navigation."
"将这三个页面实现为Next.js页面:
1. 登录:https://figma.com/design/x?node-id=1-1
2. 仪表板:https://figma.com/design/x?node-id=1-2
3. 个人资料:https://figma.com/design/x?node-id=1-3

在页面间共享组件。
使用相同的页眉和导航。"

Design System Audits

设计系统审计

"Audit this Figma file for inconsistencies:
- Colors not using variables
- Components without Code Connect
- Hardcoded spacing values
- Layers with generic names

Generate a report with locations and recommendations."
"审计这个Figma文件中的不一致之处:
- 未使用变量的颜色
- 未关联Code Connect的组件
- 硬编码的间距值
- 通用名称的图层

生成包含位置和建议的报告。"

Responsive Design Generation

响应式设计生成

"This frame has mobile, tablet, and desktop variants.
Generate responsive code that:
- Uses Tailwind breakpoints
- Maintains the same component structure
- Adjusts layout and spacing per breakpoint"
"这个帧包含移动端、平板端和桌面端变体。
生成响应式代码,满足:
- 使用Tailwind断点
- 保持相同的组件结构
- 根据断点调整布局和间距"

Reference

参考资料