Figma MCP について
Figma Context MCP は、Cursor、Windsurf、Cline などの AI コーディングツールから Figma のデザインデータを参照できるようにする MCP サーバーです。デザインからコードを生成する開発者を想定しており、レイアウト推定とキャッシュでデータを最適化します。
主な機能
- 01Flexbox と Grid を推定するレイアウト検出
- 02ベクターレイヤーの結合によるアイコン出力
- 03Figma スタイルから CSS への変換
- 04API 呼び出しを減らす 2 層キャッシュ
- 05デザインからコードへのプロンプトテンプレート
活用シーン
- 01AI コーディングツールによる Figma デザインの実装
- 02デザインファイルからの画像とアイコンのダウンロード
- 03デザイントークンとコンポーネント一覧の抽出
MCP 対応
MCP サーバーとして、get_figma_data や download_figma_images などのツール、プロンプトテンプレート、figma:// リソースをクライアントに公開します。
設定
ローカルサーバーの設定はどのクライアントでも共通です。コピーしてクライアントの MCP 設定ファイルに貼り付けてください。
ツール
5掲載時のツール一覧 · 2 週間前に更新
| パラメーター | 型 | 必須 | 説明 |
|---|---|---|---|
| url | string | はい | 追加する Figma ファイルの URL |
詳細
Figma Context MCP
AI コーディングツールと Figma デザインをシームレスに統合する MCP サーバー
機能 • クイックスタート • MCP の機能 • アーキテクチャ • ドキュメント • 中文ドキュメント
これは何ですか?
Figma Context MCP は、Model Context Protocol (MCP) サーバーであり、Figma デザインと Cursor、Windsurf、Cline などの AI コーディングアシスタントをつなぎます。
AI ツールが Figma のデザインデータに直接アクセスできると、スクリーンショットを使うよりもはるかに正確なコードを最初の試行で生成できます。
Note: このプロジェクトは Figma-Context-MCP をベースにしており、データ構造の最適化とインテリジェントなレイアウト検出アルゴリズムを備えています。
機能
主要な機能
| 機能 | 説明 |
|---|---|
| スマートレイアウト検出 | 絶対配置から Flexbox/Grid レイアウトを自動的に推論します |
| アイコンのマージ | ベクターレイヤーを単一の書き出し可能なアイコンにインテリジェントにマージします |
| CSS 生成 | Figma スタイルをクリーンで使いやすい CSS に変換します |
| 画像の書き出し | 画像とアイコンを適切な命名でダウンロードします |
| 多層キャッシュ | L1 メモリ + L2 ディスクキャッシュで API 呼び出しを削減します |
| デザインからコードへのプロンプト | AI によるコード生成を導くためのプロフェッショナルなプロンプトテンプレートを内蔵しています |
| 軽量なリソースアクセス | Resources API によりトークンの少ないデータアクセスを提供します |
主な改善点
| 機能 | 変更前 | 変更後 |
|---|---|---|
| アイコンの書き出し | 約45個の断片 | 2個にマージ(96% 削減) |
| レイアウト検出 | 手動の絶対配置 | Flexbox/Grid の自動推論 |
| CSS 出力 | 生の値 | デフォルトを削除して最適化 |
| API 呼び出し | 毎回のリクエスト | 24時間のスマートキャッシュ |
クイックスタート
前提条件
- Node.js >= 18.0.0
- API アクセスが可能な Figma アカウント
インストール
Smithery 経由(推奨)
npx -y @smithery/cli install @1yhy/Figma-Context-MCP --client claude
npm 経由
npm install -g @yhy2001/figma-mcp-server
ソースから
git clone https://github.com/1yhy/Figma-Context-MCP.git
cd Figma-Context-MCP
pnpm install
pnpm build
設定
1. Figma API トークンを取得する
- Figma アカウント設定に移動します
- 「Personal access tokens」までスクロールします
- 「Create new token」をクリックします
- トークンをコピーします
2. AI ツールの設定
Cursor / Windsurf / Cline
MCP 設定ファイルに追加します:
{
"mcpServers": {
"Figma": {
"command": "npx",
"args": ["-y", "@yhy2001/figma-mcp-server", "--stdio"],
"env": {
"FIGMA_API_KEY": "your-figma-api-key"
}
}
}
}
HTTP/SSE モード(ローカル開発)
# From source (development)
cp .env.example .env # Add FIGMA_API_KEY to .env
pnpm install && pnpm build
pnpm start # Starts on port 3333
# Or with environment variable
FIGMA_API_KEY=<your-key> pnpm start
# Or via global install
figma-mcp --figma-api-key=<your-key> --port=3333
# Connect via SSE
# URL: http://localhost:3333/sse
使用例
Please implement this Figma design: https://www.figma.com/design/abc123/MyDesign?node-id=1:234
Use React and Tailwind CSS.
MCP の機能
このサーバーは MCP の機能を全面的にサポートしています:
┌─────────────────────────────────────────────────────────────┐
│ Figma MCP Server v1.1.0 │
├─────────────────────────────────────────────────────────────┤
│ Tools (2) AI-invoked operations │
│ ├── get_figma_data Fetch design data │
│ └── download_figma_images Download image assets │
├─────────────────────────────────────────────────────────────┤
│ Prompts (3) User-selected templates │
│ ├── design_to_code Full design-to-code flow │
│ ├── analyze_components Component structure │
│ └── extract_styles Style token extraction │
├─────────────────────────────────────────────────────────────┤
│ Resources (5) Lightweight data sources │
│ ├── figma://help Usage guide │
│ ├── figma://file/{key} File metadata (~200 tok) │
│ ├── figma://file/{key}/styles Design tokens (~500 tok) │
│ ├── figma://file/{key}/components Component list (~300 tok)│
│ └── figma://file/{key}/assets Asset inventory (~400 tok) │
└─────────────────────────────────────────────────────────────┘
ツール
| ツール | 説明 | パラメータ |
|---|---|---|
get_figma_data | 簡略化されたデザインデータを取得 | fileKey, nodeId?, depth? |
download_figma_images | 画像とアイコンをダウンロード | fileKey, nodes[], localPath |
プロンプト
AI が高品質なコードを生成するための、組み込みのプロフェッショナルなプロンプトテンプレート:
| プロンプト | 説明 | パラメータ |
|---|---|---|
design_to_code | デザインからコードへのワークフローを完結 | framework?, includeResponsive? |
analyze_components | コンポーネント構造と再利用性を分析 | - |
extract_styles | デザイントークンを抽出 | - |
design_to_code ワークフローの内容:
- プロジェクト分析 - テーマ設定、グローバルスタイル、コンポーネントライブラリを読み込む
- 構造分析 - ページパターンの特定、コンポーネント分割戦略
- ASCII レイアウト設計図 - コンポーネントとアセットの注釈付きでレイアウト図を生成
- アセット管理 - 画像/アイコンの分析、ダウンロード、整理
- コード生成 - プロジェクトの規約に従ってコードを生成
- アクセシビリティ最適化 - セマンティック HTML、ARIA ラベル
- レスポンシブ対応 - モバイルレイアウトの調整
リソース
トークンを節約する軽量なデータアクセス:
# Get file metadata (~200 tokens)
figma://file/abc123
# Get design tokens (~500 tokens)
figma://file/abc123/styles
# Get component list (~300 tokens)
figma://file/abc123/components
# Get asset inventory (~400 tokens)
figma://file/abc123/assets
リソースとツールの比較:
| 機能 | ツール | リソース |
|---|---|---|
| 制御 | AI が自動で呼び出す | ユーザー/クライアントが開始 |
| トークンコスト | 高い(全データ) | 低い(要約) |
| 用途 | アクションの実行 | 閲覧と探索 |
アーキテクチャ
┌──────────────────────────────────────────────────────────────┐
│ MCP Server │
├──────────────────────────────────────────────────────────────┤
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────────────┐ │
│ │ Tools │ │ Prompts │ │ Resources │ │
│ │ (2 tools) │ │ (3 prompts) │ │ (5 resources) │ │
│ └──────┬──────┘ └─────────────┘ └──────────┬──────────┘ │
│ │ │ │
│ └──────────────────┬───────────────────┘ │
│ ▼ │
│ ┌────────────────────────────────────────────────────────┐ │
│ │ FigmaService │ │
│ │ API Calls • Validation • Error Handling │ │
│ └────────────────────────┬───────────────────────────────┘ │
│ │ │
│ ┌─────────────────┴─────────────────┐ │
│ ▼ ▼ │
│ ┌─────────────────┐ ┌─────────────────────┐ │
│ │ CacheManager │ │ Parser + Algo │ │
│ │ L1: LRU Memory │ │ • Layout Detection │ │
│ │ L2: Disk Store │ │ • Icon Merging │ │
│ └─────────────────┘ │ • CSS Generation │ │
│ └─────────────────────┘ │
└──────────────────────────────────────────────────────────────┘
キャッシュシステム
2 層のキャッシュアーキテクチャにより、API 呼び出しを大幅に削減します:
| 層 | ストレージ | 容量 | TTL | 目的 |
|---|---|---|---|---|
| L1 | メモリ LRU | 100 ノード / 50 画像 | 5〜10 分 | ホットデータへの高速アクセス |
| L2 | ディスク | 500MB | 24 時間 | 永続キャッシュ |
レイアウト検出アルゴリズム
絶対配置をセマンティックな Flexbox/Grid レイアウトに自動変換します:
Input (Figma absolute positioning):
┌─────────────────────────┐
│ ■ (10,10) ■ (110,10) │
│ ■ (10,60) ■ (110,60) │
└─────────────────────────┘
Output (Inferred Grid):
display: grid
grid-template-columns: 100px 100px
grid-template-rows: 50px 50px
gap: 10px
プロジェクト構成
src/
├── algorithms/ # Smart algorithms
│ ├── layout/ # Layout detection (Flex/Grid inference)
│ └── icon/ # Icon merge detection
├── core/ # Core parsing
│ ├── parser.ts # Figma data parser
│ ├── style.ts # CSS style generation
│ ├── layout.ts # Layout processing
│ └── effects.ts # Effects handling
├── services/ # Service layer
│ ├── figma.ts # Figma API client
│ └── cache/ # Multi-layer cache system
├── prompts/ # MCP prompt templates
├── resources/ # MCP resource handlers
├── types/ # TypeScript type definitions
├── utils/ # Utility functions
├── server.ts # MCP server main entry
└── index.ts # CLI entry
tests/
├── fixtures/ # Test data
│ ├── figma-data/ # Raw JSON from Figma API
│ └── expected/ # Expected output snapshots
├── integration/ # Integration tests
│ ├── layout-optimization.test.ts # Layout optimization tests
│ ├── output-quality.test.ts # Output quality validation
│ └── parser.test.ts # Parser tests
└── unit/ # Unit tests
├── algorithms/ # Algorithm tests (layout, icon detection)
├── resources/ # Resource handler tests
└── services/ # Service layer tests
scripts/
└── fetch-test-data.ts # Figma test data fetcher
ドキュメント
コアアルゴリズム
| 英語 | 中文 |
|---|---|
| Layout Detection | 布局检测算法 |
| Icon Detection | 图标检测算法 |
| Cache Architecture | 缓存架构设计 |
リサーチドキュメント
| 英語 | 中文 |
|---|---|
| Grid Layout Research | Grid 布局研究 |
| Layout Detection Research | 布局检测研究 |
アーキテクチャドキュメント
| 英語 | 中文 |
|---|---|
| Architecture | 系统架构 |
コマンドラインオプション
| オプション | 説明 | デフォルト |
|---|---|---|
--figma-api-key | Figma API トークン | 必須 |
--port | HTTP モード用のサーバーポート | 3333 |
--stdio | stdio モードで実行 | false |
--help | ヘルプを表示 | - |
コントリビューション
コントリビューションを歓迎します!
# Setup
git clone https://github.com/1yhy/Figma-Context-MCP.git
cd Figma-Context-MCP
pnpm install
# Development
pnpm dev # Watch mode
pnpm test # Run tests (272 test cases)
pnpm lint # Lint code
pnpm build # Build
# Debug
pnpm inspect # MCP Inspector
# Test with your own Figma data
pnpm tsx scripts/fetch-test-data.ts <fileKey> <nodeId> <outputName>
# Commit (uses conventional commits)
git commit -m "feat: add new feature"
コミットタイプ
| タイプ | 説明 |
|---|---|
feat | 新機能 |
fix | バグ修正 |
docs | ドキュメント |
style | コードスタイル |
refactor | リファクタリング |
test | テスト |
chore | メンテナンス |
リリースプロセス(メンテナー向け)
# 1. Update version in package.json and CHANGELOG.md
# 2. Commit version bump
git add -A
git commit -m "chore: bump version to x.x.x"
# 3. Publish to npm (auto runs: type-check → lint → test → build)
npm login --scope=@yhy2001 # if not logged in
pnpm run pub:release
# 4. Create git tag and push
git tag vx.x.x
git push origin main --tags
# 5. Create GitHub Release (optional)
# Go to https://github.com/1yhy/Figma-Context-MCP/releases/new
独自の Figma データでのテスト
独自の Figma デザインを使用して、レイアウト検出と最適化をテストできます:
1. 環境変数の設定
# Copy the environment template
cp .env.example .env
# Edit .env file with your configuration
FIGMA_API_KEY=your_figma_api_key_here
TEST_FIGMA_FILE_KEY=your_file_key # Optional
TEST_FIGMA_NODE_ID=your_node_id # Optional
2. Figma ノードデータの取得
# Method 1: Using command line arguments (recommended)
pnpm tsx scripts/fetch-test-data.ts <fileKey> <nodeId> <outputName>
# Example: Fetch a specific node
pnpm tsx scripts/fetch-test-data.ts UgtwrncR3GokKDIS7dpm4Z 402-34955 my-design
# Method 2: Using environment variables
TEST_FIGMA_FILE_KEY=xxx TEST_FIGMA_NODE_ID=123-456 pnpm tsx scripts/fetch-test-data.ts
パラメータ:
| パラメータ | 説明 | 取得方法 |
|---|---|---|
fileKey | Figma ファイル識別子 | URL の /design/ より後の部分、例:UgtwrncR3GokKDIS7dpm4Z |
nodeId | ノード ID | URL の node-id= パラメータ、例:402-34955 |
outputName | 出力ファイル名 | カスタム名、例:my-design |
URL 解析例:
https://www.figma.com/design/UgtwrncR3GokKDIS7dpm4Z/MyProject?node-id=402-34955
↑ fileKey ↑ nodeId
3. テストを実行して出力を検証
# Run all tests
pnpm test
# Run only integration tests (validate layout optimization)
pnpm test tests/integration/
# View output JSON files
ls tests/fixtures/figma-data/
4. 最適化結果の分析
テストは以下を自動的に検証します:
- データ圧縮 - 通常 50% 以上の圧縮率
- レイアウト検出 - Flex/Grid レイアウトの認識率
- CSS プロパティ - 冗長なプロパティのクリーンアップ
- 出力品質 - 構造の一貫性チェック
テストが失敗した場合、出力が期待に沿わない可能性があります。エラーメッセージを確認して調整するか、Issue を報告してください。
ライセンス
MIT © 1yhy
謝辞
- Figma-Context-MCP - オリジナルプロジェクト
- Model Context Protocol - MCP 仕様
- Best-README-Template - README テンプレートの参考
Made with ❤️ for the AI coding community
コメント
AI アプリケーションが外部のツールやデータソースに統一的な方法で接続するためのオープンなプロトコルです。クライアントはモデルとの対話を担い、MCP サーバーはツール・リソース・プロンプトテンプレートを提供します。標準メッセージでやり取りするため、1 つのサーバーを複数のクライアントで再利用できます。