d2-mcp
About
Create, validate, and render diagrams from D2 (Declarative Diagramming) code into SVG and PNG formats.
Details
- Author
- h0rv
- Categories
- Developer Tools, Other, Design
Jump to
Setup
Install d2-mcp in your MCP client (Claude Desktop, Cursor, Windsurf, and others).
Repository: https://github.com/h0rv/d2-mcp
Follow the installation instructions in the repository README, then restart your MCP client.
A Model Context Protocol (MCP) server for working withD2: Declarative Diagramming, enabling seamless integration of diagram creation and validation into your development workflow.
- Compile D2 Code
- Validate D2 syntax and catch errors before rendering
- Get immediate feedback on diagram structure and syntax
- Accepts either direct code or file path to D2 file
- Generate diagrams for visual feedback and refinement
- Support PNG, SVG, and ASCII output formats
- Accepts either direct code or file path to D2 file
- Returns a Markdown reference covering shapes, styling, and transport usage
go install github.com/h0rv/d2-mcp@latest
git clone https://github.com/h0rv/d2-mcp.git cd d2-mcp go build .
docker build . -t d2-mcp # Run in stdio mode (default - for MCP clients) docker run --rm -i d2-mcp # Run in stdio mode with filesystem access docker run --rm -i -v $(pwd):/data d2-mcp # Run in SSE mode (HTTP server) docker run --rm -e SSE_MODE=true -p 8080:8080 d2-mcp # Run in SSE mode with filesystem access docker run --rm -e SSE_MODE=true -p 8080:8080 -v $(pwd):/data d2-mcp
# Run in stdio mode (default - for MCP clients) docker run --rm -i ghcr.io/h0rv/d2-mcp:main # Run in stdio mode with filesystem access docker run --rm -i -v $(pwd):/data ghcr.io/h0rv/d2-mcp:main # Run in SSE mode (HTTP server) docker run --rm -e SSE_MODE=true -p 8080:8080 ghcr.io/h0rv/d2-mcp:main # Run in SSE mode with filesystem access docker run --rm -e SSE_MODE=true -p 8080:8080 -v $(pwd):/data ghcr.io/h0rv/d2-mcp:main
# Claude Desktop $EDITOR ~/Library/Application\ Support/Claude/claude_desktop_config.json # OTerm: $EDITOR ~/Library/Application\ Support/oterm/config.json
Add thed2MCP server to your respective MCP Clients config:
{ "mcpServers": { "d2": { "command": "/YOUR/ABSOLUTE/PATH/d2-mcp", "args": ["--image-type", "png"] } } }
{ "mcpServers": { "d2": { "command": "/YOUR/ABSOLUTE/PATH/d2-mcp", "args": ["--image-type", "png", "--write-files"] } } }
{ "mcpServers": { "d2": { "command": "docker", "args": ["run", "--rm", "-i", "ghcr.io/h0rv/d2-mcp:main", "--image-type", "svg"] } } }
{ "mcpServers": { "d2": { "command": "docker", "args": [ "run", "--rm", "-i", "-v", "./:/data", "ghcr.io/h0rv/d2-mcp:main", "--image-type", "ascii", "--ascii-mode", "standard", "--write-files" ] } } }
The server returns PNG output by default whenrsvg-convertfrom librsvg is available. Ifrsvg-convertis missing, the server automatically removespngfrom therender-d2tool'sformatenum and falls back to SVG. The Docker image installs librsvg plus fontconfig/DejaVu fallback fonts, so PNG works out of the box there.
# macOS brew install librsvg # Debian/Ubuntu sudo apt-get install librsvg2-bin # Alpine apk add librsvg
Override globally when starting the binary:
./d2-mcp --image-type svg # SVG output ./d2-mcp --image-type ascii # ASCII output with Unicode box drawing characters ./d2-mcp --image-type ascii --ascii-mode standard # ASCII output restricted to basic ASCII chars
Inside MCP tool calls, pass the optionalformatargument (png,svg,ascii) and, whenascii, theascii_modeargument (extended,standard) to switch formats per request.
Run the container with default PNG output over stdio:
docker run --rm -i ghcr.io/h0rv/d2-mcp:main
Switch to Unicode ASCII diagrams and capture responses as plain text:
docker run --rm -i ghcr.io/h0rv/d2-mcp:main --image-type ascii
Use basic ASCII characters and write rendered files back into your working tree (requires a bind mount):
docker run --rm -i \ -v "$(pwd)":/data \ ghcr.io/h0rv/d2-mcp:main \ --image-type ascii \ --ascii-mode standard \ --write-files
Expose the SSE server on port 8080 while emitting SVG:
docker run --rm -e SSE_MODE=true -p 8080:8080 ghcr.io/h0rv/d2-mcp:main --image-type svg
Expose the streamable HTTP transport (default endpoint/mcp) for use with MCP clients that expect the new protocol:
docker run --rm -p 8080:8080 ghcr.io/h0rv/d2-mcp:main --transport http --image-type svg
Retrieve the built-in quick reference as Markdown:
{ "tool": "fetch_d2_cheat_sheet" }
The cheat sheet highlights common shapes, layout tips, and ASCII-friendly patterns, making it ideal support material for downstream LLM prompts.
The server defaults to stdio transport for CLI-driven MCP clients. Switch transports per run:
- --transport stdio: default for local CLI integrations.
- --transport sse: legacy Server-Sent Events transport (alias:--sse).
- --transport http: streamable HTTP transport on/mcp; combine with-p/--portwhen running in Docker or containers.
- MCP_TRANSPORTsets the transport (stdio,sse,http) when flags are not provided.
- PORT(or the legacySSE_PORT) sets the listening port for SSE/HTTP transports.
- SSE_MODE=trueretains backwards compatibility by selecting the SSE transport.
Tip: Runcompile-d2first to validate, then callrender-d2with the same payload for the final output.
npx @modelcontextprotocol/inspector /YOUR/ABSOLUTE/PATH/d2-mcp/d2-mcp
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.
AI-powered SVG animation generator that transforms static files into animated SVG components using the Allyson platform
Get access to MCP server SVG and MCP server PNG icons in your vibe-coding projects
745+ CSS3 animations and 9,000+ real SVG icons for AI coding agents. 10 MCP tools. Zero-clone setup via npx.
Extract and download usable website favicons and return direct icon URLs and metadata through an MCP server.
Renders Mermaid diagram syntax to PNG or SVG images with configurable themes and backgrounds.
Quickly retrieve SVGs using the Iconify API, with no external data files required.
A MCP server that exposes SVGR functionality to convert SVG content into React components
Provides access to the Lucide icon library for use in LLM and agentic applications.
Search open SVG icon packs and fetch exact SVG markup from coding agents through MCP.
Render chart images from JSON configs with six themes, ten marks, PNG/SVG output.
Sign in to leave a review
Use Google, GitHub, or an email account so ratings stay tied to real people.
No reviews posted yet.





