MCP Design System Extractor

MCP Design System Extractor

Server that enables AI assistants to interact with Storybook design systems. Extract component HTML, analyze styles, and help with design system adoption and refactoring.

Category
访问服务器

Tools

list_components

List all UI components available in your design system/Storybook. Returns components like modals, dialogs, buttons, forms, cards, etc. with their names, categories, and stories. Use this to explore what components are available for building UI features. Use category="all" or omit category parameter to list all components. Supports pagination to handle large component libraries.

get_component_html

Extract HTML from a specific component story in Storybook. Requires a story ID (format: "component-name--story-name", e.g., "button--primary", "forms-input--default"). Use list_components or get_component_variants first to find valid story IDs.

get_component_variants

Get all story variants/states for a specific component. Returns all stories (variants) for a component with their IDs, names, and parameters. Component name should match exactly as shown in list_components (case-sensitive).

search_components

Search design system components by name, title, or category. Find UI components like modals, dialogs, popups, overlays, buttons, forms, cards, etc. Name is the component name only (e.g., "Modal", "Dialog"), title is the full story path (e.g., "Components/Overlays/Modal"), category is the grouping (e.g., "Components/Overlays"). Use "*" as query to list all components. Supports pagination for large result sets.

get_component_dependencies

Analyze rendered HTML to find which other components a given component internally uses by detecting React components, web components, and CSS class patterns

get_theme_info

Get design system theme information (colors, spacing, typography, breakpoints)

get_component_by_purpose

Find design system components by their purpose or use case. Available purposes: "form inputs" (input fields, selects, checkboxes), "navigation" (menus, breadcrumbs, tabs), "feedback" (alerts, toasts, modals, dialogs, popups), "data display" (tables, cards, lists), "layout" (grids, containers, dividers), "buttons" (all button types), "progress" (loaders, spinners), "media" (images, videos, carousels). Use this when looking for components to build specific UI features. Supports pagination for large result sets.

get_external_css

Extract design tokens from CSS files. DEFAULT BEHAVIOR: Returns ONLY tokens and file statistics (small response ~1-3K tokens). Does NOT return CSS content by default to avoid token limits. For full CSS content, explicitly set includeFullCSS=true and maxContentSize. Perfect for analyzing design system tokens without hitting response size limits.

README

MCP Design System Extractor

A Model Context Protocol (MCP) server that extracts component information from Storybook design systems. This server connects to a running Storybook instance and extracts HTML, styles, and component metadata directly from the Storybook iframe.

Features

  • 🔍 List Components: Get all available components from your Storybook
  • 📄 Extract HTML: Get the rendered HTML of any component variant with dynamic JavaScript support
  • 🔎 Search Components: Find components by name, title, or category
  • 🎛️ Component Props: Get component props/API documentation including types and defaults
  • 🔗 Component Dependencies: Analyze which components are used within other components
  • 📐 Layout Components: Get all layout components (Grid, Container, Stack, etc.) with examples
  • 🎨 Theme Information: Extract design system theme (colors, spacing, typography, breakpoints)
  • 🎯 Search by Purpose: Find components by their purpose (form inputs, navigation, feedback)
  • 🧩 Composition Examples: Get examples of how components are combined together
  • 📝 External CSS Analysis: Fetch and analyze CSS files to extract design tokens and variables

Installation

npm install
npm run build

Quick Setup

Use the interactive setup script to configure Claude Desktop:

npm run setup

This will:

  • Build the project if needed
  • Let you choose your Storybook URL (local or custom)
  • Test the connection
  • Configure Claude Desktop automatically

Manual Configuration

Alternatively, set the Storybook URL via environment variable:

export STORYBOOK_URL=http://localhost:6006

Default: http://localhost:6006

Usage

With Claude Desktop

Recommended: Use the setup script:

npm run setup

Manual: Add to your Claude Desktop configuration:

{
  "mcpServers": {
    "design-system-extractor": {
      "command": "node",
      "args": ["/path/to/mcp-design-system-extractor/dist/index.js"],
      "env": {
        "STORYBOOK_URL": "http://localhost:6006"
      }
    }
  }
}

With Claude Code

For development with Claude Code, add to your .claude_code_config.json in the project root:

{
  "mcpServers": {
    "design-system-extractor": {
      "command": "npm",
      "args": ["run", "dev"],
      "env": {
        "STORYBOOK_URL": "http://localhost:6006"
      }
    }
  }
}

Or for production build:

{
  "mcpServers": {
    "design-system-extractor": {
      "command": "node",
      "args": ["dist/index.js"],
      "env": {
        "STORYBOOK_URL": "http://localhost:6006"
      }
    }
  }
}

Then restart Claude Code to load the MCP server. You can verify it's working by using any of the design system tools in your Claude Code session.

Development

# Start in development mode
npm run dev

# Run with MCP Inspector
npm run inspector:dev

Available Tools

Core Tools

  1. list_components

    • Lists all available components from the Storybook instance
    • Returns components with their names, categories, and associated stories
    • Use category: "all" or omit category parameter to list all components
    • Filter by specific category path (e.g., "Components/Buttons", "Layout")
    • Supports pagination with page and pageSize parameters (default: 50 per page)
  2. get_component_html

    • Extracts HTML from a specific component story in Storybook
    • Requires story ID format: "component-name--story-name" (e.g., "button--primary")
    • Use list_components or get_component_variants first to find valid story IDs
    • Optional CSS style extraction for understanding component styling
    • Supports dynamic JavaScript-rendered content
  3. get_component_variants

    • Gets all story variants/states for a specific component
    • Returns all stories (variants) for a component with their IDs, names, and parameters
    • Component name must match exactly as shown in list_components (case-sensitive)
  4. search_components

    • Search components by name, title, or category using case-insensitive partial matching
    • Name is component name only (e.g., "Button")
    • Title is full story path (e.g., "Components/Forms/Button")
    • Category is the grouping (e.g., "Components/Forms")
    • Use query: "*" to list all components
    • Search in specific fields: "name", "title", "category", or "all" (default)
    • Supports pagination with page and pageSize parameters (default: 50 per page)

Component Analysis Tools

  1. get_component_props

    • Extracts component props/API documentation from Storybook's argTypes configuration
    • Includes prop names, types, default values, required status, and control options
    • Requires story ID format: "component-name--story-name"
  2. get_component_dependencies

    • Analyzes rendered HTML to find which other components a given component internally uses
    • Detects React components, web components, and CSS class patterns
    • Helps understand component relationships and composition
    • Requires story ID format: "component-name--story-name"

Design System Tools

  1. get_layout_components

    • Gets all layout components (Grid, Container, Stack, Box) with usage examples
    • Optional HTML examples for each layout component
    • Useful for understanding page structure and composition patterns
  2. get_theme_info

    • Gets design system theme information (colors, spacing, typography, breakpoints)
    • Extracts CSS custom properties/variables from the design system
    • Categorizes tokens by type for better organization
    • Optional parameter to include all CSS custom properties found

Discovery Tools

  1. get_component_by_purpose

    • Search for components by their purpose or function
    • Available purposes: "form inputs" (input fields, selects, checkboxes), "navigation" (menus, breadcrumbs, tabs), "feedback" (alerts, toasts, modals), "data display" (tables, cards, lists), "layout" (grids, containers, dividers), "buttons" (all button types), "progress" (loaders, spinners), "media" (images, videos, carousels)
    • Flexible pattern matching for finding components by use case
    • Supports pagination with page and pageSize parameters (default: 50 per page)
  2. get_component_composition_examples

    • Gets examples of how components are combined together in real-world patterns and layouts
    • Returns HTML examples showing the component used with other components in forms, cards, layouts, or complex UI patterns
    • Helps understand how components work together in practice
    • Optional limit parameter to control number of examples returned
  3. get_external_css ⚠️ TOKEN-OPTIMIZED

    • DEFAULT: Returns ONLY design tokens + file stats (avoids token limits)
    • Does NOT return CSS content by default (prevents 25K token limit errors)
    • Extracts & categorizes tokens: colors, spacing, typography, shadows, breakpoints
    • Use includeFullCSS: true only when you specifically need CSS content
    • Security-protected: only accepts URLs from the same domain as your Storybook
    • Perfect for design token extraction without hitting response size limits

Example Usage

// List all components (recommended first step)
await listComponents({ category: "all" });

// Search for all components using wildcard
await searchComponents({ query: "*", searchIn: "all" });

// Search for specific components
await searchComponents({ query: "button", searchIn: "name" });

// Get all variants of a specific component
await getComponentVariants({ componentName: "Button" });

// Get HTML for a specific button variant (use exact story ID from above)
await getComponentHTML({ 
  componentId: "button--primary",
  includeStyles: true 
});

// Get component props documentation
await getComponentProps({
  componentId: "button--primary"
});

// Find components by purpose
await getComponentByPurpose({
  purpose: "form inputs"
});

// Get layout components with examples
await getLayoutComponents({
  includeExamples: true
});

// Extract theme information
await getThemeInfo({
  includeAll: false
});

// Analyze component dependencies
await getComponentDependencies({
  componentId: "card--default"
});

// Get composition examples
await getComponentCompositionExamples({
  componentId: "button--primary",
  limit: 3
});

// RECOMMENDED: Extract design tokens only (small response, avoids token limits)
await getExternalCSS({
  cssUrl: "https://my-storybook.com/assets/main.css"
  // extractTokens: true (default), includeFullCSS: false (default)
});

// ONLY when you specifically need CSS content (may hit token limits)
await getExternalCSS({
  cssUrl: "./assets/tokens.css",
  includeFullCSS: true,
  maxContentSize: 10000
});

// Search with pagination
await searchComponents({
  query: "button",
  page: 1,
  pageSize: 10
});

AI Assistant Usage Tips

When using with Claude or other AI assistants:

  1. Start with discovery: Use list_components with category: "all" or search_components with query: "*" to see all available components
  2. Get story IDs: Use get_component_variants to find exact story IDs needed for other tools
  3. Use exact IDs: Story IDs must be in format "component-name--story-name" (e.g., "button--primary")
  4. Explore by purpose: Use get_component_by_purpose to find components by their function
  5. Debug issues: Tools now include debug information when no results are found

How It Works

The server connects to Storybook using these endpoints:

  • /index.json or /stories.json - Component metadata
  • /iframe.html?id=component--story - Rendered components

Key features:

  • Dynamic Content Support: Uses happy-dom to execute JavaScript and render dynamic content
  • Smart Caching: Caches responses for 5 minutes to improve performance
  • Retry Logic: Automatically retries failed requests up to 3 times
  • Timeout Protection: 10-second timeout on all network requests
  • Better Error Messages: Provides helpful suggestions when connections fail

It extracts:

  • Component HTML structure (including dynamically rendered content)
  • CSS classes and inline styles
  • Component props and API documentation
  • Component dependencies and relationships
  • Design system tokens and theme information
  • External CSS files and design tokens from Storybook assets

Troubleshooting

Common Issues

Empty results from list_components or search_components:

  • Ensure your Storybook is running and accessible at the configured URL
  • Check that STORYBOOK_URL environment variable is set correctly
  • Try accessing /index.json or /stories.json directly in your browser
  • Verify your Storybook has stories configured and published
  • Check the debug information returned in the tool response

"Found 0 components" with category filtering:

  • Use category: "all" or omit the category parameter to see all components first
  • Check available categories from the initial list_components call
  • Category names are case-sensitive and must match exactly

Wildcard search not working:

  • Use query: "*" (with quotes) to list all components in search_components
  • Ensure the query parameter is provided as a string

Component HTML extraction fails:

  • Ensure you're using the exact story ID format: "component-name--story-name"
  • Use get_component_variants first to find valid story IDs
  • Check that the story exists and is published in Storybook

Connection issues:

  • Verify Storybook is running (typically on port 6006)
  • Check CORS configuration in your Storybook
  • Ensure network connectivity to the Storybook URL
  • Try a different URL format (with/without trailing slash)

Requirements

  • Node.js 18+
  • Running Storybook instance
  • Network access to Storybook URL

Development

# Install dependencies
npm install

# Run TypeScript checks
npm run typecheck

# Run linting
npm run lint

# Build for production
npm run build

# Clean build files
npm run clean

License

MIT

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选