Skip to content
Back to search

gdb-mcp-server

一个支持人工智能辅助调试的 GDB MCP (Model Context Protocol) 服务器。该服务器允许 AI 代理和其他工具通过 MCP 协议与 GDB 进行交互。

Safety scan

A static text scan, not a guarantee. Select the badge to see what was scanned and every finding.

Checked today
Badge for your README
findsafeskills safety rating

Markdown

[![findsafeskills safety rating](/api/listings/yywz1999--gdb-mcp-server/badge.svg)](/listings/yywz1999--gdb-mcp-server)

HTML

<a href="/listings/yywz1999--gdb-mcp-server"><img src="/api/listings/yywz1999--gdb-mcp-server/badge.svg" alt="findsafeskills safety rating" /></a>

Install

i

Install instructions from the README

As written by the repo's author. findsafeskills has not verified these steps.

1. 克隆仓库:

   git clone https://github.com/yywz1999/gdb-mcp-server.git
   cd gdb-mcp-server

2. 安装依赖:

   python3 -m pip install -r requirements.txt

What was scanned

The files the safety scan read, as written by the repository's author and shown as plain text. Lines with a finding are marked.

README.md · README · 143 lines

View this file on GitHub (read at the repository's current version: the scan did not record which commit it read)

  1. # GDB MCP 服务器
  2. 一个支持人工智能辅助调试的 GDB MCP (Model Context Protocol) 服务器。该服务器允许 AI 代理和其他工具通过 MCP 协议与 GDB 进行交互。
  3. > **注意**:本项目目前处于开发阶段。我们欢迎社区成员提出建议和反馈,帮助我们改进这个工具。
  4. 项目地址:https://github.com/yywz1999/gdb-mcp-server
  5. ## 特性
  6. - 发现并附加到现有的 GDB 进程
  7. - 通过终端窗口与 GDB 通信(macOS 上优化支持 iTerm2,Linux 使用 tmux)
  8. - 支持 MCP 协议,便于与 AI 助手集成
  9. - 智能处理 GDB 命令阻塞,自动发送中断信号
  10. - 支持多架构、多主机和远程调试场景
  11. - 通过简单的函数调用执行常见的 GDB 调试操作:
  12. - 设置和删除断点
  13. - 单步执行代码
  14. - 检查内存
  15. - 查看寄存器和堆栈跟踪
  16. - 反汇编代码
  17. - 获取局部变量
  18. ## 演示视频
  19. 项目包含一个演示视频,展示了如何使用 GDB MCP 服务器进行附加调试的完整工作流程:
  20. https://github.com/user-attachments/assets/dbb5c2dc-1bc9-4a19-86d7-c967725bc145
  21. 通过观看此视频,您可以更直观地了解 GDB MCP 服务器如何简化多架构和远程调试场景。
  22. ## 使用说明(以Cursor为例)
  23. 1. 下载项目并验证:
  24. ``` shell
  25. git clone https://github.com/yywz1999/gdb-mcp-server.git
  26. cd gdb-mcp-server
  27. python3 -m pip install -r requirements.txt
  28. python3 ~/MCP_server/gdb-mcp-server/mcp_server.py
  29. ```
  30. 结果如下图所示,即为环境正常
  31. <img width="1440" alt="image" src="https://github.com/user-attachments/assets/03437c53-2f93-414c-b5bf-0405b5bbe8f9" />
  32. 2. 配置Cursor:
  33. <img width="553" alt="image" src="https://github.com/user-attachments/assets/e697d13f-27bf-410d-9cfe-05256e513dd2" />
  34. ## 2025/11/27 更新内容:
  35. - 1、Linux 端 tmux 适配全面升级:自动遍历所有 session/pane、过滤 `gdbserver`,精准附加到 pwndbg/gef 等交互式 gdb 会话,无需切换窗口。
  36. - 2、iTerm2 会话识别更精准:直接写入目标窗口且可按内容定位 GDB 会话,无需手动切换焦点。
  37. - 3、阻塞处理更智能:自动判定 `continue/target remote` 等高风险命令并在阻塞时发送中断信号,配合唯一标记让输出更干净。
  38. ## 与 gdb-mcp-server-main 相比的新增能力
  39. - **终端输出隔离**:tmux 侧统一插入唯一的开始/结束标记,自动清理命令和提示符,AI 仅接收结构化结果,不再混入终端错误。
  40. - **阻塞检测与自动中断**:针对 `continue`、`run`、`target remote` 等命令,提供多次轮询与 `Ctrl-C` 自动中断策略,并返回清晰提示。
  41. - **Linux 端适配**:新的 tmux 通信链可以遍历所有 session/pane,精确定位真正的 `gdb/pwndbg/gef` 进程并忽略 `gdbserver`,整个控制过程无需切换窗口。
  42. - **更安全的进程筛选**:`sys_find_gdb_processes` 与 tmux 探测逻辑会过滤 Python 启动脚本及远程 server,只附加到可交互的本地 GDB。
  43. - **API 精简**:移除了不再需要的“启动 GDB”接口,保留并强化“查找 → 附加 → 执行”主流程,让 README、工具列表与实现保持一致。
  44. ## 技术实现简介
  45. GDB MCP 服务器使用以下技术实现 GDB 的控制和通信:
  46. 1. **MCP 协议实现**:使用 [FastMCP](https://github.com/jlowin/fastmcp) 库提供符合 Model Context Protocol 规范的工具接口
  47. 2. **多种通信策略**:
  48. - **AppleScript**:在 macOS 上与 iTerm2 通信(推荐)
  49. - **pexpect**:直接与 GDB 进程通信(Linux 优先)
  50. - **键盘模拟**:作为最后的回退方案
  51. 3. **进程发现**:自动查找系统中运行的 GDB 进程,无需用户手动指定进程 ID
  52. ## 测试环境
  53. - 操作系统:macOS(Intel架构)
  54. - Python版本:Python 3.11
  55. - 终端:iTerm2
  56. ## 安装
  57. 1. 克隆仓库:
  58. ```bash
  59. git clone https://github.com/yywz1999/gdb-mcp-server.git
  60. cd gdb-mcp-server
  61. ```
  62. 2. 安装依赖:
  63. ```bash
  64. python3 -m pip install -r requirements.txt
  65. ```
  66. ## 使用方法
  67. 1. 启动服务器:
  68. ```bash
  69. python3 mcp_server.py
  70. ```
  71. 2. 使用 MCP 协议通过服务器与 GDB 交互。服务器提供以下工具函数:
  72. ### 系统工具
  73. - `sys_find_gdb_processes` - 查找所有运行的 GDB 进程
  74. - `sys_attach_to_gdb` - 附加到 GDB 进程
  75. ### GDB 调试工具
  76. - `gdb_execute_command` - 执行任意 GDB 命令
  77. - `gdb_set_breakpoint` - 设置断点
  78. - `gdb_delete_breakpoint` - 删除断点
  79. - `gdb_step` - 单步执行
  80. - `gdb_next` - 执行到下一行
  81. - `gdb_finish` - 执行到函数返回
  82. - `gdb_continue` - 继续执行
  83. - `gdb_get_registers` - 获取寄存器值
  84. - `gdb_examine_memory` - 检查内存
  85. - `gdb_get_stack` - 获取堆栈跟踪
  86. - `gdb_get_locals` - 获取局部变量
  87. - `gdb_disassemble` - 反汇编代码
  88. - `gdb_connect_remote` - 连接到远程调试目标
  89. ## macOS 上的最佳实践
  90. 在 macOS 上使用 GDB MCP 服务器时,建议:
  91. 1. 使用 iTerm2 作为终端模拟器(提供最佳支持)
  92. 2. 确保 GDB 终端窗口在启动服务器前已打开
  93. 3. 对于远程调试,建议先手动在 GDB 中设置相关配置,然后通过 MCP 服务器附加
  94. ## 故障排除
  95. ### macOS 上的常见问题
  96. 1. **窗口激活问题**:如果 GDB 窗口无法正确激活,尝试手动将其置于前台
  97. 2. **输入法状态**:确保 GDB 终端未处于中文或其他输入法状态
  98. 3. **命令阻塞**:对于阻塞的命令(如 target remote),服务器会自动发送中断信号
  99. ### Linux 上的常见问题
  100. 1. **TTY 权限**:确保当前用户有权限访问 GDB 进程的 TTY 设备
  101. 2. **pexpect 依赖**:确保已安装 pexpect 库
  102. ## 许可证
  103. 本项目采用 MIT 许可证 - 详见 [LICENSE](LICENSE) 文件

Ratings and comments

Sign in to rate this skill.

Sign in

Free to use. If it’s helped, pass it on.