xdebug-mcp 1.0.0

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 (78) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +341 -0
  3. package/dist/config.d.ts +36 -0
  4. package/dist/config.js +47 -0
  5. package/dist/config.js.map +1 -0
  6. package/dist/dbgp/connection.d.ts +52 -0
  7. package/dist/dbgp/connection.js +362 -0
  8. package/dist/dbgp/connection.js.map +1 -0
  9. package/dist/dbgp/index.d.ts +3 -0
  10. package/dist/dbgp/index.js +4 -0
  11. package/dist/dbgp/index.js.map +1 -0
  12. package/dist/dbgp/server.d.ts +34 -0
  13. package/dist/dbgp/server.js +94 -0
  14. package/dist/dbgp/server.js.map +1 -0
  15. package/dist/dbgp/types.d.ts +112 -0
  16. package/dist/dbgp/types.js +28 -0
  17. package/dist/dbgp/types.js.map +1 -0
  18. package/dist/index.d.ts +7 -0
  19. package/dist/index.js +93 -0
  20. package/dist/index.js.map +1 -0
  21. package/dist/session/code-coverage.d.ts +94 -0
  22. package/dist/session/code-coverage.js +226 -0
  23. package/dist/session/code-coverage.js.map +1 -0
  24. package/dist/session/debug-config.d.ts +102 -0
  25. package/dist/session/debug-config.js +194 -0
  26. package/dist/session/debug-config.js.map +1 -0
  27. package/dist/session/index.d.ts +10 -0
  28. package/dist/session/index.js +11 -0
  29. package/dist/session/index.js.map +1 -0
  30. package/dist/session/logpoint-manager.d.ts +94 -0
  31. package/dist/session/logpoint-manager.js +167 -0
  32. package/dist/session/logpoint-manager.js.map +1 -0
  33. package/dist/session/manager.d.ts +41 -0
  34. package/dist/session/manager.js +135 -0
  35. package/dist/session/manager.js.map +1 -0
  36. package/dist/session/profiler.d.ts +89 -0
  37. package/dist/session/profiler.js +191 -0
  38. package/dist/session/profiler.js.map +1 -0
  39. package/dist/session/request-context.d.ts +50 -0
  40. package/dist/session/request-context.js +182 -0
  41. package/dist/session/request-context.js.map +1 -0
  42. package/dist/session/session-export.d.ts +83 -0
  43. package/dist/session/session-export.js +320 -0
  44. package/dist/session/session-export.js.map +1 -0
  45. package/dist/session/session.d.ts +92 -0
  46. package/dist/session/session.js +369 -0
  47. package/dist/session/session.js.map +1 -0
  48. package/dist/session/step-filter.d.ts +81 -0
  49. package/dist/session/step-filter.js +174 -0
  50. package/dist/session/step-filter.js.map +1 -0
  51. package/dist/session/watch-manager.d.ts +64 -0
  52. package/dist/session/watch-manager.js +137 -0
  53. package/dist/session/watch-manager.js.map +1 -0
  54. package/dist/tools/advanced.d.ts +26 -0
  55. package/dist/tools/advanced.js +502 -0
  56. package/dist/tools/advanced.js.map +1 -0
  57. package/dist/tools/breakpoints.d.ts +6 -0
  58. package/dist/tools/breakpoints.js +308 -0
  59. package/dist/tools/breakpoints.js.map +1 -0
  60. package/dist/tools/execution.d.ts +6 -0
  61. package/dist/tools/execution.js +283 -0
  62. package/dist/tools/execution.js.map +1 -0
  63. package/dist/tools/index.d.ts +31 -0
  64. package/dist/tools/index.js +44 -0
  65. package/dist/tools/index.js.map +1 -0
  66. package/dist/tools/inspection.d.ts +7 -0
  67. package/dist/tools/inspection.js +431 -0
  68. package/dist/tools/inspection.js.map +1 -0
  69. package/dist/tools/session.d.ts +6 -0
  70. package/dist/tools/session.js +164 -0
  71. package/dist/tools/session.js.map +1 -0
  72. package/dist/utils/logger.d.ts +16 -0
  73. package/dist/utils/logger.js +47 -0
  74. package/dist/utils/logger.js.map +1 -0
  75. package/dist/utils/path-mapper.d.ts +13 -0
  76. package/dist/utils/path-mapper.js +56 -0
  77. package/dist/utils/path-mapper.js.map +1 -0
  78. package/package.json +56 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 kpanuragh
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.
package/README.md ADDED
@@ -0,0 +1,341 @@
1
+ # Xdebug MCP Server
2
+
3
+ [![npm version](https://badge.fury.io/js/xdebug-mcp.svg)](https://www.npmjs.com/package/xdebug-mcp)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
+
6
+ An MCP (Model Context Protocol) server that provides PHP debugging capabilities through Xdebug's DBGp protocol. This allows AI assistants like Claude to directly debug PHP applications.
7
+
8
+ ## Features
9
+
10
+ ### Core Debugging
11
+ - **Full Debug Control**: Step into, step over, step out, continue, stop
12
+ - **Breakpoints**: Line breakpoints, conditional breakpoints, exception breakpoints, function call breakpoints
13
+ - **Variable Inspection**: View all variables, get specific variables, set variable values
14
+ - **Expression Evaluation**: Evaluate PHP expressions in the current context
15
+ - **Stack Traces**: View the full call stack
16
+ - **Multiple Sessions**: Debug multiple PHP scripts simultaneously
17
+ - **Docker Support**: Works with PHP running in Docker containers
18
+
19
+ ### Advanced Features
20
+ - **Watch Expressions**: Persistent watches that auto-evaluate on each break with change detection
21
+ - **Logpoints**: Log messages without stopping execution using `{$var}` placeholders
22
+ - **Memory Profiling**: Track memory usage and execution time between breakpoints
23
+ - **Code Coverage**: Track which lines were executed during debugging
24
+ - **Request Context**: Capture `$_GET`, `$_POST`, `$_SESSION`, `$_COOKIE`, headers automatically
25
+ - **Step Filters**: Skip vendor/library code during stepping
26
+ - **Debug Profiles**: Save and restore breakpoint configurations
27
+ - **Session Export**: Export debug sessions as JSON or HTML reports
28
+
29
+ ## Installation
30
+
31
+ ### From npm (Recommended)
32
+
33
+ ```bash
34
+ npm install -g xdebug-mcp
35
+ ```
36
+
37
+ ### From Source
38
+
39
+ ```bash
40
+ git clone https://github.com/kpanuragh/xdebug-mcp.git
41
+ cd xdebug-mcp
42
+ npm install
43
+ npm run build
44
+ ```
45
+
46
+ ## MCP Server Configuration
47
+
48
+ ### For Claude Code
49
+
50
+ Add the xdebug-mcp server to your MCP configuration (`.mcp.json` or Claude settings):
51
+
52
+ **Using npm global install:**
53
+
54
+ ```json
55
+ {
56
+ "mcpServers": {
57
+ "xdebug": {
58
+ "command": "xdebug-mcp",
59
+ "env": {
60
+ "XDEBUG_PORT": "9003",
61
+ "LOG_LEVEL": "info"
62
+ }
63
+ }
64
+ }
65
+ }
66
+ ```
67
+
68
+ **Using npx:**
69
+
70
+ ```json
71
+ {
72
+ "mcpServers": {
73
+ "xdebug": {
74
+ "command": "npx",
75
+ "args": ["-y", "xdebug-mcp"],
76
+ "env": {
77
+ "XDEBUG_PORT": "9003",
78
+ "LOG_LEVEL": "info"
79
+ }
80
+ }
81
+ }
82
+ }
83
+ ```
84
+
85
+ ### With Path Mappings (for Docker)
86
+
87
+ When debugging PHP in Docker containers, you need path mappings to translate container paths to host paths:
88
+
89
+ ```json
90
+ {
91
+ "mcpServers": {
92
+ "xdebug": {
93
+ "command": "xdebug-mcp",
94
+ "env": {
95
+ "XDEBUG_PORT": "9003",
96
+ "PATH_MAPPINGS": "{\"/var/www/html\": \"/home/user/projects/myapp\"}",
97
+ "LOG_LEVEL": "info"
98
+ }
99
+ }
100
+ }
101
+ }
102
+ ```
103
+
104
+ ## PHP/Xdebug Configuration
105
+
106
+ ### php.ini (or xdebug.ini)
107
+
108
+ ```ini
109
+ [xdebug]
110
+ zend_extension=xdebug
111
+
112
+ ; Enable step debugging
113
+ xdebug.mode=debug
114
+
115
+ ; Start debugging on every request
116
+ xdebug.start_with_request=yes
117
+
118
+ ; Host where MCP server is running
119
+ ; For Docker: use host.docker.internal
120
+ ; For local PHP: use 127.0.0.1
121
+ xdebug.client_host=host.docker.internal
122
+
123
+ ; Port where MCP server listens
124
+ xdebug.client_port=9003
125
+
126
+ ; IDE key (optional, for filtering)
127
+ xdebug.idekey=mcp
128
+ ```
129
+
130
+ ### Docker Compose
131
+
132
+ ```yaml
133
+ version: '3.8'
134
+
135
+ services:
136
+ php:
137
+ image: php:8.2-apache
138
+ volumes:
139
+ - ./src:/var/www/html
140
+ - ./xdebug.ini:/usr/local/etc/php/conf.d/99-xdebug.ini
141
+ extra_hosts:
142
+ - "host.docker.internal:host-gateway" # Required for Linux
143
+ environment:
144
+ - XDEBUG_MODE=debug
145
+ - XDEBUG_CONFIG=client_host=host.docker.internal client_port=9003
146
+ ```
147
+
148
+ ## Available MCP Tools (41 Total)
149
+
150
+ ### Session Management
151
+
152
+ | Tool | Description |
153
+ |------|-------------|
154
+ | `list_sessions` | List all active debug sessions |
155
+ | `get_session_state` | Get detailed state of a session |
156
+ | `set_active_session` | Set which session is active |
157
+ | `close_session` | Close a debug session |
158
+
159
+ ### Breakpoints
160
+
161
+ | Tool | Description |
162
+ |------|-------------|
163
+ | `set_breakpoint` | Set a line or conditional breakpoint |
164
+ | `set_exception_breakpoint` | Break on exceptions |
165
+ | `set_call_breakpoint` | Break on function calls |
166
+ | `remove_breakpoint` | Remove a breakpoint |
167
+ | `update_breakpoint` | Enable/disable or modify a breakpoint |
168
+ | `list_breakpoints` | List all breakpoints |
169
+
170
+ ### Execution Control
171
+
172
+ | Tool | Description |
173
+ |------|-------------|
174
+ | `continue` | Continue to next breakpoint |
175
+ | `step_into` | Step into function calls |
176
+ | `step_over` | Step over (skip function internals) |
177
+ | `step_out` | Step out of current function |
178
+ | `stop` | Stop debugging |
179
+ | `detach` | Detach and let script continue |
180
+
181
+ ### Inspection
182
+
183
+ | Tool | Description |
184
+ |------|-------------|
185
+ | `get_stack_trace` | Get the call stack |
186
+ | `get_contexts` | Get available variable contexts |
187
+ | `get_variables` | Get all variables in scope |
188
+ | `get_variable` | Get a specific variable |
189
+ | `set_variable` | Set a variable's value |
190
+ | `evaluate` | Evaluate a PHP expression |
191
+ | `get_source` | Get source code |
192
+
193
+ ### Watch Expressions
194
+
195
+ | Tool | Description |
196
+ |------|-------------|
197
+ | `add_watch` | Add a persistent watch expression |
198
+ | `remove_watch` | Remove a watch expression |
199
+ | `evaluate_watches` | Evaluate all watches and detect changes |
200
+ | `list_watches` | List all active watches |
201
+
202
+ ### Logpoints
203
+
204
+ | Tool | Description |
205
+ |------|-------------|
206
+ | `add_logpoint` | Add a logpoint with message template |
207
+ | `remove_logpoint` | Remove a logpoint |
208
+ | `get_logpoint_history` | View log output and hit statistics |
209
+
210
+ ### Profiling
211
+
212
+ | Tool | Description |
213
+ |------|-------------|
214
+ | `start_profiling` | Start memory/time profiling |
215
+ | `stop_profiling` | Stop profiling and get results |
216
+ | `get_profile_stats` | Get current profiling statistics |
217
+ | `get_memory_timeline` | View memory usage over time |
218
+
219
+ ### Code Coverage
220
+
221
+ | Tool | Description |
222
+ |------|-------------|
223
+ | `start_coverage` | Start tracking code coverage |
224
+ | `stop_coverage` | Stop and get coverage report |
225
+ | `get_coverage_report` | View coverage statistics |
226
+
227
+ ### Debug Profiles
228
+
229
+ | Tool | Description |
230
+ |------|-------------|
231
+ | `save_debug_profile` | Save current configuration as a profile |
232
+ | `load_debug_profile` | Load a saved debug profile |
233
+ | `list_debug_profiles` | List all saved profiles |
234
+
235
+ ### Additional Tools
236
+
237
+ | Tool | Description |
238
+ |------|-------------|
239
+ | `capture_request_context` | Capture HTTP request context |
240
+ | `add_step_filter` | Add filter to skip files during stepping |
241
+ | `list_step_filters` | List step filter rules |
242
+ | `get_function_history` | View function call history |
243
+ | `export_session` | Export session as JSON/HTML report |
244
+ | `capture_snapshot` | Capture debug state snapshot |
245
+
246
+ ## Usage Examples
247
+
248
+ ### Setting a Breakpoint
249
+
250
+ ```
251
+ Use set_breakpoint with file="/var/www/html/index.php" and line=25
252
+ ```
253
+
254
+ ### Conditional Breakpoint
255
+
256
+ ```
257
+ Use set_breakpoint with file="/var/www/html/api.php", line=42, condition="$userId > 100"
258
+ ```
259
+
260
+ ### Watch Expression
261
+
262
+ ```
263
+ Use add_watch with expression="$user->email"
264
+ Use add_watch with expression="count($items)"
265
+ ```
266
+
267
+ ### Logpoint
268
+
269
+ ```
270
+ Use add_logpoint with file="/var/www/html/api.php", line=50, message="User {$userId} accessed {$endpoint}"
271
+ ```
272
+
273
+ ### Inspecting Variables
274
+
275
+ ```
276
+ Use get_variables to see all local variables
277
+ Use get_variable with name="$user" to inspect a specific variable
278
+ Use evaluate with expression="count($items)" to evaluate an expression
279
+ ```
280
+
281
+ ### Capture Request Context
282
+
283
+ ```
284
+ Use capture_request_context to see $_GET, $_POST, $_SESSION, cookies, and headers
285
+ ```
286
+
287
+ ## Environment Variables
288
+
289
+ | Variable | Default | Description |
290
+ |----------|---------|-------------|
291
+ | `XDEBUG_PORT` | `9003` | Port to listen for Xdebug connections |
292
+ | `XDEBUG_HOST` | `0.0.0.0` | Host to bind |
293
+ | `COMMAND_TIMEOUT` | `30000` | Command timeout in milliseconds |
294
+ | `PATH_MAPPINGS` | - | JSON object mapping container to host paths |
295
+ | `MAX_DEPTH` | `3` | Max depth for variable inspection |
296
+ | `MAX_CHILDREN` | `128` | Max children to return for arrays/objects |
297
+ | `MAX_DATA` | `2048` | Max data size per variable |
298
+ | `LOG_LEVEL` | `info` | Log level: debug, info, warn, error |
299
+
300
+ ## How It Works
301
+
302
+ 1. **MCP Server starts** and listens for Xdebug connections on port 9003
303
+ 2. **PHP script runs** with Xdebug enabled
304
+ 3. **Xdebug connects** to the MCP server via DBGp protocol
305
+ 4. **AI uses MCP tools** to control debugging (set breakpoints, step, inspect)
306
+ 5. **DBGp commands** are sent to Xdebug, responses parsed and returned
307
+
308
+ ```
309
+ ┌─────────────┐ MCP/stdio ┌─────────────┐ DBGp/TCP ┌─────────────┐
310
+ │ Claude │ ◄────────────────► │ xdebug-mcp │ ◄───────────────► │ Xdebug │
311
+ │ (AI Agent) │ │ Server │ │ (in PHP) │
312
+ └─────────────┘ └─────────────┘ └─────────────┘
313
+ ```
314
+
315
+ ## Troubleshooting
316
+
317
+ ### No debug sessions appearing
318
+
319
+ 1. Check that Xdebug is installed: `php -v` should show Xdebug
320
+ 2. Verify Xdebug config: `php -i | grep xdebug`
321
+ 3. Ensure `xdebug.client_host` points to the MCP server
322
+ 4. Check firewall allows connections on port 9003
323
+
324
+ ### Connection issues with Docker
325
+
326
+ 1. For Linux, add `extra_hosts: ["host.docker.internal:host-gateway"]`
327
+ 2. Verify container can reach host: `curl host.docker.internal:9003`
328
+
329
+ ### Breakpoints not hitting
330
+
331
+ 1. Ensure file paths match exactly (use container paths for Docker)
332
+ 2. Check breakpoint is resolved: `list_breakpoints`
333
+ 3. Verify script execution reaches that line
334
+
335
+ ## Contributing
336
+
337
+ Contributions are welcome! Please feel free to submit a Pull Request.
338
+
339
+ ## License
340
+
341
+ MIT
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Configuration Management
3
+ */
4
+ import { z } from 'zod';
5
+ declare const ConfigSchema: z.ZodObject<{
6
+ dbgpPort: z.ZodDefault<z.ZodNumber>;
7
+ dbgpHost: z.ZodDefault<z.ZodString>;
8
+ commandTimeout: z.ZodDefault<z.ZodNumber>;
9
+ pathMappings: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
10
+ maxDepth: z.ZodDefault<z.ZodNumber>;
11
+ maxChildren: z.ZodDefault<z.ZodNumber>;
12
+ maxData: z.ZodDefault<z.ZodNumber>;
13
+ logLevel: z.ZodDefault<z.ZodEnum<["debug", "info", "warn", "error"]>>;
14
+ }, "strip", z.ZodTypeAny, {
15
+ dbgpPort: number;
16
+ dbgpHost: string;
17
+ commandTimeout: number;
18
+ maxDepth: number;
19
+ maxChildren: number;
20
+ maxData: number;
21
+ logLevel: "debug" | "info" | "warn" | "error";
22
+ pathMappings?: Record<string, string> | undefined;
23
+ }, {
24
+ dbgpPort?: number | undefined;
25
+ dbgpHost?: string | undefined;
26
+ commandTimeout?: number | undefined;
27
+ pathMappings?: Record<string, string> | undefined;
28
+ maxDepth?: number | undefined;
29
+ maxChildren?: number | undefined;
30
+ maxData?: number | undefined;
31
+ logLevel?: "debug" | "info" | "warn" | "error" | undefined;
32
+ }>;
33
+ export type Config = z.infer<typeof ConfigSchema>;
34
+ export declare function loadConfig(): Config;
35
+ export declare function getDefaultConfig(): Config;
36
+ export {};
package/dist/config.js ADDED
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Configuration Management
3
+ */
4
+ import { z } from 'zod';
5
+ import { logger } from './utils/logger.js';
6
+ const ConfigSchema = z.object({
7
+ // DBGp server settings
8
+ dbgpPort: z.number().int().positive().default(9003),
9
+ dbgpHost: z.string().default('0.0.0.0'),
10
+ commandTimeout: z.number().int().positive().default(30000),
11
+ // Path mappings for Docker
12
+ pathMappings: z.record(z.string(), z.string()).optional(),
13
+ // Variable inspection limits
14
+ maxDepth: z.number().int().positive().default(3),
15
+ maxChildren: z.number().int().positive().default(128),
16
+ maxData: z.number().int().positive().default(2048),
17
+ // Logging
18
+ logLevel: z.enum(['debug', 'info', 'warn', 'error']).default('info'),
19
+ });
20
+ export function loadConfig() {
21
+ const rawConfig = {
22
+ dbgpPort: parseInt(process.env.XDEBUG_PORT || '9003', 10),
23
+ dbgpHost: process.env.XDEBUG_HOST || '0.0.0.0',
24
+ commandTimeout: parseInt(process.env.COMMAND_TIMEOUT || '30000', 10),
25
+ maxDepth: parseInt(process.env.MAX_DEPTH || '3', 10),
26
+ maxChildren: parseInt(process.env.MAX_CHILDREN || '128', 10),
27
+ maxData: parseInt(process.env.MAX_DATA || '2048', 10),
28
+ logLevel: process.env.LOG_LEVEL || 'info',
29
+ };
30
+ // Parse path mappings from JSON if provided
31
+ if (process.env.PATH_MAPPINGS) {
32
+ try {
33
+ rawConfig.pathMappings = JSON.parse(process.env.PATH_MAPPINGS);
34
+ }
35
+ catch {
36
+ logger.warn('Failed to parse PATH_MAPPINGS environment variable');
37
+ }
38
+ }
39
+ const config = ConfigSchema.parse(rawConfig);
40
+ // Apply log level
41
+ logger.setLevel(config.logLevel);
42
+ return config;
43
+ }
44
+ export function getDefaultConfig() {
45
+ return ConfigSchema.parse({});
46
+ }
47
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAY,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAErD,MAAM,YAAY,GAAG,CAAC,CAAC,MAAM,CAAC;IAC5B,uBAAuB;IACvB,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC;IACnD,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,OAAO,CAAC,SAAS,CAAC;IACvC,cAAc,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC;IAE1D,2BAA2B;IAC3B,YAAY,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,QAAQ,EAAE;IAEzD,6BAA6B;IAC7B,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC;IAChD,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC;IACrD,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC;IAElD,UAAU;IACV,QAAQ,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC;CACrE,CAAC,CAAC;AAIH,MAAM,UAAU,UAAU;IACxB,MAAM,SAAS,GAA4B;QACzC,QAAQ,EAAE,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,WAAW,IAAI,MAAM,EAAE,EAAE,CAAC;QACzD,QAAQ,EAAE,OAAO,CAAC,GAAG,CAAC,WAAW,IAAI,SAAS;QAC9C,cAAc,EAAE,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,eAAe,IAAI,OAAO,EAAE,EAAE,CAAC;QACpE,QAAQ,EAAE,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,SAAS,IAAI,GAAG,EAAE,EAAE,CAAC;QACpD,WAAW,EAAE,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,YAAY,IAAI,KAAK,EAAE,EAAE,CAAC;QAC5D,OAAO,EAAE,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,IAAI,MAAM,EAAE,EAAE,CAAC;QACrD,QAAQ,EAAE,OAAO,CAAC,GAAG,CAAC,SAAS,IAAI,MAAM;KAC1C,CAAC;IAEF,4CAA4C;IAC5C,IAAI,OAAO,CAAC,GAAG,CAAC,aAAa,EAAE,CAAC;QAC9B,IAAI,CAAC;YACH,SAAS,CAAC,YAAY,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;QACjE,CAAC;QAAC,MAAM,CAAC;YACP,MAAM,CAAC,IAAI,CAAC,oDAAoD,CAAC,CAAC;QACpE,CAAC;IACH,CAAC;IAED,MAAM,MAAM,GAAG,YAAY,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;IAE7C,kBAAkB;IAClB,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,QAAoB,CAAC,CAAC;IAE7C,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,MAAM,UAAU,gBAAgB;IAC9B,OAAO,YAAY,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;AAChC,CAAC"}
@@ -0,0 +1,52 @@
1
+ /**
2
+ * DBGp Connection Handler
3
+ * Handles a single Xdebug connection with message parsing and command sending.
4
+ */
5
+ import * as net from 'net';
6
+ import { EventEmitter } from 'events';
7
+ import { DbgpResponse, InitPacket, StackFrame, Context, Property, Breakpoint, StreamData } from './types.js';
8
+ export interface DbgpConnectionEvents {
9
+ init: (packet: InitPacket) => void;
10
+ response: (response: DbgpResponse) => void;
11
+ stream: (data: StreamData) => void;
12
+ close: () => void;
13
+ error: (error: Error) => void;
14
+ }
15
+ export declare class DbgpConnection extends EventEmitter {
16
+ private socket;
17
+ private commandTimeout;
18
+ private buffer;
19
+ private parserState;
20
+ private expectedLength;
21
+ private transactionId;
22
+ private pendingCommands;
23
+ private commandQueue;
24
+ private xmlParser;
25
+ private closed;
26
+ initPacket: InitPacket | null;
27
+ readonly id: string;
28
+ readonly remoteAddress: string;
29
+ constructor(socket: net.Socket, commandTimeout?: number);
30
+ private handleData;
31
+ private processBuffer;
32
+ private handleMessage;
33
+ private parseInitPacket;
34
+ private parseResponse;
35
+ private parseStream;
36
+ sendCommand(command: string, args?: Record<string, string>, data?: string): Promise<DbgpResponse>;
37
+ private processQueue;
38
+ private escapeArg;
39
+ private handleClose;
40
+ close(): void;
41
+ get isConnected(): boolean;
42
+ parseStackFrames(response: DbgpResponse): StackFrame[];
43
+ parseContexts(response: DbgpResponse): Context[];
44
+ parseProperties(response: DbgpResponse): Property[];
45
+ parseProperty(response: DbgpResponse): Property | null;
46
+ private parsePropertyNode;
47
+ parseBreakpoints(response: DbgpResponse): Breakpoint[];
48
+ parseBreakpointSet(response: DbgpResponse): {
49
+ id: string;
50
+ resolved: boolean;
51
+ };
52
+ }