Skip to main content

Claude Code MCP server for C++ debugging with GDB and clangd

Project description

cpp-debug-mcp

A Claude Code MCP server plugin for C++ debugging. Integrates GDB (via GDB/MI) and clangd (via LSP) to give Claude Code tools for stepping through code, inspecting variables, reading diagnostics, and correlating runtime state with static analysis — all from the conversation.

Prerequisites

  • Python 3.10+
  • GDB (for debugging tools)
  • clangd (for static analysis tools)
  • uv (recommended) or pip

Installation

From PyPI (once published):

pip install cpp-debug-mcp

From GitHub (always available):

pip install git+https://github.com/William-An/cpp-debug-mcp.git

From source (for development):

git clone https://github.com/William-An/cpp-debug-mcp.git
cd cpp-debug-mcp
uv venv .venv
source .venv/bin/activate
uv pip install -e .

Register with Claude Code

Option A — CLI command:

claude mcp add cpp-debug -- python3 -m cpp_debug_mcp

Option B — add to your project's .mcp.json:

{
  "mcpServers": {
    "cpp-debug": {
      "type": "stdio",
      "command": "python3",
      "args": ["-m", "cpp_debug_mcp"],
      "env": {
        "GDB_PATH": "gdb",
        "CLANGD_PATH": "clangd"
      }
    }
  }
}

Verify with /mcp inside Claude Code to confirm the server is connected.

Tools

GDB Tools (14)

Tool Description
gdb_start_session Start a GDB session for a compiled executable
gdb_end_session End a session and clean up
gdb_run Start execution (optionally stop at main)
gdb_set_breakpoint Set a breakpoint by file:line, function, or address
gdb_delete_breakpoint Delete a breakpoint by ID
gdb_list_breakpoints List all active breakpoints
gdb_continue Continue until next breakpoint or exit
gdb_step Step into, over, or out of functions
gdb_backtrace Get the call stack
gdb_list_variables List local variables in a stack frame
gdb_evaluate Evaluate a C++ expression (e.g. *ptr, arr[5])
gdb_read_memory Read raw memory at an address
gdb_thread_info List all threads and their states
gdb_raw_command Execute a raw GDB command (with safety restrictions)

LSP/clangd Tools (8)

Tool Description
lsp_start_session Start a clangd session for a project
lsp_end_session End a clangd session
lsp_diagnostics Get compile errors and warnings for a file
lsp_hover Get type/documentation info at a position
lsp_goto_definition Find where a symbol is defined
lsp_find_references Find all references to a symbol
lsp_document_symbols List all symbols in a file
lsp_signature_help Get function signature help at a call site

Combined Tools (3)

Tool Description
inspect_variable_with_type GDB runtime value + clangd type info for a variable
diagnose_crash_site Backtrace + local variables + LSP diagnostics at crash
analyze_function Breakpoint + signature + references + locals for a function

Example Usage

Compile your C++ program with debug symbols, then ask Claude Code to debug it:

> Compile main.cpp with debug symbols and find why it segfaults

Claude will:
1. Run g++ -g -O0 -o main main.cpp
2. Call gdb_start_session with the executable
3. Call gdb_run to execute until the crash
4. Call diagnose_crash_site to get the full crash report
5. Explain the root cause with backtrace, variable values, and type info

Architecture

src/cpp_debug_mcp/
├── server.py              # FastMCP entry point with lifespan management
├── gdb/
│   ├── controller.py      # Async GDB/MI subprocess wrapper (pygdbmi)
│   └── session.py         # Session lifecycle (max 4, 30min timeout)
├── lsp/
│   ├── client.py          # Async JSON-RPC client for clangd over STDIO
│   ├── protocol.py        # LSP message helpers and response parsers
│   └── session.py         # Session lifecycle (max 2, 30min timeout)
├── analysis/
│   └── correlator.py      # Cross-references GDB runtime + LSP static info
└── tools/
    ├── gdb_tools.py       # 14 GDB MCP tools
    ├── lsp_tools.py       # 8 LSP MCP tools
    └── combined_tools.py  # 3 combined analysis tools

Safety

  • Command sanitization: gdb_raw_command blocks shell, !, python, pipe, and source commands
  • Resource limits: Max 4 GDB sessions and 2 LSP sessions concurrently
  • Auto-cleanup: Stale sessions are cleaned up after 30 minutes of inactivity
  • Process lifecycle: All subprocesses are terminated on server shutdown

Running Tests

source .venv/bin/activate
uv pip install -e ".[dev]"
python -m pytest tests/ -v

GDB tests require gdb to be installed. LSP tests require clangd. Tests that need unavailable tools are automatically skipped.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cpp_debug_mcp-0.2.0.tar.gz (27.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cpp_debug_mcp-0.2.0-py3-none-any.whl (26.9 kB view details)

Uploaded Python 3

File details

Details for the file cpp_debug_mcp-0.2.0.tar.gz.

File metadata

  • Download URL: cpp_debug_mcp-0.2.0.tar.gz
  • Upload date:
  • Size: 27.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for cpp_debug_mcp-0.2.0.tar.gz
Algorithm Hash digest
SHA256 9c45a76c42dc1f75e2c7299fd084573a9f8245a78dc307e4e19ad6f4629bfb4c
MD5 a7a520655dd7f30314ac7c601cc1ed21
BLAKE2b-256 ea3623c901d07eb5e461d1b8a8b6a2371fe44a49750825b4cb6674a409bb2e75

See more details on using hashes here.

Provenance

The following attestation bundles were made for cpp_debug_mcp-0.2.0.tar.gz:

Publisher: publish.yml on William-An/cpp-debug-mcp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cpp_debug_mcp-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: cpp_debug_mcp-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 26.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for cpp_debug_mcp-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b275ed6bcc3a01b486d4bf9a905897be33540007a7e332c7167639319d630237
MD5 2600fdfb54dce856b80fa24d81a2207b
BLAKE2b-256 06b2215e1f1d3cd34ded512e922647f79449cee73c8073147e07d3b5198d3f10

See more details on using hashes here.

Provenance

The following attestation bundles were made for cpp_debug_mcp-0.2.0-py3-none-any.whl:

Publisher: publish.yml on William-An/cpp-debug-mcp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page