Mermaid MCP Server is an MCP server that helps agents turn large codebases (local folders or GitHub repositories) into Mermaid diagrams and render them as PNG images via Kroki, enabling fast, reliable understanding of a project’s structure and flow. When working with a new codebase, it’s easy to lose time jumping between folders and files. This server provides a clean, tool-based workflow for agen
Add this skill
npx mdskills install GittyBurstein/mermaid-mcp-serverWell-architected MCP server enabling agents to explore codebases and generate Mermaid diagrams with clear tool boundaries.
Mermaid MCP Server is an MCP server that helps agents turn large codebases (local folders or GitHub repositories) into Mermaid diagrams and render them as PNG images via Kroki, enabling fast, reliable understanding of a project’s structure and flow.
When working with a new codebase, it’s easy to lose time jumping between folders and files. This server provides a clean, tool-based workflow for agents to discover, read, and visualize a project — without guessing paths or inventing structure.
list_files → read_file → generate Mermaid → render_mermaid.PROJECT_ROOT.MAX_FILE_CHARS) and output directory (DIAGRAM_OUT_DIR).| Tool | Description |
|---|---|
list_files | List files from a local folder or a GitHub repo (supports root + glob filtering). |
read_file | Read file contents (local or GitHub) with a configurable max length. |
render_mermaid | Render Mermaid text via Kroki and return ImageContent (also saves to disk). |
list_filesReturns a list of files for a given source (local / github) with root + glob filtering.
source: "local" or "github"root: default "."glob: default "**/*"repo_url: required when source="github"ref: default "main"recursive: default true{
"source": "local",
"root": ".",
"glob": "**/*.py",
"recursive": true
}
{
"source": "github",
"repo_url": "https://github.com//",
"ref": "main",
"root": "src",
"glob": "**/*.py",
"recursive": true
}
read_fileReads file contents (local or GitHub) with a length limit.
source: "local" or "github"path: requiredrepo_url: required when source="github"ref: default "main"max_chars: default MAX_FILE_CHARS{
"source": "local",
"path": "src/server/server.py",
"max_chars": 200000
}
{
"source": "github",
"repo_url": "https://github.com//",
"ref": "main",
"path": "README.md",
"max_chars": 200000
}
render_mermaidAccepts Mermaid text, renders it to a PNG via Kroki, returns ImageContent, and saves the file to disk.
mermaid: required (string) — the Mermaid diagram source texttitle: optional (string) — used to derive the output filename (will be sanitized)ImageContent containing the rendered PNG bytesPROJECT_ROOT/DIAGRAM_OUT_DIR/.pngmermaid is empty → errorDIAGRAM_OUT_DIR (inside PROJECT_ROOT)PROJECT_ROOT/DIAGRAM_OUT_DIR/.png (default output dir: ./diagrams/).title (sanitized to be filesystem-safe). If title is missing, a default name is used..png already exists, it is overwritten.{
"mermaid": "flowchart LR\nA[Start] --> B[Build]\nB --> C[Run]\n",
"title": "my_flow"
}
github source).
├── README.md
├── Dockerfile
├── pyproject.toml
├── .env.example
├── .gitignore
└── src/
├── config.py # Env/config defaults
├── server/ # MCP server entrypoint
│ └── server.py
├── tools/ # MCP tools (list/read/render)
│ ├── list_files.py
│ ├── read_file.py
│ └── render_mermaid.py
├── sources/ # File sources behind one interface (Local / GitHub)
│ ├── local_source.py
│ ├── github_source.py
│ └── source_factory.py
├── core/ # Contracts + primitives (interfaces, errors, cache, pacing, rate limiting)
│ ├── interfaces.py # Source contract that shapes all implementations
│ ├── models.py
│ ├── errors.py
│ ├── paths.py # Shared path normalization + glob semantics (incl. **)
│ ├── cache.py
│ ├── pacing.py
│ └── rate_limiter.py
├── clients/ # External API clients (kept thin; shared policies live in core)
│ ├── kroki_client.py
│ └── github/
│ ├── client.py # HTTP + policy (cache/rate/pacing)
│ ├── inputs.py # normalize/validate inputs
│ └── refs.py # resolve refs (+ fallback)
├── resources/ # Mermaid styles and small assets
└── prompts/ # Server-side canonical prompts
For architecture details, see: ARCHITECTURE.md
Build and run with Docker (example):
# build image
docker build -t mermaid-mcp:latest .
# run container (example, mount project root and set env vars)
docker run --rm -it \
-v "$PWD":/app \
-e PROJECT_ROOT=/app \
-e KROKI_BASE_URL=https://kroki.io \
-e KROKI_TIMEOUT=20 \
-e DIAGRAM_OUT_DIR=diagrams \
mermaid-mcp:latest
git clone
cd
python -m venv .venv
.\.venv\Scripts\Activate.ps1
pip install .[dev]
python -m venv .venv
.venv\Scripts\activate.bat
pip install .[dev]
python -m venv .venv
source .venv/bin/activate
pip install .[dev]
This installs runtime dependencies and development extras (tests).
You can set env vars in your shell OR in the MCP client config that launches the server.
| Variable | Description | Used by |
|---|---|---|
PROJECT_ROOT | Local project root that the server is allowed to access (security boundary) | local_source |
KROKI_BASE_URL | e.g. https://kroki.io | render_mermaid |
KROKI_TIMEOUT | Kroki request timeout | render_mermaid |
DIAGRAM_OUT_DIR | Where to save PNGs (must be inside PROJECT_ROOT) | render_mermaid |
MAX_FILE_CHARS | Max characters to read from a file (prevents huge reads) | read_file |
| Variable | Description | Used by |
|---|---|---|
HTTP_VERIFY | Verify SSL certificates (as needed) | server |
GITHUB_TOKEN | Recommended to avoid GitHub rate limits; if set, adds an Authorization header | src/clients/github/client.py |
Example (Windows)
set PROJECT_ROOT=.
set KROKI_BASE_URL=https://kroki.io
set KROKI_TIMEOUT=20
set DIAGRAM_OUT_DIR=diagrams
set MAX_FILE_CHARS=200000
Example (macOS / Linux)
export PROJECT_ROOT=.
export KROKI_BASE_URL=https://kroki.io
export KROKI_TIMEOUT=20
export DIAGRAM_OUT_DIR=diagrams
export MAX_FILE_CHARS=200000
python src/server/server.py
mermaid-mcpAny MCP client that can launch a local stdio server can use this project. Below is an example configuration for Claude Desktop.
Claude Desktop stores MCP server definitions in a JSON config file.
Common locations:
%APPDATA%\Claude\claude_desktop_config.json~/Library/Application Support/Claude/claude_desktop_config.jsonIf the file doesn’t exist yet, create it.
claude_desktop_config.jsonExample (Windows):
{
"mcpServers": {
"mermaid-mcp": {
"command": "C:\\Users\\\\path\\to\\repo\\.venv\\Scripts\\python.exe",
"args": [
"C:\\Users\\\\path\\to\\repo\\src\\server\\server.py"
],
"env": {
"PROJECT_ROOT": "C:\\Users\\\\path\\to\\repo",
"KROKI_BASE_URL": "https://kroki.io",
"KROKI_TIMEOUT": "20",
"DIAGRAM_OUT_DIR": "diagrams",
"MAX_FILE_CHARS": "200000"
}
}
}
}
After saving the config file, fully close Claude Desktop and reopen it so the server is loaded.
Open Claude Desktop and check that the server tools appear (e.g. list_files, read_file, render_mermaid).
This project includes a canonical system prompt used to generate Mermaid diagrams in a consistent, tool-driven way. The prompt is registered on the MCP server under the name generate_mermaid_canonical and is defined in src/prompts/mermaid_prompt.py.
Two common ways to use it:
Client-supported prompts (recommended): If your MCP client supports server-side prompts, select the server mermaid-mcp, pick the prompt named generate_mermaid_canonical from the prompt list, and run it as the agent's system/instruction before invoking the tools. Using the server-registered prompt ensures agents always get the latest prompt text.
Copy & paste: If your client does not support server-side prompts, open src/prompts/mermaid_prompt.py, copy the prompt text, and paste it into the agent's system message or save it locally as a preset. Keep in mind you will need to update your local copy when the repository prompt changes.
Notes:
mermaid://styles/blue-flowchart to be read and embedded unchanged into generated diagrams.list_files → read_file → generate Mermaid → render_mermaid.Run the test suite:
pytest -q
This is a complete, realistic flow that demonstrates the intended pipeline:
list_files → read_file → generate Mermaid → render_mermaid.
{
"source": "github",
"repo_url": "https://github.com//",
"ref": "main",
"root": "src",
"glob": "**/*.py",
"recursive": true
}
Example selection (you choose based on what the repo contains):
src/server/server.pysrc/tools/list_files.pysrc/tools/read_file.pysrc/tools/render_mermaid.pysrc/core/interfaces.pysrc/clients/github/client.pysrc/clients/github/refs.pysrc/core/cache.pysrc/core/pacing.pysrc/core/rate_limiter.pysrc/clients/kroki_client.py{
"source": "github",
"repo_url": "https://github.com//",
"ref": "main",
"path": "src/server/server.py",
"max_chars": 200000
}
flowchart LR
A[Agent / Client] -->|list_files| B[MCP Server]
A -->|read_file| B
B --> C[Local/GitHub Source]
B --> D[Mermaid generation]
B -->|render_mermaid| E[Kroki API]
E --> F[PNG bytes]
F --> A
{
"mermaid": "",
"title": "repo_to_diagram"
}
For security and predictable behavior, see: Security boundaries
"Missing repo_url for github source" → you forgot repo_url with source="github""Missing file path" → you called read_file without path"Access outside project root is not allowed" → attempted to read outside PROJECT_ROOT"DIAGRAM_OUT_DIR must be within PROJECT_ROOT" → output dir is not inside PROJECT_ROOTNext, we plan to support more input sources beyond local folders and GitHub, so the server can generate Mermaid diagrams from additional code hosts and content providers (e.g., GitLab, Bitbucket, Azure DevOps Repos, as well as ZIP archives or single files via URL).
This will build on a unified Source abstraction: each new source will implement the same contract (list_files and read_file), while the tools remain unchanged—extending support will require only adding a new source implementation and registering it in the factory.
Install via CLI
npx mdskills install GittyBurstein/mermaid-mcp-serverMermaid MCP Server is a free, open-source AI agent skill. Mermaid MCP Server is an MCP server that helps agents turn large codebases (local folders or GitHub repositories) into Mermaid diagrams and render them as PNG images via Kroki, enabling fast, reliable understanding of a project’s structure and flow. When working with a new codebase, it’s easy to lose time jumping between folders and files. This server provides a clean, tool-based workflow for agen
Install Mermaid MCP Server with a single command:
npx mdskills install GittyBurstein/mermaid-mcp-serverThis downloads the skill files into your project and your AI agent picks them up automatically.
Mermaid MCP Server works with Claude Code, Claude Desktop, Cursor, Vscode Copilot, Windsurf, Continue Dev, Gemini Cli, Amp, Roo Code, Goose. Skills use the open SKILL.md format which is compatible with any AI coding agent that reads markdown instructions.