ID

i2y/d2mcp

开发工具

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

34 stars 8 forks 质量 56 趋势 12MIT

一台模型上下文协议(MCP)服务器,提供D2图生成和操作功能。

概览

一台模型上下文协议(MCP)服务器,提供D2图生成和操作功能。 D2 是一种现代的图表脚本语言,将文本转换为图表。该 MCP 服务器允许像 Claude 这样的 AI 助手以程序创建、渲染、导出和保存 D2 图表。 该服务器通过MCP协议提供10个工具,并附有增强的描述,以实现最佳的AI助手集成,支持简单的图表绘制和利用Oracle API构建复杂的增量图。

概述(AI 翻译)

一台模型上下文协议(MCP)服务器,提供D2图生成和操作功能。

D2 是一种现代的图表脚本语言,将文本转换为图表。该 MCP 服务器允许像 Claude 这样的 AI 助手以程序创建、渲染、导出和保存 D2 图表。

该服务器通过MCP协议提供10个工具,并附有增强的描述,以实现最佳的AI助手集成,支持简单的图表绘制和利用Oracle API构建复杂的增量图。

通过新的Oracle API集成,AI助手现在可以逐步构建和修改图表,非常适合:

  • 将对话转换为架构图
  • 随着需求讨论逐步构建流程图
  • 从数据库模式创建实体关系图
  • 通过代码分析生成系统图
  • 根据用户反馈优化图表,无需重新开始

特色

基本图示操作

  • d2_create - 创建带有可选初始内容的新图表(统一方法)
  • d2_export - 导出图表为多种格式(SVG、PNG、PDF)
  • d2_save - 将现有图表保存到文件中

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

README

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

D2 MCP Server

A Model Context Protocol (MCP) server that provides D2 diagram generation and manipulation capabilities.

D2 is a modern diagram scripting language that turns text to diagrams. This MCP server allows AI assistants like Claude to create, render, export, and save D2 diagrams programmatically.

The server provides 10 tools through the MCP protocol with enhanced descriptions for optimal AI assistant integration, enabling both simple diagram rendering and sophisticated incremental diagram building using the Oracle API.

With the new Oracle API integration, AI assistants can now build and modify diagrams incrementally, making it perfect for:

  • Converting conversations into architecture diagrams
  • Building flowcharts step-by-step as requirements are discussed
  • Creating entity relationship diagrams from database schemas
  • Generating system diagrams from code analysis
  • Refining diagrams based on user feedback without starting over

Features

Basic Diagram Operations

  • d2_create - Create new diagrams with optional initial content (unified approach)
  • d2_export - Export diagrams to various formats (SVG, PNG, PDF)
  • d2_save - Save existing diagrams to files

Oracle API for Incremental Editing

  • d2_oracle_create - Create shapes and connections incrementally
  • d2_oracle_set - Set attributes on existing elements
  • d2_oracle_delete - Delete specific elements from diagrams
  • d2_oracle_move - Move shapes between containers
  • d2_oracle_rename - Rename diagram elements
  • d2_oracle_get_info - Get information about shapes, connections, or containers
  • d2_oracle_serialize - Get the current D2 text representation of the diagram

Additional Features

  • 20 themes - Support for all D2 themes (18 light + 2 dark)

Project Structure

d2mcp/
├── cmd/                  # Application entry point
├── internal/
│   ├── domain/          # Business entities and interfaces
│   │   ├── entity/      # Domain entities
│   │   └── repository/  # Repository interfaces
│   ├── usecase/         # Business logic
│   ├── infrastructure/  # External implementations
│   │   ├── d2/          # D2 library integration
│   │   └── mcp/         # MCP server implementation
│   └── presentation/    # MCP handlers
│       └── handler/     # Tool handlers
└── pkg/                 # Public packages

Prerequisites

  • Go 1.24.3 or higher
  • D2 v0.6.7 or higher (included as dependency)
  • For PNG/PDF export (optional):
    • rsvg-convert (from librsvg) or
    • ImageMagick (convert command)

Installation

From Source

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

# Build the binary
make build

# Or build for all platforms
make build-all

Using Go Install

go install github.com/i2y/d2mcp/cmd@latest

Building

# Simple build
make build

# Run directly
make run

# Cross-platform builds
make build-all

Usage

With Claude Desktop

在 GitHub 查看完整 README

安装

This server does not publish a one-line install command.

Open the repository installation guide 新手?先看 mcpskill.org 教程 →

配置

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