GDB Debugger MCP server

Integrates GDB with AI capabilities to provide interactive debugging assistance for C/C++ applications, enabling breakpoint management, memory examination, and execution flow analysis during debugging sessions.
Back to servers
Setup instructions
Provider
yywz1999
Release date
Mar 28, 2025
Language
Python
Stats
28 stars

This MCP server enables AI agents and tools to interact with GDB using the Model Context Protocol, providing an interface for AI-assisted debugging across multiple architectures and environments.

Installation

To set up the GDB MCP server:

git clone https://github.com/yywz1999/gdb-mcp-server.git
cd gdb-mcp-server
python3 -m pip install -r requirements.txt

After installation, verify that the environment is set up correctly by running:

python3 mcp_server.py

If everything is configured properly, the server will start successfully.

Usage

Starting the Server

To launch the MCP server:

python3 mcp_server.py

Connecting to GDB

The server provides several functions to interact with GDB processes:

System Functions

  • Find GDB processes: Use sys_find_gdb_processes to discover running GDB instances

  • Attach to GDB: Connect to an existing GDB process with sys_attach_to_gdb

  • Start GDB with remote debugging: Launch GDB and connect to a remote target using sys_start_gdb_with_remote

Debugging Functions

The server exposes these GDB operations through the MCP protocol:

  • Execute custom commands: gdb_execute_command - Run any arbitrary GDB command

  • Breakpoint management:

    • gdb_set_breakpoint - Create a new breakpoint
    • gdb_delete_breakpoint - Remove an existing breakpoint
  • Code execution control:

    • gdb_step - Step into functions
    • gdb_next - Step over functions
    • gdb_finish - Run until current function returns
    • gdb_continue - Resume execution
  • System inspection:

    • gdb_get_registers - View register values
    • gdb_examine_memory - Inspect memory contents
    • gdb_get_stack - Display stack trace
    • gdb_get_locals - Show local variables
    • gdb_disassemble - View disassembled code
  • Remote debugging:

    • gdb_connect_remote - Connect to a remote debugging target

Best Practices for macOS

For optimal performance on macOS:

  • Use iTerm2 as your terminal emulator (fully supported)
  • Make sure your GDB terminal window is open before starting the server
  • For remote debugging scenarios, first set up the necessary configurations manually in GDB, then attach using the MCP server

The server includes several optimizations for macOS:

  • Enhanced iTerm2 session detection and interaction
  • Direct command writing without window focus switching
  • GDB session identification based on session content

Troubleshooting

macOS Issues

  1. Window activation problems: If the GDB window doesn't activate correctly, manually bring it to the foreground
  2. Input method: Ensure the GDB terminal isn't using Chinese or other input methods
  3. Command blocking: For commands that may block (like remote connections), the server automatically sends interrupt signals

Linux Issues

  1. TTY permissions: Verify that your current user has permission to access the TTY device used by the GDB process
  2. Dependencies: Make sure the pexpect library is properly installed

The server includes intelligent blocking detection that:

  • Automatically identifies potentially blocking commands
  • Uses timeouts to detect blocked states
  • Sends interrupt signals when blocking is detected
  • Extracts and returns partial execution results

How to install this MCP server

For Claude Code

To add this MCP server to Claude Code, run this command in your terminal:

claude mcp add-json "gdb-mcp-server" '{"command":"python3","args":["mcp_server.py"]}'

See the official Claude Code MCP documentation for more details.

For Cursor

There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json file so that it is available in all of your projects.

If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json file.

Adding an MCP server to Cursor globally

To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".

When you click that button the ~/.cursor/mcp.json file will be opened and you can add your server like this:

{
    "mcpServers": {
        "gdb-mcp-server": {
            "command": "python3",
            "args": [
                "mcp_server.py"
            ]
        }
    }
}

Adding an MCP server to a project

To add an MCP server to a project you can create a new .cursor/mcp.json file or add it to the existing one. This will look exactly the same as the global MCP server example above.

How to use the MCP server

Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.

The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.

You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.

For Claude Desktop

To add this MCP server to Claude Desktop:

1. Find your configuration file:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json
  • Linux: ~/.config/Claude/claude_desktop_config.json

2. Add this to your configuration file:

{
    "mcpServers": {
        "gdb-mcp-server": {
            "command": "python3",
            "args": [
                "mcp_server.py"
            ]
        }
    }
}

3. Restart Claude Desktop for the changes to take effect

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later