dap-mcp

by KashunCheng
Verified

local-only server

The server can only run on the client’s local machine because it depends on local resources.

Integrations

  • Supports debugging pytest modules during test execution, providing breakpoint management and step-by-step debugging capabilities for Python tests.

  • Integrates with Python debugging through debugpy, allowing the setting/removal of breakpoints, controlling execution flow, evaluating expressions, and viewing source code.

  • Provides XML-rendered output for debugging information and tool responses to integrate with MCP clients.

dap-mcp

dap-mcp模型上下文协议 (MCP)的实现,专为管理调试适配器协议 (DAP) 会话而定制。MCP 提供了一个标准化框架来优化和扩展大型语言模型的上下文窗口,在本项目中,它用于增强和简化调试工作流程。

特征

  • **调试适配器协议集成:**使用标准化协议与调试器交互。
  • **MCP 框架:**利用 MCP 优化上下文并增强调试工作流程。
  • **丰富的调试工具:**设置、列出和删除断点;控制执行(继续、步入/步出/下一步);评估表达式;更改堆栈框架;以及查看源代码。
  • **灵活的配置:**通过 JSON 配置文件自定义调试器设置、源目录和其他参数。

安装

先决条件

  • Python 3.10 或更高版本
  • uv (可选,用于运行服务器)

安装并运行服务器

安装dap-mcp及其依赖项:

pip install dap-mcp python -m dap_mcp --config config.json # Or, if you have uv installed uvx dap-mcp@latest --config config.json

配置

该项目使用 JSON 配置文件(例如.config.json )来指定调试器设置和源码目录。以下是示例配置:

{ "type": "debugpy", "debuggerPath": "/path/to/python/with/debugpy", "debuggerArgs": [ "-m", "debugpy.adapter" ], // source directories for resolving file paths // if you always use absolute paths, you can omit this "sourceDirs": [ "/path/to/source/code" ], // debugger-specific settings start here // configurations for debugpy can be found at // https://github.com/microsoft/debugpy/wiki/Debug-configuration-settings // you can use "program" instead of "module" to specify the program to debug "module": "pytest", // the python executable to use to run the debuggee "python": ["/path/to/python"], "cwd": "/path/to/working/directory" }

此配置告知调试器:

  • 调试器可执行文件及其参数的路径。
  • 断点操作期间解析文件路径的源目录。
  • 启动调试器所需的其他设置(例如模块、工作目录和解释器路径)。

可用的调试器类型

类型示例路径示例参数
调试/usr/bin/python3["-m", "debugpy.adapter"]
lldb/usr/bin/lldb-dap[]

可用工具

该项目公开了几个可以通过 MCP 框架调用的工具:

  • **启动:**启动被调试程序。
  • **set_breakpoint:**在指定的文件和行设置断点(可选条件)。
  • **remove_breakpoint:**从指定文件和行中删除断点。
  • **list_all_breakpoints:**列出调试器中当前设置的所有断点。
  • **continue_execution:**到达断点后继续程序执行。
  • **step_in:**进入函数调用。
  • **step_out:**跳出当前函数。
  • **next:**跳到下一行代码。
  • **评估:**在当前调试上下文中评估表达式。
  • **change_frame:**切换到不同的堆栈帧。
  • **view_file_around_line:**查看指定行周围的源代码(如果未指定,则使用最后提供的文件)。
  • **终止:**终止调试会话。

这些工具提供 XML 呈现的输出以便与 MCP 客户端集成。

使用其他 DAP 服务器进行扩展

要支持其他 DAP 服务器,您只需在dap_mcp/config.py文件中添加一个新的 DAP 专用配置类即可。所有 DAP 配置均从基类DAPConfig扩展而来。每个新的子类都应该:

  • 定义一个唯一type值(使用Literal )作为鉴别器。
  • 包括特定于该调试器的任何其他字段或设置。

例如,要添加对名为“mydap”的假设 DAP 服务器的支持,您可以添加:

class MyDAP(DAPConfig): type: Literal["mydap"] # Add any additional settings for MyDAP here customSetting: Optional[str] = Field( None, description="A custom setting for MyDAP." )

创建新的配置类后,通过添加新类来更新用于调试器特定配置的联合类型。例如:

DebuggerSpecificConfig = Annotated[Union[DebugPy, MyDAP], Field(..., discriminator="type")]

现在,当您提供带有"type": "mydap"的配置 JSON 时,它将使用新的MyDAP类进行解析和验证,并且您的 DAP 服务器扩展将完全集成。

贡献

欢迎贡献!贡献方式:

  1. 分叉存储库。
  2. 为您的功能或错误修复创建一个新的分支。
  3. 编写测试并确保所有检查都通过。
  4. 提交拉取请求。

请遵循编码指南并在更改中包含适当的测试。

执照

本项目采用 AGPL-3.0 许可证。详情请参阅许可证文件。

-
security - not tested
A
license - permissive license
-
quality - not tested

模型上下文协议 (MCP) 的实现,可以与调试适配器进行交互,允许语言模型在调试会话期间控制调试器、设置断点、评估表达式和导航源代码。

  1. Features
    1. Installation
      1. Prerequisites
      2. Installing and Running the Server
    2. Configuration
      1. Available Debugger Types
    3. Available Tools
      1. Extending with Other DAP Servers
        1. Contributing
      2. License
        ID: l2jcplh0de