AI代理调试协议

DAP-MCP是一个为AI代理设计的调试协议服务器,支持通过自然语言进行代码调试、断点设置和变量检查,适用于多种编程语言的开发环境。

  • by ctagard
  • Go
  • 本地部署
  • 11 星标
  • 更新于
在 GitHub 查看 ctagard/dap-mcp

使用说明

DAP-MCP:AI代理的调试适配器协议

MCP(模型上下文协议)服务器,使AI代理能够调试代码。启动调试会话、设置断点、检查变量和逐步执行代码——所有这些都是通过自然语言完成的。

为什么选择DAP-MCP?

传统的调试需要手动设置断点、遍历代码和检查状态。DAP-MCP将这些功能暴露给LLM,从而实现:

  • 人工智能辅助调试:“查找此函数返回null的原因”
  • 自动化测试:设置断点并验证变量状态
  • 代码理解:检查运行时行为以理解复杂的逻辑
  • 代币高效:复合工具,如 debug_snapshot 减少API调用

支持的语言

语言 调试适配器 状态
去吧 探究 全力支持
python 调试 全力支持
JavaScript vscode-js调试 全力支持
TypeScript vscode-js调试 全力支持
React/Vue/Svelte vscode-js调试 +Chrome 完全支持
C LLDB / GDB 全力支持
C LLDB / GDB 全力支持
生锈 LLDB / GDB 全力支持
Objective-C LLDB 全力支持
Swift LLDB 全力支持

快速开始

1.安装DAP-MCP

单线安装(推荐):

curl -sSL https://raw.githubusercontent.com/ctagard/dap-mcp/main/scripts/install.sh | bash

此自动检测您的操作系统,并使用最佳方法进行安装:

  • macOS:自制(如有)或二进制
  • Debian/Ubuntu:.deb包
  • Fedora/RHEL:.rpm包
  • 其他Linux:二进制

通过环境变量的选项:

# Install specific version
curl -sSL ... | INSTALL_VERSION=0.1.1 bash

# Install to custom directory
curl -sSL ... | INSTALL_DIR=$HOME/.local/bin bash

# Force binary install (skip package managers)
curl -sSL ... | INSTALL_METHOD=binary bash
Other installation methods

自制(macOS/Linux):

brew install ctagard/tap/dap-mcp

Debian/Ubuntu:

curl -LO https://github.com/ctagard/dap-mcp/releases/latest/download/dap-mcp_0.1.1_linux_amd64.deb
sudo dpkg -i dap-mcp_0.1.1_linux_amd64.deb

Fedora/RHEL/CentOS:

curl -LO https://github.com/ctagard/dap-mcp/releases/latest/download/dap-mcp_0.1.1_linux_amd64.rpm
sudo rpm -i dap-mcp_0.1.1_linux_amd64.rpm

转到安装:

go install github.com/ctagard/dap-mcp/cmd/dap-mcp@latest
Docker
docker pull ghcr.io/ctagard/dap-mcp:latest

# Run with stdio (for MCP)
docker run -i ghcr.io/ctagard/dap-mcp:latest
Manual Binary Download

从下载相应的存档 发布页面:

# macOS (Apple Silicon)
curl -L https://github.com/ctagard/dap-mcp/releases/download/v0.1.1/dap-mcp_0.1.1_darwin_arm64.tar.gz | tar xz
sudo mv dap-mcp /usr/local/bin/

# macOS (Intel)
curl -L https://github.com/ctagard/dap-mcp/releases/download/v0.1.1/dap-mcp_0.1.1_darwin_amd64.tar.gz | tar xz
sudo mv dap-mcp /usr/local/bin/

# Linux (amd64)
curl -L https://github.com/ctagard/dap-mcp/releases/download/v0.1.1/dap-mcp_0.1.1_linux_amd64.tar.gz | tar xz
sudo mv dap-mcp /usr/local/bin/

# Linux (arm64)
curl -L https://github.com/ctagard/dap-mcp/releases/download/v0.1.1/dap-mcp_0.1.1_linux_arm64.tar.gz | tar xz
sudo mv dap-mcp /usr/local/bin/

# Windows (amd64)
# Download dap-mcp_0.1.1_windows_amd64.zip from releases page
Build from Source
git clone https://github.com/ctagard/dap-mcp
cd dap-mcp
make build
# Binary is at ./bin/dap-mcp

2.安装调试适配器

为要调试的语言安装适配器:

# Go - Delve
go install github.com/go-delve/delve/cmd/dlv@latest

# Python - debugpy
pip install debugpy

# JavaScript/TypeScript - vscode-js-debug (see detailed instructions below)

# C/C++/Rust/Objective-C/Swift - LLDB (usually pre-installed on macOS)
# macOS: Included with Xcode Command Line Tools
xcode-select --install

# Linux (Ubuntu/Debian)
sudo apt install lldb

# Linux (Fedora)
sudo dnf install lldb

# Or use GDB instead
sudo apt install gdb   # Debian/Ubuntu
sudo dnf install gdb   # Fedora

3.配置您的AI客户端

Claude Code

添加到 ~/.claude.json:

{
  "mcpServers": {
    "dap-mcp": {
      "command": "dap-mcp",
      "args": ["--mode", "full"]
    }
  }
}

或者使用配置文件:

{
  "mcpServers": {
    "dap-mcp": {
      "command": "dap-mcp",
      "args": ["--config", "/path/to/dap-mcp-config.json"]
    }
  }
}
Claude Desktop

添加到 ~/Library/Application Support/Claude/claude_desktop_config.json (macOS)或 %APPDATA%\Claude\claude_desktop_config.json (Windows):

{
  "mcpServers": {
    "dap-mcp": {
      "command": "/usr/local/bin/dap-mcp",
      "args": ["--mode", "full"]
    }
  }
}
Cursor

添加到您的设置(Cmd/Ctrl+Shift+P→ “首选项:打开用户设置(JSON)”):

{
  "mcp.servers": {
    "dap-mcp": {
      "command": "/usr/local/bin/dap-mcp",
      "args": ["--mode", "full"]
    }
  }
}
Continue.dev

添加到 ~/.continue/config.json:

{
  "experimental": {
    "modelContextProtocolServers": [
      {
        "transport": {
          "type": "stdio",
          "command": "/usr/local/bin/dap-mcp",
          "args": ["--mode", "full"]
        }
      }
    ]
  }
}
Other MCP Clients

DAP-MCP使用stdio传输。使用以下配置您的客户端:

  • 命令:路径 dap-mcp 二进制
  • 参数: ["--mode", "full"] 或 ["--config", "/path/to/config.json"]
  • 运输标准: stdio

4.开始调试!

问你的AI助手:

“在/path/to/script.py调试我的Python脚本。在第42行设置一个断点,并在断点处显示变量。”

“为我的Go程序启动调试会话,并逐步执行主函数。”

“连接到运行在localhost:3000的React应用程序,调试按钮点击处理程序。”

配置

命令行选项

dap-mcp [OPTIONS]

OPTIONS:
    --config <path>   Path to configuration file (JSON)
    --mode <mode>     Capability mode: 'readonly' or 'full' (default: full)
    --version         Show version and exit
    --help            Show help message

配置文件

为高级设置创建JSON文件:

{
  "mode": "full",
  "allowSpawn": true,
  "allowAttach": true,
  "allowModify": true,
  "allowExecute": true,
  "maxSessions": 10,
  "adapters": {
    "go": {
      "path": "dlv",
      "buildFlags": "-gcflags='all=-N -l'"
    },
    "python": {
      "pythonPath": "python3"
    },
    "node": {
      "nodePath": "node",
      "jsDebugPath": "/path/to/vscode-js-debug/src/dapDebugServer.js",
      "sourceMapPathOverrides": {
        "/*": "${webRoot}/*",
        "webpack:///src/*": "${webRoot}/src/*"
      }
    }
  }
}

安全模式

模式 描述 用例
full 所有调试功能 开发、可信环境
readonly 仅检查,无执行控制 生产监控,不受信任的代码

细粒度权限:

  • allowSpawn:可以启动新的调试进程
  • allowAttach:可以附加到正在运行的进程
  • allowModify:可以修改变量值
  • allowExecute:可以计算任意表达式

可用工具

DAP-MCP提供了一个为LLM效率而设计的简化的12工具API。

会话管理(4个工具)

工具 说明
debug_launch 启动新的调试会话。支持直接参数OR VS代码启动.json配置
debug_attach 连接到正在运行的进程或浏览器
debug_disconnect 结束调试会话
debug_list_sessions 列出所有活动的调试会话

检查(2个工具-在所有模式下都可用)

工具 说明
debug_snapshot 主要检查工具 -在一次调用中获取完整状态(线程、堆栈、作用域、变量)
debug_evaluate 计算单个或多个表达式。支持批处理模式 expressions JSON数组

控制(6个工具-仅限全模式)

工具 说明
debug_breakpoints 在源文件中设置断点(替换文件中的所有断点)
debug_step 步与 type:“over”(下一行)、“into”(输入函数)、“out”(退出函数)
debug_continue 继续执行,直到下一个断点
debug_pause 暂停程序执行
debug_set_variable 修改变量的值
debug_run_to_line 运行到特定行并返回快照(结合断点+继续+快照)

特定语言设置

去

Delve是标准的Go调试器。安装它:

go install github.com/go-delve/delve/cmd/dlv@latest

验证安装:

dlv version

python

debugpy是微软的Python调试适配器:

pip install debugpy

对于虚拟环境,请确保在您正在调试的环境中安装了debugpy。

JavaScript/TypeScript(Node.js)

JavaScript/TypeScript调试需要vscode-js-debug:

选项1:下载预构建

# Download from releases
curl -L https://github.com/anthropics/dap-mcp/releases/latest/download/js-debug.tar.gz -O
tar xzf js-debug.tar.gz -C ~/.local/share/

选项2:从源代码构建

git clone https://github.com/microsoft/vscode-js-debug
cd vscode-js-debug
npm install --legacy-peer-deps
npx gulp vsDebugServerBundle
mv dist src  # The server expects files in src/

在dap-mcp配置中配置路径:

{
  "adapters": {
    "node": {
      "jsDebugPath": "/path/to/vscode-js-debug/src/dapDebugServer.js"
    }
  }
}

C/C++/Rust(LLDB)

LLDB是C、C++、Rust、Objective-C和Swift的推荐调试器:

# macOS - included with Xcode Command Line Tools
xcode-select --install

# Verify installation
lldb --version

对于Linux,安装LLDB:

# Ubuntu/Debian
sudo apt install lldb

# Fedora
sudo dnf install lldb

使用调试符号编译代码:

# C/C++
gcc -g -O0 myprogram.c -o myprogram
g++ -g -O0 myprogram.cpp -o myprogram
clang -g -O0 myprogram.c -o myprogram

# Rust
cargo build  # Debug build includes symbols by default

C/C++(GDB)

GDB是一种替代调试器,特别是在Linux上:

# Ubuntu/Debian
sudo apt install gdb

# Fedora
sudo dnf install gdb

# Verify installation
gdb --version

React/Vue/Svelte(浏览器调试)

对于前端框架,您可以通过Chrome进行调试:

  1. 启动您的开发服务器: npm run dev
  2. 使用 target: "chrome" 使用URL:
{
  "tool": "debug_launch",
  "args": {
    "language": "javascript",
    "target": "chrome",
    "program": "http://localhost:3000",
    "webRoot": "/path/to/your/project"
  }
}

对于使用打包器(Vite、Webpack等)的源映射解析,请配置 sourceMapPathOverrides:

{
  "adapters": {
    "node": {
      "jsDebugPath": "/path/to/dapDebugServer.js",
      "sourceMapPathOverrides": {
        "/*": "${webRoot}/*",
        "webpack:///src/*": "${webRoot}/src/*",
        "webpack:///./*": "${webRoot}/*"
      }
    }
  }
}

示例工作流

调试Go程序

User: Debug main.go and stop at line 42

AI uses:
1. debug_launch(language="go", program="./main.go", stopOnEntry=true)
2. debug_run_to_line(path="main.go", line=42)  → Returns snapshot with stack and variables

调试Python脚本

User: Why does process_data return None for this input?

AI uses:
1. debug_launch(language="python", program="script.py", stopOnEntry=true)
2. debug_run_to_line(path="script.py", line=45)  → Runs to return statement
3. debug_evaluate(expressions='["result", "len(data)", "type(data)"]')  → Batch evaluate
4. Analyzes variable state to explain the bug

调试React应用程序

User: Debug the click handler in App.jsx

AI uses:
1. debug_launch(language="javascript", target="chrome",
                program="http://localhost:3000", webRoot="/path/to/project")
2. debug_breakpoints(path="/path/to/project/src/App.jsx",
                     breakpoints='[{"line": 25}]')
3. [User clicks button in browser]
4. debug_snapshot() → Returns component state, props at breakpoint

使用VS代码launch.json配置

User: Debug my project using the "Python: Tests" configuration

AI uses:
1. debug_launch(configName="Python: Tests", workspace="/path/to/project")
   → Loads settings from .vscode/launch.json, resolves ${workspaceFolder}, etc.
2. debug_snapshot() → Returns state at entry point

建筑

┌─────────────────────────────────────────────────────────────────┐
│                     Claude / Cursor / AI Client                  │
│                           (MCP Client)                           │
└─────────────────────┬───────────────────────────────────────────┘
                      │ MCP Protocol (JSON-RPC 2.0 over stdio)
┌─────────────────────▼───────────────────────────────────────────┐
│                       DAP-MCP Server                             │
│  ┌─────────────────────────────────────────────────────────┐    │
│  │  MCP Handler → Session Manager → DAP Client             │    │
│  └─────────────────────────────────────────────────────────┘    │
└─────────────────────┬───────────────────────────────────────────┘
                      │ DAP Protocol (JSON over TCP)
┌─────────────────────▼───────────────────────────────────────────┐
│  ┌──────────┐  ┌──────────┐  ┌─────────────────────────────┐    │
│  │   Delve  │  │ debugpy  │  │      vscode-js-debug        │    │
│  │   (Go)   │  │ (Python) │  │   (JavaScript/TypeScript)   │    │
│  └──────────┘  └──────────┘  └──────────────┬──────────────┘    │
└──────────────────────────────────────────────│──────────────────┘
                                               │ CDP
                                     ┌─────────▼─────────┐
                                     │  Node.js / Chrome │
                                     └───────────────────┘

故障排除

“未找到dlv”/“未找到debugpy”

确保调试适配器在您的PATH中。对于Go:

export PATH="$PATH:$(go env GOPATH)/bin"

“未配置jsDebugPath”

您需要安装vscode-js-debug并配置其路径。看 JavaScript/TypeScript设置.

断点显示“未绑定”

对于浏览器调试,这通常意味着源映射不能正确解析。尝试:

  1. 确保 webRoot 指向您的项目根目录
  2. 配置 sourceMapPathOverrides 为了你的bundler
  3. 检查bundler配置中是否启用了源映射

附件上显示“连接被拒绝”

确保目标流程为:

  1. 使用调试标志运行(--inspect 对于Node, --remote-debugging-port Chrome)
  2. 在预期端口上监听

会话超时

增加配置中的超时时间:

{
  "sessionTimeout": "60m"
}

发展

# Build
make build

# Run tests
make test

# Run linter
make lint

# Build for all platforms
make build-all

相关项目

许可证

MIT许可证

贡献

欢迎投稿!请随时提交拉取请求。