HD

h0rv/d2-mcp

开发工具

本页由 AI 翻译,技术细节请以原文为准。 查看原文

24 stars 4 forks 质量 83 趋势 25MIT

一款用于使用 D2 的模型上下文协议(MCP)服务器:声明式图表,实现图表创建和验证无缝集成到您的开发工作流程中。

概览

一款用于使用 D2 的模型上下文协议(MCP)服务器:声明式图表,实现图表创建和验证无缝集成到您的开发工作流程中。 * 编译D2代码 * 在渲染前验证D2语法并发现错误 * 立即获得图表结构和语法反馈 * 接受直接代码或D2文件路径 * 渲染图表 * 生成图形以供视觉反馈和优化 * 支持PNG、SVG和ASCII输出格式 * 接受直接代码或D2文件路径 * 获取D2速查表 * 返回涵盖形状、样式和传输用途的Markdown参考 将d2 MCP服务器添加到你各自的MCP客户端配置中: 当 librsvg 的 rsvg-convert 可用时,服务器默认返回 PNG 输出。如果缺少 rsvg-convert,服务器会自动从 render-d2 工具的格式枚举中移除 png,并退回到 SVG。

概述(AI 翻译)

一个用于验证和渲染D2图的小型GoMCP服务器。发送完整的源代码和渲染选项;接收PNG、SVG或文本。默认服务器不保留文档、伪影或HTTP会话。它不需要D2可执行文件、浏览器或PNG转换器。

d2-mcp 2.0.0 使用 D2 0.9.0、Go 1.27.2 以及官方的 Go MCP SDK 1.8.0。D2 的 Dagre、ELK 和开源 TALA 布局已捆绑。参见输入和限制。

安装

安装一个2.0.0的二进制文件或源代码构建,然后连接Claude、Codex、Pi或VS Code。查看2.0.0发布的内容和1.2.0的迁移说明。

如果要在不安装二进制文件的情况下进行托管使用,请连接到https://d2.horv.co/mcp 使用远程 HTTP 客户端命令。

客户与运输

Stdio 仍然是默认设置。对于使用 mcpServers 的 Claude Desktop 或其他客户端:

对于无状态的可流式HTTP端点:

将可流式 HTTP MCP 客户端连接到 http://127.0.0.1:8080/mcp。例如,VS Code .vscode/mcp.json 条目:

HTTP 使用 JSON 响应,无会话 ID 和无后台事件流。每个调用都携带其源/选项;后续调用可能会返回另一个副本。在 /mcp 上 GET/DELETE 返回 405。

本页由 AI 翻译,技术细节请以原文为准。

README

以下为原文 README 节选,完整内容请查看原文。

d2-mcp

A small Go MCP server for validating and rendering D2 diagrams. Send complete source and rendering options; receive PNG, SVG, or text. The default server keeps no documents, artifacts, or HTTP sessions. It needs no D2 executable, browser, or PNG converter.

d2-mcp 2.0.0 uses D2 0.9.0, Go 1.27.2, and the official Go MCP SDK 1.8.0. D2’s Dagre, ELK, and open-source TALA layouts are bundled. See inputs and limits.

Install

Install a 2.0.0 binary or build from source, then connect Claude, Codex, Pi, or VS Code. See what shipped in 2.0.0 and the 1.2.0 migration notes.

For hosted use without installing a binary, connect to https://d2.horv.co/mcp using the remote HTTP client commands.

Clients and transports

Stdio remains the default. For Claude Desktop or another client using mcpServers:

{
  "mcpServers": {
    "d2": {
      "command": "/absolute/path/d2-mcp",
      "args": ["--image-type", "png"]
    }
  }
}

For a stateless Streamable HTTP endpoint:

./d2-mcp --transport http --host 127.0.0.1 --port 8080

Connect a Streamable HTTP MCP client to http://127.0.0.1:8080/mcp. For example, a VS Code .vscode/mcp.json entry:

{
  "servers": {
    "d2": {"type": "http", "url": "http://127.0.0.1:8080/mcp"}
  }
}

HTTP uses JSON responses, no session ID, and no background event stream. Every call carries its source/options; subsequent calls may go to another replica. GET/DELETE on /mcp return 405. Current MCP 2026-07-28 discovery and legacy initialization are handled by the SDK; integration tests cover 2025-03-26, 2025-06-18, 2025-11-25, and 2026-07-28 over HTTP. Stdio and legacy SSE retain their supported initialization protocols.

Send exactly one JSON-RPC object per HTTP POST. Batches are rejected on every protocol version, including legacy SSE message posts, to prevent unbounded aggregation of tool results. Disconnects cancel current-protocol (2026-07-28) work cooperatively; the SDK retains older protocol calls until their application deadline.

Legacy SSE remains available at /sse with --transport sse (or --sse). Its SDK-managed connections are stateful and need a stable server connection. Prefer HTTP for new integrations. MCP_TRANSPORT, PORT, and legacy SSE_MODE/SSE_PORT are still accepted; explicit transport/port flags take precedence, and --sse selects SSE.

在 GitHub 查看完整 README

安装

docker run --rm -i d2-mcp
新手?先看 mcpskill.org 教程 →

配置

{ "mcpServers": { "d2": { "command": "/absolute/path/d2-mcp", "args": ["--image-type", "png"] } } }