Mermaid Lint MCP
by yaodebian
README.md
# Mermaid Lint MCP
[δΈζηζ¬](README_zh.md) | **English**
A powerful tool for validating Mermaid diagrams with both CLI and MCP server capabilities. Perfect for developers, technical writers, and AI assistants who work with Mermaid diagrams.
## π Quick Start
### Install and Use Immediately
```bash
# Validate a Mermaid file
npx mermaid-lint-mcp lint diagram.mmd
# Validate Mermaid code directly
npx mermaid-lint-mcp lint --code "graph TD; A-->B"
# Start MCP server for AI assistants
npx mermaid-lint-mcp server
# Get help
npx mermaid-lint-mcp --help
```
No installation required! The tool will be downloaded automatically on first use.
## π― Use Cases
### For Developers
- **Pre-commit validation**: Ensure all Mermaid diagrams in your codebase are valid
- **CI/CD integration**: Add diagram validation to your build pipeline
- **Documentation quality**: Catch syntax errors before publishing docs
### For Technical Writers
- **Content validation**: Verify diagrams render correctly before publication
- **Error debugging**: Get clear error messages for syntax issues
### For AI Assistants
- **Real-time validation**: Validate generated diagrams instantly
- **MCP integration**: Seamless integration with Claude Code, Cursor, Trae, and other AI tools
- **Automated workflows**: Enable AI to self-validate diagram outputs
## π Features
- β
**Fast Validation**: Optimized for speed with browser reuse and local libraries
- β
**Multiple Formats**: Support for all Mermaid diagram types
- β
**Dual Interface**: Both CLI tool and MCP server in one package
- β
**Error Details**: Clear error messages with line numbers and suggestions
- β
**Timeout Control**: Configurable validation timeouts
- β
**Zero Config**: Works out of the box
## π οΈ Installation Options
### Option 1: Use with npx (Recommended)
No installation needed - just use `npx mermaid-lint-mcp` directly.
### Option 2: Global Installation
```bash
npm install -g mermaid-lint-mcp
# Then use: mermaid-lint-mcp
```
### Option 3: Local Project Installation
```bash
npm install mermaid-lint-mcp
# Then use: npx mermaid-lint-mcp
```
## π Usage Guide
### CLI Commands
#### Validate Diagrams
```bash
# Validate a file
npx mermaid-lint-mcp lint diagram.mmd
npx mermaid-lint-mcp diagram.mmd # 'lint' is default
# Validate code string
npx mermaid-lint-mcp lint --code "graph TD; A-->B"
# With custom timeout (5 seconds)
npx mermaid-lint-mcp lint --timeout 5000 diagram.mmd
# Validate with file option
npx mermaid-lint-mcp lint --file diagram.mmd
```
#### Start MCP Server
```bash
# Start server for AI assistant integration
npx mermaid-lint-mcp server
```
#### Get Help
```bash
npx mermaid-lint-mcp --help # Show all commands
npx mermaid-lint-mcp --version # Show version
```
### MCP Server Integration
#### For Claude Desktop
Add to your `claude_desktop_config.json`:
```json
{
"mcpServers": {
"mermaid-lint": {
"command": "npx",
"args": ["mermaid-lint-mcp", "server"]
}
}
}
```
#### For Other MCP Clients, the setup is similar to above, please refer to the official documentation
## π Supported Diagram Types
| Type | Syntax | Example |
|------|--------|---------|
| Flowchart | `flowchart TD` | Decision trees, processes |
| Sequence | `sequenceDiagram` | API interactions, workflows |
| Class | `classDiagram` | Object relationships |
| State | `stateDiagram-v2` | State machines |
| ER | `erDiagram` | Database schemas |
| Gantt | `gantt` | Project timelines |
| Pie | `pie` | Data visualization |
| Journey | `journey` | User experiences |
| Git Graph | `gitgraph` | Version control flows |
| ... | `...` | ... |
## π§ Configuration
### Validation Options
```typescript
interface ValidationOptions {
timeout?: number; // Timeout in milliseconds (default: 5000)
}
```
### Environment Variables
```bash
# Set default timeout
export MERMAID_TIMEOUT=10000
# Enable debug logging
export DEBUG=mermaid-lint-mcp
```
## π Example Outputs
### Valid Diagram
```json
{
"isValid": true,
"error": null,
"diagramType": "flowchart"
}
```
### Invalid Diagram
```json
{
"isValid": false,
"error": "Parse error on line 8: ...> C E --> F[End ---------------------^ Expecting 'SQE', 'DOUBLECIRCLEEND', 'PE', '-)', 'STADIUMEND', 'SUBROUTINEEND', 'PIPE', 'CYLINDEREND', 'DIAMOND_STOP', 'TAGEND', 'TRAPEND', 'INVTRAPEND', 'UNICODE_TEXT', 'TEXT', 'TAGSTART', got '1'",
"diagramType": "flowchart"
}
```
### CLI Output
```bash
$ npx mermaid-lint-mcp lint --code "graph TD; A-->B"
π Validating Mermaid diagram...
β
Diagram is valid!
π Diagram type: flowchart
```
## π¨ Common Issues & Solutions
### Issue: "Command not found"
**Solution**: Use `npx mermaid-lint-mcp` instead of `mermaid-lint-mcp`
### Issue: Validation timeout
**Solution**: Increase timeout with `--timeout 10000`
### Issue: Permission denied
**Solution**: Run with appropriate permissions or use `npx`
## π License
MIT License - see [LICENSE](LICENSE) file for details.
## πββοΈ Support
- π [Documentation](https://github.com/yaodebian/mermaid-lint-mcp)
- π [Report Issues](https://github.com/yaodebian/mermaid-lint-mcp/issues)
- π¬ [Discussions](https://github.com/yaodebian/mermaid-lint-mcp/discussions)
## π Related Tools
- [Mermaid](https://mermaid.js.org/) - Create diagrams with text
- [Mermaid Live Editor](https://mermaid.live/) - Online diagram editor
- [Model Context Protocol](https://modelcontextprotocol.io/) - AI integration standardTDQS
B3.2/5.0
Scored across 1 tool
Disambiguation5/5
With only one tool, there is no ambiguity; the tool's purpose is clear and distinct by default.
Naming Consistency5/5
The single tool name follows a clear verb_noun pattern (validate_mermaid_diagram), which is consistent and readable.
Tool Count2/5
A single tool for a server named 'Mermaid Lint' feels insufficient; typical linting servers include multiple tools for validation, formatting, and configuration.
Completeness1/5
The surface is severely incomplete; only validation is provided, omitting common linting operations like reporting, fixing, or configuring rules.
Maintenance
ActivityInactive
ResponsivenessNo issues