MCP Hub
Back to servers

d2-mcp

Enables AI assistants to compile, validate, and explore D2 diagrams using the official D2 WASM package. It provides tools for generating SVGs with custom layouts, themes, and icons directly from D2 source code.

glama
Updated
Mar 11, 2026

d2-mcp

MCP server for the D2 diagram language. Compile, validate, and explore D2 diagrams from any MCP-compatible AI assistant.

Uses the official @terrastruct/d2 WASM package — no CLI binary needed.

Tools

ToolDescription
compileD2 source code → SVG. Supports layout engines, themes, sketch mode, dark themes, multi-board targeting, and more.
validateCheck D2 syntax without rendering. Returns validity status and error details.
list_themesList all available D2 themes with IDs (light and dark).
list_layoutsList available layout engines (dagre, elk).
list_iconsBrowse icons from icons.terrastruct.com by category (AWS, GCP, Azure, K8s, dev, essentials, tech).

Resources

ResourceDescription
d2://syntax-referenceComplete D2 language syntax reference in markdown.

Local Development

npm install
npm run build
npm start

The server starts on port 3000 by default (override with PORT env var).

  • Health check: GET /health
  • MCP endpoint: POST /mcp (Streamable HTTP transport)

Deployment (Render)

This project includes a Dockerfile and render.yaml blueprint for one-click deployment to Render.

  1. Push this repo to GitHub
  2. In Render, create a new Blueprint and connect your repo
  3. Render will auto-detect render.yaml and deploy

Or manually create a Web Service with:

  • Environment: Docker
  • Health Check Path: /health
  • Plan: 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

ParameterTypeDescription
codestringD2 source code (required)
layout"dagre" | "elk"Layout engine (default: dagre)
sketchbooleanHand-drawn sketch mode
themeIDintegerTheme ID (see list_themes)
darkThemeIDintegerDark mode theme ID
padintegerPadding in pixels (default: 100)
centerbooleanCenter SVG in viewbox
scalenumberScale factor (default: fit to screen)
targetstringTarget board for multi-board diagrams
animateIntervalintegerAnimation interval (ms) for multi-board SVGs
noXMLTagbooleanOmit XML declaration for HTML embedding

License

MIT

Reviews

No reviews yet

Sign in to write a review