Component Library MCP Server

Component Library MCP Server

Provides AI assistants with access to private React component library documentation, props, and code examples through type-safe TypeScript integration.

Category
访问服务器

README

Component Library MCP Server (TypeScript)

A type-safe MCP (Model Context Protocol) server built with TypeScript that provides AI assistants with access to your private React component library documentation and examples.

Features

  • 🎯 Type-safe implementation using TypeScript
  • 🛠️ Modern MCP SDK with McpServer and .tool() methods
  • 📦 Three core tools:
    • list_components - Lists all components with optional category filtering
    • get_component - Retrieves detailed documentation, props, and usage
    • get_example - Provides code examples for components
  • 🔍 Smart parsing:
    • Markdown files with frontmatter metadata
    • TypeScript prop extraction from source files
    • Inline code block extraction from docs
  • Performance optimized with component caching

Quick Start

1. Install

# Clone or download the server
cd component-library-mcp-ts

# Install dependencies
npm install

# Build TypeScript
npm run build

2. Configure

Set environment variables for your paths:

export COMPONENTS_PATH="/path/to/your/component-library/src/components"
export DOCS_PATH="/path/to/your/documentation-site/content"
export EXAMPLES_PATH="/path/to/your/documentation-site/examples"

Or create a .env file:

COMPONENTS_PATH=/path/to/your/components
DOCS_PATH=/path/to/your/docs
EXAMPLES_PATH=/path/to/your/examples

3. Test

Run the test suite to verify everything works:

npm test

4. Configure Claude Desktop

Add to your Claude Desktop config (~/.config/claude/claude_desktop_config.json):

{
  "mcpServers": {
    "component-library": {
      "command": "node",
      "args": ["/absolute/path/to/component-library-mcp-ts/dist/index.js"],
      "env": {
        "COMPONENTS_PATH": "/path/to/your/library/src",
        "DOCS_PATH": "/path/to/your/docs",
        "EXAMPLES_PATH": "/path/to/your/examples"
      }
    }
  }
}

For development mode (with hot reload):

{
  "mcpServers": {
    "component-library": {
      "command": "npx",
      "args": ["tsx", "/absolute/path/to/component-library-mcp-ts/src/index.ts"],
      "env": {
        "COMPONENTS_PATH": "/path/to/your/library/src",
        "DOCS_PATH": "/path/to/your/docs",
        "EXAMPLES_PATH": "/path/to/your/examples"
      }
    }
  }
}

Documentation Structure

Organize your documentation like this:

docs/
├── components/
│   ├── Panel.md        # Component documentation with frontmatter
│   ├── Button.md
│   ├── Form.md
│   └── TextBox.md
└── examples/
    ├── Panel.tsx       # Component examples (optional)
    ├── Button.tsx
    └── Form.tsx

Component Documentation Format

Use Markdown with YAML frontmatter:

---
name: Panel
category: layout
description: A flexible container component for grouping content
importPath: '@your-library/Panel'
status: stable
version: 2.1.0
dependencies: ['Button', 'Icon']
accessibility: WCAG 2.1 AA compliant
---

# Panel Component

The Panel component provides consistent spacing and styling for grouped content.

## Props

| Prop | Type | Required | Default | Description |
|------|------|----------|---------|-------------|
| title | string | No | - | Optional header title |
| variant | 'default' \| 'bordered' \| 'shadow' | No | 'default' | Visual style |

## Usage

\`\`\`tsx
import { Panel } from '@your-library/Panel';

function Example() {
  return (
    <Panel title="Settings" variant="shadow">
      <p>Content goes here</p>
    </Panel>
  );
}
\`\`\`

TypeScript Support

The server includes full TypeScript support with:

Type Definitions

interface ComponentInfo {
  name: string;
  category?: string;
  description?: string;
  importPath?: string;
  status?: 'stable' | 'beta' | 'deprecated' | 'experimental';
  version?: string;
  dependencies?: string[];
  props?: ComponentProps;
  documentation?: string;
  accessibility?: string;
}

interface ComponentProps {
  [key: string]: {
    type: string;
    required: boolean;
    description?: string;
    defaultValue?: any;
  }
}

Prop Extraction

The server automatically extracts props from TypeScript interfaces:

// Your component file
interface PanelProps {
  /** Optional title for the panel header */
  title?: string;
  /** Visual style variant */
  variant?: 'default' | 'bordered' | 'shadow';
  /** Content to display */
  children: ReactNode;
}

Usage in Claude

Once configured, use these commands in Claude:

Basic Commands

"Use the component-library MCP to list all components"

"Get details about the Panel component using component-library"

"Show me examples of using the Form component"

"List all components in the 'forms' category"

Building Applications

"Use component-library MCP to gather information about components needed for a user dashboard"

"Help me build a settings page using our component library - get the relevant components"

Development

Scripts

# Build TypeScript
npm run build

# Run in development mode (with tsx)
npm run dev

# Run tests
npm test

# Start production server
npm start

Project Structure

component-library-mcp-ts/
├── src/
│   ├── index.ts        # Main server implementation
│   ├── types.ts        # TypeScript type definitions
│   └── test.ts         # Test suite
├── dist/               # Compiled JavaScript (after build)
├── example-docs/       # Example documentation
│   ├── components/     # Component docs with frontmatter
│   └── examples/       # Component examples
├── tsconfig.json       # TypeScript configuration
├── package.json
└── README.md

Extending the Server

Add new tools by extending the setupTools() method:

// In src/index.ts
this.server.tool(
  'search_components',
  'Search components by keyword',
  {
    query: z.string().describe('Search query'),
    limit: z.number().optional().describe('Maximum results')
  },
  async (args) => {
    // Implementation here
    return {
      content: [{
        type: 'text',
        text: JSON.stringify(results)
      }]
    };
  }
);

Advanced Features

Custom Metadata

Extend component metadata in frontmatter:

---
name: DataGrid
category: display
description: High-performance data grid with virtual scrolling
importPath: '@your-library/DataGrid'
status: beta
version: 3.0.0-beta.2
minReactVersion: 18.0.0
dependencies: 
  - VirtualScroller
  - TableHeader
  - TableCell
performance:
  maxRows: 100000
  virtualScrolling: true
accessibility: 
  wcag: 2.1 AA
  ariaSupport: full
  keyboardNavigation: true
---

Environment-Specific Configs

Use different paths for different environments:

{
  "mcpServers": {
    "component-library-dev": {
      "command": "npx",
      "args": ["tsx", "/path/to/src/index.ts"],
      "env": {
        "COMPONENTS_PATH": "/path/to/dev/components",
        "NODE_ENV": "development"
      }
    },
    "component-library-prod": {
      "command": "node",
      "args": ["/path/to/dist/index.js"],
      "env": {
        "COMPONENTS_PATH": "/path/to/prod/components",
        "NODE_ENV": "production"
      }
    }
  }
}

Troubleshooting

TypeScript Build Issues

# Clear build and rebuild
rm -rf dist
npm run build

Component Not Found

  • Ensure file naming matches component name
  • Check that paths are correctly configured
  • Verify frontmatter YAML is valid

Props Not Detected

  • Props interface must be named *Props (e.g., PanelProps)
  • Ensure component files are accessible via COMPONENTS_PATH
  • Check TypeScript syntax is valid

Server Connection Issues

  • Use absolute paths in Claude Desktop config
  • Ensure Node.js is in PATH
  • Check server has read permissions for all paths
  • Try development mode with tsx for debugging

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 模型以安全和受控的方式获取实时的网络信息。

官方
精选