MCP Mermaid Image Gen
Generates diagrams from Mermaid syntax (flowcharts, sequence diagrams, class diagrams, etc.) in multiple output formats including PNG, PDF, and SVG, with support for multiple themes and customizable backgrounds.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@MCP Mermaid Image Gen generate a flowchart for user login"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
MCP Mermaid Image Gen
An MCP server that generates diagrams from Mermaid code in multiple formats (primarily PNG and PDF, with SVG also available). This server enables AI assistants and other MCP clients to create diagrams using the Mermaid diagram syntax, with support for multiple themes, formats, and customizable backgrounds.
Overview
This MCP server wraps the Mermaid CLI (@mermaid-js/mermaid-cli) to provide diagram generation capabilities through the Model Context Protocol (MCP). It offers two operation modes:
File-based: Save diagrams to disk and return the file path
Stream-based: Return the diagram directly as base64-encoded data
Both modes work with either STDIO or SSE transport, but the stream-based mode requires an MCP client capable of handling image data.
The server is designed to be used by AI coding assistants and other tools that support the MCP protocol, allowing them to generate diagrams without needing direct access to the Mermaid CLI.
📚 For AI Assistants: See AI_SETUP_GUIDE.md for a structured guide to help users with installation.
Related MCP server: vaults-diagram-tools
Features
Generate diagrams from Mermaid syntax (flowcharts, sequence diagrams, class diagrams, etc.)
Multiple output formats:
PNG: Raster graphics, recommended for general use and broad compatibility.
PDF: Document format, perfect for print and formal documentation.
SVG: Vector graphics, available for web and scalable diagrams where specifically needed.
Support for multiple themes (default, neutral, dark, forest, base)
Customizable background colors (hex codes or named colors)
Two operation modes (both available in STDIO and SSE transport):
File-based: Save diagrams to disk and return the path
Stream-based: Return base64-encoded diagram data (requires MCP client with image support)
Comprehensive error handling and validation
Detailed logging with configurable levels
Prerequisites
Required
UV Package Manager: Install using the official installer or via
curl -LsSf https://astral.sh/uv/install.sh | shon Unix-like systems.Operating Systems: Linux, macOS, Windows are supported.
Auto-Managed (Optional Manual Install)
Node.js: Version 14 or higher. The server will attempt to use system Node.js if available.
Mermaid CLI: The server will automatically install a local copy if not found in PATH. For manual system-wide installation:
npm install -g @mermaid-js/mermaid-cli
🚀 Auto-Installation Feature: If Node.js is available but the Mermaid CLI (
mmdc) is not found, the server will automatically install it to a user-specific directory (~/.local/share/mcp_mermaid_image_gen/on Linux/macOS or%LOCALAPPDATA%\mcp_mermaid_image_gen\on Windows). This happens transparently on first use.
Installation Methods
Primary Method: UV Tool Install (Recommended)
The most reliable way to install this MCP server is using uv tool install. This creates an isolated environment and installs the server with all its dependencies:
# Install the MCP server as a UV tool
uv tool install mcp-mermaid-image-gen
# Verify installation and find the binary location
uv tool list | grep mcp-mermaid-image-gen
# Note the installation path shown in the outputFallback Method: UVX (Direct Execution)
⚠️ Warning: This method may encounter dependency conflicts if other tools in your environment use incompatible versions of shared dependencies.
# Run directly with uvx (downloads and caches on first run)
uvx mcp-mermaid-image-genPlatform-Specific Binary Locations
After installation with uv tool install, find your binary location:
macOS
# Binary typically installed at:
~/.local/bin/mcp-mermaid-image-gen
# Verify exact location:
which mcp-mermaid-image-genLinux
# Binary typically installed at:
~/.local/bin/mcp-mermaid-image-gen
# Verify exact location:
which mcp-mermaid-image-genWindows
# Binary typically installed at:
%USERPROFILE%\.local\bin\mcp-mermaid-image-gen.exe
# Verify exact location:
where mcp-mermaid-image-genConfiguring Your MCP Client
Claude Desktop Configuration
Configure Claude Desktop by editing the claude_desktop_config.json file:
macOS:
~/Library/Application Support/Claude/claude_desktop_config.jsonWindows:
%APPDATA%\Claude\claude_desktop_config.jsonLinux:
~/.config/Claude/claude_desktop_config.json
Option 1: Using UV Tool (After Installation)
{
"mcpServers": {
"mermaid_image_generator": {
"command": "/absolute/path/to/mcp-mermaid-image-gen"
}
}
}Replace /absolute/path/to/mcp-mermaid-image-gen with the actual path from the verification step above.
Option 2: Using UVX (Direct Execution)
{
"mcpServers": {
"mermaid_image_generator": {
"command": "uvx",
"args": [
"mcp-mermaid-image-gen"
]
}
}
}Other MCP Clients
Adapt the configuration to your client's format, using either:
The absolute path to the installed binary (Option 1)
The
uvxcommand withmcp-mermaid-image-genas an argument (Option 2)
Development Installation
For contributing to the server or running a modified version:
# Clone the repository
git clone https://github.com/yourusername/mcp_mermaid_image_gen.git
cd mcp_mermaid_image_gen
# Create and activate a virtual environment using UV
uv venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
# Install in development mode
uv pip install -e .
# Find the development binary
which mcp-mermaid-image-genDevelopment Configuration Example
{
"mcpServers": {
"mermaid_image_generator_dev": {
"command": "/path/to/your/project/.venv/bin/mcp-mermaid-image-gen"
}
}
}Troubleshooting
Dependency Conflicts
If you encounter dependency conflicts when using uvx:
Use
uv tool installinstead for a fully isolated environmentCheck for conflicting packages:
uv tool listIf issues persist, uninstall and reinstall:
uv tool uninstall mcp-mermaid-image-gen uv tool install mcp-mermaid-image-gen
Binary Not Found
If the MCP client can't find the binary:
Verify installation:
uv tool list | grep mcp-mermaid-image-genCheck PATH: Ensure
~/.local/binis in your PATHUse the absolute path in your client configuration
Testing with MCP Inspector
The MCP SDK includes a development console (MCP Inspector) that allows you to test the server interactively. After installation, run:
mcp dev mcp_mermaid_image_gen/server/app.pyThis will:
Start the MCP Inspector web interface
Allow testing via both STDIO and SSE transport modes
Provide a UI for calling the server's tools
Display returned images directly in the browser
Show detailed logs and debugging information
The Inspector is particularly useful for:
Testing different diagram types
Trying out various formats (PNG, PDF, and SVG)
Experimenting with themes and colors
Debugging issues with Mermaid syntax
Verifying both file and stream-based operation modes
Available Tools
generate_mermaid_diagram_file
Generates a Mermaid diagram and saves it to a local file.
Parameters:
code(str): Mermaid diagram syntaxfolder(str): Output directory pathname(str): Output filename (extension can determine format)theme(str, optional): Theme name (default, neutral, dark, forest, base)backgroundColor(str, optional): Background color (hex or named color)format(str, optional): Output format. Recommended: "png". Also supports "pdf". "svg" is available but not recommended for general use. If not specified:Inferred from filename extension (e.g., "diagram.png" -> png).
Defaults to "png" if no valid extension or format is provided.
Returns: Path to the generated file
Format Selection Priority:
Explicit
formatparameter if providedFile extension in
nameparameter if validDefaults to PNG if neither is specified
generate_mermaid_diagram_stream
Generates a Mermaid diagram and returns it directly as base64-encoded data. Requires an MCP client that supports handling image data (like the MCP Inspector).
Parameters:
code(str): Mermaid diagram syntaxtheme(str, optional): Theme name (default, neutral, dark, forest, base)backgroundColor(str, optional): Background color (hex or named color)format(str, optional): Output format. Recommended: "png". Also supports "pdf". "svg" is available but not recommended. Defaults to "png" if not specified.
Returns: Base64-encoded diagram data with appropriate MIME type:
PNG:
image/pngPDF:
application/pdfSVG:
image/svg+xml(available if explicitly requested)
Transport Modes
Both STDIO and SSE transport modes support all server functionality. The choice between them depends on your use case:
STDIO Mode (Default)
Synchronous operation
Simple command-line integration
Works with all tools and operation modes
Ideal for scripts and command-line tools
Example client: MCP Inspector, Cursor
SSE Mode
Asynchronous operation
HTTP-based communication
Works with all tools and operation modes
Ideal for web applications and services
Example client: MCP Inspector, web applications
Client Compatibility
The server supports any MCP client, but some features require specific client capabilities:
File-based generation (
generate_mermaid_diagram_file):Requires client to have file system access
Works with all MCP clients
Client must be able to read the returned file path
Stream-based generation (
generate_mermaid_diagram_stream):Requires client capable of handling base64-encoded image data
Works with MCP Inspector and other image-capable clients
No file system access needed
The MCP Inspector (included with the MCP SDK) supports all features in both transport modes.
Usage
The server provides two entry points:
mcp_mermaid_image_gen-server: The MCP server# Run with stdio transport (default) mcp_mermaid_image_gen-server # Run with SSE transport mcp_mermaid_image_gen-server --transport sse --port 3001mcp_mermaid_image_gen-client: Test client (for development)mcp_mermaid_image_gen-client "your mermaid code here"
Logging
The server logs all activity to both stderr and a rotating log file. Log files are stored in OS-specific locations:
macOS:
~/Library/Logs/mcp-servers/mcp_mermaid_image_gen.logLinux:
Root user:
/var/log/mcp-servers/mcp_mermaid_image_gen.logNon-root:
~/.local/state/mcp-servers/logs/mcp_mermaid_image_gen.log
Windows:
%USERPROFILE%\AppData\Local\mcp-servers\logs\mcp_mermaid_image_gen.log
Log files are automatically rotated when they reach 10MB, with up to 5 backup files kept.
Configure logging level with the LOG_LEVEL environment variable:
LOG_LEVEL=DEBUG mcp_mermaid_image_gen-serverValid log levels: DEBUG, INFO (default), WARNING, ERROR, CRITICAL
Author
Tim Kitchens (timkitch@codingthefuture.ai)
License
This project is licensed under the MIT License. See the LICENSE file for details.
Available Tools
2 toolsgenerate_mermaid_diagram_fileA
Generate a Mermaid diagram and save it to a local file system directory.
SYSTEM PREREQUISITES:
Node.js must be installed (v14 or higher)
Mermaid CLI must be installed globally: npm install -g @mermaid-js/mermaid-cli
The 'mmdc' command must be available in the system PATH
Python 3.8 or higher with MCP tools installed
IMPORTANT TRANSPORT & ACCESS REQUIREMENTS:
Works with both STDIO and SSE transport modes
REQUIRES: The MCP client (e.g., AI assistant) must have access to the local file system where the image is saved
The client must have write permissions for the specified folder
PARAMETER GUIDANCE:
code: Valid Mermaid diagram syntax (see https://mermaid.js.org/)
folder: Absolute or relative path to an existing directory with write permissions
name: Filename for the diagram (extension can determine format if format not specified)
theme: Theme name for the diagram. MUST be one of: ["default", "neutral", "dark", "forest", "base"]
default: Default theme for all diagrams
neutral: Great for black and white documents that will be printed
dark: Works well with dark-colored elements or dark-mode
forest: Contains shades of green
base: The only theme that can be modified for customization
backgroundColor: Optional hex color code (e.g., '#FFFFFF') or color name (e.g., 'white', 'transparent')
format: Output format. Recommended: "png". Also supports "pdf". "svg" is available but not recommended for general use. If not specified:
Inferred from filename extension (e.g., "diagram.png" -> png).
Defaults to "png" if no valid extension or format is provided.
RESPONSE:
Returns the absolute path to the generated file
The client must be able to access this path to use the generated image
USE CASE: Best suited for scenarios where:
The client needs to persist the diagram to disk
The client has local file system access
The client needs to reference the image file path in subsequent operations
Inputs: code (required), folder (required), name (required), theme, +2 more.
generate_mermaid_diagram_streamA
Generate a Mermaid diagram and return it directly as a base64-encoded image.
SYSTEM PREREQUISITES:
Node.js must be installed (v14 or higher)
Mermaid CLI must be installed globally: npm install -g @mermaid-js/mermaid-cli
The 'mmdc' command must be available in the system PATH
Python 3.8 or higher with MCP tools installed
MCP client must support SSE transport and binary/base64 image handling
IMPORTANT TRANSPORT REQUIREMENTS:
REQUIRES SSE TRANSPORT MODE ONLY
Will NOT work with STDIO transport
DO NOT use this endpoint if your MCP client doesn't support SSE transport
DO NOT use this endpoint if your client can't handle binary/base64 image data
PARAMETER GUIDANCE:
code: Valid Mermaid diagram syntax (see https://mermaid.js.org/)
theme: Theme name for the diagram. MUST be one of: ["default", "neutral", "dark", "forest", "base"]
default: Default theme for all diagrams
neutral: Great for black and white documents that will be printed
dark: Works well with dark-colored elements or dark-mode
forest: Contains shades of green
base: The only theme that can be modified for customization
backgroundColor: Optional hex color code (e.g., '#FFFFFF') or color name (e.g., 'white', 'transparent')
format: Output format. Recommended: "png". Also supports "pdf". "svg" is available but not recommended. Defaults to "png" if not specified.
RESPONSE:
Returns the diagram as a base64-encoded image in the specified format
No file system access or permissions required
Image data is streamed directly back to the client
USE CASE: Best suited for scenarios where:
The client is using SSE transport mode
The client can handle base64-encoded image data
No need to persist the image to disk
No file system access is available or desired
Inputs: code (required), theme, backgroundColor, format.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 2 tools
Each tool has a distinct output method: file persistence vs. base64 streaming. No ambiguity between them.
Both tools follow the same verb_noun pattern 'generate_mermaid_diagram_' with a suffix differentiating output type ('file' vs 'stream').
Only 2 tools, but they cover the two primary output modes for a focused diagram generation server. Slightly thin but reasonable.
Core functionality of generating Mermaid diagrams as images is covered via file and stream. Lacks SVG-specific handling or validation tools, but these are minor gaps.
Maintenance
Related MCP Connectors
Render, verify, describe, and safely edit Mermaid diagrams through MCP.
Create and manage Mermaid.js flowcharts and diagrams with AI agents via MCP.
MCP server for generating rough-draft project plans from natural-language prompts.
Collaborative whiteboard MCP server — create objects, connectors, C4 diagrams, and manage boards
Related MCP Servers
- AlicenseBqualityBmaintenanceA Model Context Protocol (MCP) server that converts Mermaid diagrams to PNG images.1289 npm234MIT
- AlicenseNot gradedqualityDmaintenanceMCP server for rendering Mermaid diagrams and generating source-code diagrams, with tools to render text/files and produce dependency/class diagrams.55 npmMIT
- FlicenseNot gradedqualityDmaintenanceMCP server that generates Mermaid diagrams with live browser preview, supports real-time rendering and SVG/PNG export.13-
- AlicenseAqualityAmaintenanceMCP server for creating and editing diagrams using draw.io. Allows generating diagrams from Mermaid or XML, searching shapes, and opening them in draw.io for export.20Apache 2.0