Mermaid MCP is a Model Context Protocol server that provides programmatic Mermaid diagram generation
to LLM agents. It wraps the mcp-mermaid npm package (v0.4.1) in a Docker container
with headless Chromium, enabling AI agents to convert Mermaid syntax into PNG images (base64),
raw SVG markup, saved PNG files, or public mermaid.ink URLs on demand.
The server exposes a single MCP tool (generate_mermaid_diagram) over SSE transport
on port 3033, routed through Traefik at mermaid-mcp.home. It is part of the
MCP Tools Stack alongside Grafana MCP, Hugging Face MCP, and PubMed MCP.
Key value: Allows any MCP-compatible agent (Claude Code, Gemini CLI, n8n)
to generate diagrams without requiring a browser or local Mermaid installation.
MCP Tools
1
Transport
SSE
Port
3033
Base Image
Node 20
Output Formats
6
Package
mcp-mermaid 0.4.1
2. Runtime Architecture
Diagram A -- Runtime Request Flow
Request Flow
An MCP client (Claude Code, Gemini CLI, n8n) sends a generate_mermaid_diagram tool call over SSE transport to mermaid-mcp.home.
Traefik terminates TLS and proxies the request to the mermaid-mcp container on port 3033.
The MCP server validates the input (Mermaid syntax, theme, background color, output type) using Zod schemas.
mermaid-isomorphic renders the Mermaid syntax into SVG using a cached renderer instance.
If a raster output is needed (base64 or file), Playwright drives headless Chromium to capture a PNG screenshot of the rendered SVG.
The result is returned to the client as base64 image data, raw SVG text, a saved file path, or a public mermaid.ink URL.
5. Public Interfaces
MCP Tools
The server exposes a single tool via the MCP protocol:
Tool
Description
generate_mermaid_diagram
Generate mermaid diagram and chart with mermaid syntax dynamically. Converts Mermaid text definitions into rendered diagrams.
Input Parameters
Parameter
Type
Required
Default
Description
mermaid
string
Yes
--
The Mermaid diagram syntax to render (e.g., graph TD; A-->B;)
Chromium (installed via Playwright with system deps)
Exposed port
3033
CMD
mcp-mermaid -t sse -p 3033 -H 0.0.0.0
Restart policy
unless-stopped
Docker network
hosting_web (external)
Environment variables
None required
Traefik labels
traefik.enable=false (routed via file provider in dynamic.yml)
External hostname
mermaid-mcp.home (LAN only via Pi-hole DNS)
Build and Deploy
# Build the image
cd /home/rod/_rod/_mcp-tools
docker compose build --no-cache mermaid-mcp
# Deploy
docker compose up -d mermaid-mcp
# View logs
docker logs -f mermaid-mcp
# Health check
curl -s http://mermaid-mcp.home/sse
Dockerfile Walkthrough
FROM node:20-bookworm-slim
WORKDIR /app
# Skip Playwright's browser download during npm install,
# then install separately with system dependencies
ENV PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1
RUN npm install -g mcp-mermaid
# Playwright installs Chromium + required Debian system libs
RUN npx playwright install --with-deps chromium
EXPOSE 3033
CMD ["mcp-mermaid", "-t", "sse", "-p", "3033", "-H", "0.0.0.0"]
Why two-step Playwright install? Setting PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1
during npm install prevents downloading browsers redundantly. The explicit
npx playwright install --with-deps chromium then installs only Chromium along with
the correct system dependencies (libatk, libcups, libnss3, etc.) for the Debian Bookworm base.