Skip to main content
Glama
denizzeybek-fe

Insider Design System MCP

README.md
# ๐ŸŽจ Insider Design System MCP

**Automated Model Context Protocol server** for the Insider Design System. Enables AI assistants like Claude to discover, understand, and generate code for 60+ Design System components with **automated extraction** from source code.

**Version**: 2.0 (Automated Extraction)
**Status**: โœ… Production Ready
**Last Updated**: 2025-11-21

---

## โœจ Features

### ๐Ÿค– Automated Extraction
- **Zero Manual Work**: Automatically extracts component metadata from Vue source files
- **Always Up-to-Date**: Re-run extraction when Design System changes (~5 minutes)
- **Rich Metadata**: Props, emits, enums, validators, slots - all extracted automatically

### ๐Ÿ“Š Comprehensive Data
- **62 Components**: Full coverage of Insider Design System
- **1,087 Props**: With types, defaults, and validators
- **30 Enums**: STYLES, TYPES, SIZES automatically detected
- **Real Usage Analysis**: Common mistakes detected from analytics-fe codebase
- **Manual Enrichments**: Critical components have detailed examples and notes

### ๐Ÿ”ง MCP Tools
- `list-components` - List all components
- `get-component` - **๐Ÿ†• Markdown format** - Get component info in human-readable format with **77% token savings**
- `search-components` - Search by name/description
- `generate-code` - Generate Vue component code
- `map-figma-component` - Map Figma to DS components

### โšก Markdown Format (NEW!)
The `get-component` tool now returns component documentation in **Markdown format** for massive token savings:

**Benefits:**
- ๐Ÿ’ฐ **77% token savings** compared to JSON format (690KB โ†’ 161KB)
- ๐Ÿ“– **Human-readable** format with clear structure
- ๐ŸŽฏ **~135,335 tokens saved** across all components
- โšก **Faster responses** with smaller payloads

**Top Performers:**
- InButtonV2: 88% savings (55KB โ†’ 6.6KB)
- InDropdownMenu: 87% savings (36KB โ†’ 4.8KB)
- InTooltipV2: 86% savings (31KB โ†’ 4.2KB)

**Format includes:**
- Props with types, defaults, descriptions
- Events with payloads
- Examples with code snippets
- Common mistakes and best practices
- Related components

### ๐Ÿ“š MCP Resources
- `ds://components` - All components list
- `ds://registry` - Registry metadata
- `ds://component/{name}` - Individual component
- `ds://categories` - Component categories

---

## ๐Ÿ“– Documentation

**โ†’ See [docs/](docs/) for complete documentation index**

- **[Architecture](docs/architecture/)** - System design and data flow
  - [How It Works](docs/architecture/how-it-works.md) - Complete architecture overview
  - [Smart Filter Layer](docs/architecture/smart-filter-layer.md) - Token optimization system
  - [Figma Integration](docs/architecture/figma-integration.md) - Figma to Vue workflow

- **[Guides](docs/guides/)** - How-to guides and workflows
  - [Developer Workflow](docs/guides/workflow.md) - Day-to-day development
  - [Enrichment Strategy](docs/guides/enrichment-strategy.md) - Creating enrichments
  - [Enrichment Template](docs/guides/enrichment-template.md) - Enrichment templates

- **[Reference](docs/reference/)** - API and tool references
  - [Agent Usage](docs/reference/agent-usage.md) - Specialized agents guide

---

## ๐Ÿš€ Quick Start

### Prerequisites

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

### Installation

```bash
# 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
```

**Need help with extraction scripts?** See [WORKFLOW.md](WORKFLOW.md) for detailed usage guide.

---

## โš™๏ธ Configuration

### Claude Desktop

Add to `~/Library/Application Support/Claude/claude_desktop_config.json`:

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

### Environment Variables

```bash
# 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"
```

---

## ๐Ÿ”„ Data Extraction Pipeline

### Architecture

```
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
```

### Extraction Commands

```bash
# 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
```

### What Gets Extracted?

**1. Component Metadata** (`extract-components.ts`)
- Props (type, default, required, validator)
- Emits (from `$emit()` calls)
- Enums (const STYLES = {...})
- Slots
- Version (V1/V2)

**2. Storybook Examples** (`extract-storybook.ts`)
- Code examples from stories
- Descriptions
- Categories

**3. Real Usage Analysis** (`extract-usage.ts`)
- Usage counts from analytics-fe
- Common mistakes (auto-detected)
- Most used props
- Real code patterns

**4. Manual Enrichments** (overlay)
- Detailed valueFormat for critical props
- Common mistakes documentation
- Helper functions
- Migration guides

---

## ๐Ÿ“– Usage Examples

### ๐ŸŽฏ Complete Walkthrough: From Raw Request to Implementation

**Scenario:** You need a button that opens a dropdown menu.

#### Step 1: Optimize Your Raw Request

```bash
# 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"
```

Claude calls `mcp__design-system__optimize-prompt` and returns:

```markdown
# 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
```

#### Step 2: Use the Optimized Prompt

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

Claude executes:

1. **Gets InButtonV2 docs** (Markdown format)
   - Original: 55KB JSON โ†’ 6.6KB Markdown
   - Token savings: 88% (~12,198 tokens)

2. **Gets InDropdownMenu docs** (Markdown format)
   - Original: 36KB JSON โ†’ 4.8KB Markdown
   - Token savings: 87% (~8,214 tokens)

3. **Generates integrated Vue code:**

```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>
```

#### Summary

**Total token savings:** ~20,412 tokens (87.5% reduction)
**Time saved:** Claude uses the right tools in the right order
**Quality:** Proper integration, best practices included

---

### ๐Ÿ’ก Pro Tips

**Always optimize raw requests first:**

โŒ **Don't do this:**
```
User: "I need a button"
```
Claude searches through code files, wastes time.

โœ… **Do this:**
```
User: "Use optimize-prompt: I need a button"
```
Claude gets optimized prompt โ†’ Uses MCP tools โ†’ Fast & accurate implementation.

**Works everywhere:**
- โœ… analytics-fe project
- โœ… marketing-web project
- โœ… customer-portal project
- โœ… ANY project with Design System MCP configured

---

### ๐ŸŽฏ Quick Reference: optimize-prompt

```typescript
// 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?")
```

### Get Component Details

```typescript
// 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"
/>
```

Token savings: 55KB โ†’ 6.6KB (88% reduction)
```

### Search Components

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

### Generate Code

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

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

---

## ๐Ÿงช Testing

```bash
# Test combined dataset
npm run test:data

# Test production build
npm run test:production

# Run unit tests
npm test

# Coverage
npm run test:coverage
```

---

## ๐Ÿ“‚ Project Structure

```
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
```

---

## ๐Ÿ”„ Update Workflow

### When Design System Changes

```bash
# 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! โœ…
```

**Before**: 2-3 hours manual work
**Now**: 5 minutes automated! ๐Ÿš€

**For more scenarios and detailed workflow guide**, see [WORKFLOW.md](WORKFLOW.md).

---

## ๐Ÿ’ก Key Innovations

### 1. Automated Extraction
No more manual JSON editing. Parser reads Vue files directly.

### 2. Enum Resolution
```javascript
// Source: const STYLES = { SOLID: 'solid', GHOST: 'ghost' }
// Extracted: enums: [{ name: "STYLES", values: {...} }]
// Runtime: validValues: ["solid", "ghost", "text"] โœ…
```

### 3. Real Usage Intelligence
Scans analytics-fe for common mistakes:
```json
{
  "mistake": "Using number for iconSize",
  "occurrences": 12,
  "fix": "Use string: icon-size=\"24\"",
  "severity": "critical"
}
```

### 4. Layered Enrichment
```
Auto-extracted (100% coverage)
    +
Manual enrichments (critical details)
    =
Best of both worlds! โœ…
```

---

## ๐Ÿ“Š Data Quality

```
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)
```

---

## ๐ŸŽฏ Benefits

### For Developers
- โœ… Accurate component information
- โœ… Enum values always correct
- โœ… Common mistakes documented
- โœ… Real usage examples
- โœ… Fast code generation

### For Design System Team
- โœ… Zero manual maintenance
- โœ… Always synchronized with source
- โœ… Easy updates (5 minutes)
- โœ… Automatic mistake detection

### Expected Impact
- Code Generation Accuracy: 30% โ†’ **85%**
- First-Try Correctness: 20% โ†’ **80%**
- Onboarding Time: **-70%**
- Design System Questions: **-50%**

---

## ๐Ÿ› ๏ธ Development

### Scripts

```bash
# 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
```

### Adding New Enrichments

**Option 1: Use enrichment-maker agent** (Recommended)
```bash
# 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
```

**Option 2: Manual creation**
```bash
# 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
```

---

## ๐Ÿ“š Documentation

- **README.md** (this file) - Quick start & overview
- **WORKFLOW.md** - โญ **When and how to run extraction scripts**
- **AGENT_USAGE.md** - ๐Ÿค– **How to use agents and slash commands**
- **HOW_IT_WORKS.md** - Architecture deep dive
- **COMPLETION_REPORT.md** - Full project report
- **CLEANUP_SUMMARY.md** - Cleanup history
- **CLAUDE.md** - Instructions for Claude Code

---

## ๐Ÿค Contributing

1. Fork the repository
2. Create feature branch: `git checkout -b feature/amazing`
3. Make changes
4. Run tests: `npm test`
5. Commit: `git commit -m "feat: add amazing feature"`
6. Push: `git push origin feature/amazing`
7. Submit Pull Request

---

## ๐Ÿ“„ License

UNLICENSED - Internal use only (Insider)

---

## ๐Ÿ’ฌ Support

For questions and issues:
- Create GitHub issue
- Contact Design System team
- Slack: #design-system

---

## ๐ŸŽ‰ Success Stories

> "Component metadata is now always accurate. Claude generates correct code on first try!"
> โ€” Developer using MCP

> "We updated 15 components in Design System. Re-extraction took 5 minutes!"
> โ€” Design System Team

---

**Built with** โค๏ธ **by the Insider Design System Team**

**Powered by**: Claude Code (Sonnet 4.5)

TDQS

B3.4/5.0

Scored across 14 tools

Disambiguation3/5

Most tools have clear verb+object distinctions, but several overlap: get-component versus get-props/get-events/get-examples, get-ds-for-figma versus map-figma-component, and generate-code versus generate-figma-component. Descriptions clarify intent somewhat, but an agent could easily select the wrong tool for a similar task.

Naming Consistency4/5

Tool names uniformly follow lowercase snake_case with a verb-object structure (list/get/search/generate/map/validate/convert). Minor inconsistencies like get-ds-for-figma and the pair generate-figma-component versus convert-figma-to-vue slightly break the pattern but remain predictable.

Tool Count4/5

14 tools is a reasonable count for a design-system documentation and Figma conversion server. However, some tools feel redundant or consolidatable, such as get-ds-for-figma and map-figma-component, making the set slightly heavier than necessary.

Completeness4/5

The server covers component discovery, detailed documentation, props/events/examples, code generation, and Figma mapping/validation/conversion well. Minor gaps like design tokens, theme variables, or component dependency relationships are missing but not critical for the core workflow.

Maintenance

ActivityInactive
ResponsivenessNo issues