Carbon MCP
Enables developers and designers to work with the Carbon Design System through tools for generating components, applying codemods, validating accessibility, converting design tokens, and searching documentation.
README
carbon-mcp
Local MCP (Model Context Protocol) server for the Carbon Design System — Advanced MVP for internal demos and production use.
🚧 Status: Proposal Submitted to Carbon
This project is a proposal submitted to the Carbon Design System repository.
- Issue: #20855
- Status: Awaiting maintainer feedback
- Proposed: Add to Carbon monorepo or create official
carbon-design-system/carbon-mcprepository
The Carbon team is reviewing this proposal. Once feedback is received, the code will be adapted accordingly.
🚀 Quickstart
-
Clone repo
git clone https://github.com/SandeepBaskaran/carbon-mcp.git cd carbon-mcp -
Install dependencies
npm install # or pnpm install -
Configure environment (optional)
cp .env.example .env # Edit .env to add API keys if needed (FIGMA_TOKEN, GITHUB_TOKEN) -
Start the server
npm run devServer will start on
http://localhost:4000 -
Test it out
# List available tools curl http://localhost:4000/tools # Generate a component (dry-run) curl -X POST http://localhost:4000/tool/generateComponent \ -H "Content-Type: application/json" \ -d '{"component_name": "PrimaryCard", "dry_run": true}'
🛠️ Tools (MVP)
Developer Tools
generateComponent— Generate Carbon React component + Storybook story + tests (dry-run default)codemodReplace— Apply codemods to convert existing components to Carbon equivalents (dry-run default)validateComponent— Validate component against Carbon patterns and accessibility guidelinestokenConverter— Convert design tokens (JSON) to CSS variables, SCSS maps, and JS tokens
Documentation Tools
searchDocs— Search local Carbon docs index with semantic/keyword matching
Designer Tools
themePreview— Generate static HTML previews for Carbon theme variants (light/dark/custom)figmaSync— Scaffold for Figma token sync (requires FIGMA_TOKEN in environment)
🔒 Safety & Destructive Operations
All destructive changes (writing to disk, modifying files) require:
confirm_destructive: truedry_run: false
Recommended workflow:
- Run with
dry_run: true(default) to preview changes - Review the output/patches
- Run again with
dry_run: falseandconfirm_destructive: trueto apply
Example: Generate Component (Safe Workflow)
# Step 1: Dry-run to preview
curl -X POST http://localhost:4000/tool/generateComponent \
-H "Content-Type: application/json" \
-d '{
"component_name": "PrimaryCard",
"dry_run": true,
"explain": true
}'
# Step 2: Apply changes
curl -X POST http://localhost:4000/tool/generateComponent \
-H "Content-Type: application/json" \
-d '{
"component_name": "PrimaryCard",
"dry_run": false,
"confirm_destructive": true
}'
📚 API Reference
Endpoints
| Method | Endpoint | Description |
|---|---|---|
| GET | /health |
Health check |
| GET | /tools |
List all available tools |
| GET | /tool/:name/schema |
Get schema for specific tool |
| POST | /tool/:name |
Execute a tool |
Tool Examples
1. Generate Component
POST /tool/generateComponent
{
"component_name": "PrimaryCard",
"props": {
"compact": "boolean",
"icon": "string"
},
"target_path": "src/components/PrimaryCard",
"dry_run": true,
"explain": true
}
Response:
{
"files": [
{
"path": "src/components/PrimaryCard/PrimaryCard.tsx",
"content": "import React from 'react'..."
}
],
"changed_files": [],
"dry_run": true,
"logs": [...],
"trace_id": "genc-1234567890",
"explanation": "Generated Carbon React component..."
}
2. Codemod Replace
POST /tool/codemodReplace
{
"codemod_name": "btn-old-to-carbon",
"files_glob": "src/**/*.{tsx,jsx}",
"dry_run": true
}
Response:
{
"dry_run_result": "3 files would be modified",
"patches": [
{
"file": "src/pages/Home.tsx",
"patch": "@@ -1,6 +1,6 @@..."
}
],
"changed_files": ["src/pages/Home.tsx"],
"logs": [...],
"trace_id": "codemod-1234567890"
}
3. Search Docs
POST /tool/searchDocs
{
"query": "Carbon Button aria roles",
"k": 5
}
Response:
{
"results": [
{
"title": "Button — Carbon React",
"path": "docs/components/button.md",
"snippet": "The Button component supports kinds: primary, secondary...",
"score": 0.98
}
],
"logs": [...],
"trace_id": "search-1234567890"
}
4. Token Converter
POST /tool/tokenConverter
{
"input_path": "tokens/tokens.json",
"outputs": ["css_vars", "scss_map", "js_tokens"],
"output_dir": "tokens",
"dry_run": true
}
5. Validate Component
POST /tool/validateComponent
{
"file_path": "src/components/MyButton/MyButton.tsx",
"rules": ["props", "accessibility", "tokens"]
}
Response:
{
"valid": false,
"errors": [],
"warnings": [
{
"type": "warning",
"rule": "accessibility",
"message": "Icon-only buttons should have aria-label"
}
],
"logs": [...],
"trace_id": "validate-1234567890"
}
6. Theme Preview
POST /tool/themePreview
{
"themes": ["white", "g10", "g90", "g100"],
"output_path": "theme-previews",
"dry_run": true
}
🔧 Development
Project Structure
carbon-mcp/
├── src/
│ ├── server/
│ │ ├── index.ts # Server bootstrap
│ │ ├── toolRegistry.ts # Tool registration
│ │ └── tools/ # Tool handlers
│ │ ├── generateComponent.ts
│ │ ├── codemodReplace.ts
│ │ ├── searchDocs.ts
│ │ ├── tokenConverter.ts
│ │ ├── validateComponent.ts
│ │ ├── themePreview.ts
│ │ └── figmaSync.ts
│ ├── lib/ # Utilities
│ │ ├── logger.ts
│ │ ├── fileUtils.ts
│ │ ├── templateUtils.ts
│ │ ├── codemodUtils.ts
│ │ ├── diffUtils.ts
│ │ └── tokenUtils.ts
│ ├── schemas/ # JSON schemas
│ └── templates/ # Component templates
├── package.json
├── tsconfig.json
└── README.md
Available Scripts
npm run dev # Start development server with hot reload
npm run build # Build TypeScript to dist/
npm start # Run production server
npm test # Run tests
npm run lint # Lint code
Adding a New Tool
- Create handler in
src/server/tools/myTool.ts - Create schema in
src/schemas/myTool.json - Register in
src/server/toolRegistry.ts - Update this README
🧪 Testing
npm test
Tests use Jest + ts-jest. Test files are located next to source files with .test.ts extension.
🔐 Security & Privacy
- No secrets in logs: The logger automatically redacts sensitive keys (tokens, passwords, API keys)
- Telemetry opt-in: Set
ANALYTICS_ENABLED=truein.envto enable (disabled by default) - File access: Tools only access files within the repo root
- Audit trails: All operations are logged with trace IDs for auditing
🌐 Environment Variables
| Variable | Required | Description |
|---|---|---|
PORT |
No | Server port (default: 4000) |
FIGMA_TOKEN |
No | Figma Personal Access Token for figmaSync |
GITHUB_TOKEN |
No | GitHub token for PR automation |
ANALYTICS_ENABLED |
No | Enable telemetry (default: false) |
CARBON_VERSION |
No | Carbon version to use (default: latest) |
📖 Common Codemods
btn-old-to-carbon
Replaces old <button className="btn-old"> with Carbon <Button kind="primary">
class-to-style
Refactors className styles that match Carbon tokens into token usage
replace-grid
Swaps custom grid with Carbon Grid
image-to-asset
Converts inline base64 images to static assets
🤝 Contributing
- Follow TypeScript best practices
- Add tests for new tools
- Update schemas and documentation
- Keep tools deterministic and idempotent
- Use dry-run by default for destructive operations
📝 License
MIT
🔗 Resources
Made with ❤️ for the Carbon Design System community
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。