Skip to main content
Glama

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:

  1. File-based: Save diagrams to disk and return the file path

  2. 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 | sh on 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

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 output

Fallback 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-gen

Platform-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-gen

Linux

# Binary typically installed at:
~/.local/bin/mcp-mermaid-image-gen

# Verify exact location:
which mcp-mermaid-image-gen

Windows

# Binary typically installed at:
%USERPROFILE%\.local\bin\mcp-mermaid-image-gen.exe

# Verify exact location:
where mcp-mermaid-image-gen

Configuring 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.json

  • Windows: %APPDATA%\Claude\claude_desktop_config.json

  • Linux: ~/.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 uvx command with mcp-mermaid-image-gen as 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-gen

Development 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:

  1. Use uv tool install instead for a fully isolated environment

  2. Check for conflicting packages: uv tool list

  3. If 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:

  1. Verify installation: uv tool list | grep mcp-mermaid-image-gen

  2. Check PATH: Ensure ~/.local/bin is in your PATH

  3. Use 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.py

This will:

  1. Start the MCP Inspector web interface

  2. Allow testing via both STDIO and SSE transport modes

  3. Provide a UI for calling the server's tools

  4. Display returned images directly in the browser

  5. 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 syntax

  • folder (str): Output directory path

  • name (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:

    1. Inferred from filename extension (e.g., "diagram.png" -> png).

    2. Defaults to "png" if no valid extension or format is provided.

Returns: Path to the generated file

Format Selection Priority:

  1. Explicit format parameter if provided

  2. File extension in name parameter if valid

  3. Defaults 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 syntax

  • 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. Defaults to "png" if not specified.

Returns: Base64-encoded diagram data with appropriate MIME type:

  • PNG: image/png

  • PDF: application/pdf

  • SVG: 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:

  1. 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

  2. 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:

  1. 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 3001
  2. mcp_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.log

  • Linux:

    • Root user: /var/log/mcp-servers/mcp_mermaid_image_gen.log

    • Non-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-server

Valid 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 tools
generate_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:

    1. Inferred from filename extension (e.g., "diagram.png" -> png).

    2. 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:

  1. The client needs to persist the diagram to disk

  2. The client has local file system access

  3. The client needs to reference the image file path in subsequent operations

ParametersJSON Schema
NameRequiredDescriptionDefault
codeYes
folderYes
nameYes
themeNo
backgroundColorNo
formatNo

TDQS

A4.2/5.0
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations provided, so description carries full burden. It covers transport modes, prerequisites, and response format. However, it does not disclose behaviors like overwriting files, error handling if folder is missing, or side effects.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Well-structured with clear sections (purpose, prerequisites, parameter guidance, response, use case). Slightly lengthy but each section adds value. Front-loaded with primary purpose.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given no output schema and 6 parameters, description provides thorough guidance on parameters, prerequisites, and use cases. Lacks error handling details and examples, but is largely complete for typical usage.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 0%, but description's PARAMETER GUIDANCE section provides detailed explanations for all 6 parameters, including options for theme, format inference, and background color. This adds significant value beyond the bare schema.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific verb 'generate' and resource 'Mermaid diagram' and the action of saving to file system. It distinguishes from the sibling tool 'generate_mermaid_diagram_stream' by focusing on file persistence.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides a USE CASE section with explicit scenarios (client needs to persist to disk, has local FS access, needs file path). It also includes SYSTEM PREREQUISITES and ACCESS REQUIREMENTS. However, it does not explicitly state when not to use this tool vs the sibling stream tool.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

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:

  1. The client is using SSE transport mode

  2. The client can handle base64-encoded image data

  3. No need to persist the image to disk

  4. No file system access is available or desired

ParametersJSON Schema
NameRequiredDescriptionDefault
codeYes
themeNo
backgroundColorNo
formatNo

TDQS

A4.6/5.0
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description provides extensive behavioral details: system prerequisites, transport constraints, no file system access, and direct base64 streaming. However, it lacks specifics about error handling or behavior when prerequisites are not met.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is well-structured with clear sections and front-loaded purpose. While somewhat verbose, the level of detail is justified given the tool's complexity (streaming, prerequisites, transport). Could be slightly more concise but remains effective.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

The description covers system prerequisites, parameter usage, response format, and use cases, which is comprehensive for a tool with 4 parameters and no output schema. It could mention potential errors or limitations, but overall it provides sufficient context for an agent to decide to invoke the tool.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema has 0% description coverage, but the description compensates fully by explaining each parameter's purpose, allowed values for theme, formatting guidance for backgroundColor and format, and default behaviors. This adds significant value beyond the schema.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: generate a Mermaid diagram and return it as a base64-encoded image. It distinguishes from the sibling tool 'generate_mermaid_diagram_file' by emphasizing streaming and no file persistence.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides explicit when-to-use and when-not-to-use guidance, including system prerequisites, transport requirements (SSE only), and a dedicated 'USE CASE' section. It implicitly contrasts with the sibling tool for file-based persistence.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

TDQS

A4.4/5.0
Disambiguation5/5

Each tool has a distinct output method: file persistence vs. base64 streaming. No ambiguity between them.

Naming Consistency5/5

Both tools follow the same verb_noun pattern 'generate_mermaid_diagram_' with a suffix differentiating output type ('file' vs 'stream').

Tool Count4/5

Only 2 tools, but they cover the two primary output modes for a focused diagram generation server. Slightly thin but reasonable.

Completeness4/5

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

ActivityInactive
ResponsivenessSyncing

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Connectors

Related MCP Servers

  • F
    license
    Not graded
    quality
    D
    maintenance
    MCP server that generates Mermaid diagrams with live browser preview, supports real-time rendering and SVG/PNG export.
    12
  • A
    license
    A
    quality
    A
    maintenance
    MCP 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.
    2
    0
    Apache 2.0

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/codingthefuturewithai/mcp_mermaid_image_gen'

If you have feedback or need assistance with the MCP directory API, please join our Discord server