cpp-debug-mcp

cpp-debug-mcp

Provides GDB and clangd-based tools for debugging C++ programs, enabling step execution, variable inspection, diagnostics, and combined runtime-static analysis.

Category
访问服务器

README

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

Quick Start

Register the MCP server globally (all projects, auto-updates):

claude mcp add --scope user cpp-debug -- uvx cpp-debug-mcp

That's it. Verify with /mcp inside Claude Code to confirm the server is connected.

Installation Options

Auto-updating via uvx (recommended)

No install step needed — uvx fetches the latest version from PyPI on each invocation. Just register with the command above.

From PyPI

pip install cpp-debug-mcp

From GitHub

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 ".[dev]"

Register with Claude Code

Global (all projects)

claude mcp add --scope user cpp-debug -- uvx cpp-debug-mcp

Per-project (CLI)

claude mcp add cpp-debug -- uvx cpp-debug-mcp

Per-project (.mcp.json)

{
  "mcpServers": {
    "cpp-debug": {
      "type": "stdio",
      "command": "uvx",
      "args": ["cpp-debug-mcp"]
    }
  }
}
Scope Flag Config file Availability
User --scope user ~/.claude.json All projects, private to you
Project --scope project .mcp.json This project, shared via git
Local (default) .mcp.json This project, private to you

Tools

GDB Tools (16)

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)
gdb_open_console Open an interactive GDB console via tmux (requires tmux)
gdb_close_console Close the interactive GDB console

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/
    ├── fmt.py             # Human-readable output formatting
    ├── gdb_tools.py       # 16 GDB MCP tools (incl. interactive console)
    ├── 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

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选