d2-mcp
Provides a comprehensive D2 language syntax reference as a resource in Markdown format.
Compiles D2 diagram source code into SVG images, supporting layout engines, themes, and various rendering options.
Allows for the generation of SVG output with or without XML declarations to facilitate embedding in HTML or other XML-based documents.
Click on "Install 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., "@d2-mcprender a d2 diagram for a microservices architecture in sketch mode"
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.
d2-mcp
MCP server for the D2 diagram language. Compile, validate, and explore D2 diagrams from any MCP-compatible AI assistant.
Uses the native D2 CLI binary (installed automatically in the Docker image) to compile diagrams into SVG and PNG.
Tools
Tool | Description |
| D2 source code → SVG/PNG. Supports layout engines, themes, sketch mode, dark themes, multi-board targeting, and more. |
| Check D2 syntax without rendering. Returns validity status and error details. |
| List all available D2 themes with IDs (light and dark). |
| List available layout engines ( |
| Browse icons from icons.terrastruct.com by category (AWS, GCP, Azure, K8s, dev, essentials, tech). |
Resources
Resource | Description |
| Complete D2 language syntax reference in markdown. |
Local Development
Prerequisites
Node.js 22+
D2 CLI — install from d2lang.com or set the
D2_PATHenv var to the binary location.Icons (optional) — run
scripts/download-icons.sh ./iconsthen setICONS_DIR=./iconsto enable local icon resolution. Without this, icon URLs are passed through to the D2 CLI as-is.
npm install
npm run build
npm startFor development with auto-reload:
npm run devThe server starts on port 3000 by default (override with PORT env var).
Health check:
GET /healthMCP endpoint:
POST /mcp(Streamable HTTP transport)
Environment Variables
Variable | Default | Description |
|
| HTTP server port |
|
| Path to the D2 CLI binary (resolved via |
|
| Directory containing downloaded SVG icons for local resolution |
Deployment (Render)
This project includes a Dockerfile and render.yaml blueprint for one-click deployment to Render. The Docker image automatically installs the D2 CLI binary and downloads all icons at build time.
Push this repo to GitHub
In Render, create a new Blueprint and connect your repo
Render will auto-detect
render.yamland deploy
Or manually create a Web Service with:
Environment: Docker
Health Check Path:
/healthPlan: Free
Connecting to the MCP Server
Once deployed, configure your MCP client to connect via Streamable HTTP:
{
"mcpServers": {
"d2": {
"url": "https://your-service.onrender.com/mcp"
}
}
}Replace the URL with your actual Render service URL (or http://localhost:3000/mcp for local).
Compile Tool Options
Parameter | Type | Description |
| string | D2 source code (required) |
|
| Layout engine (default: dagre) |
| boolean | Hand-drawn sketch mode |
| integer | Theme ID (see |
| integer | Dark mode theme ID |
| integer | Padding in pixels (default: 100) |
| boolean | Center SVG in viewbox |
| number | Scale factor (default: fit to screen) |
| string | Target board for multi-board diagrams |
| integer | Animation interval (ms) for multi-board SVGs |
| boolean | Omit XML declaration for HTML embedding |
License
MIT
This server cannot be installed
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Latest Blog Posts
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/ryanmccauley/d2-mcp'
If you have feedback or need assistance with the MCP directory API, please join our Discord server