Figma Integration Skill
Figma MCP integration patterns for klara-theme design-to-code workflows.
When Active
- Working in
libs/klara-theme/ - Using Figma MCP tools (
get_design_context,get_variable_defs, etc.) - Documenting components from Figma designs
- Mapping design tokens between Figma and klara-theme
- Validating implementations against Figma designs
MCP Tool Reference
| Tool | Purpose | When to Use |
|---|---|---|
get_design_context(nodeId) |
Fetch React+Tailwind representation | Always first for any Figma node |
get_variable_defs(nodeId) |
Extract design tokens/variables | Always second after get_design_context |
get_screenshot(nodeId) |
Get visual reference image | Required for validation |
get_metadata(nodeId) |
Get XML node structure (IDs, names, positions) | Only if get_design_context output is truncated |
Tool Usage Pattern
1. get_design_context(nodeId) → design representation
2. get_variable_defs(nodeId) → token extraction
3. get_screenshot(nodeId) → visual reference
4. Convert to klara-theme patterns
5. Validate against screenshot
Golden Rules
- Be explicit — Specify exactly which tools and nodes you want. Do not ask vaguely for "tokens."
- Never implement from
get_metadataalone — Always follow withget_design_contextfor the nodes you are building. - Treat
get_design_contextoutput as a representation — It returns React+Tailwind; you must convert to klara-theme patterns (forwardRef,theme-ui-label, token mapping). - Avoid large selections — Work in small chunks. If truncated, use
get_metadatato identify sub-nodes, then fetch each withget_design_context. - Prefer reuse — Check
src/lib/components/before creating anything new. - Always validate visually — Call
get_screenshotand compare against your implementation.
Token Mapping
klara-theme uses a 3-layer token system:
| Layer | Location | Purpose |
|---|---|---|
| Primitives | _tokens/1_primitives/ |
Raw values (colors, spacing, typography) |
| Themes | _tokens/2_themes/ |
Semantic tokens (light/dark) |
| Components | _tokens/3_components/ |
Component-specific tokens |
Figma Variable → CSS Variable Mapping
Figma variables map to klara-theme CSS variables via theme-constants.ts:
// Figma: "color/background/primary" → CSS: "--klara-bg-primary"
// Figma: "spacing/md" → CSS: "--klara-spacing-md"
When extracting tokens from get_variable_defs:
- Identify the Figma variable name
- Look up the corresponding CSS variable in
theme-constants.ts - Map to the correct token layer
Anti-Truncation Strategy
Large Figma selections may truncate. Handle with:
- Work in small chunks — Select individual components, not entire frames
- Fallback pattern:
- If
get_design_contexttruncates → callget_metadatafor structure - Extract child node IDs from metadata
- Call
get_design_contexton each child separately
- If
- Progressive extraction — Start with the parent, then drill into children
Visual Validation
After implementation, always validate:
- Call
get_screenshot(nodeId)for the Figma design - Compare against your implementation visually
- Check for:
- Layout alignment
- Spacing consistency
- Color accuracy
- Typography matching
- State variations (hover, focus, disabled)
Drift Categories
If differences found, categorize as:
- Intentional: Design evolved, implementation is correct
- Bug: Implementation error, needs fix
- Enhancement: Design improvement not yet implemented
Aspect Files
| Aspect | Purpose |
|---|---|
references/extraction-procedure.md |
Step-by-step Figma data extraction with anti-truncation handling |
Related Resources
- klara-theme docs:
libs/klara-theme/CLAUDE.md - ui-lib-dev skill:
ui-lib-dev— Component pipeline (plan, implement, audit, fix, document) - Schemas:
libs/klara-theme/figma-data/schema/component-data.schema.json— Figma component data structurecomponent-mapping.schema.json— Prop mapping structure
- Manifest:
libs/klara-theme/figma-data/manifest.json— Component tracking
Output Formats
Component Data (.figma.json)
{
"componentKey": "button",
"componentSetNodeId": "1:2592",
"variants": [...],
"tokens": {...},
"extractedAt": "2025-01-15T10:00:00Z"
}
Prop Mapping (.mapping.json)
{
"componentKey": "button",
"props": {
"variant": {
"figmaProperty": "Type",
"values": { "primary": "Primary", "secondary": "Secondary" }
}
}
}