mermaid-mcp
Provides tools for managing Mermaid diagrams and collections, including listing, reading, creating, updating, and deleting diagrams and collections through the Mermaid REST API.
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., "@mermaid-mcplist my mermaid diagrams named 'flowchart'"
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
An MCP server that gives an AI agent full access to your Mermaid diagrams and collections — list, read, create, update and delete over the Mermaid REST API.
Two transports.
stdiofor local agents (Claude Code, opencode), stateless Streamable HTTP for remote clients and shared deployments.No database, no session state. It is a thin, well-behaved proxy in front of the Mermaid API: whatever the backend can do, the agent can do.
Per-caller credentials. Each HTTP request carries its own Mermaid API key, so one deployment can serve many users without leaking anyone's diagrams.
Tools
Tool | What it does |
| List diagrams. Optional |
| Fetch one diagram by id, including its full Mermaid source. |
| Create a diagram from a name and Mermaid source, optionally in a collection. |
| Change a diagram's |
| Permanently delete a diagram. |
| List collections (diagram folders). |
| Create a collection. |
| Delete a collection. Its diagrams survive and become unfiled. |
list_diagramsreturns the full source of every diagram in the page, so responses get large fast. Give the agent asearchterm or a smalllimitwhen it only needs an overview.
Related MCP server: MCP Diagram Server
Quick start
Local agent (stdio)
Create an API key in the Mermaid dashboard (avatar menu → API keys), then point your client at this server:
npm install
MERMAID_API_KEY=ek_... npm run start:stdioClaude Code
claude mcp add mermaid --env MERMAID_API_KEY=ek_... -- node /path/to/mermaid-mcp/src/index.js --stdioopencode — add to opencode.json:
{
"$schema": "https://opencode.ai/config.json",
"mcp": {
"mermaid": {
"type": "local",
"command": ["node", "/path/to/mermaid-mcp/src/index.js", "--stdio"],
"environment": { "MERMAID_API_KEY": "ek_..." },
"enabled": true
}
}
}Remote client (HTTP)
MERMAID_BASE_URL=https://mermaid.alward.dev PORT=8120 node src/index.jsThe endpoint is POST http://<host>:8120/mcp, stateless. Send the caller's key on every request:
curl -X POST http://localhost:8120/mcp \
-H 'content-type: application/json' \
-H 'accept: application/json, text/event-stream' \
-H "authorization: Bearer $MERMAID_API_KEY" \
-d '{"jsonrpc":"2.0","id":1,"method":"tools/list","params":{}}'accept must include both application/json and text/event-stream, as the MCP Streamable
HTTP spec requires.
opencode / other remote MCP clients:
{
"$schema": "https://opencode.ai/config.json",
"mcp": {
"mermaid": {
"type": "remote",
"url": "https://mermaid.example.com/mcp",
"enabled": true,
"headers": { "authorization": "Bearer ek_..." }
}
}
}Docker
docker build -t mermaid-mcp .
docker run -d -p 8120:8120 -e MERMAID_BASE_URL=https://mermaid.alward.dev mermaid-mcpThe image runs as the unprivileged node user and ships a HEALTHCHECK against /healthz, so
docker run reports healthy on its own.
Deploying to a server
The repo is the source of truth. Clone it on the host and build from the checkout:
git clone https://github.com/anas-alward/mermaid-mcp.git mcp-server
cd mcp-server && npm ci # only needed to run the suite on the hostTo deploy an update:
cd mcp-server && git pull
cd .. && docker compose build mcp && docker compose up -d mcp
docker compose ps # wait for (healthy)
curl -s localhost:8120/healthz # version confirms which build is liveTwo things to know when the server directory is a git checkout:
.envis gitignored, so it never travels with the clone. Create it on the host; the compose file declares itrequired: false, and the server only reads it for--stdio..dockerignoreexcludes.git, so clone history stays out of the build context and the image.
Without git on the host, rsync the tree instead — the deploy directory only needs to match the
repository, plus .env.
Authentication
The server holds no credentials of its own. In HTTP mode the key must arrive on the request, as either header:
authorization: Bearer ek_...
x-mermaid-api-key: ek_...A request without one gets 401 and a JSON-RPC error explaining how to fix it. MERMAID_API_KEY
is only consulted in --stdio mode, where there are no HTTP headers to read it from.
Changed in 1.0.0. 0.2.0 silently fell back to the server's
MERMAID_API_KEYwhen a request carried no key — which meant a publicly reachable deployment would hand one account's diagrams to anonymous callers. HTTP mode is now strict.
Upgrading from 0.2.x
Entry point moved:
node server.mjs→node src/index.js(add--stdiofor stdio mode). ContainerCMDand client configs need the new path.HTTP requests must carry their own key;
MERMAID_API_KEYis now stdio-only.MERMAID_HOST_HEADERis gone. It never worked —fetchwill not let you overrideHost— so if you were reaching a backend directly, pointMERMAID_BASE_URLat the address that routes to it.Tool names, parameters and responses are unchanged.
Configuration
All configuration is environment variables, validated at boot: a bad value stops the process with a message naming the variable, rather than failing later on the first tool call.
Variable | Default | Purpose |
|
| Origin of the Mermaid deployment. No trailing slash, no |
| — | Dashboard API key. stdio mode only; ignored in HTTP mode. |
|
| HTTP bind address. Use |
|
| HTTP port. |
|
| Path the MCP endpoint is served from. |
|
| Abort an upstream call that takes longer. |
|
| Largest accepted MCP request body. |
|
|
|
|
| Comma-separated browser origins, or |
| — | Comma-separated |
Copy .env.example as a starting point. The process does not read .env files itself — use your
process manager, docker run -e, or --env-file.
HTTP endpoints
Route | Purpose |
| MCP JSON-RPC. Stateless; no session id is issued. |
| Liveness/readiness for load balancers and the Docker healthcheck. |
| Service name, version and where things live. |
|
|
Errors are always JSON-RPC shaped: -32700 for a malformed body, -32600 for a bad request or
missing key, -32603 for an internal fault. Upstream failures (bad key, missing diagram, timeout)
come back as tool results with isError: true, so the agent can read what went wrong and retry
instead of seeing a transport crash.
Security knobs. Auth is a bearer token, not a cookie, so there is no CSRF surface; CORS_ORIGINS
only matters for browser clients. Set ALLOWED_HOSTS when the server is reachable from a browser to
close off DNS-rebinding. Terminate TLS in front of it — the server speaks plain HTTP.
Operations. Logs go to stderr, one line per event, with credential-shaped fields redacted. Set
LOG_LEVEL=debug to also see rejected requests. SIGINT/SIGTERM drain in-flight requests and
exit 0, with a 10s backstop.
Development
npm install
npm test # node:test — no network, no API key needed
npm run dev # HTTP mode with --watchThe suite runs against an in-process mock of the Mermaid API, so it is fast and hermetic. It covers the API client (auth, error mapping, timeouts, id encoding), all eight tools through a real MCP client, and the HTTP layer (auth, CORS, host validation, body limits, JSON-RPC error shapes).
Layout
src/
index.js entry point: transport selection, shutdown, fatal error handling
config.js environment parsing and validation
logger.js levelled stderr logging with redaction
api.js Mermaid REST client: auth, timeout, error translation
tools.js the eight MCP tools
http.js Express app, stateless Streamable HTTP, health, CORS, host checks
test/ node:test suites + mock backendAdding a tool means adding one server.registerTool(...) block in src/tools.js and a test in
test/tools.test.js. Nothing else needs to know about it.
Before you publish
git init, then push — CI runs the suite on Node 20 and 22.
License
MIT © 2026 Anas Alward. See LICENSE.
This server cannot be deployed
Maintenance
Related MCP Connectors
Create and manage Mermaid.js flowcharts and diagrams with AI agents via MCP.
Render, verify, describe, and safely edit Mermaid diagrams through MCP.
Generate dynamic Mermaid diagrams and charts with AI assistance. Customize styles and export diagr…
Let Claude, Cursor, or ChatGPT author Mermaid diagrams your team can read and share.
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.16 npm1MIT
- AlicenseNot gradedqualityDmaintenanceEnables creating, manipulating, and managing Mermaid diagrams with automatic saving and multi-format conversion from JSON, CSV, Python, Markdown, and plain text.8MIT
- FlicenseNot gradedqualityDmaintenanceEnables AI to create, edit, and manage Mermaid diagrams via MCP, with real-time preview in a browser-based editor.3-
- AlicenseNot gradedqualityBmaintenanceEnables AI agents to interact with a local Mermaid diagram editor via MCP, allowing them to get and set diagrams programmatically.11,734,476 npm13Apache 2.0