cpp-debug-mcp 0.1.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. cpp_debug_mcp-0.1.1/LICENSE +21 -0
  2. cpp_debug_mcp-0.1.1/PKG-INFO +187 -0
  3. cpp_debug_mcp-0.1.1/README.md +160 -0
  4. cpp_debug_mcp-0.1.1/pyproject.toml +46 -0
  5. cpp_debug_mcp-0.1.1/setup.cfg +21 -0
  6. cpp_debug_mcp-0.1.1/setup.py +2 -0
  7. cpp_debug_mcp-0.1.1/src/cpp_debug_mcp/__init__.py +1 -0
  8. cpp_debug_mcp-0.1.1/src/cpp_debug_mcp/__main__.py +6 -0
  9. cpp_debug_mcp-0.1.1/src/cpp_debug_mcp/analysis/__init__.py +0 -0
  10. cpp_debug_mcp-0.1.1/src/cpp_debug_mcp/analysis/correlator.py +260 -0
  11. cpp_debug_mcp-0.1.1/src/cpp_debug_mcp/gdb/__init__.py +0 -0
  12. cpp_debug_mcp-0.1.1/src/cpp_debug_mcp/gdb/controller.py +136 -0
  13. cpp_debug_mcp-0.1.1/src/cpp_debug_mcp/gdb/session.py +146 -0
  14. cpp_debug_mcp-0.1.1/src/cpp_debug_mcp/lsp/__init__.py +0 -0
  15. cpp_debug_mcp-0.1.1/src/cpp_debug_mcp/lsp/client.py +210 -0
  16. cpp_debug_mcp-0.1.1/src/cpp_debug_mcp/lsp/protocol.py +213 -0
  17. cpp_debug_mcp-0.1.1/src/cpp_debug_mcp/lsp/session.py +91 -0
  18. cpp_debug_mcp-0.1.1/src/cpp_debug_mcp/server.py +52 -0
  19. cpp_debug_mcp-0.1.1/src/cpp_debug_mcp/tools/__init__.py +0 -0
  20. cpp_debug_mcp-0.1.1/src/cpp_debug_mcp/tools/combined_tools.py +110 -0
  21. cpp_debug_mcp-0.1.1/src/cpp_debug_mcp/tools/fmt.py +301 -0
  22. cpp_debug_mcp-0.1.1/src/cpp_debug_mcp/tools/gdb_tools.py +395 -0
  23. cpp_debug_mcp-0.1.1/src/cpp_debug_mcp/tools/lsp_tools.py +265 -0
  24. cpp_debug_mcp-0.1.1/src/cpp_debug_mcp.egg-info/PKG-INFO +187 -0
  25. cpp_debug_mcp-0.1.1/src/cpp_debug_mcp.egg-info/SOURCES.txt +32 -0
  26. cpp_debug_mcp-0.1.1/src/cpp_debug_mcp.egg-info/dependency_links.txt +1 -0
  27. cpp_debug_mcp-0.1.1/src/cpp_debug_mcp.egg-info/requires.txt +6 -0
  28. cpp_debug_mcp-0.1.1/src/cpp_debug_mcp.egg-info/top_level.txt +1 -0
  29. cpp_debug_mcp-0.1.1/tests/test_gdb_controller.py +114 -0
  30. cpp_debug_mcp-0.1.1/tests/test_lsp_client.py +161 -0
  31. cpp_debug_mcp-0.1.1/tests/test_tools_combined.py +104 -0
  32. cpp_debug_mcp-0.1.1/tests/test_tools_gdb.py +92 -0
  33. cpp_debug_mcp-0.1.1/tests/test_tools_lsp.py +83 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 William-An
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,187 @@
1
+ Metadata-Version: 2.4
2
+ Name: cpp-debug-mcp
3
+ Version: 0.1.1
4
+ Summary: Claude Code MCP server for C++ debugging with GDB and clangd
5
+ Author: William-An
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/William-An/cpp-debug-mcp
8
+ Project-URL: Repository, https://github.com/William-An/cpp-debug-mcp
9
+ Project-URL: Issues, https://github.com/William-An/cpp-debug-mcp/issues
10
+ Classifier: Development Status :: 3 - Alpha
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Programming Language :: Python :: 3.10
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3.13
17
+ Classifier: Topic :: Software Development :: Debuggers
18
+ Requires-Python: >=3.10
19
+ Description-Content-Type: text/markdown
20
+ License-File: LICENSE
21
+ Requires-Dist: fastmcp>=2.0
22
+ Requires-Dist: pygdbmi>=0.11
23
+ Provides-Extra: dev
24
+ Requires-Dist: pytest>=7.0; extra == "dev"
25
+ Requires-Dist: pytest-asyncio>=0.21; extra == "dev"
26
+ Dynamic: license-file
27
+
28
+ # cpp-debug-mcp
29
+
30
+ A [Claude Code](https://claude.ai/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.
31
+
32
+ ## Prerequisites
33
+
34
+ - Python 3.10+
35
+ - [GDB](https://www.gnu.org/software/gdb/) (for debugging tools)
36
+ - [clangd](https://clangd.llvm.org/) (for static analysis tools)
37
+ - [uv](https://github.com/astral-sh/uv) (recommended) or pip
38
+
39
+ ## Installation
40
+
41
+ **From PyPI** (once published):
42
+
43
+ ```bash
44
+ pip install cpp-debug-mcp
45
+ ```
46
+
47
+ **From GitHub** (always available):
48
+
49
+ ```bash
50
+ pip install git+https://github.com/William-An/cpp-debug-mcp.git
51
+ ```
52
+
53
+ **From source** (for development):
54
+
55
+ ```bash
56
+ git clone https://github.com/William-An/cpp-debug-mcp.git
57
+ cd cpp-debug-mcp
58
+ uv venv .venv
59
+ source .venv/bin/activate
60
+ uv pip install -e .
61
+ ```
62
+
63
+ ## Register with Claude Code
64
+
65
+ **Option A** — CLI command:
66
+
67
+ ```bash
68
+ claude mcp add cpp-debug -- python3 -m cpp_debug_mcp
69
+ ```
70
+
71
+ **Option B** — add to your project's `.mcp.json`:
72
+
73
+ ```json
74
+ {
75
+ "mcpServers": {
76
+ "cpp-debug": {
77
+ "type": "stdio",
78
+ "command": "python3",
79
+ "args": ["-m", "cpp_debug_mcp"],
80
+ "env": {
81
+ "GDB_PATH": "gdb",
82
+ "CLANGD_PATH": "clangd"
83
+ }
84
+ }
85
+ }
86
+ }
87
+ ```
88
+
89
+ Verify with `/mcp` inside Claude Code to confirm the server is connected.
90
+
91
+ ## Tools
92
+
93
+ ### GDB Tools (14)
94
+
95
+ | Tool | Description |
96
+ |---|---|
97
+ | `gdb_start_session` | Start a GDB session for a compiled executable |
98
+ | `gdb_end_session` | End a session and clean up |
99
+ | `gdb_run` | Start execution (optionally stop at `main`) |
100
+ | `gdb_set_breakpoint` | Set a breakpoint by file:line, function, or address |
101
+ | `gdb_delete_breakpoint` | Delete a breakpoint by ID |
102
+ | `gdb_list_breakpoints` | List all active breakpoints |
103
+ | `gdb_continue` | Continue until next breakpoint or exit |
104
+ | `gdb_step` | Step into, over, or out of functions |
105
+ | `gdb_backtrace` | Get the call stack |
106
+ | `gdb_list_variables` | List local variables in a stack frame |
107
+ | `gdb_evaluate` | Evaluate a C++ expression (e.g. `*ptr`, `arr[5]`) |
108
+ | `gdb_read_memory` | Read raw memory at an address |
109
+ | `gdb_thread_info` | List all threads and their states |
110
+ | `gdb_raw_command` | Execute a raw GDB command (with safety restrictions) |
111
+
112
+ ### LSP/clangd Tools (8)
113
+
114
+ | Tool | Description |
115
+ |---|---|
116
+ | `lsp_start_session` | Start a clangd session for a project |
117
+ | `lsp_end_session` | End a clangd session |
118
+ | `lsp_diagnostics` | Get compile errors and warnings for a file |
119
+ | `lsp_hover` | Get type/documentation info at a position |
120
+ | `lsp_goto_definition` | Find where a symbol is defined |
121
+ | `lsp_find_references` | Find all references to a symbol |
122
+ | `lsp_document_symbols` | List all symbols in a file |
123
+ | `lsp_signature_help` | Get function signature help at a call site |
124
+
125
+ ### Combined Tools (3)
126
+
127
+ | Tool | Description |
128
+ |---|---|
129
+ | `inspect_variable_with_type` | GDB runtime value + clangd type info for a variable |
130
+ | `diagnose_crash_site` | Backtrace + local variables + LSP diagnostics at crash |
131
+ | `analyze_function` | Breakpoint + signature + references + locals for a function |
132
+
133
+ ## Example Usage
134
+
135
+ Compile your C++ program with debug symbols, then ask Claude Code to debug it:
136
+
137
+ ```
138
+ > Compile main.cpp with debug symbols and find why it segfaults
139
+
140
+ Claude will:
141
+ 1. Run g++ -g -O0 -o main main.cpp
142
+ 2. Call gdb_start_session with the executable
143
+ 3. Call gdb_run to execute until the crash
144
+ 4. Call diagnose_crash_site to get the full crash report
145
+ 5. Explain the root cause with backtrace, variable values, and type info
146
+ ```
147
+
148
+ ## Architecture
149
+
150
+ ```
151
+ src/cpp_debug_mcp/
152
+ ├── server.py # FastMCP entry point with lifespan management
153
+ ├── gdb/
154
+ │ ├── controller.py # Async GDB/MI subprocess wrapper (pygdbmi)
155
+ │ └── session.py # Session lifecycle (max 4, 30min timeout)
156
+ ├── lsp/
157
+ │ ├── client.py # Async JSON-RPC client for clangd over STDIO
158
+ │ ├── protocol.py # LSP message helpers and response parsers
159
+ │ └── session.py # Session lifecycle (max 2, 30min timeout)
160
+ ├── analysis/
161
+ │ └── correlator.py # Cross-references GDB runtime + LSP static info
162
+ └── tools/
163
+ ├── gdb_tools.py # 14 GDB MCP tools
164
+ ├── lsp_tools.py # 8 LSP MCP tools
165
+ └── combined_tools.py # 3 combined analysis tools
166
+ ```
167
+
168
+ ## Safety
169
+
170
+ - **Command sanitization**: `gdb_raw_command` blocks `shell`, `!`, `python`, `pipe`, and `source` commands
171
+ - **Resource limits**: Max 4 GDB sessions and 2 LSP sessions concurrently
172
+ - **Auto-cleanup**: Stale sessions are cleaned up after 30 minutes of inactivity
173
+ - **Process lifecycle**: All subprocesses are terminated on server shutdown
174
+
175
+ ## Running Tests
176
+
177
+ ```bash
178
+ source .venv/bin/activate
179
+ uv pip install -e ".[dev]"
180
+ python -m pytest tests/ -v
181
+ ```
182
+
183
+ GDB tests require `gdb` to be installed. LSP tests require `clangd`. Tests that need unavailable tools are automatically skipped.
184
+
185
+ ## License
186
+
187
+ MIT
@@ -0,0 +1,160 @@
1
+ # cpp-debug-mcp
2
+
3
+ A [Claude Code](https://claude.ai/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.
4
+
5
+ ## Prerequisites
6
+
7
+ - Python 3.10+
8
+ - [GDB](https://www.gnu.org/software/gdb/) (for debugging tools)
9
+ - [clangd](https://clangd.llvm.org/) (for static analysis tools)
10
+ - [uv](https://github.com/astral-sh/uv) (recommended) or pip
11
+
12
+ ## Installation
13
+
14
+ **From PyPI** (once published):
15
+
16
+ ```bash
17
+ pip install cpp-debug-mcp
18
+ ```
19
+
20
+ **From GitHub** (always available):
21
+
22
+ ```bash
23
+ pip install git+https://github.com/William-An/cpp-debug-mcp.git
24
+ ```
25
+
26
+ **From source** (for development):
27
+
28
+ ```bash
29
+ git clone https://github.com/William-An/cpp-debug-mcp.git
30
+ cd cpp-debug-mcp
31
+ uv venv .venv
32
+ source .venv/bin/activate
33
+ uv pip install -e .
34
+ ```
35
+
36
+ ## Register with Claude Code
37
+
38
+ **Option A** — CLI command:
39
+
40
+ ```bash
41
+ claude mcp add cpp-debug -- python3 -m cpp_debug_mcp
42
+ ```
43
+
44
+ **Option B** — add to your project's `.mcp.json`:
45
+
46
+ ```json
47
+ {
48
+ "mcpServers": {
49
+ "cpp-debug": {
50
+ "type": "stdio",
51
+ "command": "python3",
52
+ "args": ["-m", "cpp_debug_mcp"],
53
+ "env": {
54
+ "GDB_PATH": "gdb",
55
+ "CLANGD_PATH": "clangd"
56
+ }
57
+ }
58
+ }
59
+ }
60
+ ```
61
+
62
+ Verify with `/mcp` inside Claude Code to confirm the server is connected.
63
+
64
+ ## Tools
65
+
66
+ ### GDB Tools (14)
67
+
68
+ | Tool | Description |
69
+ |---|---|
70
+ | `gdb_start_session` | Start a GDB session for a compiled executable |
71
+ | `gdb_end_session` | End a session and clean up |
72
+ | `gdb_run` | Start execution (optionally stop at `main`) |
73
+ | `gdb_set_breakpoint` | Set a breakpoint by file:line, function, or address |
74
+ | `gdb_delete_breakpoint` | Delete a breakpoint by ID |
75
+ | `gdb_list_breakpoints` | List all active breakpoints |
76
+ | `gdb_continue` | Continue until next breakpoint or exit |
77
+ | `gdb_step` | Step into, over, or out of functions |
78
+ | `gdb_backtrace` | Get the call stack |
79
+ | `gdb_list_variables` | List local variables in a stack frame |
80
+ | `gdb_evaluate` | Evaluate a C++ expression (e.g. `*ptr`, `arr[5]`) |
81
+ | `gdb_read_memory` | Read raw memory at an address |
82
+ | `gdb_thread_info` | List all threads and their states |
83
+ | `gdb_raw_command` | Execute a raw GDB command (with safety restrictions) |
84
+
85
+ ### LSP/clangd Tools (8)
86
+
87
+ | Tool | Description |
88
+ |---|---|
89
+ | `lsp_start_session` | Start a clangd session for a project |
90
+ | `lsp_end_session` | End a clangd session |
91
+ | `lsp_diagnostics` | Get compile errors and warnings for a file |
92
+ | `lsp_hover` | Get type/documentation info at a position |
93
+ | `lsp_goto_definition` | Find where a symbol is defined |
94
+ | `lsp_find_references` | Find all references to a symbol |
95
+ | `lsp_document_symbols` | List all symbols in a file |
96
+ | `lsp_signature_help` | Get function signature help at a call site |
97
+
98
+ ### Combined Tools (3)
99
+
100
+ | Tool | Description |
101
+ |---|---|
102
+ | `inspect_variable_with_type` | GDB runtime value + clangd type info for a variable |
103
+ | `diagnose_crash_site` | Backtrace + local variables + LSP diagnostics at crash |
104
+ | `analyze_function` | Breakpoint + signature + references + locals for a function |
105
+
106
+ ## Example Usage
107
+
108
+ Compile your C++ program with debug symbols, then ask Claude Code to debug it:
109
+
110
+ ```
111
+ > Compile main.cpp with debug symbols and find why it segfaults
112
+
113
+ Claude will:
114
+ 1. Run g++ -g -O0 -o main main.cpp
115
+ 2. Call gdb_start_session with the executable
116
+ 3. Call gdb_run to execute until the crash
117
+ 4. Call diagnose_crash_site to get the full crash report
118
+ 5. Explain the root cause with backtrace, variable values, and type info
119
+ ```
120
+
121
+ ## Architecture
122
+
123
+ ```
124
+ src/cpp_debug_mcp/
125
+ ├── server.py # FastMCP entry point with lifespan management
126
+ ├── gdb/
127
+ │ ├── controller.py # Async GDB/MI subprocess wrapper (pygdbmi)
128
+ │ └── session.py # Session lifecycle (max 4, 30min timeout)
129
+ ├── lsp/
130
+ │ ├── client.py # Async JSON-RPC client for clangd over STDIO
131
+ │ ├── protocol.py # LSP message helpers and response parsers
132
+ │ └── session.py # Session lifecycle (max 2, 30min timeout)
133
+ ├── analysis/
134
+ │ └── correlator.py # Cross-references GDB runtime + LSP static info
135
+ └── tools/
136
+ ├── gdb_tools.py # 14 GDB MCP tools
137
+ ├── lsp_tools.py # 8 LSP MCP tools
138
+ └── combined_tools.py # 3 combined analysis tools
139
+ ```
140
+
141
+ ## Safety
142
+
143
+ - **Command sanitization**: `gdb_raw_command` blocks `shell`, `!`, `python`, `pipe`, and `source` commands
144
+ - **Resource limits**: Max 4 GDB sessions and 2 LSP sessions concurrently
145
+ - **Auto-cleanup**: Stale sessions are cleaned up after 30 minutes of inactivity
146
+ - **Process lifecycle**: All subprocesses are terminated on server shutdown
147
+
148
+ ## Running Tests
149
+
150
+ ```bash
151
+ source .venv/bin/activate
152
+ uv pip install -e ".[dev]"
153
+ python -m pytest tests/ -v
154
+ ```
155
+
156
+ GDB tests require `gdb` to be installed. LSP tests require `clangd`. Tests that need unavailable tools are automatically skipped.
157
+
158
+ ## License
159
+
160
+ MIT
@@ -0,0 +1,46 @@
1
+ [project]
2
+ name = "cpp-debug-mcp"
3
+ version = "0.1.1"
4
+ description = "Claude Code MCP server for C++ debugging with GDB and clangd"
5
+ requires-python = ">=3.10"
6
+ license = "MIT"
7
+ authors = [
8
+ {name = "William-An"},
9
+ ]
10
+ readme = "README.md"
11
+ classifiers = [
12
+ "Development Status :: 3 - Alpha",
13
+ "Intended Audience :: Developers",
14
+ "Programming Language :: Python :: 3",
15
+ "Programming Language :: Python :: 3.10",
16
+ "Programming Language :: Python :: 3.11",
17
+ "Programming Language :: Python :: 3.12",
18
+ "Programming Language :: Python :: 3.13",
19
+ "Topic :: Software Development :: Debuggers",
20
+ ]
21
+ dependencies = [
22
+ "fastmcp>=2.0",
23
+ "pygdbmi>=0.11",
24
+ ]
25
+
26
+ [project.urls]
27
+ Homepage = "https://github.com/William-An/cpp-debug-mcp"
28
+ Repository = "https://github.com/William-An/cpp-debug-mcp"
29
+ Issues = "https://github.com/William-An/cpp-debug-mcp/issues"
30
+
31
+ [project.optional-dependencies]
32
+ dev = [
33
+ "pytest>=7.0",
34
+ "pytest-asyncio>=0.21",
35
+ ]
36
+
37
+ [build-system]
38
+ requires = ["setuptools>=68.0"]
39
+ build-backend = "setuptools.build_meta"
40
+
41
+ [tool.setuptools.packages.find]
42
+ where = ["src"]
43
+
44
+ [tool.pytest.ini_options]
45
+ asyncio_mode = "auto"
46
+ testpaths = ["tests"]
@@ -0,0 +1,21 @@
1
+ [metadata]
2
+ name = cpp-debug-mcp
3
+ version = 0.1.1
4
+ description = Claude Code MCP server for C++ debugging with GDB and clangd
5
+
6
+ [options]
7
+ package_dir =
8
+ = src
9
+ packages = find:
10
+ python_requires = >=3.10
11
+ install_requires =
12
+ fastmcp>=2.0
13
+ pygdbmi>=0.11
14
+
15
+ [options.packages.find]
16
+ where = src
17
+
18
+ [egg_info]
19
+ tag_build =
20
+ tag_date = 0
21
+
@@ -0,0 +1,2 @@
1
+ from setuptools import setup
2
+ setup()
@@ -0,0 +1 @@
1
+ """Claude Code MCP server for C++ debugging with GDB and clangd."""
@@ -0,0 +1,6 @@
1
+ """Entry point for python -m cpp_debug_mcp."""
2
+
3
+ from cpp_debug_mcp.server import mcp
4
+
5
+ if __name__ == "__main__":
6
+ mcp.run()