Skip to main content
Glama

GDB MCP Server

An MCP (Model Context Protocol) server that provides AI assistants with programmatic access to GDB debugging sessions. This allows AI models to interact with debuggers in the same way IDEs like VS Code and CLion do, using the GDB/MI (Machine Interface) protocol.

Features

  • Full GDB Control: Start sessions, execute commands, control program execution

  • Thread Analysis: Inspect threads, get backtraces, analyze thread states

  • Breakpoint Management: Set conditional breakpoints, temporary breakpoints

  • Hardware Breakpoints: Use CPU debug registers when software breakpoints are not suitable

  • Multi-line Commands: Send commands, define, python, and other GDB command blocks

  • Blocking Execution Control: run, continue, step, next, and finish wait until the target stops

  • Variable Inspection: Evaluate expressions, inspect variables and registers

  • Core Dump Analysis: Load and analyze core dumps with custom initialization

  • Flexible Initialization: Run GDB scripts or commands on startup

Related MCP server: gdb and rr Debugging

Fixes in This Fork

This fork focuses on making GDB MCP easier for AI agents to use in real debugging sessions:

  • Fixed execution commands returning too early. run, continue, step, next, and finish now wait until GDB reports *stopped, so breakpoint hits and crashes are returned with the same command.

  • Added a top-level stopped object to execution results, including stop reason, frame, thread, and breakpoint number when GDB provides them.

  • Fixed multi-line GDB command blocks. commands ... end, define ... end, python ... end, if ... end, and while ... end no longer deadlock.

  • Added per-command timeout_sec for long-running debug operations.

  • Added hardware breakpoint support with hardware=true.

  • Added an SSH stdio bridge example for running the MCP server on a remote VM while the MCP client runs locally.

Architecture

This server uses the GDB/MI (Machine Interface) protocol, which is the same interface used by professional IDEs. It provides:

  • Structured, machine-parseable output

  • Full access to GDB's debugging capabilities

  • Reliable command execution and response handling

Installation

Prerequisites

  • Python 3.10 or higher

  • GDB installed and available in PATH

Quick Start

# Install pipx if needed
python3 -m pip install --user pipx
python3 -m pipx ensurepath

# Install gdb-mcp-server
cd /path/to/gdb-mcp
pipx install .

For alternative installation methods (virtual environment, manual setup), see INSTALL.md.

Configuration

Claude Desktop

Add this to your Claude Desktop configuration file:

Location:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json

  • Linux: ~/.config/Claude/claude_desktop_config.json

  • Windows: %APPDATA%\Claude\claude_desktop_config.json

Configuration:

{
  "mcpServers": {
    "gdb": {
      "command": "gdb-mcp-server"
    }
  }
}

For other installation methods and MCP clients, see INSTALL.md.

opencode

Add a project-level opencode.json:

{
  "$schema": "https://opencode.ai/config.json",
  "mcp": {
    "gdb": {
      "type": "local",
      "command": ["gdb-mcp-server"],
      "enabled": true,
      "timeout": 20000
    }
  }
}

For remote VM debugging, run the MCP server over SSH with the bridge example:

{
  "$schema": "https://opencode.ai/config.json",
  "mcp": {
    "gdb_remote": {
      "type": "local",
      "command": ["python", "examples/gdb_mcp_ssh_bridge.py"],
      "enabled": true,
      "timeout": 20000,
      "env": {
        "GDB_MCP_SSH_HOST": "your-vm-host",
        "GDB_MCP_SSH_USER": "root",
        "GDB_MCP_REMOTE_COMMAND": "cd /path/to/gdb-mcp && GDB_MCP_LOG_LEVEL=ERROR exec ./venv/bin/python -m gdb_mcp"
      }
    }
  }
}

Use SSH keys when possible. If password auth is required, set GDB_MCP_SSH_PASSWORD in your shell environment instead of committing it to opencode.json.

Start opencode from the project directory and tell the agent:

use gdb_remote

Environment Variables

The GDB MCP Server supports the following environment variables:

GDB_PATH

Specify the path to the GDB executable to use. This is useful when:

  • You have multiple GDB versions installed

  • GDB is installed in a non-standard location

  • You want to use a custom or patched GDB build

Default: gdb (resolved via system PATH)

Example:

export GDB_PATH=/usr/local/bin/gdb-13.2
gdb-mcp-server

Note: The gdb_path parameter in the gdb_start_session tool overrides this environment variable if both are specified.

GDB_MCP_LOG_LEVEL

Set the logging level for the server.

Default: INFO Options: DEBUG, INFO, WARNING, ERROR, CRITICAL

Example:

export GDB_MCP_LOG_LEVEL=DEBUG
gdb-mcp-server

Available Tools

The GDB MCP Server provides 22 tools for controlling GDB debugging sessions:

Session Management:

  • gdb_start_session - Start a new GDB session with optional initialization

  • gdb_execute_command - Execute GDB commands (CLI or MI format)

  • gdb_call_function - Call a function in the target process (dedicated tool for separate permissioning)

  • gdb_get_status - Get current session status

  • gdb_stop_session - Stop the current session

Thread & Frame Navigation:

  • gdb_get_threads - List all threads

  • gdb_select_thread - Select a specific thread

  • gdb_get_backtrace - Get stack trace for a thread

  • gdb_select_frame - Select a specific stack frame

  • gdb_get_frame_info - Get information about the current frame

Breakpoint Management:

  • gdb_set_breakpoint - Set breakpoints with optional conditions, temporary mode, or hardware mode

  • gdb_list_breakpoints - List all breakpoints with structured data

  • gdb_delete_breakpoint - Delete a breakpoint by number

  • gdb_enable_breakpoint - Enable a breakpoint

  • gdb_disable_breakpoint - Disable a breakpoint

Execution Control:

  • gdb_continue - Continue execution

  • gdb_step - Step into functions

  • gdb_next - Step over functions

  • gdb_interrupt - Pause a running program

Data Inspection:

  • gdb_evaluate_expression - Evaluate expressions

  • gdb_get_variables - Get local variables

  • gdb_get_registers - Get CPU registers

For detailed documentation of each tool including parameters, return values, and examples, see TOOLS.md.

Usage Examples

Example 1: Analyzing a Core Dump

User: "Load the core dump at /tmp/core.12345, set the sysroot to /opt/sysroot, and tell me how many threads there were when it crashed."

AI Actions:

  1. Start session with init commands:

{
  "init_commands": [
    "file /path/to/executable",
    "core-file /tmp/core.12345",
    "set sysroot /opt/sysroot"
  ]
}
  1. Get threads: gdb_get_threads

  2. Report: "There were 8 threads when the program crashed."

Example 2: Conditional Breakpoint Investigation

User: "Set a breakpoint at process_data but only when the count variable is greater than 100, then continue execution."

AI Actions:

  1. Set conditional breakpoint:

{
  "location": "process_data",
  "condition": "count > 100"
}
  1. Continue execution: gdb_continue

  2. When hit, inspect state

For more detailed usage examples and workflows, see examples/USAGE_GUIDE.md and examples/README.md.

Advanced Usage

Custom GDB Initialization Scripts

Create a .gdb file with your setup commands:

# setup.gdb
file /path/to/myprogram
core-file /path/to/core

# Set up symbol paths
set sysroot /opt/sysroot
set solib-search-path /opt/libs:/usr/local/lib

# Convenience settings
set print pretty on
set print array on
set pagination off

Then use it:

{
  "init_commands": ["source setup.gdb"]
}

Python Initialization Scripts

You can also use GDB's Python API:

# init.py
import gdb
gdb.execute("file /path/to/program")
gdb.execute("core-file /path/to/core")
# Custom analysis

Use with:

{
  "init_commands": ["source init.py"]
}

Working with Running Processes

While this server primarily works with core dumps and executables, you can attach to running processes:

{
  "init_commands": [
    "attach 12345"  // PID of running process
  ]
}

Note: This requires appropriate permissions (usually root or same user).

Troubleshooting

Common Issues

GDB Not Found

which gdb
gdb --version

Long-running Execution

Execution commands block until the target stops, exits, crashes, or times out. For long-running programs, pass a larger timeout_sec to gdb_execute_command, gdb_continue, gdb_step, or gdb_next.

If the target is still running after the timeout, use gdb_interrupt to pause it.

Program States:

  • Not started: Use gdb_execute_command with "run" or "start"

  • Running: Program is executing - use gdb_interrupt to pause it

  • Paused (at breakpoint): Use gdb_continue, gdb_step, gdb_next, inspect variables

  • Finished: Program has exited - restart with "run" if needed

Missing Debug Symbols

Always check the warnings field in gdb_start_session response! Compile your programs with the -g flag.

For detailed troubleshooting, installation issues, and more solutions, see INSTALL.md.

How It Works

  1. GDB/MI Protocol: The server communicates with GDB using the Machine Interface (MI) protocol, the same interface used by IDEs.

  2. pygdbmi Library: We use the excellent pygdbmi library to handle the low-level protocol details and response parsing.

  3. MCP Integration: The server exposes GDB functionality as MCP tools, allowing AI assistants to:

    • Understand the available debugging operations

    • Execute commands with proper parameters

    • Interpret structured responses

  4. Session Management: A single GDB session is maintained per server instance, allowing stateful debugging across multiple tool calls.

Contributing

Contributions welcome! Areas for improvement:

  • Additional GDB commands (e.g., watchpoints, memory inspection)

  • Better error handling and recovery

  • Enhanced output formatting

License

MIT

References

Available Tools

22 tools
gdb_call_functionA

Call a function in the target process. WARNING: This is a privileged operation that executes code in the debugged program. It can call any function accessible in the current context, including: - Standard library functions: printf, malloc, free, etc. - Program functions: any function defined in the program - System calls via wrappers The function executes with full privileges of the debugged process. Use with caution as it may have side effects and modify program state. Examples: 'printf("debug: x=%d\n", x)', 'my_cleanup_func()', 'strlen(str)'. Requires session_id parameter (obtained from gdb_start_session).

Inputs: session_id (required), function_call (required).

gdb_continueA

Continue execution of the program until next breakpoint or completion. IMPORTANT: Only use this when the program is PAUSED (e.g., at a breakpoint). If the program hasn't been started yet, use gdb_execute_command with 'run' instead. If the program is already running, this will fail - use gdb_interrupt to pause it first. Requires session_id parameter (obtained from gdb_start_session).

Inputs: session_id (required), timeout_sec.

gdb_delete_breakpointA

Delete a breakpoint by its number. Use gdb_list_breakpoints to see breakpoint numbers. Once deleted, the breakpoint cannot be recovered. Requires session_id parameter (obtained from gdb_start_session).

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

gdb_disable_breakpointA

Disable a breakpoint by its number without deleting it. Disabled breakpoints are not hit but remain in the breakpoint list. Use gdb_enable_breakpoint to re-enable it later. Requires session_id parameter (obtained from gdb_start_session).

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

gdb_enable_breakpointA

Enable a previously disabled breakpoint by its number. Enabled breakpoints will pause execution when hit. Requires session_id parameter (obtained from gdb_start_session).

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

gdb_evaluate_expressionA

Evaluate a C/C++ expression in the current context and return its value. Can access variables, dereference pointers, call functions, etc. Requires session_id parameter (obtained from gdb_start_session).

Inputs: session_id (required), expression (required).

gdb_execute_commandA

Execute a GDB command. Supports both CLI and MI commands. CLI commands (like 'info breakpoints', 'list', 'print x') are automatically handled and their output is formatted for readability. Multi-line commands (like 'commands', 'define', 'python') are supported; separate lines with \n. MI commands (starting with '-', like '-break-list', '-exec-run') return structured data. NOTE: For calling functions in the target process, prefer using the dedicated gdb_call_function tool instead of 'call' command, as it provides better structured output and can be separately permissioned. Common examples: 'info breakpoints', 'info threads', 'run', 'print variable', 'list main', 'disassemble func'. Requires session_id parameter (obtained from gdb_start_session).

Inputs: session_id (required), command (required), timeout_sec.

gdb_get_backtraceB

Get the stack backtrace for a specific thread or the current thread. Shows function calls, file locations, and line numbers. Requires session_id parameter (obtained from gdb_start_session).

Inputs: session_id (required), thread_id, max_frames.

gdb_get_frame_infoA

Get information about the current stack frame. Returns details about the currently selected frame including function name, file location, line number, and address. Use gdb_select_frame to change the current frame first if needed. Requires session_id parameter (obtained from gdb_start_session).

Inputs: session_id (required).

gdb_get_registersA

Get CPU register values for the current frame. Requires session_id parameter (obtained from gdb_start_session).

Inputs: session_id (required).

gdb_get_statusB

Get the current status of the GDB session. Requires session_id parameter (obtained from gdb_start_session).

Inputs: session_id (required).

gdb_get_threadsA

Get information about all threads in the debugged process, including thread IDs, states, and the current thread. Requires session_id parameter (obtained from gdb_start_session).

Inputs: session_id (required).

gdb_get_variablesB

Get local variables for a specific stack frame in a thread. Requires session_id parameter (obtained from gdb_start_session).

Inputs: session_id (required), thread_id, frame.

gdb_interruptA

Interrupt (pause) a running program. Use this when: 1) The program is running and hasn't hit a breakpoint, 2) You want to pause execution to inspect state or set breakpoints, 3) The program appears stuck or you want to see where it is. After interrupting, you can use other commands like gdb_get_backtrace, gdb_get_variables, or gdb_continue. Requires session_id parameter (obtained from gdb_start_session).

Inputs: session_id (required).

gdb_list_breakpointsA

List all breakpoints as structured data with detailed information. Returns an array of breakpoint objects, each containing: number, type, enabled status, address, function name, source file, line number, and hit count. Use this to verify breakpoints were set correctly, check which have been hit (times field), and inspect their exact locations. Much easier to filter and analyze than text output. Requires session_id parameter (obtained from gdb_start_session).

Inputs: session_id (required).

gdb_nextA

Step over to the next line (doesn't enter function calls). IMPORTANT: Only works when program is PAUSED at a specific location. Use this to step over function calls without entering them. Requires session_id parameter (obtained from gdb_start_session).

Inputs: session_id (required), timeout_sec.

gdb_select_frameA

Select a specific stack frame to make it the current frame. Frame 0 is the innermost (current) frame, higher numbers are outer frames. After selecting a frame, commands like gdb_get_variables and gdb_evaluate_expression will operate in the context of that frame. Use gdb_get_backtrace to see available frames and their numbers. Requires session_id parameter (obtained from gdb_start_session).

Inputs: session_id (required), frame_number (required).

gdb_select_threadA

Select a specific thread to make it the current thread. After selecting a thread, subsequent commands like gdb_get_backtrace, gdb_get_variables, and gdb_evaluate_expression will operate on this thread. Use gdb_get_threads to see available thread IDs. Requires session_id parameter (obtained from gdb_start_session).

Inputs: session_id (required), thread_id (required).

gdb_set_breakpointA

Set a breakpoint at a function, file:line, or address. Supports conditional breakpoints and temporary breakpoints. Supports hardware-assisted breakpoints with hardware=true. Returns breakpoint details including number, address, and location. Use gdb_list_breakpoints to verify breakpoints were set correctly. Requires session_id parameter (obtained from gdb_start_session).

Inputs: session_id (required), location (required), condition, temporary, +1 more.

gdb_start_sessionA

Start a new GDB debugging session. Can load an executable, core dump, or run custom initialization commands. Automatically detects and reports important warnings such as: missing debug symbols (not compiled with -g), file not found, or invalid executable. Check the 'warnings' field in the response for critical issues that may affect debugging. Available parameters: program (executable path), args (program arguments), core (core dump path - uses --core flag for proper symbol resolution), init_commands (GDB commands to run after loading), env (environment variables), gdb_path (GDB binary path), working_dir (directory to run program from). IMPORTANT for core dump debugging: Set 'sysroot' and 'solib-search-path' AFTER loading the core (either via 'core' parameter or 'core-file' init_command) for symbols to resolve correctly. Returns a session_id integer that must be passed to all other GDB tools.

Inputs: program, args, init_commands, env, +3 more.

gdb_stepA

Step into the next instruction (enters function calls). IMPORTANT: Only works when program is PAUSED at a specific location. Use this for single-stepping through code to debug line-by-line. Requires session_id parameter (obtained from gdb_start_session).

Inputs: session_id (required), timeout_sec.

gdb_stop_sessionA

Stop the current GDB session and clean up resources. Requires session_id parameter (obtained from gdb_start_session).

Inputs: session_id (required).

Tool Schema Changelog

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

Loading tool schema changelog…

    TDQS

    A4.2/5.0

    Scored across 22 tools

    Disambiguation5/5

    Each tool has a distinct purpose: session management, breakpoint operations, execution control, state inspection, and selection. There is no overlap; even stepping and continuing are clearly differentiated.

    Naming Consistency5/5

    All tool names follow the consistent pattern gdb_<verb> or gdb_<verb>_<noun> (e.g., gdb_set_breakpoint, gdb_get_backtrace). The prefix and naming style are uniform.

    Tool Count5/5

    22 tools cover the essential GDB debugging workflow without being excessive. Each tool serves a necessary function, and the count is well-scoped for a debugger server.

    Completeness5/5

    The tool surface covers the full debugging lifecycle: session start/stop, breakpoint management, execution control, thread/stack inspection, variable/register access, and expression evaluation. Any missing features can be accessed via gdb_execute_command, making the set comprehensive.

    Maintenance

    ActivityInactive
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      D
      maintenance
      An MCP server that provides programmatic access to the GNU Debugger (GDB), enabling AI models to interact with GDB through natural language for debugging tasks.
      9
      Apache 2.0
    • A
      license
      A
      quality
      D
      maintenance
      MCP server that exposes GDB debugging as tools. An AI assistant can set breakpoints, run programs, step through code, inspect variables and memory, and examine registers — all via structured tool calls. Reverse debugging with rr is also supported.
      34
      3
      MIT
    • 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
      Not graded
      quality
      D
      maintenance
      An MCP server that exposes LLDB debugging capabilities, enabling AI-assisted interactive debugging of C/C++ applications through 40 specialized tools.
      22 PyPI
      4
      MIT