mermaid mcp server
A Model Context Protocol (MCP) server that converts Mermaid diagrams to PNG images.
A Model Context Protocol (MCP) server that converts Mermaid diagrams to PNG images.
A Model Context Protocol (MCP) server that converts Mermaid diagrams to PNG images. This server allows AI assistants and other applications to generate visual diagrams from textual descriptions using the Mermaid markdown syntax.
The server uses Puppeteer to launch a headless browser, render the Mermaid diagram to SVG, and capture a screenshot of the rendered diagram. The process involves:
npx tsc
"mcpServers": {
"mermaid": {
"command": "npx",
"args": [
npx @peng-shawn/mermaid-mcp-server
]
}
}
env CONTENT_IMAGE_SUPPORTED=false npx @peng-shawn/mermaid-mcp-server
You can find a list of mermaid diagrams under ./diagrams
, they are created using Cursor agent with prompt: "generate mermaid diagrams and save them in a separate diagrams folder explaining how renderMermaidPng work"
Run the server with inspector for testing and debugging:
npx @modelcontextprotocol/inspector node dist/index.js
The server will start and listen on stdio for MCP protocol messages.
Learn more about inspector here.
To install Mermaid Diagram Generator for Claude Desktop automatically via Smithery:
npx -y @smithery/cli install @peng-shawn/mermaid-mcp-server --client claude
When running in Docker containers (including via Smithery), you may need to handle Chrome dependencies:
Option 1: During Docker image build:
- Set PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true
when installing Puppeteer
- Install Chrome/Chromium in your Docker container
- Set PUPPETEER_EXECUTABLE_PATH
at runtime to point to the Chrome installation
Option 2: Use Puppeteer's bundled Chrome:
- Ensure your Docker container has the necessary dependencies for Chrome
- No need to set PUPPETEER_SKIP_CHROMIUM_DOWNLOAD
- The code will use the bundled browser automatically
For Smithery users, the latest version should work without additional configuration.
The server exposes a single tool:
generate
: Converts Mermaid diagram code to a PNG imagecode
: The Mermaid diagram code to rendertheme
: (optional) Theme for the diagram. Options: "default", "forest", "dark", "neutral"backgroundColor
: (optional) Background color for the diagram, e.g. 'white', 'transparent', '#F0F0F0'name
: Name for the generated file (required when CONTENT_IMAGE_SUPPORTED=false)folder
: Absolute path to save the image to (required when CONTENT_IMAGE_SUPPORTED=false)The behavior of the generate
tool depends on the CONTENT_IMAGE_SUPPORTED
environment variable:
CONTENT_IMAGE_SUPPORTED=true
(default): The tool returns the image directly in the responseCONTENT_IMAGE_SUPPORTED=false
: The tool saves the image to the specified folder and returns the file pathCONTENT_IMAGE_SUPPORTED
: Controls whether images are returned directly in the response or saved to disktrue
(default): Images are returned directly in the responsefalse
: Images are saved to disk, requiring name
and folder
parameters// Generate a flowchart with default settings
{
"code": "flowchart TD
A[Start] --> B{Is it?}
B -->|Yes| C[OK]
B -->|No| D[End]"
}
// Generate a sequence diagram with forest theme and light gray background
{
"code": "sequenceDiagram
Alice->>John: Hello John, how are you?
John-->>Alice: Great!",
"theme": "forest",
"backgroundColor": "#F0F0F0"
}
// Generate a class diagram and save it to disk
{
"code": "classDiagram
Class01 <|-- AveryLongClass
Class03 *-- Class04
Class05 o-- Class06",
"theme": "dark",
"name": "class_diagram",
"folder": "/path/to/diagrams"
}
Yes, but it does not support the theme
and backgroundColor
options. Plus, having a dedicated server makes it easier to create mermaid diagrams with different MCP clients.
Cursor does not support inline images in responses yet.
This project uses GitHub Actions to automate the publishing process to npm.
# Using a specific version number
npm run release 0.1.4
# Using semantic version increments
npm run release patch # Increments the patch version (e.g., 0.1.3 → 0.1.4)
npm run release minor # Increments the minor version (e.g., 0.1.3 → 0.2.0)
npm run release major # Increments the major version (e.g., 0.1.3 → 1.0.0)
git tag v0.1.4 # Use the appropriate version number
git push origin v0.1.4
Note: You need to set up the NPM_TOKEN
secret in your GitHub repository settings. To do this:
1. Generate an npm access token with publish permissions
2. Go to your GitHub repository → Settings → Secrets and variables → Actions
3. Create a new repository secret named NPM_TOKEN
with your npm token as the value
MIT