Python model context protocol(MCP) server for mermaid
Project description
Mermaid MCP
Model Context Protocol server for Mermaid diagrams.
Overview
Mermaid-MCP provides a server and CLI interface for creating, validating, and rendering Mermaid diagrams. It uses the mmdc (Mermaid CLI) to generate static SVG, PNG, or PDF files from Mermaid diagram specifications.
Features
- API server for diagram generation and validation
- CLI tool for local diagram rendering
- Custom theme support
- Multiple output formats (SVG, PNG, PDF)
- Support for all Mermaid diagram types
Installation
# Using pip
pip install mermaid-mcp
# Using uv
uv pip install mermaid-mcp
Usage
CLI
# Generate a diagram
mermaid-mcp cli chart flowchart diagram.mmd output.svg
# Validate a diagram
mermaid-mcp cli validate flowchart diagram.mmd
Server
# Start the server
mermaid-mcp server start
# Install as a launch agent (macOS)
mermaid-mcp server install --port=27312
Theme Support
Mermaid-MCP supports several methods of applying themes to your diagrams:
- Built-in Mermaid themes: "default", "forest", "dark", "neutral", "base"
- Custom CSS themes from the
css/directory - Custom JSON theme configurations in the
themes/directory
Using a Theme
In CLI mode
# Use a built-in theme
mermaid-mcp cli chart --theme=dark flowchart diagram.mmd output.svg
# Use a CSS theme
mermaid-mcp cli chart --css-theme=dark-mode flowchart diagram.mmd output.svg
# Use a JSON theme
mermaid-mcp cli chart --json-theme=forest-night flowchart diagram.mmd output.svg
In Server mode
// Example request to /generate/flowchart
{
"input": "graph TD\n A[Start] --> B[End]",
"css_theme": "dark-mode"
}
Creating Custom Themes
CSS Themes
Create a CSS file in the css/ directory with CSS variables for theming:
/* my-theme.css */
:root {
/* General theme */
--mermaid-primary-color: #282a36;
--mermaid-primary-border-color: #bd93f9;
--mermaid-primary-text-color: #f8f8f2;
/* Node styling */
--mermaid-node-border: #bd93f9;
--mermaid-node-background: #44475a;
--mermaid-node-text: #f8f8f2;
/* More variables... */
}
Important: CSS themes must use direct color values (hexadecimal, rgb, etc.) and not CSS variable references like var(--name).
JSON Themes
Create a JSON file in the themes/ directory:
{
"theme": "base",
"themeVariables": {
"primaryColor": "#282a36",
"primaryBorderColor": "#bd93f9",
"primaryTextColor": "#f8f8f2",
"secondaryColor": "#44475a",
"lineColor": "#bd93f9",
"nodeBorder": "#bd93f9",
"darkMode": true
}
}
API Reference
Endpoints
GET /themes- List available themesPOST /generate/{chart_type}- Generate a chartPOST /validate/{chart_type}- Validate a chartGET /help/{chart_type}- Get help for a specific chart type
Development
# Clone the repository
git clone https://github.com/yourusername/mermaid-mcp.git
cd mermaid-mcp
# Install dependencies
pip install -e .
# Run tests
python -m tests.test_themes
License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mermaid_mcp-0.1.2.tar.gz.
File metadata
- Download URL: mermaid_mcp-0.1.2.tar.gz
- Upload date:
- Size: 21.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
78a6c04f3cdd4de5fc07a58333bd5dc4f24b59c0900f935c5e4b1350555c6922
|
|
| MD5 |
5db0ecd842fbe90d2ccc53b9dcf2c133
|
|
| BLAKE2b-256 |
cb6eef02f640b841c5ae61785e935c4c53f2ab689c8467eaa5cf52190c3bd661
|
File details
Details for the file mermaid_mcp-0.1.2-py3-none-any.whl.
File metadata
- Download URL: mermaid_mcp-0.1.2-py3-none-any.whl
- Upload date:
- Size: 20.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
737dd410b971d3a1cb8a1835e284eed1f24eced977891d10b8664b42618c2897
|
|
| MD5 |
0448cdfee72df9f6974c57bea9882296
|
|
| BLAKE2b-256 |
f873d68ff69bb9fba30ec9969c2f4a04be174554bddc80a309066fde8874bed6
|