The Mermaid MCP Server analyzes codebases (local or GitHub) and generates visual Mermaid diagrams rendered as PNG images through a structured workflow.
List files from local project folders or GitHub repositories with filtering options (glob patterns, root paths, recursive traversal)
Read file contents from local or GitHub sources with configurable character limits (default 200,000 chars)
Render Mermaid diagrams to PNG images via Kroki API, returning image data and saving to disk with sanitized filenames
Follow structured pipeline: list files → read selected files → generate Mermaid diagram → render to PNG
Maintain security boundaries: Local file access restricted to configured
PROJECT_ROOTto prevent unauthorized accessConfigure via environment variables: Control file size limits (
MAX_FILE_CHARS), output directory (DIAGRAM_OUT_DIR), Kroki API settings, and GitHub authenticationIntegrate with MCP clients: Connect to Claude Desktop or other MCP-compatible clients via stdio server configuration
Use canonical prompts: Leverage server-side prompts that guide agents to generate consistent diagrams following best practices
Handle both local and remote sources: Work with local development environments or analyze public/private GitHub repositories with branch/ref selection through a unified interface
Enables listing and reading files from GitHub repositories, supporting branch/ref selection, glob filtering, and recursive directory traversal for codebase analysis and diagram generation.
Renders Mermaid diagram source text to PNG images via Kroki API, with automatic file saving and support for custom titles and output directory configuration.
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 of the main.py file in my local project"
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 — one MCP server to diagram any project (Local/GitHub → Mermaid → PNG)
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.
Why this server
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.
Key features
Local + GitHub sources: analyze either a local project folder or a remote repository.
Agent-friendly pipeline:
list_files→read_file→ generate Mermaid →render_mermaid.Safe local access boundary: local reads are restricted to
PROJECT_ROOT.Configurable limits: control max file size (
MAX_FILE_CHARS) and output directory (DIAGRAM_OUT_DIR).Portable output: rendered diagrams are returned as image content and also saved as PNG files.
It exposes three tools:
Tool | Description |
| List files from a local folder or a GitHub repo (supports root + glob filtering). |
| Read file contents (local or GitHub) with a configurable max length. |
| Render Mermaid text via Kroki and return |
1) list_files
Returns a list of files for a given source (local / github) with root + glob filtering.
Parameters
source:"local"or"github"root: default"."glob: default"**/*"repo_url: required whensource="github"ref: default"main"recursive: defaulttrue
Example (local)
Example (github)
2) read_file
Reads file contents (local or GitHub) with a length limit.
Parameters
source:"local"or"github"path: requiredrepo_url: required whensource="github"ref: default"main"max_chars: defaultMAX_FILE_CHARS
Example (local)
Example (github)
3) render_mermaid
Accepts Mermaid text, renders it to a PNG via Kroki, returns ImageContent, and saves the file to disk.
Parameters
mermaid: required (string) — the Mermaid diagram source texttitle: optional (string) — used to derive the output filename (will be sanitized)
Returns
ImageContentcontaining the rendered PNG bytesAlso writes the PNG file to
PROJECT_ROOT/DIAGRAM_OUT_DIR/<filename>.png
Behavior
If
mermaidis empty → errorFile is saved under
DIAGRAM_OUT_DIR(insidePROJECT_ROOT)Output path: the image is saved to
PROJECT_ROOT/DIAGRAM_OUT_DIR/<filename>.png(default output dir:./diagrams/).Filename: derived from
title(sanitized to be filesystem-safe). Iftitleis missing, a default name is used.Name collisions: if
<filename>.pngalready exists, it is overwritten.
Example
Requirements
Python 3.10+ (recommended)
Internet access (for Kroki, and for GitHub when using
githubsource)
Project structure
For architecture details, see: ARCHITECTURE.md
Docker (optional)
Build and run with Docker (example):
Installation & Setup
1) Clone the repo
2) Create a venv + install dependencies
Windows (PowerShell):
Windows (CMD):
macOS/Linux:
This installs runtime dependencies and development extras (tests).
3) Configuration (Environment Variables)
You can set env vars in your shell OR in the MCP client config that launches the server.
Required / Recommended
Variable | Description | Used by |
| Local project root that the server is allowed to access (security boundary) |
|
| e.g. |
|
| Kroki request timeout |
|
| Where to save PNGs (must be inside |
|
| Max characters to read from a file (prevents huge reads) |
|
Optional
Variable | Description | Used by |
| Verify SSL certificates (as needed) |
|
| Recommended to avoid GitHub rate limits; if set, adds an |
|
Example (Windows)
Example (macOS / Linux)
4) Run the server (stdio)
Server name: mermaid-mcp
Connect an MCP client (example: Claude Desktop)
Any MCP client that can launch a local stdio server can use this project. Below is an example configuration for Claude Desktop.
1) Locate Claude Desktop config
Claude Desktop stores MCP server definitions in a JSON config file.
Common locations:
Windows:
%APPDATA%\Claude\claude_desktop_config.jsonmacOS:
~/Library/Application Support/Claude/claude_desktop_config.json
If the file doesn’t exist yet, create it.
2) Add this server to claude_desktop_config.json
Example (Windows):
3) Restart Claude Desktop
After saving the config file, fully close Claude Desktop and reopen it so the server is loaded.
4) Verify tools are available
Open Claude Desktop and check that the server tools appear (e.g. list_files, read_file, render_mermaid).
Using the canonical prompt
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 namedgenerate_mermaid_canonicalfrom 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:
The canonical prompt enforces strict tool usage and requires the canonical style resource
mermaid://styles/blue-flowchartto be read and embedded unchanged into generated diagrams.The prompt expects the agent to follow the pipeline:
list_files→read_file→ generate Mermaid →render_mermaid.
Testing
Run the test suite:
End-to-end example:
This is a complete, realistic flow that demonstrates the intended pipeline:
list_files → read_file → generate Mermaid → render_mermaid.
Step 1 — List files from a GitHub repo
Step 2 — Pick a small set of important files (5–12)
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
Step 3 — Read the chosen files
Step 4 — Generate Mermaid from what you read
Step 5 — Render Mermaid to PNG
Security & Predictable Behavior
For security and predictable behavior, see: Security boundaries
Troubleshooting
"Missing repo_url for github source"→ you forgotrepo_urlwithsource="github""Missing file path"→ you calledread_filewithoutpath"Access outside project root is not allowed"→ attempted to read outsidePROJECT_ROOT"DIAGRAM_OUT_DIR must be within PROJECT_ROOT"→ output dir is not insidePROJECT_ROOT
Future work (additional sources)
Next, 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.