mermaid-mcp-server
A lightweight MCP server that provides real-time Mermaid diagram syntax validation with support for all diagram types.
README
Mermaid MCP Server
A lightweight Model Context Protocol (MCP) server that provides real-time Mermaid diagram syntax validation with minimal memory footprint.
Features
- ✅ Real-time Syntax Validation: Instant validation while you edit diagrams
- 🚀 Ultra Lightweight: Minimal memory usage, optimized for performance
- 🎯 100% Compatibility: Supports all Mermaid diagram types
- 📊 Detailed Error Reporting: Line numbers, error classification, and suggestions
- 🔧 Batch Validation: Validate multiple diagrams at once
- 📈 Performance Monitoring: Track validation times and memory usage
Supported Diagram Types
- Flowcharts (
graph,flowchart) - Sequence Diagrams (
sequenceDiagram) - Class Diagrams (
classDiagram) - State Diagrams (
stateDiagram) - Entity Relationship Diagrams (
erDiagram) - Gantt Charts (
gantt) - User Journey (
journey) - Pie Charts (
pie) - Git Graphs (
gitgraph) - Mind Maps (
mindmap) - Timelines (
timeline) - C4 Architecture (
c4) - Sankey Diagrams (
sankey) - Block Diagrams (
block) - Architecture Diagrams (
architecture)
Installation
- Clone this repository:
git clone <repository-url>
cd mermaid-mcp-server
- Install dependencies:
npm install
- Add to your MCP client configuration:
Claude Desktop Configuration
Add to your claude_desktop_config.json:
{
"mcpServers": {
"mermaid": {
"command": "node",
"args": ["/path/to/mermaid-mcp-server/server.js"],
"env": {}
}
}
}
Usage Examples
Basic Syntax Validation
// Validate a simple flowchart
const result = await validate_mermaid({
diagramCode: `graph TD
A[Start] --> B{Decision}
B -->|Yes| C[Process]
B -->|No| D[End]
C --> D`
});
Real-time Validation Hook
// Real-time validation during editing
const realtimeResult = await mermaid_realtime_validate({
diagramCode: "sequenceDiagram\n A->>B: Hello",
changeType: "add",
lineNumber: 2
});
Batch Validation
// Validate multiple diagrams at once
const batchResult = await validate_mermaid_batch({
diagrams: [
"graph TD\n A --> B",
"sequenceDiagram\n A->>B: Test",
"invalid diagram code"
]
});
API Reference
Tools
validate_mermaid
Validates a single Mermaid diagram.
Parameters:
diagramCode(string, required): The Mermaid diagram code to validate
Returns:
{
"isValid": true,
"error": null,
"type": null,
"line": null,
"suggestion": null,
"processingTime": 12,
"diagramType": "graph",
"elementCount": 4
}
mermaid_realtime_validate
Real-time validation for live editing scenarios.
Parameters:
diagramCode(string, required): Current diagram codechangeType(string, required): Type of change (add,remove,modify,full)lineNumber(number, optional): Line where change occurred
Returns: Enhanced validation result with change metadata.
validate_mermaid_batch
Validates multiple diagrams in a single call.
Parameters:
diagrams(array, required): Array of diagram codes
Returns:
{
"summary": {
"total": 3,
"valid": 2,
"invalid": 1,
"averageProcessingTime": 15.3
},
"results": [...]
}
get_mermaid_info
Gets server information and supported diagram types.
Returns:
{
"server": {
"name": "mermaid-mcp-server",
"version": "1.0.0",
"uptime": 3600
},
"supportedTypes": [...],
"stats": {...},
"features": [...]
}
Error Types
The server classifies errors into these categories:
syntax: General syntax errorsno_type: Missing diagram type declarationunknown_command: Unsupported commandsparse: Parsing errorsidentifier: Invalid identifiersrelation: Connection/arrow issuesgeneral: Other errors
Performance Optimization
Memory Management
- Lazy initialization of Mermaid engine
- Minimal dependencies
- Efficient garbage collection
- No DOM rendering (validation only)
Processing Speed
- Direct Mermaid parsing without rendering
- Optimized error extraction
- Batch processing capabilities
- Performance metrics tracking
Usage Tips
- Use
mermaid_realtime_validatefor live editing - Use
validate_mermaid_batchfor multiple diagrams - Check
processingTimeto monitor performance - Monitor memory usage with
get_mermaid_info
Development
Running in Development Mode
npm run dev
Testing
# Test with various diagram types
node test.js
Environment Variables
NODE_ENV: Set todevelopmentfor debug loggingGC_INTERVAL: Garbage collection interval (default: 60000ms)
Configuration
The server can be configured via environment variables:
# Enable debug logging
DEBUG=mermaid-mcp-server
# Set memory limit (MB)
MEMORY_LIMIT=128
# Enable performance monitoring
PERFORMANCE_MONITORING=true
Troubleshooting
Common Issues
-
Server won't start
- Check Node.js version (>=18.0.0 required)
- Verify all dependencies are installed
- Check for port conflicts if applicable
-
Memory usage high
- Restart server periodically
- Use batch validation instead of many single calls
- Monitor memory usage via
get_mermaid_info
-
Validation errors
- Ensure proper diagram syntax
- Check supported diagram types
- Use real-time validation for immediate feedback
Debug Mode
Enable debug logging:
DEBUG=mermaid-mcp-server:* npm start
License
MIT License
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
Support
For issues and questions:
- Create an issue on GitHub
- Check the troubleshooting section
- Review the API documentation
推荐服务器
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 模型以安全和受控的方式获取实时的网络信息。