Design Tokens Extraction
Extract and normalize design tokens from design files into standardized formats.
Overview
This skill enables extraction of design tokens from Figma, Sketch, and Penpot design files using their respective MCP servers. Extracted tokens are normalized to the W3C Design Tokens Community Group format for platform-agnostic storage and conversion.
This skill covers:
- Connecting to design files via MCP servers (Figma, Sketch, Penpot)
- Extracting color, typography, spacing, and shadow tokens
- Normalizing extracted data to W3C DTCG format
- Converting to platform-specific formats (Swift, CSS, Tailwind)
This skill does NOT cover:
- Design file creation or modification
- Visual design decisions
- Component code generation (see
design-to-swiftui skill)
Quick Reference
MCP Server Tools
| Server |
Tool |
Purpose |
figma |
get_file |
Read Figma file structure |
figma |
get_styles |
Extract published styles |
figma |
get_local_variables |
Extract variables/tokens |
sketch-context |
get_document |
Read Sketch document |
sketch-context |
get_shared_styles |
Extract shared styles |
sketch-context |
get_color_assets |
Extract color variables |
penpot |
get_file |
Read Penpot file |
penpot |
get_components |
List design components |
Token Categories
| Category |
Properties Extracted |
| Color |
hex, rgb, hsl, opacity, description |
| Typography |
family, size, weight, lineHeight, letterSpacing |
| Spacing |
value (px, rem), description |
| Shadow |
color, offsetX, offsetY, blur, spread |
| Border Radius |
value (px, rem) |
| Duration |
value (ms) |
Workflow: Extract Tokens from Design File
Step 1: Connect to Design Source
Determine the design source and use the appropriate MCP server:
Figma:
Use figma MCP server with get_file tool
Input: file_key from Figma URL (e.g., "abc123" from figma.com/file/abc123/...)
Sketch:
Use sketch-context MCP server with get_document tool
Input: file path to .sketch file
Penpot:
Use penpot MCP server with get_file tool
Input: project_id and file_id from Penpot URL
Step 2: Extract Raw Design Data
Query the MCP server for design tokens:
Colors:
- Get published color styles (Figma:
get_styles, Sketch: get_shared_styles)
- Get color variables (Figma:
get_local_variables, Sketch: get_color_assets)
- Extract from component fills if no styles defined
Typography:
- Get text styles from design system
- Extract font family, size, weight, line height, letter spacing
- Map font weights to numeric values (400, 500, 600, etc.)
Spacing:
- Look for spacing tokens in variables/styles
- Extract from auto-layout settings if available
- Check for spacing scale documentation
Shadows:
- Get effect styles (drop shadows, inner shadows)
- Extract color, offset, blur, spread values
Step 3: Normalize to W3C Format
Transform extracted data to W3C Design Tokens structure:
{
"$schema": "https://design-tokens.github.io/community-group/format/",
"color": {
"<category>": {
"<name>": {
"$value": "#hexcode",
"$type": "color",
"$description": "From design file"
}
}
},
"typography": {
"fontFamily": { ... },
"fontSize": { ... },
"fontWeight": { ... }
},
"spacing": { ... },
"shadow": { ... }
}
Step 4: Output in Requested Format
Use the appropriate output style:
design-token-json - W3C DTCG format (default)
design-token-swift - Swift extensions
design-token-css - CSS custom properties
design-token-tailwind - Tailwind config
Extraction Patterns
Figma Color Extraction
When reading from Figma:
Published Styles (preferred):
- Use
get_styles with style_type: "FILL"
- Returns named color styles with descriptions
Variables (Figma variables):
- Use
get_local_variables
- Filter by
resolvedType: "COLOR"
- Group by collection name
Component Fills (fallback):
- Traverse component nodes
- Extract unique fill colors
- Auto-generate names from component path
Sketch Color Extraction
When reading from Sketch:
Shared Styles:
- Use
get_shared_styles with style_type: "layer"
- Extract fill colors from style attributes
Color Assets:
- Use
get_color_assets
- Returns swatch library colors
Document Colors:
- Access document-level color palette
- Often contains brand colors
Penpot Color Extraction
When reading from Penpot:
Color Library:
- Access file's color library
- Returns named colors with metadata
Component Colors:
- Extract from component definitions
- Track color references
Normalization Rules
Color Normalization
| Source Format |
Target Format |
rgba(r, g, b, a) |
#RRGGBBAA |
rgb(r, g, b) |
#RRGGBB |
hsl(h, s%, l%) |
#RRGGBB (converted) |
{ r, g, b } (0-1) |
#RRGGBB (scaled) |
{ r, g, b } (0-255) |
#RRGGBB |
Typography Normalization
| Property |
Source Variations |
Target |
| Font Size |
12px, 0.75rem, 12 |
"0.75rem" or 12 |
| Font Weight |
"bold", 700, "semibold" |
700 (numeric) |
| Line Height |
1.5, 150%, 24px |
1.5 (unitless ratio) |
| Letter Spacing |
0.5px, 0.02em |
"0.02em" |
Naming Normalization
| Source Style |
Target Style |
Example |
color/primary/500 |
color.primary.500 |
Nested groups |
Primary Color |
primaryColor |
camelCase |
primary-color |
primaryColor |
camelCase |
PRIMARY_COLOR |
primaryColor |
camelCase |
Source Metadata
Preserve source information for traceability:
{
"color": {
"primary": {
"$value": "#2196F3",
"$type": "color",
"$extensions": {
"com.figma": {
"variableId": "VariableID:1234",
"styleId": "S:abc123",
"collectionName": "Brand Colors"
}
}
}
}
}
Troubleshooting
No Tokens Found
Symptoms: Extraction returns empty or minimal tokens
Solution:
- Verify design file has published styles (not just local colors)
- Check if using Figma variables vs. older style system
- Look for design system component library
- Try extracting from specific frames/components
Authentication Failed
Symptoms: MCP server returns 401 or access denied
Solution:
- Verify
FIGMA_ACCESS_TOKEN is set for Figma
- Ensure Sketch app is running for sketch-context
- Check Penpot MCP server is running locally
Inconsistent Naming
Symptoms: Token names don't match expected format
Solution:
- Check original design file naming conventions
- Use normalization rules consistently
- Consider mapping file to enforce naming standards
See Also
design-token-json style - W3C format output
design-token-swift style - Swift code output
design-to-swiftui skill - Generate SwiftUI views from tokens
design-system-management skill - Manage token libraries
1---2name: design-tokens-extraction3description: Extract design tokens (colors, typography, spacing, shadows) from Figma, Sketch, and Penpot design files via MCP servers and normalize to W3C format4---56# Design Tokens Extraction78Extract and normalize design tokens from design files into standardized formats.910## Overview1112This skill enables extraction of design tokens from Figma, Sketch, and Penpot design files using their respective MCP servers. Extracted tokens are normalized to the W3C Design Tokens Community Group format for platform-agnostic storage and conversion.1314**This skill covers:**1516- Connecting to design files via MCP servers (Figma, Sketch, Penpot)17- Extracting color, typography, spacing, and shadow tokens18- Normalizing extracted data to W3C DTCG format19- Converting to platform-specific formats (Swift, CSS, Tailwind)2021**This skill does NOT cover:**2223- Design file creation or modification24- Visual design decisions25- Component code generation (see `design-to-swiftui` skill)2627## Quick Reference2829### MCP Server Tools3031| Server | Tool | Purpose |32|--------|------|---------|33| `figma` | `get_file` | Read Figma file structure |34| `figma` | `get_styles` | Extract published styles |35| `figma` | `get_local_variables` | Extract variables/tokens |36| `sketch-context` | `get_document` | Read Sketch document |37| `sketch-context` | `get_shared_styles` | Extract shared styles |38| `sketch-context` | `get_color_assets` | Extract color variables |39| `penpot` | `get_file` | Read Penpot file |40| `penpot` | `get_components` | List design components |4142### Token Categories4344| Category | Properties Extracted |45|----------|---------------------|46| Color | hex, rgb, hsl, opacity, description |47| Typography | family, size, weight, lineHeight, letterSpacing |48| Spacing | value (px, rem), description |49| Shadow | color, offsetX, offsetY, blur, spread |50| Border Radius | value (px, rem) |51| Duration | value (ms) |5253## Workflow: Extract Tokens from Design File5455### Step 1: Connect to Design Source5657Determine the design source and use the appropriate MCP server:5859**Figma:**6061```text62Use figma MCP server with get_file tool63Input: file_key from Figma URL (e.g., "abc123" from figma.com/file/abc123/...)64```6566**Sketch:**6768```text69Use sketch-context MCP server with get_document tool70Input: file path to .sketch file71```7273**Penpot:**7475```text76Use penpot MCP server with get_file tool77Input: project_id and file_id from Penpot URL78```7980### Step 2: Extract Raw Design Data8182Query the MCP server for design tokens:8384**Colors:**85861. Get published color styles (Figma: `get_styles`, Sketch: `get_shared_styles`)872. Get color variables (Figma: `get_local_variables`, Sketch: `get_color_assets`)883. Extract from component fills if no styles defined8990**Typography:**91921. Get text styles from design system932. Extract font family, size, weight, line height, letter spacing943. Map font weights to numeric values (400, 500, 600, etc.)9596**Spacing:**97981. Look for spacing tokens in variables/styles992. Extract from auto-layout settings if available1003. Check for spacing scale documentation101102**Shadows:**1031041. Get effect styles (drop shadows, inner shadows)1052. Extract color, offset, blur, spread values106107### Step 3: Normalize to W3C Format108109Transform extracted data to W3C Design Tokens structure:110111```json112{113 "$schema": "https://design-tokens.github.io/community-group/format/",114 "color": {115 "<category>": {116 "<name>": {117 "$value": "#hexcode",118 "$type": "color",119 "$description": "From design file"120 }121 }122 },123 "typography": {124 "fontFamily": { ... },125 "fontSize": { ... },126 "fontWeight": { ... }127 },128 "spacing": { ... },129 "shadow": { ... }130}131```132133### Step 4: Output in Requested Format134135Use the appropriate output style:136137- `design-token-json` - W3C DTCG format (default)138- `design-token-swift` - Swift extensions139- `design-token-css` - CSS custom properties140- `design-token-tailwind` - Tailwind config141142## Extraction Patterns143144### Figma Color Extraction145146When reading from Figma:1471481. **Published Styles** (preferred):149 - Use `get_styles` with `style_type: "FILL"`150 - Returns named color styles with descriptions1511522. **Variables** (Figma variables):153 - Use `get_local_variables`154 - Filter by `resolvedType: "COLOR"`155 - Group by collection name1561573. **Component Fills** (fallback):158 - Traverse component nodes159 - Extract unique fill colors160 - Auto-generate names from component path161162### Sketch Color Extraction163164When reading from Sketch:1651661. **Shared Styles**:167 - Use `get_shared_styles` with `style_type: "layer"`168 - Extract fill colors from style attributes1691702. **Color Assets**:171 - Use `get_color_assets`172 - Returns swatch library colors1731743. **Document Colors**:175 - Access document-level color palette176 - Often contains brand colors177178### Penpot Color Extraction179180When reading from Penpot:1811821. **Color Library**:183 - Access file's color library184 - Returns named colors with metadata1851862. **Component Colors**:187 - Extract from component definitions188 - Track color references189190## Normalization Rules191192### Color Normalization193194| Source Format | Target Format |195|---------------|---------------|196| `rgba(r, g, b, a)` | `#RRGGBBAA` |197| `rgb(r, g, b)` | `#RRGGBB` |198| `hsl(h, s%, l%)` | `#RRGGBB` (converted) |199| `{ r, g, b }` (0-1) | `#RRGGBB` (scaled) |200| `{ r, g, b }` (0-255) | `#RRGGBB` |201202### Typography Normalization203204| Property | Source Variations | Target |205|----------|-------------------|--------|206| Font Size | `12px`, `0.75rem`, `12` | `"0.75rem"` or `12` |207| Font Weight | `"bold"`, `700`, `"semibold"` | `700` (numeric) |208| Line Height | `1.5`, `150%`, `24px` | `1.5` (unitless ratio) |209| Letter Spacing | `0.5px`, `0.02em` | `"0.02em"` |210211### Naming Normalization212213| Source Style | Target Style | Example |214|--------------|--------------|---------|215| `color/primary/500` | `color.primary.500` | Nested groups |216| `Primary Color` | `primaryColor` | camelCase |217| `primary-color` | `primaryColor` | camelCase |218| `PRIMARY_COLOR` | `primaryColor` | camelCase |219220## Source Metadata221222Preserve source information for traceability:223224```json225{226 "color": {227 "primary": {228 "$value": "#2196F3",229 "$type": "color",230 "$extensions": {231 "com.figma": {232 "variableId": "VariableID:1234",233 "styleId": "S:abc123",234 "collectionName": "Brand Colors"235 }236 }237 }238 }239}240```241242## Troubleshooting243244### No Tokens Found245246**Symptoms:** Extraction returns empty or minimal tokens247248**Solution:**2492501. Verify design file has published styles (not just local colors)2512. Check if using Figma variables vs. older style system2523. Look for design system component library2534. Try extracting from specific frames/components254255### Authentication Failed256257**Symptoms:** MCP server returns 401 or access denied258259**Solution:**2602611. Verify `FIGMA_ACCESS_TOKEN` is set for Figma2622. Ensure Sketch app is running for sketch-context2633. Check Penpot MCP server is running locally264265### Inconsistent Naming266267**Symptoms:** Token names don't match expected format268269**Solution:**2702711. Check original design file naming conventions2722. Use normalization rules consistently2733. Consider mapping file to enforce naming standards274275## See Also276277- `design-token-json` style - W3C format output278- `design-token-swift` style - Swift code output279- `design-to-swiftui` skill - Generate SwiftUI views from tokens280- `design-system-management` skill - Manage token libraries