home / mcp / d2 mcp server

D2 MCP Server

Provides D2 diagram generation and manipulation via MCP with rendering, exporting, saving, and incremental Oracle API editing.

Installation
Add the following to your MCP client configuration file.

Configuration

View docs
{
  "mcpServers": {
    "i2y-d2mcp": {
      "command": "/path/to/d2mcp",
      "args": [
        "-transport=stdio"
      ]
    }
  }
}

You can generate, render, export, and iteratively refine D2 diagrams with the D2 MCP Server. It exposes a set of diagram operations and an Oracle API for incremental editing, so you can turn conversations into diagrams, evolve diagrams step by step, and export final visuals in multiple formats.

How to use

Install and run the D2 MCP Server, then connect your MCP client to execute diagram operations. Use the standard d2_create to start a new diagram, d2_export to render to a chosen format, and d2_save to store diagrams. For iterative development, harness the Oracle API with d2_oracle_create, d2_oracle_set, d2_oracle_delete, d2_oracle_move, d2_oracle_rename, d2_oracle_get_info, and d2_oracle_serialize to progressively build and adjust diagrams without regenerating the entire diagram.

How to install

Prerequisites: Go 1.24.3 or higher and D2 v0.6.7 or higher.

From source cloning and building the binary, run these commands in sequence.

# Clone the repository
git clone https://github.com/i2y/d2mcp.git
cd d2mcp

# Build the binary
make build

# Optional: build for all platforms
make build-all

Additional setup notes

Two primary transport modes are supported for running the MCP server locally: stdio and SSE (Server-Sent Events). Use stdio for direct process communication and SSE for HTTP-based streaming. You can also run a streamable HTTP transport if you prefer a single HTTP endpoint.

Examples below show how to configure the MCP runner in client configuration files or command lines. Replace /path/to/d2mcp with the actual path to your built binary.

Available tools

d2_create

Create a new diagram with an optional initial content. Use it as the starting point for both empty and content-initial diagrams.

d2_export

Export a diagram to a specific format such as SVG, PNG, or PDF.

d2_save

Save an existing diagram to a file on disk.

d2_oracle_create

Incrementally create shapes and connections within a diagram without regenerating the entire diagram.

d2_oracle_set

Set attributes on existing diagram elements to refine appearance or behavior.

d2_oracle_delete

Delete specified elements from the diagram, including their descendants where applicable.

d2_oracle_move

Move elements between containers, with optional inclusion of descendants.

d2_oracle_rename

Rename diagram elements to improve clarity or organization.

d2_oracle_get_info

Retrieve information about shapes, connections, or containers for inspection.

d2_oracle_serialize

Get the current D2 text representation of the diagram including all Oracle API changes.

Sequence Diagram support

Create and render D2 sequence diagrams with actors, interactions, and grouping.