设计系统组件自动提取服务

自动化提取并管理设计系统组件元数据的服务,支持AI助手自动生成代码和文档,适用于前端开发效率提升。

  • by denizzeybek-fe
  • TypeScript
  • 本地部署
  • 更新于
在 GitHub 查看 denizzeybek-fe/design-system-mcp

使用说明

🎨 内部设计系统MCP

自动模型上下文协议服务器 内部设计系统。使像Claude这样的人工智能助手能够发现、理解和生成60多个设计系统组件的代码 自动提取 源代码。

版本:2.0(自动提取) 状态: ✅ 生产就绪 最后更新: 2025-11-21


✨ 特性

🤖 自动提取

  • 零人工操作:自动从Vue源文件中提取组件元数据
  • 始终保持最新:当设计系统发生变化时重新运行提取(约5分钟)
  • 元数据:道具、发射、枚举、验证器、插槽-所有这些都是自动提取的

📊 综合数据

  • 62组件:全面覆盖内幕设计系统
  • 1087道具:使用类型、默认值和验证器
  • 30枚举:款式、类型、尺寸自动检测
  • 实际使用情况分析:从分析fe代码库中检测到的常见错误
  • 手动丰富:关键组件有详细的示例和注释

🔧 MCP工具

  • list-components -列出所有组件
  • get-component - 🆕 Markdown格式 -使用以下命令以人类可读的格式获取组件信息 77%的代币节省
  • search-components -按名称/描述搜索
  • generate-code -生成Vue组件代码
  • map-figma-component -将Figma映射到DS组件

⚡ Markdown格式(新增!)

这 get-component 工具现在返回组件文档 Markdown格式 为了节省大量代币:

优点:

  • 💰 77%的代币节省 与JSON格式(690KB)相比→ 161KB)
  • 📖 人类可读 结构清晰的格式
  • 🎯 已保存约135335个代币 所有组件
  • ⚡ 更快的响应 有效载荷较小

最佳表现者:

  • InButtonV2:88%的节省(55KB→ 6.6KB)
  • InDropdownMenu:节省87%(36KB→ 4.8KB)
  • InTooltipV2:86%的节省(31KB→ 4.2KB)

格式包括:

  • 带有类型、默认值和描述的道具
  • 带有有效载荷的事件
  • 带有代码片段的示例
  • 常见错误和最佳实践
  • 相关组件

📚 MCP资源

  • ds://components -所有组件列表
  • ds://registry -注册表元数据
  • ds://component/{name} -单个组件
  • ds://categories -组件类别

📖 文档

→ See docs/ 获取完整的文档索引


🚀 快速开始

先决条件

  • Node.js>=20.0.0
  • npm>=10.0.0

安装

# Clone repository
git clone <repo-url>
cd design-system-mcp

# Install dependencies
npm install

# Extract component metadata (first time)
npm run extract:all

# Build
npm run build

# Test
npm run test:production

需要提取脚本的帮助吗? 看 工作流.md 了解详细的使用指南。


⚙️ 配置

克劳德桌面版

添加到 ~/Library/Application Support/Claude/claude_desktop_config.json:

{
  "mcpServers": {
    "design-system": {
      "command": "node",
      "args": ["/Users/YOUR_USERNAME/path/to/design-system-mcp/dist/index.js"]
    }
  }
}

环境变量

# Design System source path (for extraction)
export DS_PATH="/Users/YOUR_USERNAME/path/to/insider-design-system"

# Analytics FE path (for usage analysis)
export ANALYTICS_FE_PATH="/Users/YOUR_USERNAME/path/to/analytics-fe"

🔄 数据提取管道

建筑

Design System Source Code (Vue files)
         ↓ AUTOMATED EXTRACTION
data/combined.json (209 KB)
         ↓ BUILD & COPY
dist/data/combined.json
         ↓ RUNTIME LOADING
MCP Server (in-memory, enum-resolved)
         ↓ FAST QUERIES
Claude Code

提取命令

# Extract all data (run when Design System changes)
npm run extract:all

# Or run individually:
npm run extract:components  # Parse Vue components → data/components.json
npm run extract:storybook   # Extract examples → data/storybook.json
npm run extract:usage       # Analyze usage → data/usage.json
npm run extract:argtypes    # Sync possibleValues from storybook argTypes
npm run extract:merge       # Merge all → data/combined.json

# Rebuild MCP server
npm run build

提取了什么?

1.组件元数据 (extract-components.ts)

  • Props(类型、默认值、必需值、验证器)
  • 发射(来自 $emit() 呼叫)
  • 枚举(const STYLES={…})
  • 插槽
  • 版本(V1/V2)

2.故事书示例 (extract-storybook.ts)

  • 故事中的代码示例
  • 描述
  • 分类

3.实际使用情况分析 (extract-usage.ts)

  • 来自分析功能的使用计数
  • 常见错误(自动检测)
  • 最常用的道具
  • 真实代码模式

4.手动丰富 (叠加)

  • 关键道具的详细值格式
  • 常见错误文档
  • 帮助函数
  • 迁移指南

📖 使用示例

🎯 完整演练:从原始请求到实施

脚本: 您需要一个打开下拉菜单的按钮。

第一步:优化您的原始请求

# In Claude Code (works in ANY project with Design System MCP!)
User: "Use optimize-prompt to transform this request: I need a button that opens a dropdown menu"

克劳德打电话来 mcp__design-system__optimize-prompt 并返回:

# Original Prompt
I need a button that opens a dropdown menu

# Analysis
- Language: English
- Intent: implement
- Components: InButtonV2, InDropdownMenu
- Complexity: medium
- Estimated Token Savings: ~24,000 tokens

# Optimized Prompt
I need to implement InButtonV2 and InDropdownMenu components with proper integration.

Please use the Design System MCP to:

1. Get documentation for both components
   - Tool: mcp__design-system__get-component
   - Components: InButtonV2, InDropdownMenu
   - Note: Markdown format saves ~87% tokens on average

2. Generate implementation code
   - Tool: mcp__design-system__generate-code
   - Include integration between components

Requirements:
- Primary styling for main actions
- Dropdown opens below trigger element
- Proper state management between components

Show me:
✅ Which components you're using
✅ Token savings from Markdown format for each component
✅ The generated Vue code
✅ Integration example showing how components work together

步骤2:使用优化提示

User: "Now use the optimized prompt above to implement the button + dropdown"

克劳德执行:

  1. 获取InButtonV2文档 (Markdown格式)

    • 原始文件:55KB JSON→ 6.6KB Markdown
    • 代币节省:88%(约12198个代币)
  2. 获取InDropdownMenu文档 (Markdown格式)

    • 原始文件:36KB JSON→ 4.8KB Markdown
    • 代币节省:87%(约8214个代币)
  3. 生成集成的Vue代码:

<template>
  <div class="button-dropdown-container">
    <InButtonV2
      id="actions-button"
      :type="TYPES.PRIMARY"
      :styling="STYLES.SOLID"
      label-text="Actions"
      @click="toggleDropdown"
    />

    <InDropdownMenu
      v-if="isOpen"
      :items="menuItems"
      @item-click="handleItemClick"
      @close="isOpen = false"
    />
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue';
import { InButtonV2, InDropdownMenu } from '@useinsider/design-system-vue';
import '@useinsider/design-system-vue/dist/design-system-vue.css';

const isOpen = ref(false);

const menuItems = [
  { id: 'export', label: 'Export Data', icon: 'download' },
  { id: 'share', label: 'Share Report', icon: 'share' },
  { id: 'settings', label: 'Settings', icon: 'settings' },
];

const toggleDropdown = () => {
  isOpen.value = !isOpen.value;
};

const handleItemClick = (item: any) => {
  console.log('Clicked:', item.id);
  isOpen.value = false;
};
</script>

总结

代币节省总额: 约20412个代币(减少87.5%) 节省的时间: Claude以正确的顺序使用正确的工具 质量: 适当的集成,包括最佳实践


💡 专业提示

始终首先优化原始请求:

❌ 不要这样做:

User: "I need a button"

克劳德搜索代码文件,浪费时间。

✅ 执行以下操作:

User: "Use optimize-prompt: I need a button"

Claude获得优化提示→ 使用MCP工具→ 快速准确的实施。

适用于所有地方:

  • ✅ 分析有限元项目
  • ✅ 营销网络项目
  • ✅ 客户门户项目
  • ✅ 配置了设计系统MCP的任何项目

🎯 快速参考:优化提示

// Single component
mcp__design-system__optimize-prompt("I need a button")

// Multiple components
mcp__design-system__optimize-prompt("button and dropdown menu")

// Migration task
mcp__design-system__optimize-prompt("migrate InDatePicker from V1 to V2")

// Debug issue
mcp__design-system__optimize-prompt("InSelect not working, showing errors")

// Learning
mcp__design-system__optimize-prompt("how to use InTooltipV2?")

获取组件详细信息

// Claude automatically calls:
mcp__design-system__get-component("InButtonV2")

// Returns in Markdown format (88% token savings):
# InButtonV2

**Version:** v2

## Props

### `styling`
**Type:** `String` | **Default:** `"STYLES.SOLID"`

**Allowed values:** `solid`, `ghost`, `text`

### `type`
**Type:** `String` | **Default:** `"TYPES.PRIMARY"`

...

## Examples

### Basic Primary Button
```vue
<InButtonV2
  id="primary-btn"
  styling="solid"
  type="primary"
  label-text="Click Me"
/>

代币节省:55KB→ 6.6KB(减少88%)


### Search Components

```typescript
mcp__design-system__search-components("button")
// Returns: InButton, InButtonV2, InCreateButton...

生成代码

mcp__design-system__generate-code({
  component: "InButtonV2",
  props: { styling: "solid", type: "primary" }
})

// Returns:
// <InButtonV2
//   id="button-1"
//   styling="solid"
//   type="primary"
//   label-text="Button"
// />

🧪 测试

# Test combined dataset
npm run test:data

# Test production build
npm run test:production

# Run unit tests
npm test

# Coverage
npm run test:coverage

📂 项目结构

design-system-mcp/
├── 📄 README.md                      # This file
├── 📄 COMPLETION_REPORT.md           # Full project report
├── 📄 HOW_IT_WORKS.md                # Architecture deep dive
├── 📄 CLEANUP_SUMMARY.md             # Cleanup history
├── 📦 package.json                   # Dependencies & scripts
├── 🔧 tsup.config.ts                 # Build configuration
│
├── 📂 src/                           # Source code
│   ├── index.ts                      # Entry point
│   ├── server.ts                     # MCP server
│   ├── tools/index.ts                # MCP tools
│   ├── resources/index.ts            # MCP resources
│   ├── types/index.ts                # TypeScript types
│   └── registry/
│       ├── combined-loader.ts        # ⭐ Dataset loader (NEW)
│       ├── enrichments/              # Manual enrichments
│       │   ├── InButtonV2.json
│       │   ├── InDatePickerV2.json
│       │   └── InSelect.json
│       └── migrations/               # V1→V2 guides
│           └── InDatePicker-to-V2.json
│
├── 📂 scripts/                       # Extraction scripts
│   ├── extract-components.ts         # Vue component parser
│   ├── extract-storybook.ts          # Example extractor
│   ├── extract-usage.ts              # Usage analyzer
│   └── merge-datasets.ts             # Dataset combiner
│
├── 📂 data/                          # Extracted data
│   ├── components.json               # 148 KB - Parsed components
│   ├── storybook.json                # 1.6 KB - Examples
│   ├── usage.json                    # Real usage data
│   └── combined.json                 # 209 KB - ⭐ FINAL DATASET
│
└── 📂 dist/                          # Build output
    ├── index.js                      # Bundled MCP server
    └── data/combined.json            # Runtime dataset

🔄 更新工作流

当设计系统发生变化时

# 1. Pull latest Design System
cd /path/to/insider-design-system
git pull

# 2. Re-extract metadata
cd /path/to/design-system-mcp
npm run extract:all          # ~5 minutes

# 3. Rebuild MCP server
npm run build

# 4. Test
npm run test:production

# 5. Commit (optional)
git add data/combined.json
git commit -m "chore: update component metadata"
git push

# Claude Desktop will auto-reload! ✅

之前:2-3小时的体力劳动 现在:5分钟自动完成! 🚀

了解更多场景和详细的工作流程指南,请参阅 工作流.md.


💡 关键创新

1.自动提取

不再需要手动编辑JSON。解析器直接读取Vue文件。

2.枚举解析

// Source: const STYLES = { SOLID: 'solid', GHOST: 'ghost' }
// Extracted: enums: [{ name: "STYLES", values: {...} }]
// Runtime: validValues: ["solid", "ghost", "text"] ✅

3.真实使用智能

扫描分析功能以查找常见错误:

{
  "mistake": "Using number for iconSize",
  "occurrences": 12,
  "fix": "Use string: icon-size=\"24\"",
  "severity": "critical"
}

4.分层富集

Auto-extracted (100% coverage)
    +
Manual enrichments (critical details)
    =
Best of both worlds! ✅

📊 数据质量

Components: 62 (100% coverage)
Props: 1,087 (with types, defaults, validators)
Enums: 30 (automatically detected)
Emits: 170
Manual Enrichments: 3 (InButtonV2, InDatePickerV2, InSelect)
Migration Guides: 1
File Size: 209 KB (combined.json)

🎯 益处

对于开发者

  • ✅ 准确的组件信息
  • ✅ 枚举值始终正确
  • ✅ 记录常见错误
  • ✅ 实际使用示例
  • ✅ 快速代码生成

设计系统团队

  • ✅ 零人工维护
  • ✅ 始终与源同步
  • ✅ 轻松更新(5分钟)
  • ✅ 自动错误检测

预期影响

  • 代码生成精度:30%→ 85%
  • 首次尝试正确率:20%→ 80%
  • 入职时间: -70%
  • 设计系统问题: -50%

🛠️ 发展

脚本

# Build
npm run build              # Build for production
npm run dev                # Watch mode

# Extraction
npm run extract:components # Extract component metadata
npm run extract:storybook  # Extract examples
npm run extract:usage      # Analyze real usage
npm run extract:merge      # Merge all datasets
npm run extract:all        # Run all extractions

# Testing
npm test                   # Run unit tests
npm run test:coverage      # Coverage report
npm run test:data          # Test dataset validity
npm run test:production    # Test production build

# Code Quality
npm run lint               # Run ESLint
npm run lint:fix           # Fix linting issues
npm run typecheck          # TypeScript check

添加新的丰富功能

选项1:使用富集剂 (推荐)

# Let AI generate enrichment for you
# In Claude Code: "Use enrichment-maker agent to create enrichment for InTooltipV2"

# Agent analyzes component and creates:
# - valueFormat for complex props
# - commonMistakes documentation
# - Real-world examples
# - Helper functions

# Then merge and build:
npm run extract:merge
npm run build

选项2:手动创建

# 1. Create enrichment file
touch src/registry/enrichments/InTooltipV2.json

# 2. Add detailed metadata
# (See existing enrichments: InButtonV2, InDatePickerV2, InSelect)

# 3. Rebuild
npm run extract:merge
npm run build

📚 文档

  • README.md (此文件)-快速入门和概述
  • 工作流.md - ⭐ 何时以及如何运行提取脚本
  • 代理商_用法.md - 🤖 如何使用代理和斜线命令
  • HOW_IT_WORKS.md -建筑深度挖掘
  • 完成_报告.md -完整项目报告
  • 清除_摘要.md -清理历史记录
  • CLAUDE.md -克劳德代码说明

🤝 贡献

  1. 复刻仓库
  2. 创建要素分支: git checkout -b feature/amazing
  3. 进行更改
  4. 运行测试: npm test
  5. 承诺: git commit -m "feat: add amazing feature"
  6. 推: git push origin feature/amazing
  7. 提交拉取请求

📄 许可证

未经许可-仅供内部使用(内部人士)


💬 支持

关于问题和议题:

  • 创建GitHub问题
  • 联系设计系统团队
  • Slack:#设计系统

🎉 成功案例

“组件元数据现在总是准确的。Claude第一次尝试就生成了正确的代码!” --使用MCP的开发人员

“我们更新了设计系统中的15个组件。重新提取需要5分钟!” --设计系统团队


内置于 ❤️ 由Insider设计系统团队

由...驱动:克劳德密码(十四行诗4.5)