Figma MCP服务器

Figma MCP服务器是一个基于MCP协议的Figma自动化平台,提供设计文件的读取、分析和修改功能,支持多种AI代理和插件集成。

  • by Zaki-goumri
  • TypeScript
  • 本地部署
  • 2 星标
  • 更新于
在 GitHub 查看 Zaki-goumri/figma-mcp-server

使用说明

Figma MCP服务器架构

🏗️ 整体架构

┌─────────────────────────────────────────────────────────────────────────┐
│                           AI Agents Layer                              │
│  ┌─────────┐  ┌─────────┐  ┌─────────┐  ┌─────────┐  ┌─────────┐       │
│  │ Claude  │  │ ChatGPT │  │ Gemini  │  │ Cursor  │  │ Custom  │       │
│  └─────────┘  └─────────┘  └─────────┘  └─────────┘  └─────────┘       │
└─────────────────────────┬───────────────────────────────────────────────┘
                          │ Standard MCP Protocol
┌─────────────────────────┴───────────────────────────────────────────────┐
│                      MCP Server Core                                   │
│  ┌─────────────────┐  ┌─────────────────┐  ┌─────────────────┐         │
│  │   Tool Handler  │  │ Resource Handler│  │ Prompt Handler  │         │
│  └─────────────────┘  └─────────────────┘  └─────────────────┘         │
│                                │                                        │
│  ┌─────────────────────────────┴─────────────────────────────┐         │
│  │                Service Layer                              │         │
│  │  ┌─────────────┐ ┌─────────────┐ ┌─────────────┐         │         │
│  │  │ Figma API   │ │ Cache Layer │ │ Plugin Comm │         │         │
│  │  │ Service     │ │             │ │ (Optional)  │         │         │
│  │  └─────────────┘ └─────────────┘ └─────────────┘         │         │
│  └─────────────────────────────────────────────────────────┘         │
└─────────────────────┬───────────────────────────────────────────────────┘
                      │
┌─────────────────────┴───────────────────────────────────────────────────┐
│                    External Services                                   │
│  ┌─────────────────┐  ┌─────────────────┐  ┌─────────────────┐         │
│  │  Figma REST API │  │ Figma Plugin    │  │    Database     │         │
│  │                 │  │   (Optional)    │  │   (Optional)    │         │
│  └─────────────────┘  └─────────────────┘  └─────────────────┘         │
└─────────────────────────────────────────────────────────────────────────┘

📁 项目结构


figma-mcp-server/
├── package.json
├── tsconfig.json
├── .env.example
├── README.md
├── src/
│   ├── index.ts                    # Entry point
│   ├── server/
│   │   ├── mcp-server.ts          # Core MCP server setup
│   │   ├── tool-handler.ts        # Tool request handling
│   │   ├── resource-handler.ts    # Resource management
│   │   └── prompt-handler.ts      # Prompt definitions
│   ├── services/
│   │   ├── figma-api.ts           # Figma REST API client
│   │   ├── cache.ts               # Caching layer
│   │   ├── plugin-comm.ts         # Plugin communication (future)
│   │   └── design-intelligence.ts # AI-powered features
│   ├── tools/
│   │   ├── base-tool.ts           # Abstract tool class
│   │   ├── read-tools/            # Read operations
│   │   │   ├── get-document.ts
│   │   │   ├── get-nodes.ts
│   │   │   ├── search-nodes.ts
│   │   │   └── export-nodes.ts
│   │   ├── write-tools/           # Write operations (future)
│   │   │   ├── create-nodes.ts
│   │   │   ├── modify-nodes.ts
│   │   │   └── delete-nodes.ts
│   │   └── analysis-tools/        # AI-powered analysis
│   │       ├── analyze-design.ts
│   │       ├── suggest-improvements.ts
│   │       └── check-accessibility.ts
│   ├── types/
│   │   ├── figma.ts              # Figma API types
│   │   ├── mcp.ts                # MCP-specific types
│   │   └── common.ts             # Shared types
│   └── utils/
│       ├── errors.ts             # Error handling
│       ├── validation.ts         # Input validation
│       └── helpers.ts            # Utility functions
├── tests/
│   ├── unit/
│   ├── integration/
│   └── fixtures/
└── docs/
    ├── API.md
    ├── TOOLS.md
    └── DEPLOYMENT.md

🚀 实施阶段

第一阶段:基础(第一周)

目标:具有基本读取操作的基本MCP服务器

特性:

  • ✅ 使用TypeScript设置MCP服务器
  • ✅ Figma REST API集成
  • ✅ 基本身份验证
  • ✅ 基本阅读工具:
    • get_document -获取文档信息
    • get_nodes -获取特定节点
    • search_nodes -按类型/名称搜索
    • export_nodes -导出为图像

可交付成果:可以读取Figma文件的工作MCP服务器

第2阶段:增强阅读(第2周)

目标:高级读取功能和缓存

特性:

  • ✅ 性能缓存层
  • ✅ 高级搜索功能
  • ✅ 批量操作
  • ✅ 附加工具:
    • get_components -列出本地组件
    • get_styles -获取文档样式
    • get_comments -阅读评论
    • analyze_structure -文档结构分析

可交付成果:快速、功能丰富的只读MCP服务器

第三阶段:人工智能(第三周)

目标:AI驱动的设计分析和建议

特性:

  • ✅ 设计模式识别
  • ✅ 可达性分析
  • ✅ 设计系统合规性检查
  • ✅ 聪明的建议
  • ✅ 工具:
    • analyze_design_system -检查一致性
    • suggest_improvements -人工智能建议
    • check_accessibility -A11y合规性
    • find_similar_components -图案匹配

可交付成果:智能设计分析能力

第4阶段:写操作(第4周)

目标:通过REST API的基本写入功能

特性:

  • ✅ 评论创建和管理
  • ✅ 文件组织操作
  • ✅ 插件集成准备
  • ✅ 工具:
    • create_comment -添加评论
    • update_comment -修改评论
    • organize_files -档案管理
    • prepare_plugin_setup -插件脚手架

可交付成果:启用写入的MCP服务器

第5阶段:插件集成(第5+周)

目标:通过Figma插件完全读/写

特性:

  • ✅ Figma插件开发
  • ✅ 实时通信
  • ✅ 完整的CRUD操作
  • ✅ 实时选择跟踪

可交付成果:完整的Figma自动化平台

🛠️ 技术栈

核心技术

  • TypeScript -类型安全开发
  • Node.js -运行时环境
  • MCP-SDK -官方Anthropic SDK
  • 萨德 -运行时验证
  • 温斯顿 -日志记录

开发工具

  • 开玩笑 -测试框架
  • ESLint -代码linting
  • 更漂亮 -代码格式
  • 哈士奇 -Git挂钩
  • 变更集 -版本管理

可选增强功能

  • 雷迪斯 -高级缓存
  • PostgreSQL -持久存储
  • 网络套接字 -实时通信
  • OpenAI API -增强的AI功能

🎯 关键设计原则

1. 通用兼容性

  • 遵守标准MCP协议
  • 适用于任何MCP兼容代理
  • 没有特定于代理的依赖关系

2. 模块化架构

  • 清晰地分离关注点
  • 易于扩展和修改
  • 基于插件的工具系统

3. 性能优先

  • 智能缓存策略
  • 批量操作支持
  • 优化的API调用

4. 开发者体验

  • 全面的TypeScript类型
  • 清除错误消息
  • 大量文件
  • 易于本地开发

5. 可扩展性

  • 水平缩放支持
  • 速率限制
  • 资源管理
  • 配置驱动

📋 分步实施计划

步骤1:项目设置

mkdir figma-mcp-server
cd figma-mcp-server
pnpm init
# Install dependencies
# Setup TypeScript
# Configure dev tools

步骤2:核心MCP服务器

// Basic server setup with MCP SDK
// Tool registration system
// Request/response handling

步骤3:Figma API集成

// REST API client
// Authentication handling
// Rate limiting
// Error handling

第四步:必备工具

// Document reading tools
// Node information tools
// Search capabilities
// Export functionality

步骤5:测试和验证

# Unit tests
# Integration tests
# MCP agent compatibility tests

🔧 配置系统

interface FigmaMCPConfig {
  figma: {
    token: string;
    rateLimitPerMinute: number;
    timeoutMs: number;
  };
  cache: {
    enabled: boolean;
    ttlSeconds: number;
    maxSize: number;
  };
  features: {
    aiAnalysis: boolean;
    pluginSupport: boolean;
    batchOperations: boolean;
  };
  logging: {
    level: 'debug' | 'info' | 'warn' | 'error';
    file?: string;
  };
}

🚀 入门命令

# Development
npm run dev          # Start in development mode
npm run build        # Build for production
npm run test         # Run tests
npm run lint         # Lint code

# Usage with different agents
npx figma-mcp-server  # Direct usage
# Add to MCP config for Claude, ChatGPT, etc.

📈 未来的增强功能

高级功能

  • 多文件操作 -跨多个Figma文件工作
  • 版本控制集成 -类似Git的设计操作
  • 团队协作 -多用户会话管理
  • 设计代币 -先进的设计系统管理
  • 自动化测试 -视觉回归测试
  • 人工智能生成的设计 -根据描述创建设计

平台集成

  • Slack/Discord机器人 -设计更新和通知
  • CI/CD集成 -自动化设计验证
  • Jira/线性 -将设计链接到门票
  • 汇流 -设计文档生成
  • 故事书 -组件库同步

准备好开始第一步了吗?请告诉我,我将指导您建立项目基金会!