d2-mcp
Create, validate, and render diagrams from D2 (Declarative Diagramming) code into SVG and PNG formats.
d2-mcp
A Model Context Protocol (MCP) server for working with D2: Declarative Diagramming, enabling seamless integration of diagram creation and validation into your development workflow.
Tools:
- 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
- Render Diagrams
- Generate diagrams for visual feedback and refinement
- Support for both vector (SVG) and raster (PNG) output formats
- Accepts either direct code or file path to D2 file
Install
Option 1: Install Binary Release
Option 2: Install via go
go install github.com/h0rv/d2-mcp@latest
Option 3: Build Locally
git clone https://github.com/h0rv/d2-mcp.git
cd d2-mcp
go build .
Option 4: Build Image Locally
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 SSE_MODE=true -p 8080:8080 -e d2-mcp
# Run in SSE mode with filesystem access
docker run --rm -e SSE_MODE=true -p 8080:8080 -v $(pwd):/data d2-mcp
Option 5: Run Container Image
# 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
Setup with MCP Client
MacOS:
# Claude Desktop
$EDITOR ~/Library/Application\ Support/Claude/claude_desktop_config.json
# OTerm:
$EDITOR ~/Library/Application\ Support/oterm/config.json
Add the d2 MCP server to your respective MCP Clients config:
Using Binary:
{
"mcpServers": {
"d2": {
"command": "/YOUR/ABSOLUTE/PATH/d2-mcp",
"args": ["--image-type", "png"]
}
}
}
Using Binary with file output:
{
"mcpServers": {
"d2": {
"command": "/YOUR/ABSOLUTE/PATH/d2-mcp",
"args": ["--image-type", "png", "--write-files"]
}
}
}
Using Docker:
{
"mcpServers": {
"d2": {
"command": "docker",
"args": ["run", "--rm", "-i", "ghcr.io/h0rv/d2-mcp:main"]
}
}
}
Using Docker with filesystem access:
{
"mcpServers": {
"d2": {
"command": "docker",
"args": ["run", "--rm", "-i", "-v", "./:/data", "ghcr.io/h0rv/d2-mcp:main"]
}
}
}
Development
Debugging
npx @modelcontextprotocol/inspector /YOUR/ABSOLUTE/PATH/d2-mcp/d2-mcp
Related Servers
Scout Monitoring MCP
sponsorPut performance and error data directly in the hands of your AI assistant.
Alpha Vantage MCP Server
sponsorAccess financial market data: realtime & historical stock, ETF, options, forex, crypto, commodities, fundamentals, technical indicators, & more
ShellAgent
An MCP server for executing shell commands, requiring Node.js 18 or newer.
UML-MCP-Server
Generate various UML diagrams from natural language or PlantUML code. Returns PlantUML code, image URLs, and saves diagrams locally.
MCP Terminal Server
A secure command-line interface server for the Model Context Protocol (MCP) that allows AI models to interact with a user's terminal.
Roblox Studio MCP Server
An AI-powered MCP server for Roblox Studio development, featuring advanced NLP, semantic analysis, and multi-turn conversation capabilities.
Azure DevOps
Interact with Azure DevOps Work Items using the Azure DevOps REST API.
MCP Android Agent
Automate Android devices using the uiautomator2 library, requiring adb and a connected device.
Hostname MCP Server
A lightweight server for hostname detection and system context.
CircleCI
Enable AI Agents to fix build failures from CircleCI.
Image Generation
Generate images from text using the Stable Diffusion WebUI API (ForgeUI/AUTOMATIC-1111).
Adaptive Graph of Thoughts
An intelligent scientific reasoning framework that uses graph structures and Neo4j to perform advanced reasoning via the Model Context Protocol (MCP).