mcp-mermaidjs-to-image
Converts Mermaid.js diagram syntax into high-resolution PNG images, with support for many diagram types, syntax guidance, keyword validation, themes, backgrounds, scaling, and rendering diagrams from files.
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-mermaidjs-to-image Render this Mermaid flowchart to PNG: graph TD; A-->B"
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-mermaidjs-to-image (v0.1.0)
A high-performance Model Context Protocol (MCP) server that converts Mermaid.js diagram syntax into crisp, high-resolution PNG images.
Powered by the official Mermaid.js v12.3.0 engine, providing native support for 37+ diagram types (including native UML Use-Case, Swimlanes, Cloud Architecture, Network Packets, Kanban, and more).
Compatible with Antigravity, Cline, Codex, Claude Code, Cursor, and Claude Desktop.
Key Features
Latest Mermaid.js Engine (v12.3.0): Complete native support for all 37+ diagram types—UML Use-Case (
usecase-beta), Swimlanes (swimlane-beta), Flowcharts, Sequence Diagrams, Class Diagrams, Cloud Architecture, Network Packets, Kanban, GitGraphs, Mindmaps, and more.3-Step AI Workflow: Implements a progressive disclosure architecture:
get_supported_diagrams: Discover available keywords, aliases, and categories.get_diagram_syntax_guide: Retrieve precise grammar rules, connectors, and verified examples on demand.render_mermaid_to_png: Render crisp PNGs with mandatory keyword validation.
Mandatory Keyword Validation: Rejects requests missing or having invalid
diagram_type, returning a categorized list of available keywords to eliminate guesswork and syntax hallucinations.Smart Alias Normalization: Transparently maps aliases (
usecase/use-case→usecase-beta,swimlane/swimlanes→swimlane-beta) across arguments and syntax headers.Multimodal AI Ready: Returns the rendered diagram directly as an MCP
image/pngblock so multimodal AI assistants can visually inspect and verify their diagrams in real time.AI-Optimized Verbose Diagnostics: If syntax fails, returns actionable diagnostics with line numbers, code frames (
> Line N | ... ^), and diagram-specific remediation hints withisError: trueso the AI can self-correct immediately.Sub-100ms Rendering: Uses a persistent headless browser singleton with lazy initialization and an automatic 5-minute idle shutdown.
High-DPI Retina Output: Renders at 2x scale by default (configurable up to 3x or 4x).
Flexible Themes & Backgrounds: Supports
default,neutral,dark,forest, andbasethemes, plus solid or transparent backgrounds.Zero Cloud Dependencies: Runs 100% locally with automatic fallback to system Microsoft Edge or Google Chrome if needed.
Related MCP server: Mermaid MCP Server
The 3-Step AI Agent Workflow
To avoid flooding the AI's context window while guaranteeing 100% syntax compliance, the server separates discovery, syntax knowledge, and image rasterization into three focused tools:
flowchart TD
AI["🤖 Calling AI Agent"]
subgraph MCP ["📦 mcp-mermaidjs-to-image"]
T1["🛠️ 1. get_supported_diagrams\n(Mermaid v12.3.0 Catalog)"]
T2["🛠️ 2. get_diagram_syntax_guide\n(Exact grammar, connectors, pitfalls & examples)"]
T3["🛠️ 3. render_mermaid_to_png\n(Mandatory diagram_type + high-DPI rasterization)"]
end
AI -->|"1. Discover available types"| T1
T1 -.->|"Returns keywords & points to guide"| AI
AI -->|"2. Query syntax for specific type (e.g. usecase-beta)"| T2
T2 -.->|"Returns precise syntax & verified examples"| AI
AI -->|"3. Render diagram (diagram_type + syntax)"| T3
T3 -->|"Returns high-resolution PNG image"| AIMCP Tools Reference
Tool 1: get_supported_diagrams
Returns the Mermaid.js engine version (v12.3.0) and the complete catalog of all 37+ supported diagram types, keywords, aliases, and categories.
Parameters:
Parameter | Type | Required | Description |
|
| No | Optional category filter: |
|
| No | Optional search keyword to filter by name, keyword, or description |
Output:
Formatted markdown table of supported diagram types with accepted aliases and a guide prompt to query
get_diagram_syntax_guide.
Tool 2: get_diagram_syntax_guide
Returns authoritative syntax rules, keyword requirements, relationship connectors, common pitfalls, and verified working examples for a specific diagram type.
Parameters:
Parameter | Type | Required | Description |
|
| Yes | The diagram keyword or alias (e.g. |
Output:
Exact header declaration requirements (e.g.
usecase-beta\ndirection LR).Core syntax elements and item declarations.
Connector operators (e.g.
-->,..> :include,..> :extend,--|>).Common pitfalls to avoid (e.g. "Do NOT write
system { }, usesystemBoundary ... end").Minimal and complete verified working examples.
Tool 3: render_mermaid_to_png
Converts Mermaid diagram syntax directly into a high-resolution PNG image.
Parameters:
Parameter | Type | Required | Default | Description |
|
| Yes | — | Required diagram type keyword (e.g. |
|
| Yes | — | The Mermaid diagram code (e.g. |
|
| No |
| Optional file path where the PNG will be saved on disk |
|
| No |
| Visual theme: |
|
| No |
| Background color: |
|
| No |
| Resolution scale factor (1 for standard, 2 for retina, 3 for ultra-crisp) |
|
| No |
| Viewport width hint in pixels |
|
| No |
| Viewport height hint in pixels |
Output:
image: Base64-encodedimage/pngbuffer for inline AI inspection.text: Execution summary with dimensions, scale factor, and saved path.
Tool 4: render_mermaid_file
Reads a local .mmd or .mermaid file and renders it directly to a PNG file on disk.
Parameters:
Parameter | Type | Required | Default | Description |
|
| Yes | — | Required diagram type keyword |
|
| Yes | — | Path to source |
|
| Yes | — | Destination path for the |
|
| No |
| Visual theme |
|
| No |
| Background color |
|
| No |
| Resolution scale factor |
Mandatory Keyword Validation & Rejection Protocol
To prevent syntax confusion and incorrect diagram type selection, render_mermaid_to_png and render_mermaid_file strictly require the diagram_type parameter.
If an AI passes an invalid or missing diagram_type, the tool immediately responds with isError: true and an informative rejection message:
❌ **Diagram Render Rejected: Mandatory Diagram Type Missing or Invalid**
Unrecognized diagram type: "invalid_type".
Mermaid.js engine v12.3.0 requires an explicit `diagram_type` parameter to ensure accurate rendering and prevent syntax mismatch.
### Available Keywords by Category:
- **UML & Process**: `usecase-beta`, `swimlane-beta`, `flowchart`, `sequenceDiagram`, `classDiagram`, `stateDiagram-v2`, `erDiagram`, `agentflow-beta`
- **Architecture & Systems**: `architecture`, `C4Context`, `C4Container`, `C4Component`, `packet-beta`, `block-beta`, `flowchart-elk`, `eventmodeling`, `wardley-beta`
- **Project Planning**: `gantt`, `timeline`, `kanban`, `gitGraph`, `journey`
- **Charts & Visual Analytics**: `pie`, `quadrantChart`, `xychart-beta`, `sankey-beta`, `mindmap`, `radar-beta`, `venn-beta`, `treemap`, `ishikawa-beta`, `cynefin-beta`
- **Grammar & Specs**: `railroad-beta`, `railroad-ebnf-beta`, `railroad-abnf-beta`, `railroad-peg-beta`, `requirementDiagram`, `treeView-beta`
💡 **How to proceed**:
1. Call `get_supported_diagrams` to browse all diagram options and accepted aliases.
2. Call `get_diagram_syntax_guide({ diagram_type: "<keyword>" })` to retrieve exact syntax rules and verified examples.
3. Provide the valid `diagram_type` alongside your `mermaid_syntax` to render your diagram.Supported Diagram Types (Mermaid v12.3.0)
Category | Canonical Keywords | Accepted Aliases |
UML & Process |
|
|
Architecture & Systems |
|
|
Project Planning |
|
|
Charts & Visual Analytics |
|
|
Grammar & Specs |
|
|
Quick Setup & Client Configurations
1. Build & Link Locally
git clone <repo-url> mcp-mermaidjs-to-image
cd mcp-mermaidjs-to-image
npm install
npm run build
npm linkCompiled entry point:
c:\Users\Public\Downloads\projects\mcp-mermaidjs-to-image\dist\index.js
2. Client Configurations
Antigravity
Add to your Antigravity MCP configuration (~/.gemini/config/mcp_config.json):
{
"mcpServers": {
"mermaid-to-image": {
"command": "node",
"args": ["c:/Users/Public/Downloads/projects/mcp-mermaidjs-to-image/dist/index.js"],
"disabled": false
}
}
}Cline (cline_mcp_settings.json)
{
"mcpServers": {
"mermaid-to-image": {
"command": "node",
"args": ["c:/Users/Public/Downloads/projects/mcp-mermaidjs-to-image/dist/index.js"]
}
}
}Claude Code (CLI)
claude mcp add mermaid-to-image -- node c:/Users/Public/Downloads/projects/mcp-mermaidjs-to-image/dist/index.jsCodex / Cursor (mcp.json)
{
"mcpServers": {
"mermaid-to-image": {
"command": "node",
"args": ["c:/Users/Public/Downloads/projects/mcp-mermaidjs-to-image/dist/index.js"]
}
}
}Claude Desktop (claude_desktop_config.json)
{
"mcpServers": {
"mermaid-to-image": {
"command": "node",
"args": ["c:/Users/Public/Downloads/projects/mcp-mermaidjs-to-image/dist/index.js"]
}
}
}Verbose Error Diagnostics Example
When an AI provides broken syntax (e.g. B -- invalid syntax -- C), the tool sets isError: true and responds with detailed markdown:
❌ **Mermaid Render Failed: Syntax Error**
- **Diagram Type**: `graph`
- **Location**: Line 3
**Code Context**:1 | graph TD
2 | A[Start] --> B(Valid Step)
3 | B -- invalid syntax -- C | ^ 4 | C --> D[End]
**Error Details**:
Lexical error on line 3. Unrecognized text.
...nvalid syntax -- C C --> D[End
-----------------------^
💡 **Remediation Hint**:
Check connector arrows (e.g. `-->`, `---`, `-.->`, `==>`). If you have labels on links, wrap them in pipes: `A -->|label| B` or use `A -- label --> B`. Ensure node labels containing special characters (brackets, parens, quotes) are enclosed in double quotes, e.g. `id["Node (Label)"]`.Testing
Run the automated test suites:
# 1. Renderer unit tests
npm test
# 2. Full MCP Tools protocol & validation test suite
node --import tsx test/mcp-tools-suite.test.tsOutput:
🧪 Starting MCP Tools Test Suite...
✅ Connected to MCP Server via Stdio Transport.
--- Test 1: List Tools ---
Available tools: [
'get_supported_diagrams',
'get_diagram_syntax_guide',
'render_mermaid_to_png',
'render_mermaid_file'
]
✅ Test 1 Passed: All 4 tools registered.
--- Test 2: get_supported_diagrams ---
✅ Test 2 Passed: get_supported_diagrams returned engine version & catalog.
--- Test 3: get_diagram_syntax_guide (usecase-beta) ---
✅ Test 3 Passed: get_diagram_syntax_guide returned detailed grammar rules and examples.
--- Test 4: Rejection on Invalid diagram_type ---
✅ Test 4 Passed: Properly rejected invalid diagram_type and returned keyword feedback.
--- Test 5: Render Use-Case Diagram with Alias Normalization ---
✅ Test 5 Passed: Successfully normalized alias and rendered native UML Use-Case diagram to PNG.
--- Test 6: Render Swimlane Diagram ---
✅ Test 6 Passed: Successfully rendered native Swimlanes diagram to PNG.
🎉 ALL 6 TESTS PASSED SUCCESSFULLY!License
MIT
Available Tools
4 toolsget_diagram_syntax_guideB
Returns authoritative syntax rules, keyword requirements, relationship connectors, common pitfalls, and verified working examples for a specific diagram type (e.g. "usecase-beta", "swimlane-beta", "sequenceDiagram", "architecture", "flowchart").
Inputs: diagram_type (required).
get_supported_diagramsA
Returns the Mermaid.js engine version (v12.3.0) and the full catalog of all 37+ supported diagram types, keywords, aliases, and categories. Pointers guide the AI to query get_diagram_syntax_guide for deep syntax rules.
Inputs: query, category.
render_mermaid_fileB
Reads a local .mmd or .mermaid file, validates the mandatory diagram_type, renders it into a high-resolution PNG image, and writes the output file to disk.
Inputs: input_path (required), output_path (required), diagram_type (required), scale, +4 more.
render_mermaid_to_pngA
Renders Mermaid.js diagram syntax into a high-resolution PNG image. Requires an explicit diagram_type keyword (e.g. "usecase-beta", "swimlane-beta", "sequenceDiagram", "flowchart"). Rejects requests if diagram_type is missing or invalid, returning valid keyword feedback.
Inputs: diagram_type (required), mermaid_syntax (required), scale, theme, +4 more.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 4 tools
The four tools split cleanly into two discovery tools (catalog vs. per-type syntax) and two rendering tools (inline source vs. file input), and each description states its input/output mode explicitly. render_mermaid_to_png vs. render_mermaid_file is the only near-pair, and the inline-vs-disk distinction is unambiguous.
All names follow a consistent verb_noun snake_case pattern (get_supported_diagrams, get_diagram_syntax_guide, render_mermaid_to_png, render_mermaid_file). The two get_ tools are discovery and the two render_ tools are execution, reinforcing the pattern semantically.
Four tools is well within a tight, focused scope for a single-purpose rendering server: two are needed because diagram syntax knowledge must be looked up before rendering, and two cover the two legitimate input modes. No tool looks redundant or missing at this size.
The lifecycle — discover supported types, fetch syntax rules, render from string or file — is covered end to end, with validation feedback on bad diagram_type. Minor gaps remain around output options (e.g. SVG/PDF or theme/size control) that agents could otherwise want, but the core workflow has no dead ends.
Maintenance
Related MCP Connectors
Generate dynamic Mermaid diagrams and charts with AI assistance. Customize styles and export diagr…
Create workflow, sequence, architecture, and mind map diagrams via AI assistants.
Let Claude, Cursor, or ChatGPT author Mermaid diagrams your team can read and share.
Create and manage Mermaid.js flowcharts and diagrams with AI agents via MCP.
Related MCP Servers
- AlicenseBqualityDmaintenanceEnables AI assistants to generate and render Mermaid diagrams (flowcharts, sequence diagrams, etc.) as PNG/SVG images with local file saving and HTTP access URLs. Supports batch processing and intelligent caching for efficient diagram creation.128 npm1MIT
- AlicenseNot gradedqualityDmaintenanceEnables agents to search official Mermaid diagram syntax documentation and validate Mermaid diagram code before presenting it to users, ensuring syntactically correct flowcharts, sequence diagrams, class diagrams, and other Mermaid visualizations.805 npmMIT
- FlicenseNot gradedqualityDmaintenanceEnables the dynamic generation of various software development diagrams, such as flowcharts, sequence diagrams, and architecture diagrams, using Mermaid syntax. It includes tools for diagram validation and provides instructions for exporting results to multiple formats including SVG and PNG.-
- AlicenseAqualityCmaintenanceLets agents construct Mermaid diagrams from structured JSON IR and render them as PNG or SVG.3MIT