Skip to main content
Glama

d2-mcp

用于 D2 图表语言 的 MCP 服务器。从任何兼容 MCP 的 AI 助手编译、验证和探索 D2 图表。

使用原生 D2 CLI 二进制文件(在 Docker 镜像中自动安装)将图表编译为 SVG 和 PNG。

工具

工具

描述

compile

D2 源代码 → SVG/PNG。支持布局引擎、主题、草图模式、深色主题、多画板目标等。

validate

在不渲染的情况下检查 D2 语法。返回有效性状态和错误详情。

list_themes

列出所有可用的 D2 主题及其 ID(浅色和深色)。

list_layouts

列出可用的布局引擎(dagreelk)。

list_icons

按类别(AWS、GCP、Azure、K8s、dev、essentials、tech)浏览 icons.terrastruct.com 中的图标。

资源

资源

描述

d2://syntax-reference

Markdown 格式的完整 D2 语言语法参考。

本地开发

先决条件

  • Node.js 22+

  • D2 CLI — 从 d2lang.com 安装,或将 D2_PATH 环境变量设置为二进制文件路径。

  • 图标(可选) — 运行 scripts/download-icons.sh ./icons 然后设置 ICONS_DIR=./icons 以启用本地图标解析。如果不这样做,图标 URL 将按原样传递给 D2 CLI。

npm install
npm run build
npm start

用于自动重载的开发:

npm run dev

服务器默认在 3000 端口启动(可通过 PORT 环境变量覆盖)。

  • 健康检查:GET /health

  • MCP 端点:POST /mcp(可流式传输的 HTTP 传输)

环境变量

变量

默认值

描述

PORT

3000

HTTP 服务器端口

D2_PATH

d2

D2 CLI 二进制文件的路径(默认通过 PATH 解析)

ICONS_DIR

./icons

包含已下载 SVG 图标以供本地解析的目录

部署 (Render)

本项目包含一个 Dockerfilerender.yaml 蓝图,可一键部署到 Render。Docker 镜像会在构建时自动安装 D2 CLI 二进制文件并下载所有图标。

  1. 将此仓库推送到 GitHub

  2. 在 Render 中,创建一个新的 Blueprint 并连接您的仓库

  3. Render 将自动检测 render.yaml 并进行部署

或者手动创建一个 Web Service

  • 环境: Docker

  • 健康检查路径: /health

  • 计划: 免费

连接到 MCP 服务器

部署完成后,配置您的 MCP 客户端以通过可流式传输的 HTTP 进行连接:

{
  "mcpServers": {
    "d2": {
      "url": "https://your-service.onrender.com/mcp"
    }
  }
}

将 URL 替换为您实际的 Render 服务 URL(或本地的 http://localhost:3000/mcp)。

编译工具选项

参数

类型

描述

code

string

D2 源代码(必需)

layout

"dagre"

"elk"

布局引擎(默认:dagre)

sketch

boolean

手绘草图模式

themeID

integer

主题 ID(参见 list_themes

darkThemeID

integer

深色模式主题 ID

pad

integer

像素填充(默认:100)

center

boolean

在视图框中居中 SVG

scale

number

缩放比例(默认:适应屏幕)

target

string

多画板图表的目标画板

animateInterval

integer

多画板 SVG 的动画间隔(毫秒)

noXMLTag

boolean

省略 HTML 嵌入的 XML 声明

许可证

MIT

-
security - not tested
F
license - not found
-
quality - not tested

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/ryanmccauley/d2-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server