Skip to main content

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:

  1. Built-in Mermaid themes: "default", "forest", "dark", "neutral", "base"
  2. Custom CSS themes from the css/ directory
  3. 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 themes
  • POST /generate/{chart_type} - Generate a chart
  • POST /validate/{chart_type} - Validate a chart
  • GET /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

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mermaid_mcp-0.1.2.tar.gz (21.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mermaid_mcp-0.1.2-py3-none-any.whl (20.7 kB view details)

Uploaded Python 3

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

Hashes for mermaid_mcp-0.1.2.tar.gz
Algorithm Hash digest
SHA256 78a6c04f3cdd4de5fc07a58333bd5dc4f24b59c0900f935c5e4b1350555c6922
MD5 5db0ecd842fbe90d2ccc53b9dcf2c133
BLAKE2b-256 cb6eef02f640b841c5ae61785e935c4c53f2ab689c8467eaa5cf52190c3bd661

See more details on using hashes here.

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

Hashes for mermaid_mcp-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 737dd410b971d3a1cb8a1835e284eed1f24eced977891d10b8664b42618c2897
MD5 0448cdfee72df9f6974c57bea9882296
BLAKE2b-256 f873d68ff69bb9fba30ec9969c2f4a04be174554bddc80a309066fde8874bed6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page