Token导航 LogoToken导航TokenDH.com
Figma Context MCP logo
设计创作stdio官方级别未说明来源级核验

Figma Context MCP

MCP Server

@smithery/cli

Figma Context MCP是一款连接Figma设计与AI编程工具的协议服务器,通过智能布局检测和资源优化,实现高效的设计转代码功能。

工具数

0

提示词数

0

GitHub Stars

24

资源数

0
TypeScriptClaudeAI代理ClaudeCursorWindsurfCline

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

作者 / 组织

1yhy

提供方

1yhy

最后核验

2026/5/17 20:23

运行时

Node.js

快速接入

先看主来源和安装命令,再打开仓库或文档;下面只保留这个条目的关键接入事实。

命令预览

npx -y @smithery/cli install @1yhy/Figma-Context-MCP --client claude

详细介绍

Figma Context MCP

MCP server for seamless Figma design integration with AI coding tools

Features • Quick Start • MCP Capabilities • Architecture • Documentation • 中文文档

______________________________________________________________________

这是什么?

Figma上下文MCP是一个 模型上下文协议(MCP) 将Figma设计与AI编码助手连接起来的服务器,如 光标, 帆板运动,以及 克莱恩.

当人工智能工具可以直接访问Figma设计数据时,它们在第一次尝试时就会生成更准确的代码,远远好于使用屏幕截图。

备注:本项目基于 Figma上下文MCP,具有优化的数据结构和智能布局检测算法。

特性

核心能力

能力描述
智能布局检测根据绝对定位自动推断Flexbox/Grid布局
图标合并智能地将矢量层合并为单个可导出图标
CSS生成将Figma样式转换为干净、可用的CSS
图像导出下载具有正确命名的图像和图标
多层缓存一级内存+二级磁盘缓存,减少API调用
设计到代码提示内置专业提示模板,指导AI代码生成
轻量级资源访问资源API提供低令牌数据访问

关键改进

特征之前之后
图标导出~45个碎片2个合并(减少96%)
布局检测手动绝对自动Flexbox/Grid推理
CSS输出原始值优化并删除默认值
API调用每次请求24小时智能缓存

快速开始

先决条件

  • Node.js>=18.0.0
  • 具有API访问权限的Figma帐户

安装

史密斯路(推荐)

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. 滚动到“个人访问令牌”
  3. 点击“创建新令牌”
  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 Mode (Local Development)

# 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= pnpm start

# Or via global install
figma-mcp --figma-api-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   │    │
│                                   └─────────────────────┘    │
└──────────────────────────────────────────────────────────────┘

缓存系统

双层缓存体系结构显著减少了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

______________________________________________________________________

文档

核心算法

研究文件

架构文件

English中文
建筑系统架构

______________________________________________________________________

命令行选项

选项描述默认值
--figma-api-keyFigma API令牌必需
--portHTTP模式的服务器端口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   

# Commit (uses conventional commits)
git commit -m "feat: add new feature"

提交类型

类型描述
feat新功能
fixBug修复
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   

# 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文件标识符后面的部分 /design/ 在URL中。, UgtwrncR3GokKDIS7dpm4Z
nodeId节点IDnode-id= URL中的参数。, 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属性 -冗余属性清理
  • 输出质量 -结构一致性检查

如果测试失败,输出可能不符合预期。检查错误消息以调整或报告问题。

______________________________________________________________________

许可证

麻省理工学院 © 1个月

致谢

______________________________________________________________________

Made with ❤️ for the AI coding community

目录标签

目录标签

TypeScriptClaudeAI代理设计转代码本地部署Figma集成AI辅助开发布局检测CSS生成

支持客户端

ClaudeCursorWindsurfCline

接入字段

传输方式(transport,传输协议)

stdio

鉴权方式(authType,认证方式)

token

运行时(runtime,运行环境)

Node.js

部署方式(deploymentType,部署类型)

remote-capable

来源包(packageName,安装包名)

@smithery/cli

工具数量(toolCount,工具数)

0

资源数量(resourceCount,资源数)

0

提示词数量(promptCount,提示词数)

0

权限和风险

stdiotokenremote-capable

接入前请确认传输方式、认证方式和部署位置,并根据实际工具能力限制访问范围。

安装前确认

不要直接授予不必要的文件、网络或账号权限;先核对安装命令和配置内容。

来源信息

继续浏览同类 MCP