loading…
Search for a command to run...
loading…
An MCP server that enables AI assistants to control GDB debugging sessions, including breakpoint management, thread analysis, and variable inspection, using the
An MCP server that enables AI assistants to control GDB debugging sessions, including breakpoint management, thread analysis, and variable inspection, using the GDB/MI protocol.
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.
commands, define, python, and other GDB command blocksrun, continue, step, next, and finish wait until the target stopsThis fork focuses on making GDB MCP easier for AI agents to use in real debugging sessions:
run, continue, step, next, and finish now wait until GDB reports *stopped, so breakpoint hits and crashes are returned with the same command.stopped object to execution results, including stop reason, frame, thread, and breakpoint number when GDB provides them.commands ... end, define ... end, python ... end, if ... end, and while ... end no longer deadlock.timeout_sec for long-running debug operations.hardware=true.This server uses the GDB/MI (Machine Interface) protocol, which is the same interface used by professional IDEs. It provides:
# 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.
Add this to your Claude Desktop configuration file:
Location:
~/Library/Application Support/Claude/claude_desktop_config.json~/.config/Claude/claude_desktop_config.json%APPDATA%\Claude\claude_desktop_config.jsonConfiguration:
{
"mcpServers": {
"gdb": {
"command": "gdb-mcp-server"
}
}
}
For other installation methods and MCP clients, see INSTALL.md.
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
The GDB MCP Server supports the following environment variables:
GDB_PATHSpecify the path to the GDB executable to use. This is useful when:
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_LEVELSet the logging level for the server.
Default: INFO
Options: DEBUG, INFO, WARNING, ERROR, CRITICAL
Example:
export GDB_MCP_LOG_LEVEL=DEBUG
gdb-mcp-server
The GDB MCP Server provides 22 tools for controlling GDB debugging sessions:
Session Management:
gdb_start_session - Start a new GDB session with optional initializationgdb_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 statusgdb_stop_session - Stop the current sessionThread & Frame Navigation:
gdb_get_threads - List all threadsgdb_select_thread - Select a specific threadgdb_get_backtrace - Get stack trace for a threadgdb_select_frame - Select a specific stack framegdb_get_frame_info - Get information about the current frameBreakpoint Management:
gdb_set_breakpoint - Set breakpoints with optional conditions, temporary mode, or hardware modegdb_list_breakpoints - List all breakpoints with structured datagdb_delete_breakpoint - Delete a breakpoint by numbergdb_enable_breakpoint - Enable a breakpointgdb_disable_breakpoint - Disable a breakpointExecution Control:
gdb_continue - Continue executiongdb_step - Step into functionsgdb_next - Step over functionsgdb_interrupt - Pause a running programData Inspection:
gdb_evaluate_expression - Evaluate expressionsgdb_get_variables - Get local variablesgdb_get_registers - Get CPU registersFor detailed documentation of each tool including parameters, return values, and examples, see TOOLS.md.
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:
{
"init_commands": [
"file /path/to/executable",
"core-file /tmp/core.12345",
"set sysroot /opt/sysroot"
]
}
gdb_get_threadsUser: "Set a breakpoint at process_data but only when the count variable is greater than 100, then continue execution."
AI Actions:
{
"location": "process_data",
"condition": "count > 100"
}
gdb_continueFor more detailed usage examples and workflows, see examples/USAGE_GUIDE.md and examples/README.md.
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"]
}
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"]
}
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).
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:
gdb_execute_command with "run" or "start"gdb_interrupt to pause itgdb_continue, gdb_step, gdb_next, inspect variablesMissing 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.
GDB/MI Protocol: The server communicates with GDB using the Machine Interface (MI) protocol, the same interface used by IDEs.
pygdbmi Library: We use the excellent pygdbmi library to handle the low-level protocol details and response parsing.
MCP Integration: The server exposes GDB functionality as MCP tools, allowing AI assistants to:
Session Management: A single GDB session is maintained per server instance, allowing stateful debugging across multiple tool calls.
Contributions welcome! Areas for improvement:
MIT
Добавь это в claude_desktop_config.json и перезапусти Claude Desktop.
{
"mcpServers": {
"gdb-mcp": {
"command": "npx",
"args": []
}
}
}