Provides D2 diagram generation and manipulation via MCP with rendering, exporting, saving, and incremental Oracle API editing.
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.
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.
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-allTwo 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.
Create a new diagram with an optional initial content. Use it as the starting point for both empty and content-initial diagrams.
Export a diagram to a specific format such as SVG, PNG, or PDF.
Save an existing diagram to a file on disk.
Incrementally create shapes and connections within a diagram without regenerating the entire diagram.
Set attributes on existing diagram elements to refine appearance or behavior.
Delete specified elements from the diagram, including their descendants where applicable.
Move elements between containers, with optional inclusion of descendants.
Rename diagram elements to improve clarity or organization.
Retrieve information about shapes, connections, or containers for inspection.
Get the current D2 text representation of the diagram including all Oracle API changes.
Create and render D2 sequence diagrams with actors, interactions, and grouping.