mermaid-mcp-server Public
About
MCP server for generating Mermaid diagrams from projects (local/GitHub) and rendering via Kroki.
Details
- Author
- gittyburstein
- Categories
- Developer Tools, Other
Jump to
3) Configuration (Environment Variables)
You can set env vars in your shell OR in the MCP client config that launches the server.
set PROJECT_ROOT=. set KROKI_BASE_URL=https://kroki.io set KROKI_TIMEOUT=20 set DIAGRAM_OUT_DIR=diagrams set MAX_FILE_CHARS=200000
export PROJECT_ROOT=. export KROKI_BASE_URL=https://kroki.io export KROKI_TIMEOUT=20 export DIAGRAM_OUT_DIR=diagrams export MAX_FILE_CHARS=200000
mermaid-mcp — one MCP server to diagram any project (Local/GitHub → Mermaid → PNG)
Mermaid MCP Serveris an MCP server that helps agents turn large codebases (local folders or GitHub repositories) intoMermaid diagramsand render them asPNG imagesviaKroki, 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 todiscover,read, andvisualizea project — without guessing paths or inventing structure.
- 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 toPROJECT_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.
Returns a list of files for a given source (local/github) withroot+globfiltering.
- source:"local"or"github"
- root: default"."
- glob: default"/"
- repo_url: required whensource="github"
- ref: default"main"
- recursive: defaulttrue
{ "source": "local", "root": ".", "glob": "/.py", "recursive": true }
{ "source": "github", "repo_url": "https://github.com/<owner>/<repo>", "ref": "main", "root": "src", "glob": "/.py", "recursive": true }
Reads file contents (local or GitHub) with a length limit.
- source:"local"or"github"
- path: required
- repo_url: required whensource="github"
- ref: default"main"
- max_chars: defaultMAX_FILE_CHARS
{ "source": "local", "path": "src/server/server.py", "max_chars": 200000 }
{ "source": "github", "repo_url": "https://github.com/<owner>/<repo>", "ref": "main", "path": "README.md", "max_chars": 200000 }
Accepts Mermaid text, renders it to a PNG via Kroki, returnsImageContent, and saves the file to disk.
- mermaid: required (string) — the Mermaid diagram source text
- title: optional (string) — used to derive the output filename (will be sanitized)
- ImageContentcontaining the rendered PNG bytes
- Also writes the PNG file toPROJECT_ROOT/DIAGRAM_OUT_DIR/<filename>.png
- Ifmermaidis empty → error
- File is saved underDIAGRAM_OUT_DIR(insidePROJECT_ROOT)
- Output path: the image is saved toPROJECT_ROOT/DIAGRAM_OUT_DIR/<filename>.png(default output dir:./diagrams/).
- Filename: derived fromtitle(sanitized to be filesystem-safe). Iftitleis missing, a default name is used.
- Name collisions: if<filename>.pngalready exists, it is overwritten.
{ "mermaid": "flowchart LR\nA[Start] --> B[Build]\nB --> C[Run]\n", "title": "my_flow" }
- Python 3.10+ (recommended)
- Internet access (for Kroki, and for GitHub when usinggithubsource)
. ├── 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 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 <REPO_URL> cd <REPO_DIR>
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).
3) Configuration (Environment Variables)
You can set env vars in your shell OR in the MCP client config that launches the server.
set PROJECT_ROOT=. set KROKI_BASE_URL=https://kroki.io set KROKI_TIMEOUT=20 set DIAGRAM_OUT_DIR=diagrams set MAX_FILE_CHARS=200000
export PROJECT_ROOT=. export KROKI_BASE_URL=https://kroki.io export KROKI_TIMEOUT=20 export DIAGRAM_OUT_DIR=diagrams export MAX_FILE_CHARS=200000
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.
Claude Desktop stores MCP server definitions in a JSON config file.
- Windows:%APPDATA%\Claude\claude_desktop_config.json
- macOS:~/Library/Application Support/Claude/claude_desktop_config.json
If the file doesn’t exist yet, create it.
2) Add this server toclaude_desktop_config.json
{ "mcpServers": { "mermaid-mcp": { "command": "C:\\Users\\<YOU>\\path\\to\\repo\\.venv\\Scripts\\python.exe", "args": [ "C:\\Users\\<YOU>\\path\\to\\repo\\src\\server\\server.py" ], "env": { "PROJECT_ROOT": "C:\\Users\\<YOU>\\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 namegenerate_mermaid_canonicaland is defined insrc/prompts/mermaid_prompt.py.
-
Client-supported prompts (recommended): If your MCP client supports server-side prompts, select the servermermaid-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, opensrc/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.
- The canonical prompt enforces strict tool usage and requires the canonical style resourcemermaid://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.
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/<owner>/<repo>", "ref": "main", "root": "src", "glob": "/.py", "recursive": true }
Step 2 — Pick a small set of important files (5–12)
Example selection (you choose based on what the repo contains):
- src/server/server.py
- src/tools/list_files.py
- src/tools/read_file.py
- src/tools/render_mermaid.py
- src/core/interfaces.py
- src/clients/github/client.py
- src/clients/github/refs.py
- src/core/cache.py
- src/core/pacing.py
- src/core/rate_limiter.py
- src/clients/kroki_client.py
{ "source": "github", "repo_url": "https://github.com/<owner>/<repo>", "ref": "main", "path": "src/server/server.py", "max_chars": 200000 }
Step 4 — Generate Mermaid from what you read
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": "<paste the Mermaid from Step 4 (or the generated Mermaid diagram)>", "title": "repo_to_diagram" }
For security and predictable behavior, see:Security boundaries
- "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
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 unifiedSourceabstraction: each new source will implement the same contract (list_filesandread_file), while the tools remain unchanged—extending support will require only adding a new source implementation and registering it in the factory.
This is a web browser that enables your coding agent, such as Claude Code, to visit websites on your behalf and assist you in identifying bugs or creating UI test cases.
Extentos is a multi-vendor development platform for adding smart-glasses capabilities to existing iOS and Android apps. The simplest analogy is Stripe for smart glasses
An MCP server tailored for React Native–first development using Gluestack UI
Create and read feature flags, review experiments, generate flag types, search docs, and interact with GrowthBook's feature flagging and experimentation platform.
Gives AI agents public URLs (tunnels) for localhost, live HTTP traffic inspection, snapshot publishing, and access control.
Understand, develop, and debug authorization policies in Oso Cloud.
Up-to-date documentation for your coding agent. Covers 1000s of public repos and sites. Built by ref.tools
Points agents to the canonical Agentry install docs for errors, product analytics, and deploy attribution.
Gives coding agents deterministic, read-only documentation handoffs with edit boundaries, ownership, and required checks before repository changes.
Deterministic JSON checks with signed evidence and x402-paid execution
Search Apple's Developer Documentation with smart search and wildcard support.
Sign in to leave a review
Use Google, GitHub, or an email account so ratings stay tied to real people.
No reviews posted yet.





