mermaid-mcp-server
The mermaid-mcp-server converts Mermaid diagram code into PNG images with the following capabilities:
Supports various themes: default, forest, dark, and neutral
Allows customization of background colors
Returns generated images directly or saves them to a specified folder
Provides error handling with detailed messages
Integrates with AI assistants via the Model Context Protocol (MCP)
Click on "Install 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., "@mermaid-mcp-servergenerate a flowchart showing our user login process with forest theme"
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.
Mermaid MCP Server
A Model Context Protocol (MCP) server that converts Mermaid diagrams to PNG images or SVG files. This server allows AI assistants and other applications to generate visual diagrams from textual descriptions using the Mermaid markdown syntax.
Features
Converts Mermaid diagram code to PNG images or SVG files
Supports multiple diagram themes (default, forest, dark, neutral)
Customizable background colors
Uses Puppeteer for high-quality headless browser rendering
Implements the MCP protocol for seamless integration with AI assistants
Flexible output options: return images/SVG directly or save to disk
Error handling with detailed error messages
Related MCP server: Mermaid MCP Server
How It Works
The server uses Puppeteer to launch a headless browser, render the Mermaid diagram to SVG, and optionally capture a screenshot of the rendered diagram. The process involves:
Launching a headless browser instance
Creating an HTML template with the Mermaid code
Loading the Mermaid.js library
Rendering the diagram to SVG
Either saving the SVG directly or taking a screenshot as PNG
Either returning the image/SVG directly or saving it to disk
Build
npx tscUsage
Use with Claude desktop
{
"mcpServers": {
"mermaid": {
"command": "npx",
"args": ["-y", "@peng-shawn/mermaid-mcp-server"]
}
}
}Use with Cursor and Cline
env CONTENT_IMAGE_SUPPORTED=false npx -y @peng-shawn/mermaid-mcp-serverYou 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 with inspector
Run the server with inspector for testing and debugging:
npx @modelcontextprotocol/inspector node dist/index.jsThe server will start and listen on stdio for MCP protocol messages.
Learn more about inspector here.
Installing via Smithery
To install Mermaid Diagram Generator for Claude Desktop automatically via Smithery:
npx -y @smithery/cli install @peng-shawn/mermaid-mcp-server --client claudeDocker and Smithery Environments
When running in Docker containers (including via Smithery), you may need to handle Chrome dependencies:
The server now attempts to use Puppeteer's bundled browser by default
If you encounter browser-related errors, you have two options:
Option 1: During Docker image build:
Set
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=truewhen installing PuppeteerInstall Chrome/Chromium in your Docker container
Set
PUPPETEER_EXECUTABLE_PATHat 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_DOWNLOADThe code will use the bundled browser automatically
For Smithery users, the latest version should work without additional configuration.
API
The server exposes a single tool:
generate: Converts Mermaid diagram code to a PNG image or SVG fileParameters:
code: 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'outputFormat: (optional) Output format for the diagram. Options: "png", "svg" (defaults to "png")name: Name for the generated file (required when CONTENT_IMAGE_SUPPORTED=false)folder: Absolute path to save the image/SVG to (required when CONTENT_IMAGE_SUPPORTED=false)
The behavior of the generate tool depends on the CONTENT_IMAGE_SUPPORTED environment variable:
When
CONTENT_IMAGE_SUPPORTED=true(default): The tool returns the image/SVG directly in the responseWhen
CONTENT_IMAGE_SUPPORTED=false: The tool saves the image/SVG to the specified folder and returns the file path
Environment Variables
CONTENT_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, requiringnameandfolderparameters
Examples
Basic Usage
// Generate a flowchart with default settings
{
"code": "flowchart TD\n A[Start] --> B{Is it?}\n B -->|Yes| C[OK]\n B -->|No| D[End]"
}With Theme and Background Color
// Generate a sequence diagram with forest theme and light gray background
{
"code": "sequenceDiagram\n Alice->>John: Hello John, how are you?\n John-->>Alice: Great!",
"theme": "forest",
"backgroundColor": "#F0F0F0"
}Saving to Disk (when CONTENT_IMAGE_SUPPORTED=false)
// Generate a class diagram and save it to disk as PNG
{
"code": "classDiagram\n Class01 <|-- AveryLongClass\n Class03 *-- Class04\n Class05 o-- Class06",
"theme": "dark",
"name": "class_diagram",
"folder": "/path/to/diagrams"
}Generating SVG Output
// Generate a state diagram as SVG
{
"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"
}FAQ
Doesn't Claude desktop already support mermaid via canvas?
Yes, but it doesn't support the theme and backgroundColor options. Plus, having a dedicated server makes it easier to create mermaid diagrams with different MCP clients.
Why do I need to specify CONTENT_IMAGE_SUPPORTED=false when using with Cursor?
Cursor doesn't support inline images in responses yet.
Publishing
This project uses GitHub Actions to automate the publishing process to npm.
Method 1: Using the Release Script (Recommended)
Make sure all your changes are committed and pushed
Run the release script with either a specific version number or a semantic version increment:
# 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)The script will:
Validate the version format or semantic increment
Check if you're on the main branch
Detect and warn about version mismatches between files
Update all version references consistently (package.json, package-lock.json, and index.ts)
Create a single commit with all version changes
Create and push a git tag
The GitHub workflow will then automatically build and publish to npm
Method 2: Manual Process
Update your code and commit the changes
Create and push a new tag with the version number:
git tag v0.1.4 # Use the appropriate version number git push origin v0.1.4The GitHub workflow will automatically:
Build the project
Publish to npm with the version from the tag
Note: You need to set up the NPM_TOKEN secret in your GitHub repository settings. To do this:
Generate an npm access token with publish permissions
Go to your GitHub repository → Settings → Secrets and variables → Actions
Create a new repository secret named
NPM_TOKENwith your npm token as the value
Badges
License
MIT
Available Tools
1 toolgenerateC
Generate PNG image or SVG from mermaid markdown
| Name | Required | Description | Default |
|---|---|---|---|
| backgroundColor | No | Background color for the diagram, e.g. 'white', 'transparent', '#F0F0F0' (optional) | |
| code | Yes | The mermaid markdown to generate an image from | |
| folder | No | Absolute path to save the image to (optional) | |
| name | No | Name of the diagram (optional) | |
| outputFormat | No | Output format for the diagram (optional, defaults to 'png') | |
| theme | No | Theme for the diagram (optional) |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
No annotations are provided, so the description carries the full burden of behavioral disclosure. It mentions the tool generates images from mermaid markdown but doesn't cover important behavioral aspects like file system interactions (saving to a folder), performance characteristics, error handling, or any side effects. For a tool that writes files, this is a significant gap in transparency.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
The description is extremely concise—a single sentence that directly states the tool's function without any fluff. It's front-loaded and efficiently communicates the core purpose, making it easy for an agent to parse quickly.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
Given the tool's complexity (6 parameters, file output, no output schema) and lack of annotations, the description is insufficient. It doesn't explain what the tool returns, how errors are handled, or the implications of optional parameters like 'folder'. For a generative tool with file system operations, more context is needed for safe and effective use.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
The schema description coverage is 100%, meaning all parameters are well-documented in the schema itself. The description doesn't add any meaningful parameter semantics beyond what's already in the schema (e.g., it doesn't explain parameter interactions or provide examples). This meets the baseline for high schema coverage but doesn't enhance understanding.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
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 PNG image or SVG from mermaid markdown'. It specifies the verb ('Generate'), resource ('PNG image or SVG'), and source material ('mermaid markdown'), making the function unambiguous. However, since there are no sibling tools mentioned, it doesn't need to distinguish from alternatives, so it doesn't reach the highest score of 5.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
The description provides no guidance on when to use this tool versus alternatives, prerequisites, or context. It simply states what the tool does without indicating scenarios where it's appropriate or any limitations. This lack of usage context leaves the agent without operational guidance.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
TDQS
With only one tool, there is no possibility of ambiguity or overlap between tools. The tool's purpose is clearly defined and distinct by default.
A single tool inherently has perfect naming consistency, as there are no other tools to compare against. The name 'generate' is simple and follows a verb-based pattern.
One tool is too few for a server's purpose, as it severely limits functionality and suggests the server is under-scoped. A typical MCP server should offer multiple operations to handle a domain comprehensively.
The tool surface is severely incomplete for a mermaid diagramming domain. It only provides generation, missing essential operations like validation, editing, listing diagram types, or managing diagram states, which are necessary for agent workflows.
Maintenance
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
Render, verify, describe, and safely edit Mermaid diagrams through MCP.
Collaborative whiteboard MCP server — create objects, connectors, C4 diagrams, and manage boards
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.
Related MCP Servers
- AlicenseBqualityCmaintenanceA Model Context Protocol server that validates and renders Mermaid diagrams.18856MIT
- -licenseNot gradedqualityNot gradedmaintenanceA server that implements the Model Context Protocol (MCP), providing an interface for LLM applications to generate mermaid.js visualizations and diagrams.
- AlicenseAqualityBmaintenanceA Model Context Protocol server that converts Mermaid diagram code into various image formats (PNG, JPG, SVG, PDF) with theme customization options for AI clients.39MIT
- AlicenseAqualityDmaintenanceAn MCP server that generates diagrams from Mermaid code in multiple formats (PNG, PDF, SVG).21MIT
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
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/peng-shawn/mermaid-mcp-server'
If you have feedback or need assistance with the MCP directory API, please join our Discord server