mcpField
F
Figma MCP

Figma MCP

ローカル
github.com/1yhyメディア・デザイン3047 週間前に更新

Figma MCP について

Figma Context MCP は、Cursor、Windsurf、Cline などの AI コーディングツールから Figma のデザインデータを参照できるようにする MCP サーバーです。デザインからコードを生成する開発者を想定しており、レイアウト推定とキャッシュでデータを最適化します。

主な機能

  1. 01Flexbox と Grid を推定するレイアウト検出
  2. 02ベクターレイヤーの結合によるアイコン出力
  3. 03Figma スタイルから CSS への変換
  4. 04API 呼び出しを減らす 2 層キャッシュ
  5. 05デザインからコードへのプロンプトテンプレート

活用シーン

  1. 01AI コーディングツールによる Figma デザインの実装
  2. 02デザインファイルからの画像とアイコンのダウンロード
  3. 03デザイントークンとコンポーネント一覧の抽出

MCP 対応

MCP サーバーとして、get_figma_data や download_figma_images などのツール、プロンプトテンプレート、figma:// リソースをクライアントに公開します。

設定

ローカルサーバーの設定はどのクライアントでも共通です。コピーしてクライアントの MCP 設定ファイルに貼り付けてください。

mcp.json · 共通設定
{
"mcpServers": {
"figma-context-mcp-1yhy": {
"command": "npx",
"args": [
"-y",
"figma-mcp"
]
}
}
}
起動コマンドnpx -y figma-mcp

ローカルサーバーにはマシン上の実行環境(Node.js 18 以上など)が必要です。設定ファイルの場所はクライアントごとに異なります。

パッケージ
npmfigma-mcp

ツール

5

掲載時のツール一覧 · 2 週間前に更新

パラメーター型必須説明
urlstringはい追加する Figma ファイルの URL

詳細


Figma MCP
Figma Context MCP

AI コーディングツールと Figma デザインをシームレスに統合する MCP サーバー

Smithery Badge npm version License Stars TypeScript MCP SDK

機能 • クイックスタート • 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 トークンを取得する
  1. Figma アカウント設定に移動します
  2. 「Personal access tokens」までスクロールします
  3. 「Create new token」をクリックします
  4. トークンをコピーします
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 ワークフローの内容:

  1. プロジェクト分析 - テーマ設定、グローバルスタイル、コンポーネントライブラリを読み込む
  2. 構造分析 - ページパターンの特定、コンポーネント分割戦略
  3. ASCII レイアウト設計図 - コンポーネントとアセットの注釈付きでレイアウト図を生成
  4. アセット管理 - 画像/アイコンの分析、ダウンロード、整理
  5. コード生成 - プロジェクトの規約に従ってコードを生成
  6. アクセシビリティ最適化 - セマンティック HTML、ARIA ラベル
  7. レスポンシブ対応 - モバイルレイアウトの調整
リソース

トークンを節約する軽量なデータアクセス:

# 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メモリ LRU100 ノード / 50 画像5〜10 分ホットデータへの高速アクセス
L2ディスク500MB24 時間永続キャッシュ
レイアウト検出アルゴリズム

絶対配置をセマンティックな 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 ResearchGrid 布局研究
Layout Detection Research布局检测研究
アーキテクチャドキュメント
英語中文
Architecture系统架构

コマンドラインオプション

オプション説明デフォルト
--figma-api-keyFigma API トークン必須
--portHTTP モード用のサーバーポート3333
--stdiostdio モードで実行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

パラメータ:

パラメータ説明取得方法
fileKeyFigma ファイル識別子URL の /design/ より後の部分、例:UgtwrncR3GokKDIS7dpm4Z
nodeIdノード IDURL の 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

謝辞


Made with ❤️ for the AI coding community

コメント

MCP は初めてですか?

プロトコルの概要から最初のサーバーの導入まで、よくある疑問にまとめて答えます。

AI アプリケーションが外部のツールやデータソースに統一的な方法で接続するためのオープンなプロトコルです。クライアントはモデルとの対話を担い、MCP サーバーはツール・リソース・プロンプトテンプレートを提供します。標準メッセージでやり取りするため、1 つのサーバーを複数のクライアントで再利用できます。