Skip to main content
Glama

gdb-mcp

Give your coding agent hands on a real GDB — Linux userland dynamic debugging.

An MCP server that lets Claude Code, Codex, or any MCP client drive live Linux gdb sessions (pwndbg-aware): launch or attach, control execution, inspect state, triage crashes (live or core dumps), drive inferior stdio, and delegate bounded pwn loops inside gdb.

CI Python Platform License: MIT Tests

Quick Start · Tools · Architecture · Scope Gate · 中文文档


Why gdb-mcp?

Most "debugger MCP" projects parse GDB/MI output or scrape terminal screens. gdb-mcp takes a different route: a small stdlib-only Python plugin runs inside the gdb process and talks to the server over a JSON-lines control channel — so pwndbg contexts, pwntools-launched sessions, and reverse-execution all just work, with none of the prompt-scraping fragility.

  • Sharp userland surface — the default pwn profile exposes 17 focused tools (consolidated from 36, ~5.2k tokens total and bounded by a CI-enforced schema byte budget). Static analysis, kernel VMs, and enterprise HTTP stacks are deliberately out of scope (ADR-0001).

  • Built for pwn, not just debugging — one-call crash triage & replay, glibc heap(action="bins") + standalone heap(action="chunk") decoding (safe-linking aware), allocation return timelines, checkpoint/restore, inferior_io(action="send") / inferior_io(action="read") for menu targets, and an evidence-backed campaign state machine.

  • Token-frugal by design — control_execution(action="continue", wait=True, with_context=True) returns the stop picture (verdict + key registers + backtrace + disassembly) in one call; oversized outputs spill to disk instead of flooding context.

  • Delegated execution — bounded loops (trace, heap_arm, fuzz_loop, minimize, bp_stats, verify_pc_control) run inside gdb at native speed and return constant-size summaries; interrupt cancels an active policy cleanly with partial results.

  • Fails fast before the first launch — gdb-mcp --selfcheck reports the gdb command/version, embedded Python, pwndbg visibility, plugin file, and listener port in one JSON report, exiting non-zero when a session could not start. Linux defaults to the native launcher; Windows defaults to WSL.

  • pwntools stays in charge — gdb.debug() / gdb.attach() sessions register automatically; the server never fights your scripts for I/O.

  • Verified against reality — unit tests (including seeded protocol fuzzing), real-gdb CI smokes across gdb 12 / 15 / 18, and a 72-task acceptance benchmark across 9 families (including pwn_workflow, reference-solved 72/72).

Related MCP server: gdb-mcp

Quick Start

1. Install (Windows side with WSL2 backend, or natively on Linux):

pip install -e .

The default launcher follows the host: native on Linux, wsl on Windows. Override it with --launcher / GDB_MCP_LAUNCHER; point at a specific binary with --gdb-path / GDB_MCP_GDB_PATH (for example gdb-multiarch).

2. Prepare Linux / WSL2:

sudo apt install gdb python3 python3-pip gcc   # pwndbg optional but recommended

3. Register with your MCP client:

When the MCP server runs on Windows and launches gdb in WSL2, use --launcher wsl explicitly. Claude Code (.mcp.json):

{
  "mcpServers": {
    "gdb-mcp": {
      "command": "gdb-mcp",
      "args": ["--launcher", "wsl"],
      "env": { "GDB_MCP_PORT": "3939" }
    }
  }
}

When the MCP client and server run inside Linux or WSL2, install the package there and use --launcher native instead (do not invoke WSL from inside WSL):

{
  "mcpServers": {
    "gdb-mcp": {
      "command": "gdb-mcp",
      "args": ["--launcher", "native"],
      "env": { "GDB_MCP_PORT": "3939" }
    }
  }
}

Cursor uses the same shape in ~/.cursor/mcp.json. Codex CLI (Windows host; change wsl to native inside Linux/WSL2):

[mcp_servers.gdb-mcp]
command = "gdb-mcp"
args = ["--launcher", "wsl"]
env = { GDB_MCP_PORT = "3939" }

4. Check the launcher before debugging. gdb-mcp --selfcheck prints a JSON report and exits non-zero when a session could not start: the gdb command and version, embedded Python, pwndbg visibility, the installed plugin file, and whether the listener port is free. It accepts the same --launcher, --gdb-path, and --port flags as the server.

gdb-mcp --selfcheck

5. Call tools through your MCP client. These Python-shaped blocks are MCP call notation, not an importable Python API or standalone Python script. Use your own Linux target path; replace SESSION_ID with the session ID returned by launch_gdb. The examples below are individual operations, not one script.

Start with the bundled example (examples/hello.c):

gcc -g -O0 -o /tmp/gdb-mcp-hello examples/hello.c
launch_gdb(program="/tmp/gdb-mcp-hello", run=False)
breakpoint(action="set", location="break_here", session_id="SESSION_ID")
execute_command(command="run", session_id="SESSION_ID")
control_execution(action="wait", timeout_ms=10000, session_id="SESSION_ID")
inspect_code(action="backtrace", max_frames=8, session_id="SESSION_ID")
kill_session(force=True, session_id="SESSION_ID")

examples/crasher.c is the crash-triage example; the menu example below uses a pty for interactive I/O.

launch_gdb(program="/tmp/menu", stdio="pty", run=True)
control_execution(action="continue", wait=True, with_context=True, session_id="SESSION_ID")
inferior_io(action="send", text="1\n", session_id="SESSION_ID")
inferior_io(action="read", since_seq=0, session_id="SESSION_ID")

Only resume a stopped inferior; send/read stdio while it runs at a menu prompt. For a stopped session, these are additional operations: bins require pwndbg, chunk requires a valid chunk address (replace the example address), and loading a core requires a matching executable already loaded.

heap(action="bins", session_id="SESSION_ID")
heap(action="chunk", address="0x555555559290", session_id="SESSION_ID")
load_target(path="/tmp/menu", session_id="SESSION_ID")
load_target(path="/tmp/core.menu", core=True, session_id="SESSION_ID")

Alternatively, keep your pwntools workflow untouched and load the installed plugin (run this script inside Linux/WSL2, with the package installed there):

from pathlib import Path
from pwn import *
import gdb_mcp

plugin = Path(gdb_mcp.__file__).resolve().parent / "plugin" / "gdb_mcp_plugin.py"
io = gdb.debug("./vuln", gdb_args=["-x", str(plugin)])

Tool Catalog

17 tools by default in the pwn profile (~5.2k tokens), 10 under GDB_MCP_TOOL_PROFILE=core (~3.3k tokens), plus 1 experimental tool (diff_sessions, behind --experimental).

Profile

Purpose

core

Minimal 10-tool session/execution/state/breakpoint/crash surface

pwn (default)

Core + heap, checkpoints, policies, campaign, inferior stdio, threads/frames, target loading

Group

Tools

Sessions

launch_gdb (program, attach_pid, or script for pwntools; optional stdio="pty") kill_session (force/forget) session_info (list/status/events/output/export)

Execution & I/O

control_execution (continue/step/next/stepi/nexti/finish/until/reverse_*/wait/interrupt, with_context=True) execute_command (raw gdb/pwndbg, multi-line, paginated + result_file slicing) inferior_io (send/read over pty)

State & Breakpoints

memory (read/write/map with core fallback) registers (read/write) inspect_code (disassemble/backtrace/evaluate) thread_frame (list_threads/select_thread/select_frame) load_target (path, optional core=True for a core dump; no action) breakpoint (set/list/delete/enable/disable)

Crash & Pwn

crash_report (triage + optional checkpoint replay/minimize/evidence) heap (bins via pwndbg / chunk standalone with safe-linking decode) checkpoint (create/list/restore/diff) run_policy (trace/heap_arm·read·disarm/fuzz_loop/crash_check/minimize/bp_stats/verify_pc_control) campaign (get/set/note/detect/protections/pattern)

kill_session separates four outcomes instead of one ambiguous "killed":

Call

What happens

kill_session()

plugin detaches; gdb and the inferior keep running

kill_session(force=True)

termination of a launched process tree is requested; an attached gdb is asked to quit

kill_session(forget=True)

also drops the server-side record

kill_session(force=True, forget=True)

request termination and drop the record

Results carry launched, process_termination, and termination_note; termination is a request, not proof that the process exited.

Architecture

Claude Code / any MCP client ──stdio──► gdb-mcp server (17 default tools)
        ▲  campaign state · journals · policies
        │
        │ TCP JSON-lines (scoped session tokens, heartbeats)
        ▼
gdb process (WSL2 / native Linux)
  └─ gdb_mcp_plugin.py — in-process stdlib-only bridge
       ├─ all gdb API calls marshalled to gdb's main thread
       ├─ stop/running/exited events pushed as they happen
       └─ coexists with pwndbg & pwntools (never touches prompt or I/O)

Launchers: WSL2 (--launcher wsl, default on Windows) and native Linux (--launcher native, default on Linux). Transport: stdio.

Concurrency semantics. Within one session, tool calls execute strictly one-at-a-time: the plugin marshals every gdb API call onto gdb's main thread, and the server serializes requests per session. Execution verbs while the inferior runs fail fast with INFERIOR_RUNNING. Different sessions are fully independent.

Compatibility. Verified against gdb 12.1 (CI ubuntu-22.04), gdb 15.x (CI ubuntu-24.04), and gdb 18.1 + pwndbg (WSL2).

Security Model

  • TCP listener is loopback-only (127.0.0.1:3939) by default; non-loopback binds require --token / GDB_MCP_TOKEN.

  • Launched gdb sessions use session-scoped HMAC tokens — the master token never reaches child processes.

  • Capability model: every tool declares observe, debug, target, host, or admin. --readonly keeps only observe tools plus the read-only view breakpoint(action="list") (excluding execute_command, control_execution, launch_gdb, breakpoint mutations, writes, and policies). Retained tools still reject mutating actions: session_info(action="export") and inspect_code(action="evaluate") return READONLY; status, backtrace, and disassembly remain available.

  • Unsafe command gate: debugger-escaping commands (shell, !, pipe, python, source, dump, append, restore, set exec-wrapper, set auto-load, set startup-with-shell, …) are blocked at both server and plugin layers unless --allow-unsafe. The gate is abbreviation-aware and checks every line of multi-command strings, verified against real gdb in CI.

  • Journals, session state, result files, and exported scripts are written 0600 with explicit schema validation on reload.

Testing

# unit (no gdb required)
python -m pytest tests/ -q

# real-gdb suites (WSL2 or native Linux)
wsl bash tests/integration/run_wsl_integration.sh # plugin <-> server protocol
wsl bash tests/integration/run_policy_smoke.sh    # policy loops (trace/bp_stats)
wsl bash tests/integration/run_pc_control_smoke.sh # PC-control verification
wsl bash tests/integration/run_heap_smoke.sh      # heap timeline (allocation returns)
wsl bash tests/integration/run_io_smoke.sh        # inferior stdio over a pty
wsl bash tests/integration/run_unsafe_gate_probe.sh # unsafe gate premises
PYTHONPATH=src python tests/integration/run_mcp_tools_e2e.py --distro kali-linux

# acceptance benchmark (72 tasks across 9 families, incl. pwn_workflow)
python -m bench.framework.cli build --distro kali-linux
python -m bench.framework.cli selfcheck --distro kali-linux

For the installed-package MCP end-to-end regression, first build a wheel and install it into a clean Linux/WSL2 virtual environment, then run python -I tests/integration/run_native_install_smoke.py using that venv's Python. This tests the installed wheel over MCP stdio with the native launcher through the generated gdb-mcp entry point; it is not a source-tree smoke. CI runs it on Ubuntu 22.04 with Python 3.10 and Ubuntu 24.04 with Python 3.13. Do not use an editable install, PYTHONPATH=src, or a plugin-path override for this check.

Contributing

Issues and PRs welcome — please keep python -m pytest tests/ -q and ruff check src tests bench clean, and check new capabilities against ADR-0001.

License

MIT © gdb-mcp contributors

Available Tools

27 tools
continue_executionA

Resume the inferior: continue / step / next / stepi / nexti / finish / until. Returns immediately; use wait_for_stop to wait for the next stop event, or rely on the async stop notification.

Inputs: mode, session_id, until_addr.

crash_reportA

One-call crash triage: signal, fault address, PC, registers, backtrace, disassembly around PC, memory at PC/SP/fault address and the head of the memory map. Use after wait_for_stop (or after a stop notification). Best-effort: unreadable pieces are reported in warnings instead of failing the whole call.

Inputs: max_frames, session_id.

disassembleA

Disassemble count instructions at start (address, gdb expression, function name — or the current PC when omitted).

Inputs: count, start, session_id.

evaluateA

Evaluate a gdb expression against the live inferior (PIE-aware): 'main', '&puts@got', '$rax+8', '*(char**)0x404000'.

Inputs: expression (required), session_id.

execute_commandA

Execute a raw gdb command and return its output. Use for pwndbg-specific commands (vmmap, heap, got, checksec, ropgadget, search, ...) or any other gdb CLI command. Works while the inferior is running (queued until the next stop).

Inputs: command (required), keep_ansi, session_id.

get_backtraceC

Stack backtrace: pc, function name, source file/line per frame.

Inputs: max_frames, session_id.

get_memory_mapA

Memory mappings of the inferior (info proc mappings — works without pwndbg). For richer output use execute_command('vmmap').

Inputs: session_id.

get_process_outputA

Tail the stdout/stderr log of a launched session (gdb or script). Requires the session to have been started by launch_gdb / launch_script.

Inputs: session_id, tail_lines.

get_stop_reasonB

The reason the inferior last stopped (signal, fault address, breakpoint info).

Inputs: session_id.

interruptA

Interrupt the running inferior (equivalent to Ctrl-C in gdb). The inferior stops and a stop notification is emitted.

Inputs: session_id.

kill_sessionA

End a session. For gdb, the default detaches the plugin and leaves gdb running; force=True also terminates gdb. Script sessions are terminated gracefully by default or killed with force=True.

Inputs: force, session_id.

launch_gdbA

Launch gdb with the MCP plugin loaded inside WSL2 (background process, log captured to a file). program may be a Windows or WSL path; the session registers itself when the plugin connects. With run=True, the inferior is started immediately (equivalent to gdb -ex run).

Inputs: cwd, env, run, args, +4 more.

launch_scriptA

Launch a Python (typically pwntools) script inside WSL2. script must be an absolute Windows or WSL file path; inline code is not supported. If the script starts gdb with the MCP plugin loaded (via gdb_args/gdbscript), the new gdb session id is returned once it registers. A script that exits without gdb returns immediately with its state, return code, and log tail.

Inputs: script (required), cwd, env, args, +3 more.

list_breakpointsB

List all breakpoints/watchpoints.

Inputs: session_id.

list_sessionsA

List all known sessions (gdb plugin connections and launched processes) with their state.

Inputs: no named parameters.

list_threadsA

List inferior threads and which one is selected.

Inputs: session_id.

load_targetA

Load a program (file <path>) or core dump (core-file <path>) into the gdb session. For gdb sessions started without an inferior.

Inputs: path (required), core, session_id.

manage_breakpointA

Delete / enable / disable a breakpoint by number.

Inputs: action (required), number (required), session_id.

quit_gdbA

Detach the MCP plugin from gdb. With kill_gdb=True, also quit gdb itself (and with it the debugged process). Default leaves the externally launched gdb running.

Inputs: kill_gdb, session_id.

read_memoryB

Read raw memory from the inferior. address may be an int, a hex string ('0x401000'), or a gdb expression ('main+0x10', '&puts@got'). Returns hex, printable-ascii, and unreadable ranges.

Inputs: address (required), length, session_id.

read_registersA

Read register values (all general-purpose registers by default, or the named subset).

Inputs: names, session_id.

select_frameA

Select a stack frame by level (0 = innermost) for subsequent register/memory/local inspection.

Inputs: level (required), session_id.

session_statusC

Detailed status of one gdb session: state, inferior info, last stop reason.

Inputs: session_id.

set_breakpointC

Set a breakpoint at an address/symbol/expression ('main', '*main+0x20', '0x401000'). Types: breakpoint (software), hw (hardware), watch, hw_watch.

Inputs: location (required), type, thread, pending, +3 more.

wait_for_stopA

Wait until the inferior stops (signal, breakpoint, exit) or the timeout elapses. Returns immediately when the inferior is already stopped.

Inputs: session_id, timeout_ms.

write_memoryB

Write raw bytes (given as a hex string, e.g. '9090c3' or '90 90 c3') to the inferior's memory.

Inputs: hex (required), address (required), session_id.

write_registerC

Write a register. value is a gdb expression (e.g. '0x401000', '$rax+8', 'main').

Inputs: name (required), value (required), session_id.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    B3.4/5.0

    Scored across 27 tools

    Disambiguation4/5

    Most tools target distinct gdb actions such as memory, registers, breakpoints, and execution control. The main ambiguity is between quit_gdb and kill_session, which overlap in detaching/terminating sessions, but descriptions are detailed enough to guide selection in most cases.

    Naming Consistency4/5

    The set mostly follows verb_noun conventions: list_*, get_*, read_*, write_*, set_breakpoint, launch_*. Minor inconsistencies exist, such as session_status and crash_report using noun phrases instead of get_* and interrupt/continue_execution/wait_for_stop using different patterns, but the overall style remains readable and predictable.

    Tool Count3/5

    At 27 tools, the set is above the typical well-scoped range and feels heavy, though gdb is a broad debugging domain and most tools cover a concrete operation. The count could be reduced by merging quit_gdb into kill_session and avoiding the catch-all nature of execute_command.

    Completeness4/5

    The core debugging lifecycle is well covered: launching/loading targets, breakpoints, execution control, memory and register inspection, threads/frames, and crash triage. Minor gaps such as setting breakpoint conditions or modifying variables directly can be worked around using execute_command or evaluate.

    Maintenance

    ActivityActive
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      B
      quality
      D
      maintenance
      Enables AI assistants to control GDB debugger via MCP protocol for local and remote debugging, supporting CTF Pwn, crash analysis, and ELF inspection.
      13
      1
      MIT
    • A
      license
      B
      quality
      C
      maintenance
      MCP server wrapping GDB and GEF for dynamic analysis, enabling interactive debugging and memory inspection via GDB/MI protocol.
      14
      1
      MIT
    • A
      license
      B
      quality
      D
      maintenance
      MCP server that wraps gdb to enable LLMs to drive live debugging sessions, including starting sessions on binaries, attaching to processes, and running commands.
      7
      1,428 PyPI
      4
      MIT