compile-d2LABSCO SUMMARY
The diagram is checked before it is drawn.
Compiling first is what makes this usable in a loop: the model gets told exactly where the syntax broke, fixes it, and only then renders — and in ASCII mode it can read its own output and iterate without a human looking at the picture.
What it is
A Go server for D2, the declarative diagramming language. It compiles D2 source to catch syntax errors before anything renders, produces the diagram in the format you asked for, and carries a built-in cheat sheet so the model has the syntax to hand rather than guessing at it.
What you get
compile-d2— validates D2 source and surfaces syntax errors, taking eithercodeor afile_pathrender-d2— renders topng,svgorascii, withascii_modechoosingextendedUnicode box drawing orstandardbasic characters; ASCII is the one an LLM can read backfetch_d2_cheat_sheet— a Markdown reference covering shapes, styling and layout, useful as support material in a prompt- Optional file output with
--write-files, so rendered diagrams land in a mounted directory rather than only in the response
Requirements
Install with go install github.com/h0rv/d2-mcp@latest, build from source, or run the container image ghcr.io/h0rv/d2-mcp:main. PNG output needs rsvg-convert from librsvg present — install it with brew, apt or apk — and without it the server removes png from the format enum and falls back to SVG rather than failing; the Docker image ships librsvg and fallback fonts, so PNG works there out of the box. Defaults to stdio; --transport http serves the streamable endpoint at /mcp and --transport sse the legacy one, with MCP_TRANSPORT and PORT as environment overrides. Writing files requires a bind mount, since the container has no view of your working tree otherwise.
Setup effort
One command — go install github.com/h0rv/d2-mcp@latest
USE CASES
Drawing the architecture you just described
Compile the D2 first to catch errors, then render the same source to the format you want.
Letting the model check its own diagram
Render to ASCII so the output comes back as text the model can read and refine, rather than an image it cannot inspect.
Writing a diagram into the repository
Run with file output and a mounted working directory so the rendered file lands next to the code it documents.
Getting the syntax right without leaving the chat
Pull the cheat sheet into the prompt so shapes, styling and layout conventions are available before the first attempt.
Validating a diagram file in place
Both tools take a file path as well as inline code, so an existing .d2 file can be checked without pasting it.
3 tools
Listed in project docs. Your client may show a different list.
render-d2fetch_d2_cheat_sheetBEFORE YOU INSTALL
What to know first
Tools you get
3 tools named in the project's documentation.
Where it runs
Both documented clients run the server on your machine.
INSTALLATION
Connect your client
Server setup
go install github.com/h0rv/d2-mcp@latestMCP Clients
Claude Desktop, oterm
{
"mcpServers": {
"d2": {
"command": "<YOUR_ABSOLUTE_PATH>/d2-mcp",
"args": [
"--image-type",
"png"
]
}
}
}