gdb-mcp

gdb-mcp

Enables AI agents to debug C/C++ programs with GDB or LLDB, supporting breakpoints, stepping, variable inspection, and function calls.

Category
访问服务器

README

gdb-mcp

An MCP server that lets an AI agent drive a full C/C++ debugging session — set breakpoints, step, inspect memory and variables, evaluate expressions, and call functions — using either GDB or LLDB behind one unified tool surface.

It works by speaking the Debug Adapter Protocol (DAP) to the debugger that ships with your toolchain (gdb -i dap or lldb-dap), so a single set of tools drives both debuggers.

Validated end-to-end with Claude Code, Codex CLI, and Cursor CLI — each agent independently used these tools to debug a live program and extract correct runtime state.


Features

  • Three ways to start: launch a prebuilt binary, compile-then-debug a source file, or attach to a running process (by PID).
  • Execution control: continue, step (over / into / out, line or instruction granularity), and a lock-free pause that can interrupt a running program.
  • Breakpoints: source (file:line) and function breakpoints, with conditions, hit counts, and logpoints; data breakpoints (watchpoints); stable handles for reliable removal.
  • Inspection: backtraces, threads, stack frames, scopes, lazy variable expansion (structs/arrays/STL), expression evaluation and function calls (foo(x)), set-variable, read-memory, and disassembly.
  • Source listing around the current stop, plus a raw-command escape hatch (dbg_raw_command) for anything the structured tools don't cover.
  • Agent-friendly output: verbose DAP payloads are trimmed to compact JSON, with stop-epoch guards so an agent can't accidentally read a stale frame or variable reference after the program advances.

Prerequisites

  • Python 3.11+
  • A DAP-capable debugger:
    • GDB ≥ 14 (ships the gdb -i dap interpreter), or
    • lldb-dap (bundled with LLVM / Xcode; on macOS it is found via xcrun -f lldb-dap).
  • A C/C++ toolchain (cc/clang/gcc) for the compile-then-debug mode and to build debuggees with -g.
  • uv (recommended) or pip.

Platform note. On Linux, run debuggers normally. On macOS, live debugging needs the debugserver attach permission — if dbg_start returns "Not allowed to attach", enable Developer Mode once: sudo DevToolsSecurity -enable. macOS arm64 GDB cannot debug native Mach-O binaries; use LLDB locally and GDB on Linux.

Installation

git clone https://github.com/birdeclipse/gdb-mcp.git
cd gdb-mcp
uv venv && uv pip install -e ".[dev]"   # or: pip install -e ".[dev]"

Verify the server starts and advertises its tools:

uv run gdb-mcp        # starts the MCP server on stdio (Ctrl-C to stop)
uv run pytest -m mcp  # asserts the server advertises all 20 tools

Registering with an agent

The server runs over stdio. The robust invocation lets uv resolve the project venv regardless of PATH (replace /path/to/gdb-mcp with your clone path):

command: uv
args:    ["run", "--directory", "/path/to/gdb-mcp", "gdb-mcp"]

Ready-to-edit config snippets live in integrations/. Summary:

Agent How
Claude Code claude mcp add gdb-mcp -- uv run --directory /path/to/gdb-mcp gdb-mcp — or merge integrations/mcp.claude.json into .mcp.json
Codex CLI merge integrations/codex.config.toml into ~/.codex/config.toml
Cursor CLI copy integrations/mcp.cursor.json to .cursor/mcp.json (project) or ~/.cursor/mcp.json

If you pip install the package so gdb-mcp is on PATH, you can use command: gdb-mcp with empty args instead.

Tools

All tools except dbg_start take a session_id.

Tool Purpose
dbg_start Start a session: mode = launch / compile_launch / attach, debugger = gdb / lldb
dbg_terminate Kill (launch) or detach (attach) and free the session
dbg_continue Resume until the next stop / exit
dbg_step Step over / into / out; line or instruction granularity
dbg_pause Interrupt a running program (lock-free)
dbg_set_breakpoint file:line or function; optional condition, hit_condition, log_message
dbg_list_breakpoints List source / function / data breakpoints with handles
dbg_remove_breakpoint Remove by stable handle
dbg_set_watchpoint Data breakpoint on a variable (read / write / rw)
dbg_backtrace Stack frames for a thread
dbg_list_threads All threads
dbg_select_frame Set the active frame for eval / scopes / variables
dbg_scopes Variable scopes (Locals, …) for a frame
dbg_variables Expand a variablesReference (lazy struct/array/STL expansion)
dbg_evaluate Evaluate an expression or call a function (foo(x))
dbg_set_variable Set a variable to a new value
dbg_read_memory Read raw memory (base64)
dbg_disassemble Disassemble around an address
dbg_source Source lines around a location
dbg_raw_command Run a raw gdb/lldb command (escape hatch)

Example: a debugging session

A typical agent flow against a program with a Point pt = {3, 7} local:

  1. dbg_start(mode="launch", debugger="lldb", program="/path/to/a.out") → stops at entry, returns a session_id.
  2. dbg_set_breakpoint(session_id, file="main.c", line=6) → verified, handle 1.
  3. dbg_continue(session_id) → {state: "stopped", reason: "breakpoint", frame: {function: "main", file: "main.c", line: 6}}.
  4. dbg_backtrace(session_id) → frames.
  5. dbg_scopes(session_id) → Locals; dbg_variables(session_id, ref=…) → pt (expandable) → expand → {x: 3, y: 7}.
  6. dbg_evaluate(session_id, "pt.x + pt.y") → 10.
  7. dbg_terminate(session_id).

How it works

agent ──MCP tool call──▶ MCP server (Python, asyncio)
                              │  Session Manager  (session_id → one debuggee)
                              │  DAP Client       (Content-Length framing,
                              │                    request/response + async events)
                              ▼  spawns
                    gdb -i dap   |   lldb-dap
                              ▼
                      debuggee process

Execution tools are event-driven: continue/step resolve on the debugger's next stopped/exited event, not on the request response. See docs/ARCHITECTURE.md for the design and CONTRIBUTING.md for development.

Testing

uv run pytest                # everything
uv run pytest tests/unit     # offline (scripted fake adapter) — no debugger
uv run pytest -m mcp         # MCP stdio handshake + tool advertisement
uv run pytest -m integration # live debugger on the C fixtures (auto-skips if none)

The integration suite probes for a working debugger and skips cleanly when none is available, so it is safe to run anywhere.

License

MIT

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选