Logo vun d2-mcp

d2-mcp

Communautéit
h0rv

Create, validate, and render diagrams from D2 (Declarative Diagramming) code into SVG and PNG formats.

Editeurh0rv
Repositoryd2-mcp
SproochGo
Forks
4
Stären
21
Disponibel Tools
0
Transporttypstdio
Kategorien
LizenzMIT
Linken
  • Tools mat KI-Workflows verbannen

    d2-mcp stellt MCP-Funktioune bereit, déi vu kompatibele KI-Clienten a KI-Agente kënne benotzt ginn.

  • 0 disponibel Tools

    Kuckt Iech déi opruffbar Aktiounen hei drënner un, mat Nimm a Beschreiwungen, wa se vum Server geliwwert ginn.

  • Konfiguratioun fir ze kopéieren

    Benotzt d'Installatiounsbeispiller, fir dëse Server an Ärem bevorzugte MCP-Client ze konfiguréieren.

  • Indicateure fir Open Source

    21 Stären an 4 Forks aus dem verlinkte Repository.

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 PNG, SVG, and ASCII output formats
    • Accepts either direct code or file path to D2 file
  • Fetch D2 Cheat Sheet
    • Returns a Markdown reference covering shapes, styling, and transport usage

Install

Option 1: Install Binary Release

bash

Option 2: Install via go

bash
go install github.com/h0rv/d2-mcp@latest

Option 3: Build Locally

bash
git clone https://github.com/h0rv/d2-mcp.git
cd d2-mcp
go build .

Option 4: Build Image Locally

bash
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 -e SSE_MODE=true -p 8080:8080 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

bash
# 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:

bash
# 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:

json
{
    "mcpServers": {
        "d2": {
            "command": "/YOUR/ABSOLUTE/PATH/d2-mcp",
            "args": ["--image-type", "png"]
        }
    }
}

Using Binary with file output:

json
{
    "mcpServers": {
        "d2": {
            "command": "/YOUR/ABSOLUTE/PATH/d2-mcp",
            "args": ["--image-type", "png", "--write-files"]
        }
    }
}

Using Docker:

json
{
    "mcpServers": {
        "d2": {
            "command": "docker",
            "args": ["run", "--rm", "-i", "ghcr.io/h0rv/d2-mcp:main", "--image-type", "svg"]
        }
    }
}

Using Docker with filesystem access:

json
{
    "mcpServers": {
        "d2": {
            "command": "docker",
            "args": [
                "run", "--rm", "-i",
                "-v", "./:/data",
                "ghcr.io/h0rv/d2-mcp:main",
                "--image-type", "ascii",
                "--ascii-mode", "standard",
                "--write-files"
            ]
        }
    }
}

Rendering Formats

The server returns PNG output by default when rsvg-convert from librsvg is available. If rsvg-convert is missing, the server automatically removes png from the render-d2 tool's format enum and falls back to SVG. The Docker image installs librsvg plus fontconfig/DejaVu fallback fonts, so PNG works out of the box there.

Install librsvg for local binaries:

bash
# macOS
brew install librsvg

# Debian/Ubuntu
sudo apt-get install librsvg2-bin

# Alpine
apk add librsvg

Override globally when starting the binary:

bash
./d2-mcp --image-type svg        # SVG output
./d2-mcp --image-type ascii      # ASCII output with Unicode box drawing characters
./d2-mcp --image-type ascii --ascii-mode standard  # ASCII output restricted to basic ASCII chars

Inside MCP tool calls, pass the optional format argument (png, svg, ascii) and, when ascii, the ascii_mode argument (extended, standard) to switch formats per request.

Docker Usage Examples

Run the container with default PNG output over stdio:

bash
docker run --rm -i ghcr.io/h0rv/d2-mcp:main

Switch to Unicode ASCII diagrams and capture responses as plain text:

bash
docker run --rm -i ghcr.io/h0rv/d2-mcp:main --image-type ascii

Use basic ASCII characters and write rendered files back into your working tree (requires a bind mount):

bash
docker run --rm -i \
  -v "$(pwd)":/data \
  ghcr.io/h0rv/d2-mcp:main \
  --image-type ascii \
  --ascii-mode standard \
  --write-files

Expose the SSE server on port 8080 while emitting SVG:

bash
docker run --rm -e SSE_MODE=true -p 8080:8080 ghcr.io/h0rv/d2-mcp:main --image-type svg

Expose the streamable HTTP transport (default endpoint /mcp) for use with MCP clients that expect the new protocol:

bash
docker run --rm -p 8080:8080 ghcr.io/h0rv/d2-mcp:main --transport http --image-type svg

Cheat Sheet Tool

Retrieve the built-in quick reference as Markdown:

json
{
  "tool": "fetch_d2_cheat_sheet"
}

The cheat sheet highlights common shapes, layout tips, and ASCII-friendly patterns, making it ideal support material for downstream LLM prompts.

Transports

The server defaults to stdio transport for CLI-driven MCP clients. Switch transports per run:

  • --transport stdio: default for local CLI integrations.
  • --transport sse: legacy Server-Sent Events transport (alias: --sse).
  • --transport http: streamable HTTP transport on /mcp; combine with -p/--port when running in Docker or containers.

Environment overrides:

  • MCP_TRANSPORT sets the transport (stdio, sse, http) when flags are not provided.
  • PORT (or the legacy SSE_PORT) sets the listening port for SSE/HTTP transports.
  • SSE_MODE=true retains backwards compatibility by selecting the SSE transport.

Tool Reference

ToolDescriptionKey Arguments
compile-d2Validates D2 source and surfaces syntax errors.code (string) or file_path (string)
render-d2Renders diagrams to PNG, SVG, or ASCII (ASCII is LLM-friendly).code/file_path, format (png, svg, ascii), ascii_mode (extended, standard)
fetch_d2_cheat_sheetReturns a Markdown cheat sheet with examples and best practices.None

Tip: Run compile-d2 first to validate, then call render-d2 with the same payload for the final output.

Development

Debugging

bash
npx @modelcontextprotocol/inspector /YOUR/ABSOLUTE/PATH/d2-mcp/d2-mcp

d2-mcp MCP mat verschiddene KI-Modeller benotzen

TypingMind verbënnt MCP-Tools um Niveau vum Aarbechtsberäich. Soubal d2-mcp verbonnen ass, kënnt Dir et mat verschiddene KI-Modeller an TypingMind benotzen, amplaz et fir all Modell separat anzeriichten. Dës MCP-Integratioun leeft lokal iwwer den TypingMind-MCP-Connector op Ärem Apparat.

Ariichtungsuleedung fir de lokale Connector ze benotzen

Benotzt dës Optioun, wann den MCP-Server Zougrëff op lokal Fichieren, Appen oder privat Ressourcen op Ärem Computer brauch.

1

D'MCP-Astellungen opmaachen

Gitt an TypingMind op „Astellungen“, „Erweidert Astellungen“, dann op „Model Context Protocol“ a wielt „Connector ariichten“.

  1. Maacht TypingMind an Ärem Browser op.
  2. Klickt op d'Astellungssymbol.
  3. Gitt op „Erweidert Astellungen“.
  4. Maacht d'Sektioun „Model Context Protocol“ op.
  5. Klickt op „Connector ariichten“ a wielt „Dësen Apparat“.
Ariichtungsbildschierm vum TypingMind-MCP-Connector mat „Dësen Apparat“ ausgewielt
2

De Connector-Befeel ausféieren

Wielt „Dësen Apparat“, kopéiert de Befeel aus TypingMind a féiert en am Terminal aus. Loosst de Prozess lafen, wärend Dir MCP benotzt.

  1. Kopéiert den Ariichtungsbefeel, deen TypingMind uweist.
  2. Maacht Terminal op macOS oder Windows Terminal op Windows op.
  3. Pescht de Befeel an a féiert en aus.
  4. Bestätegt d'Installatioun vum Package, wann den Terminal Iech freet, ob Dir weiderfuere wëllt.
  5. Loosst den Terminal an de Prozess doranner lafen, wärend Dir MCP-Tools benotzt.
3

d2-mcp als Server derbäisetzen

Wann de Connector-Status „Prett“ ass, klickt op „Serveren änneren“ a pescht d'MCP-Serverkonfiguratioun an.

  1. Waart, bis de Connector-Status „Prett“ weist.
  2. Klickt op „Serveren änneren“.
  3. Pescht d'MCP-Serverkonfiguratioun vu d2-mcp an.
  4. Späichert d'Serverlëscht.
  5. Aktualiséiert, wann Dir kontrolléiere wëllt, ob de Connector nach ëmmer prett ass.
MCP-Astellunge vun TypingMind mat aktivem Server an dem Knäppchen „Serveren änneren“
{
  "mcpServers": {
    "d2-mcp": {
      "command": "npx",
      "args": [
        "-y",
        "<mcp-server-package>"
      ]
    }
  }
}
4

D'Verbindung mat verschiddene Modeller benotzen

Späichert d'Serverlëscht, maacht „Plugins“ op an aktivéiert d'MCP-Tools vu d2-mcp. Wielt dann e belibegen ënnerstëtzte KI-Modell an TypingMind a benotzt d'Tools am Chat oder weist se engem KI-Agent zou.

  1. Maacht d'Säit „Plugins“ an TypingMind op.
  2. Aktivéiert d'MCP-Tools vu d2-mcp.
  3. Start e Chat a wielt de KI-Modell, deen Dir benotze wëllt.
  4. Benotzt d'MCP-Tools am Chat oder weist se engem KI-Agent zou.
  5. Wiesselt bei Bedarf op en anere KI-Modell, ouni MCP nei ze verbannen.
TypingMind-Chat mat aktivéierte MCP-Tools an engem ausgewielte KI-Modell
Hëlleft Dir mir bei dëser Aufgab mat d2-mcp?
d2-mcp
Jo. Ech hunn et gelies.
Dat hunn ech mat d2-mcp fonnt.

Heefeg gestallte Froen

Fir wat gëtt de MCP-Server d2-mcp benotzt?

d2-mcp ass e MCP-Server, deen et kompatibele KI-Clienten erlaabt, sech mat externen Tools a Kontext ze verbannen. An TypingMind kënnt Dir dëse MCP-Server eemol derbäisetzen a seng Tools an Ärem KI-Aarbechtsberäich zur Verfügung stellen.

Kann ech d2-mcp MCP mat méi KI-Modeller an TypingMind benotzen?

Jo. TypingMind verbënnt MCP-Tools um Niveau vum Aarbechtsberäich. Sou kënnt Dir d2-mcp mat verschiddene KI-Modeller wéi Claude, ChatGPT, Gemini oder anere Modeller benotzen, déi Dir an TypingMind konfiguréiert hutt, ouni de MCP-Server fir all Modell separat anzeriichten.

Firwat d2-mcp MCP mat TypingMind benotzen?

TypingMind ass eng vun de beschte Benotzeruewerfläche fir LLM-Chat, well et méi KI-Modeller, Prompts, Plugins, KI-Agenten, API-Schlësselen a MCP-Tools an engem Aarbechtsberäich zesummebréngt. Wann d2-mcp verbonnen ass, kënnt Dir seng MCP-Tools mat Äre bevorzugte Modeller benotzen a gläichzäiteg Är Chataarbecht an TypingMind organiséieren.

Wéi verbannen ech d2-mcp MCP mat TypingMind?

d2-mcp leeft iwwer de lokale MCP-Connector vun TypingMind. Dat eegent sech am beschten, wann de MCP-Server Zougrëff op lokal Fichieren, Desktop-Apps, Kommandozeilen-Tools oder privat Ressourcen op Ärem Computer brauch.

Wéi eng Tools stellt d2-mcp MCP an TypingMind zur Verfügung?

d2-mcp stellt MCP-Funktiounen zur Verfügung, déi Dir op der Plugins-Säit vun TypingMind aktivéiere kënnt, fir se am Chat ze benotzen oder KI-Agenten zouzeweisen.

Muss ech meng API-Schlëssele mat TypingMind deelen, fir d2-mcp MCP ze benotzen?

Nee. TypingMind setzt op lokal Veraarbechtung a léisst Iech d'Kontroll iwwer Är Modellubidder, API-Schlësselen, Prompts a MCP-Konfiguratioun. Wann d2-mcp eng Authentifizéierung verlaangt, setzt déi néideg Headeren, OAuth-Astellungen oder lokal Konfiguratioun fir dee MCP-Server derbäi, wann Dir d'Verbindung erstallt.

Änlech MCP-Serveren

All weisen

Elo Ären eegene KI-Workspace ariichten

Abonnéiert Iech op eisen Newsletter, fir iwwer nei Funktiounen an zukünfteg Gewënnspiller informéiert ze ginn 👇