Mermaid Diagram Generator MCP server

Converts Mermaid diagrams to PNG images using Puppeteer for high-quality headless browser rendering, supporting multiple themes and customizable backgrounds.
Back to servers
Provider
Shawn Peng
Release date
Mar 06, 2025
Language
TypeScript
Package
Stats
5.2K downloads
109 stars

The Mermaid MCP Server converts Mermaid diagram code into PNG images or SVG files. This tool enables AI assistants and applications to generate visual diagrams from textual descriptions using Mermaid markdown syntax, with support for multiple themes and customizable backgrounds.

Installation Options

Install via npm

npm install @peng-shawn/mermaid-mcp-server

Install via Smithery

For Claude Desktop, you can automatically install using Smithery:

npx -y @smithery/cli install @peng-shawn/mermaid-mcp-server --client claude

Setup and Configuration

Configure for Claude Desktop

Add the following to your Claude Desktop configuration:

{
  "mcpServers": {
    "mermaid": {
      "command": "npx",
      "args": ["-y", "@peng-shawn/mermaid-mcp-server"]
    }
  }
}

Configure for Cursor and Cline

When using with Cursor or Cline, run:

env CONTENT_IMAGE_SUPPORTED=false npx -y @peng-shawn/mermaid-mcp-server

Run with Inspector (for testing)

npx @modelcontextprotocol/inspector node dist/index.js

Environment Variables

  • CONTENT_IMAGE_SUPPORTED: Controls image handling
    • true (default): Images are returned directly in the response
    • false: Images are saved to disk (requires name and folder parameters)

Usage Examples

Basic Diagram Generation

{
  "code": "flowchart TD\n    A[Start] --> B{Is it?}\n    B -->|Yes| C[OK]\n    B -->|No| D[End]"
}

Custom Theme and Background

{
  "code": "sequenceDiagram\n    Alice->>John: Hello John, how are you?\n    John-->>Alice: Great!",
  "theme": "forest",
  "backgroundColor": "#F0F0F0"
}

Save to Disk (when CONTENT_IMAGE_SUPPORTED=false)

{
  "code": "classDiagram\n    Class01 <|-- AveryLongClass\n    Class03 *-- Class04\n    Class05 o-- Class06",
  "theme": "dark",
  "name": "class_diagram",
  "folder": "/path/to/diagrams"
}

Generate SVG Output

{
  "code": "stateDiagram-v2\n    [*] --> Still\n    Still --> [*]\n    Still --> Moving\n    Moving --> Still\n    Moving --> Crash\n    Crash --> [*]",
  "outputFormat": "svg",
  "name": "state_diagram",
  "folder": "/path/to/diagrams"
}

API Reference

The server provides a single tool:

generate

Converts Mermaid diagram code to a PNG image or SVG file

Parameters:

  • code: The Mermaid diagram code to render
  • theme: (optional) Diagram theme - "default", "forest", "dark", or "neutral"
  • backgroundColor: (optional) Background color (e.g., 'white', 'transparent', '#F0F0F0')
  • outputFormat: (optional) "png" or "svg" (defaults to "png")
  • name: Filename for the generated file (required when CONTENT_IMAGE_SUPPORTED=false)
  • folder: Absolute path to save the image/SVG (required when CONTENT_IMAGE_SUPPORTED=false)

Docker Usage

When running in Docker containers:

Option 1: Use system Chrome

  • Set PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true during installation
  • Install Chrome/Chromium in your Docker container
  • Set PUPPETEER_EXECUTABLE_PATH to point to Chrome

Option 2: Use bundled Chrome

  • Ensure your container has necessary Chrome dependencies
  • No need to set PUPPETEER_SKIP_CHROMIUM_DOWNLOAD

Troubleshooting

Common Issues

  • If using with Cursor, make sure to set CONTENT_IMAGE_SUPPORTED=false
  • For Docker environments, ensure proper Chrome/Chromium dependencies are installed

How to add this MCP server to Cursor

There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json file so that it is available in all of your projects.

If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json file.

Adding an MCP server to Cursor globally

To add a global MCP server go to Cursor Settings > MCP and click "Add new global MCP server".

When you click that button the ~/.cursor/mcp.json file will be opened and you can add your server like this:

{
    "mcpServers": {
        "cursor-rules-mcp": {
            "command": "npx",
            "args": [
                "-y",
                "cursor-rules-mcp"
            ]
        }
    }
}

Adding an MCP server to a project

To add an MCP server to a project you can create a new .cursor/mcp.json file or add it to the existing one. This will look exactly the same as the global MCP server example above.

How to use the MCP server

Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.

The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.

You can also explictly ask the agent to use the tool by mentioning the tool name and describing what the function does.

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later