figma-design-extraction
npx skills add https://github.com/petbrains/mvp-builder --skill figma-design-extraction
Agent 安装分布
Skill 文档
Figma Design Extraction
Extract design tokens, screen structure, and visual references from Figma files.
Process: CHECK â PARSE â DISCOVER â EXTRACT â ORGANIZE
The goal is to pull structured, source-tracked design data from Figma for use in design-setup pipelines, conflict resolution, and downstream code generation. Every extracted value carries its source tag â this matters because downstream consumers (like design-setup Phase 3) need to know whether a token came from an explicit Figma Variable definition or was inferred from applied styles, since that affects conflict resolution priority.
Step 0: CHECK â Verify MCP Connection
Before any extraction, verify the Figma MCP server responds:
whoami()
If this fails or isn’t available, warn the user and skip all Figma steps. Don’t attempt tool calls that will error out â it wastes context and confuses the workflow.
Step 1: PARSE â Get IDs from URL
URL Formats
https://figma.com/design/:fileKey/:fileName?node-id=X-Y
https://figma.com/file/:fileKey/:fileName?node-id=X-Y
https://figma.com/proto/:fileKey/:fileName?node-id=X-Y
What to Extract
- fileKey: segment after
/design/,/file/, or/proto/ - nodeId:
node-idquery param, convert dash â colon (1-2â1:2)
URL: https://figma.com/design/kL9xQn2VwM8pYrTb4ZcHjF/MyApp?node-id=42-15
â fileKey: kL9xQn2VwM8pYrTb4ZcHjF
â nodeId: 42:15
Decision Rules
| Condition | Action |
|---|---|
URL has /design/, /file/, /proto/ |
Parse and proceed |
URL has /board/ (FigJam) |
Warn: “FigJam not supported” â skip |
URL has /slides/ |
Warn: “Slides not supported” â skip |
| No URL, MCP connected | Can still extract variables â see “No URL Available” below |
| No URL, MCP not connected | Warn: “No Figma source available” â skip |
| nodeId missing in URL | Fetch root pages first, then navigate |
No URL Available
If there’s no Figma URL but the figma MCP is connected (Step 0 passed), get_variable_defs still works â it returns all variables for the file without a specific node. You can extract tokens without screenshots or screen discovery. For screen-level extraction (screenshots, design context), a URL with a nodeId or page reference is needed.
Step 2: DISCOVER â Map File Structure
2.1 Fetch Page Overview
Call get_metadata to get XML structure with node IDs, layer types, names, positions, sizes.
Depth strategy matters because large files overwhelm in a single call:
- Start at the provided nodeId (or page level like
0:1) to get top-level frames - If response is too large or truncated â narrow to individual pages
- For each page, identify top-level frames â these are your screens
2.2 Build Screen Inventory
Extract from metadata:
SCREENS[] = [{
nodeId: "X:Y",
name: "Login Screen",
page: "Authentication",
width: N,
height: N,
slug: "login-screen" â kebab-case for pipeline references
}]
Slug normalization:
- “Login Screen” â
login-screen - “Dashboard / Overview” â
dashboard-overview - “01 – Onboarding Flow” â
onboarding-flow - Strip leading numbers and separators, convert spaces/slashes to hyphens
2.3 Large File Strategy
If the file has many pages:
- Fetch page-level metadata first
- For each page, fetch frame-level children separately
- Focus on top-level frames â skip deeply nested component internals
- Log skipped content: “Skipped N nested components in page X”
Step 3: EXTRACT â Pull Design Data
Three independent extraction types. Run what the consumer needs.
3.1 Variables (Primary Token Source)
get_variable_defs returns variable definitions â a flat map of paths to values.
Categorize by inspecting the path structure. Figma variable paths vary wildly between teams â there’s no universal naming convention. Common patterns include:
color/primary/500 â color token
primitives/color/blue/500 â color token
semantic/text/primary â color token (semantic layer)
font/body/size â typography token
text/heading/weight â typography token
spacing/lg â spacing token
space/4 â spacing token
radius/md â border-radius token
shadow/card â shadows token
breakpoint/md â breakpoints token
duration/fast â animation token
easing/default â animation token
Categorization strategy: Look at the value type first (hex color â color, numeric with px/rem â typography/spacing, shadow definition â shadows), then use the path as a naming hint. Don’t force paths into a rigid taxonomy â let the actual data guide categorization.
Mark all values with source: "figma-variables" â these are intentional design decisions by the designer, not just what happened to be applied to a frame. This distinction drives conflict resolution downstream: a variable definition is stronger evidence than an applied style.
When variables come back empty â this is common. Many Figma files use local styles instead of Variables. Don’t treat this as an error. Fall back to design context (3.2).
3.2 Design Context (Fallback Token Source)
get_design_context returns rich structured data: layout, typography, colors, component structure, spacing, padding.
Use this when:
- Variables (3.1) returned empty or sparse
- You need applied-style values (what’s actually on frames, not just defined)
- Understanding component patterns (Auto Layout, constraints, variants)
Extract token-like values from:
- Color fills â color tokens
- Text styles (font family, size, weight, line-height) â typography tokens
- Auto Layout spacing/padding â spacing tokens
- Corner radius â border-radius tokens
- Effects (shadows, blurs) â shadows tokens
- Transition/animation properties â animation tokens
Extract component information from:
- Named component instances â component name, variant properties
- Auto Layout containers with semantic names â layout components
- Repeated patterns across screens â shared components
Mark all values with source: "figma-context" â these are inferred from usage, not declared as variables. They’re valid design data but carry less authority in conflict resolution because a designer might have applied a one-off value to a frame without intending it as a system token.
Truncation handling (critical for complex designs):
- If response is too large â call
get_metadatafirst to get the node map - Identify specific child nodes from metadata
- Fetch children individually with
get_design_context - Merge results
3.3 Screenshots (Visual References)
get_screenshot renders the node as an image. Return screenshot data for each screen â the caller specifies save paths.
For each screen in SCREENS[], capture a screenshot. These serve as visual truth during implementation and validation.
Practical notes:
- Capture all top-level screens identified in DISCOVER
- If a screen screenshot fails â log warning, continue with remaining screens
- Very large frames may timeout â try child frames as fallback
- Screenshots are supplementary â extraction continues even if screenshots fail
Step 4: ORGANIZE â Structure Results
Where to Save
The caller decides the output path â this skill extracts and structures data, it doesn’t own the file layout. If no path is specified, return the data structures in-memory for the caller to place where it needs them.
4.1 Unified Token Map
Merge tokens from all sources into a single map. Source tracking enables downstream conflict resolution when file-based tokens disagree with Figma tokens.
FIGMA_TOKENS = {
colors: {
"primary-500": { value: "#3B82F6", source: "figma-variables" },
"surface": { value: "#FFFFFF", source: "figma-context" }
},
typography: {
"body-size": { value: "16px", source: "figma-variables" },
"heading-weight": { value: "700", source: "figma-context" }
},
spacing: { ... },
"border-radius": { ... },
shadows: { ... },
animation: { ... },
breakpoints: { ... }
}
Merge priority: figma-variables wins over figma-context when both provide the same token. Variables are explicit declarations; context values are inferred from usage.
4.2 Component List
Extract component information from design context responses into a structured list:
FIGMA_COMPONENTS = [{
figmaName: "Button / Primary",
dsName: "Button",
variants: ["primary", "secondary", "ghost"],
confidence: "high",
source: "figma-context"
}]
Confidence levels:
highâ named component instance with clear variant propertiesmediumâ repeated pattern with consistent naminglowâ inferred from layout structure, name is ambiguous
If design context returned no component data â FIGMA_COMPONENTS = [] (empty, not error).
4.3 Screen Index
FIGMA_SCREENS = [{
slug: "login-screen",
nodeId: "42:15",
name: "Login Screen",
page: "Authentication",
dimensions: "375Ã812",
hasScreenshot: true,
hasDesignContext: true
}]
4.4 Extraction Summary
Output a summary after extraction so the calling command (or the user) can quickly assess what data is available without parsing the full token map. This is especially important when extraction is partial â the consumer needs to know which data sources succeeded and which gaps remain.
Include these fields:
Figma Extraction Summary
Source: [URL or "no URL â variables only"]
Screens: [N] discovered, [N] with screenshots
Tokens: [N] from Variables, [N] from Context, [N] total unique
Components: [N] discovered
Warnings: [list if any]
Workflows
Full Extraction (design-setup)
The default workflow when design-setup provides a Figma URL:
CHECK: whoami â verify connection
PARSE: URL â fileKey + nodeId
DISCOVER: get_metadata â SCREENS[]
EXTRACT: get_variable_defs â tokens (primary)
get_design_context on the most visually complex screens â tokens (fallback) + components
Pick screens with the most child nodes in metadata â they tend to have
richer style diversity (forms, dashboards > splash screens, empty states).
Start with 2-3 screens; add more if token yield is sparse.
get_screenshot for each screen â visual references (caller saves to disk)
ORGANIZE: Merge token map, build component list, build screen index, output summary
Token-Only (validation/comparison)
When you just need to compare Figma tokens against file-based tokens:
CHECK: whoami â verify connection
PARSE: URL â fileKey + nodeId
EXTRACT: get_variable_defs â tokens
If sparse (<5 tokens): get_design_context on 1-2 complex screens â more tokens
ORGANIZE: Token map with sources for conflict resolution
Screen Catalog (ux/ui commands)
When you need screen structure and visuals, not tokens:
CHECK: whoami â verify connection
PARSE: URL â fileKey + nodeId
DISCOVER: get_metadata â SCREENS[]
EXTRACT: get_screenshot for each screen (caller saves to disk)
ORGANIZE: Screen index with screenshots
Example: Full Extraction
Given URL: https://figma.com/design/kL9xQn2VwM8pYrTb4ZcHjF/MyApp?node-id=0-1
Step 0: whoami() â â connected as "design-team@example.com"
Step 1: Parse URL
fileKey: kL9xQn2VwM8pYrTb4ZcHjF
nodeId: 0:1
Step 2: get_metadata(fileKey, nodeId: "0:1")
â Page "Auth" has frames: Login (42:15, 375Ã812), Register (42:30, 375Ã812)
â Page "Main" has frames: Dashboard (50:1, 1440Ã900), Settings (50:20, 1440Ã900)
SCREENS = [
{ nodeId: "42:15", slug: "login", page: "Auth" },
{ nodeId: "42:30", slug: "register", page: "Auth" },
{ nodeId: "50:1", slug: "dashboard", page: "Main" },
{ nodeId: "50:20", slug: "settings", page: "Main" }
]
Step 3a: get_variable_defs(fileKey)
â 12 variables found: color/primary/500=#3B82F6, color/neutral/100=#F5F5F5,
spacing/sm=8, spacing/md=16, spacing/lg=24, radius/md=8, ...
â All tagged source: "figma-variables"
Step 3b: get_design_context(fileKey, nodeId: "50:1") â Dashboard has most children
â Found additional: font-family=Inter, heading-size=24px, body-size=14px,
shadow-card=0 2px 4px rgba(0,0,0,0.1)
â Components: Button/Primary (3 variants), Card, Input, Avatar
â All tagged source: "figma-context"
Step 3c: get_screenshot for each of 4 screens
â 4/4 captured, returned to caller for saving
Step 4: Merge â 12 variable tokens + 4 context tokens = 16 total unique
Components: 4 discovered (Button: high, Card: medium, Input: medium, Avatar: low)
Summary: 4 screens, 16 tokens, 4 components, 4 screenshots, 0 warnings
Error Handling
Figma extraction is enrichment, not requirement. The pipeline continues without Figma data â it just has less information for conflict resolution.
| Error | Response |
|---|---|
whoami fails (Step 0) |
MCP not connected â warn user, skip all Figma steps |
| Invalid URL format | Warn with supported formats â skip |
| FigJam/Slides URL | Warn “not supported for token extraction” â skip |
| Empty variables | Normal â fall back to design context (3.2) |
| Truncated response | Narrow scope â fetch children individually |
| Screenshot timeout | Log warning â try smaller child frames â continue |
| Permission denied | Warn “check Figma file sharing settings” â skip |
| All extractions fail | Warn â continue pipeline without Figma data |
Quick Reference
| Step | Tool | Purpose |
|---|---|---|
| CHECK | whoami |
Verify MCP connection |
| DISCOVER | get_metadata |
File structure, pages, frames, node IDs |
| EXTRACT tokens | get_variable_defs |
Design Variables (primary token source) |
| EXTRACT context | get_design_context |
Applied styles, layout, components (fallback) |
| EXTRACT visuals | get_screenshot |
Visual reference for each screen |
| Source Tag | Meaning | Priority |
|---|---|---|
figma-variables |
Explicitly defined Figma Variable | Higher |
figma-context |
Inferred from applied styles on frames | Lower |