diagram-mcp
diagram-mcp
MCP 服务器,将图表即代码文本渲染为您磁盘上的 PNG 文件。无需浏览器、无需网络、无需外部服务。适合生成流程图,放入文档、工单或 README 中。

工具
render_diagram:将代码渲染为 PNG,返回文件路径preview_diagram:将图表绘制为文本图形,直接显示在对话中,不写入文件validate_diagram:解析并报告带行号的错误,不写入任何内容diagram_syntax:语言参考
Related MCP server: mermaid-mcp
安装
需要 Node 20.12+。
git clone https://github.com/JVmano/diagram-mcp.git
cd diagram-mcp
npm install
npm run build然后将其注册到 Claude Code:
claude mcp add diagram --scope user \
--env DIAGRAM_MCP_OUTPUT_DIR=$HOME/Documents/diagram-renders \
-- node "$(pwd)/dist/index.js"或者手动将其添加到 .mcp.json / 您的用户配置:
{
"mcpServers": {
"diagram": {
"type": "stdio",
"command": "node",
"args": ["/absolute/path/to/diagram-mcp/dist/index.js"],
"env": { "DIAGRAM_MCP_OUTPUT_DIR": "/absolute/path/to/renders" }
}
}
}重启会话,然后请求一个图表。拉取更改后,再次运行 npm run build。
语言
title "Reward approval flow"
direction TB
node event "Conversion recorded" shape=rounded
node auto "Auto-approve?" shape=diamond size=200x100
node queue "Manual review queue"
event -> auto
auto -> queue "no"形状:rect、rounded、ellipse、diamond、hexagon。连接:from -> to ["label"] [style=solid|dashed]。使用 at=x,y 指定的位置是可选的。省略它们,布局将自动放置形状。调用 diagram_syntax 获取完整参考。
配置
全部为可选配置,且都有默认值。参阅 .env.example。渲染输出到 DIAGRAM_MCP_OUTPUT_DIR(默认 ~/Documents/diagram-renders)。显式的 outputPath 必须位于该目录或工作目录内,除非 DIAGRAM_MCP_ALLOW_ANY_OUTPUT_PATH=true。
开发
npm test # unit tests
npm run test:e2e # builds, then drives the server over stdio
npm run verify # typecheck, test, build, e2esrc/core 中的解析器、布局和 SVG 生成与一个本地图表编辑器项目共享;当该项目被检出到相邻目录时,npm run check:sync 会将它们与该项目进行差异比较。
许可证
MIT
Available Tools
4 toolsdiagram_syntaxDiagram language referenceARead-onlyIdempotent
Return the full diagram-as-code language reference, with shapes, options and a worked example.
Inputs: no named parameters.
preview_diagramPreview diagram as textARead-onlyIdempotent
Draw the diagram as text art so it can be shown directly in the conversation. Writes no file. Use render_diagram when a PNG is needed.
Inputs: code (required), maxCols.
render_diagramRender diagram to PNGA
Render diagram-as-code text to a PNG file and return the path. Runs locally with no browser and no network. Returns an error listing the offending line numbers if the code does not parse.
Inputs: code (required), name, scale, padding, +3 more.
validate_diagramValidate diagram codeARead-onlyIdempotent
Parse diagram code and report errors and warnings with line numbers, without writing any file.
Inputs: code (required).
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 4 tools
Each tool has a distinct purpose: syntax reference, validation, text preview, and PNG rendering. The descriptions clearly differentiate the outputs, and render_diagram explicitly notes when to use it over preview_diagram.
Three tools follow the verb_diagram pattern (render_diagram, validate_diagram, preview_diagram), while diagram_syntax reverses the order. The convention is still readable and consistent in style, with only a minor deviation.
Four tools is well-scoped for a diagram-as-code server. Each tool covers a necessary part of the workflow without redundancy or unnecessary bulk.
The toolset covers the full authoring loop: learn the syntax, validate the code, preview as text, and render to a PNG file. There are no obvious missing operations for the stated local rendering purpose.
Maintenance
Related MCP Connectors
Render, validate, encode/decode PlantUML diagram-as-code; 22 diagram types. Free, no auth.
Draws UI wireframes from a small text language: multi-screen boards with notes and flow arrows.
Render, verify, describe, and safely edit Mermaid diagrams through MCP.
Diagrams, badges, charts and QR codes as plain image URLs you can paste into Markdown.
Related MCP Servers
- AlicenseAqualityDmaintenanceConverts Markdown files into professional diagrams such as flowcharts, mind maps, and architecture diagrams using Mermaid.js and custom SVG renderers. It enables users to list, render, and export visualizations in multiple formats including SVG, PNG, and PDF.3MIT
- AlicenseAqualityDmaintenanceRenders Mermaid diagram markup to PNG images using Puppeteer/Chromium. Enables AI-generated diagrams to be previewed inline and saved to disk.114 npmMIT
- FlicenseBqualityCmaintenanceEnables creating and maintaining technical diagrams from .dot sources, with validation, rendering to SVG/PNG/PDF, and publishing into Markdown while automatically partitioning oversized graphs.6-
- AlicenseNot gradedqualityBmaintenanceEnables AI assistants and coding tools to turn a few lines describing a system into clean, hand-sketched architecture diagrams in a consistent style, saving them as SVG or PNG files. Supports themes, automatic product icons, groups, sequence diagrams and cloud icon packs.1MIT