Figma MCP Complete

Figma MCP Complete

Exports Figma designs as ready-to-use HTML/CSS and validates pixel-perfect accuracy with image comparison and visual regression testing.

Category
访问服务器

README

🎨 Figma MCP Complete

By Nour Shamrok

Figma to Code MCP + Pixel Perfect Validation

Export Figma designs as ready-to-use HTML/CSS + Validate pixel-perfect accuracy ✨

License: MIT Node.js Python


📖 Table of Contents


🎯 Overview

Figma MCP Complete solves the biggest problem in design-to-code workflows:

The Problem ❌

Figma MCP (existing):
  → Returns only JSON metadata
  → Claude guesses colors, fonts, spacing
  → Needs manual fixes
  → 30 minutes per component ⏱️

Result: Frustration, mistakes, wasted time 😫

The Solution ✅

Figma MCP Better (this project):
  → Returns Screenshot + CSS + HTML + JSON
  → Claude knows exactly what to build
  → Ready-to-use code
  → 30 seconds per component ⚡

Result: Perfect accuracy, zero iterations 🎉

✨ Features

🎨 Figma MCP Better

  • Screenshot Export - Visual reference for accuracy
  • CSS Generation - Production-ready styles
  • HTML Code - Copy-paste ready components
  • Design Tokens - Automated design system extraction
  • High DPI Support - 2x resolution for Retina displays

Pixel Perfect Validator

  • Image Comparison - Pixel-by-pixel accuracy checking
  • Visual Regression Testing - Percy.io integration
  • Heatmap Generation - See exact differences
  • Responsive Testing - Mobile, Tablet, Desktop
  • CI/CD Integration - GitHub Actions workflow

📊 Color & Typography Verification

  • ✅ RGB to Hex conversion
  • ✅ Font accuracy checking
  • ✅ Spacing validation (padding, margin, gap)
  • ✅ Shadow & effects verification
  • ✅ Border radius matching

🚀 Installation

Prerequisites

  • Node.js ≥ 16.0.0 (Download)
  • Python ≥ 3.8 (Download)
  • Git (Optional, for GitHub)

Step 1: Download & Extract

# Download figma-mcp-complete.zip
# Extract to your desired location
cd figma-mcp-complete

Step 2: Install Dependencies

# Install Node packages
npm install --save-dev playwright

# Install Python packages
pip install opencv-python numpy pillow

# Optional: For Percy.io validation
npm install --save-dev @percy/cli

Step 3: Setup Environment

Create .env file:

cat > .env << 'EOF'
FIGMA_TOKEN=figd_xxxxxxxxxxxxx
SIMULATOR_PORT=3000
PERCY_TOKEN=percy_xxxxxxxxxxxxx  # Optional
EOF

Get your Figma Token: https://www.figma.com/developers/api#access-tokens

Step 4: Verify Installation

# Test the setup
node figma-mcp-comparison.js

# Output should show comparison of old vs new MCP ✅

⚡ Quick Start

Export Figma Design to HTML/CSS

# Set your Figma token
export FIGMA_TOKEN="figd_xxxxxxxxxxxxx"

# Export frame from Figma
node figma-mcp-better.js FILE_ID NODE_ID "Component Name"

# Results saved to:
# figma-export/
# ├── index.html       ← Copy-paste this!
# ├── style.css        ← Or this!
# ├── data.json        ← Or everything here
# └── tokens.json      ← Design system

Get Figma IDs

  1. Open your Figma file: https://www.figma.com/file/YOUR_FILE_ID/...
  2. Copy the FILE_ID from URL
  3. Right-click on a frame → Copy link → Extract NODE_ID

Example:

URL: https://www.figma.com/file/abc123def456/MyDesign?node-id=789:123
FILE_ID: abc123def456
NODE_ID: 789:123

Validate Design Accuracy

# Start your simulator/app
npm run start:simulator &

# Capture simulator screenshots
npm run capture:simulator

# Compare with Figma
npm run pixel-perfect

# Results:
# ✅ Similarity: 99.8%
# ✅ All colors match
# ✅ Typography verified
# ✅ Pixel Perfect!

📚 Usage

Basic Workflow

# 1. Export from Figma
export FIGMA_TOKEN="..."
node figma-mcp-better.js FILE NODE "Button"

# 2. Get HTML/CSS
cat figma-export/index.html
# <button style="background-color: #FF5722; ...">

# 3. Copy to your project
# Done! ✨

Advanced: Export Multiple Frames

// export-all.js
const BetterFigmaMCP = require('./figma-mcp-better');

const mcp = new BetterFigmaMCP(process.env.FIGMA_TOKEN);

const frames = [
  { id: '123:45', name: 'Login Button' },
  { id: '123:46', name: 'Signup Form' },
  { id: '123:47', name: 'Dashboard Header' }
];

(async () => {
  for (const frame of frames) {
    const result = await mcp.exportFrame(FILE_ID, frame.id, frame.name);
    await mcp.saveExport(result, `./exports/${frame.name}`);
    console.log(`✅ Exported: ${frame.name}`);
  }
})();

Run:

node export-all.js

Integration with Claude AI

// Use with Claude API
const BetterFigmaMCP = require('./figma-mcp-better');

const figmaData = await mcp.exportFrame(fileId, nodeId);

// Claude now gets:
// - figmaData.screenshot     → Visual reference
// - figmaData.css            → Styling
// - figmaData.html           → Code
// - figmaData.designTokens   → System

// Result: Claude writes perfect code! 🎯

📋 Examples

Example 1: Button Component

export FIGMA_TOKEN="figd_xxx"
node figma-mcp-better.js abc123 "456:789" "Primary Button"

Output: figma-export/index.html

<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title>Primary Button</title>
  <style>
    .container {
      background-color: #FF5722;
      color: #FFFFFF;
      font-size: 16px;
      font-family: Inter;
      font-weight: 700;
      padding: 12px 24px;
      border-radius: 8px;
      box-shadow: 4px 4px 8px rgba(0,0,0,0.3);
    }
  </style>
</head>
<body>
  <button class="container">Click me</button>
</body>
</html>

Example 2: Design System Extraction

node figma-mcp-better.js abc123 "def:456" "Design System"

Output: figma-export/tokens.json

{
  "colors": {
    "primary": "#FF5722",
    "secondary": "#2196F3",
    "text": "#212121"
  },
  "typography": {
    "heading": {
      "fontFamily": "Montserrat",
      "fontSize": 32,
      "fontWeight": 700,
      "lineHeight": 1.2
    },
    "body": {
      "fontFamily": "Open Sans",
      "fontSize": 16,
      "fontWeight": 400,
      "lineHeight": 1.5
    }
  },
  "spacing": {
    "xs": "4px",
    "sm": "8px",
    "md": "16px",
    "lg": "24px"
  }
}

Example 3: Pixel Perfect Validation

npm run pixel-perfect

Output:

🎨 Comparing 5 screens...

1. login-mobile: 99.8% ✅
2. dashboard-mobile: 99.5% ✅
3. profile-mobile: 99.9% ✅
4. settings-mobile: 99.2% ✅
5. onboarding-mobile: 99.7% ✅

============================================================
PIXEL PERFECT VALIDATION RESULTS
============================================================

Average Similarity: 99.62%
Threshold: 99.0%
Screens Checked: 5

✅ ALL SCREENS PASSED PIXEL PERFECT VALIDATION!

🔌 API Reference

BetterFigmaMCP Class

Constructor

const mcp = new BetterFigmaMCP(figmaToken);

Methods

exportFrame(fileId, nodeId, frameName)

Export a single frame.

const result = await mcp.exportFrame(
  'abc123def456',
  '789:123',
  'Login Button'
);

// Returns:
{
  name: 'Login Button',
  screenshot: 'https://...',
  css: { ... },
  html: '<button>...</button>',
  designTokens: { ... },
  json: { ... }
}
saveExport(data, outputDir)

Save export to files.

await mcp.saveExport(result, './exports');

// Creates:
// ./exports/index.html
// ./exports/style.css
// ./exports/data.json
// ./exports/tokens.json
extractCSS(node)

Extract CSS from Figma node.

const css = mcp.extractCSS(figmaNode);
// Returns: { backgroundColor, fontSize, ... }
extractDesignTokens(file)

Extract design system tokens.

const tokens = mcp.extractDesignTokens(figmaFile);
// Returns: { colors, typography, spacing, shadows }

✅ Pixel Perfect Validation

How It Works

1. Export Figma screenshot → figma-baseline/
2. Capture simulator screenshot → simulator-screenshots/
3. Compare pixel-by-pixel → reports/
4. Generate heatmap of differences

Run Validation

# Capture simulator
npm run capture:simulator

# Compare with Figma
npm run pixel-check

# Or full validation
npm run pixel-perfect

Thresholds

Similarity Status Action
99%+ ✅ PASS Merge!
95-99% ⚠️ REVIEW Check heatmap
<95% ❌ FAIL Fix design

View Heatmap

Differences appear in reports/heatmap_*.png:

  • 🔴 Red = Large differences
  • 🟡 Yellow = Small differences
  • 🔵 Blue/Green = Identical

🚀 GitHub Actions CI/CD

Automatic Validation on Push

The project includes GitHub Actions workflow that:

  1. ✅ Validates on every push
  2. ✅ Checks pixel-perfect accuracy
  3. ✅ Blocks merge if validation fails
  4. ✅ Comments on PRs with results

Setup GitHub Actions

# Copy workflow file
.github/workflows/pixel-perfect.yml

# Commit to GitHub
git add .github/
git commit -m "Add pixel perfect CI/CD"
git push

# Set branch protection
GitHub → Settings → Branches
→ Require status checks to pass
→ Select "Pixel Perfect Validation"

Require Pixel Perfect

Now you cannot merge without passing validation! 🔒

PR created
  ↓
GitHub Actions runs
  ↓
Pixel Perfect test passes?
  ↓
❌ No → PR blocked 🚫
  ↓
✅ Yes → Can merge ✅

🐛 Troubleshooting

Installation Issues

"npm: command not found"

# Install Node.js
https://nodejs.org/

# Verify:
node --version
npm --version

"python3: command not found"

# Install Python
https://python.org/downloads

# Verify:
python3 --version

"ModuleNotFoundError: No module named 'cv2'"

# Reinstall Python packages
pip install --upgrade opencv-python numpy pillow

Runtime Issues

"FIGMA_TOKEN not set"

# Set token
export FIGMA_TOKEN="figd_xxxxxxxxxxxxx"

# Or create .env file
echo "FIGMA_TOKEN=figd_xxxxxxxxxxxxx" > .env

"Node FILE_ID NODE_ID not found"

# Get correct IDs from Figma URL
# https://www.figma.com/file/YOUR_FILE_ID/...?node-id=YOUR_NODE_ID

# Verify they're correct
echo $FIGMA_TOKEN

"Screenshots don't match"

# Check DPI consistency
# Ensure both screenshots are 2x scale (Retina)

# Manually verify
open figma-export/index.html
open reports/heatmap_*.png

Performance

Slow export?

# Reduce resolution
node figma-mcp-better.js FILE NODE --scale=1

Memory issues?

# Process one frame at a time
# Or increase Node memory
node --max-old-space-size=4096 figma-mcp-better.js

📊 Comparison: Old vs New

Feature Old Figma MCP Figma MCP Complete
Screenshot
CSS
HTML
Design Tokens
Color Format RGB(0-1) 😩 #HEX 😊
Font Size Just number px (web standard)
Ready to Use ❌ 30 min ✅ 30 sec
Claude Accuracy 60% 99%+
Iterations Needed Many Zero

🤝 Contributing

Contributions welcome!

# Fork & clone
git clone https://github.com/YOUR_FORK/figma-mcp-complete.git
cd figma-mcp-complete

# Create branch
git checkout -b feature/amazing-feature

# Make changes
# Test thoroughly
npm test

# Push & create PR
git push origin feature/amazing-feature

Development

# Run tests
npm test

# Lint code
npm run lint

# Build docs
npm run docs

📝 License

MIT License - See LICENSE file


🙏 Acknowledgments

  • Built with ❤️ for designers and developers
  • Inspired by real design-to-code workflow problems
  • Thanks to Figma & Anthropic communities

📞 Support

Documentation

Issues & Questions

Community


⭐ If you find this useful, please star! ⭐

Star this repo to show support ✨
Share with your team 👥
Contribute improvements 🚀

🎯 Roadmap

  • [ ] Web UI for exports
  • [ ] Figma plugin integration
  • [ ] Multiple design system formats
  • [ ] Real-time validation
  • [ ] Browser extension
  • [ ] Cloud storage integration

📈 Stats

✅ Lines of code: 5000+
✅ Supported Figma nodes: 15+
✅ Export formats: 5+ (HTML, CSS, JSON, etc)
✅ Validation accuracy: 99%+
✅ Performance: <30s per component

Made with ❤️ for better design-to-code workflows

Created by Nour Shamrok 🚀

Star | Watch | Fork

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选