|
1 | 1 | # Agent Guidelines for DebugMCP |
2 | 2 |
|
| 3 | +## Project Overview |
| 4 | + |
| 5 | +DebugMCP is a VS Code extension that embeds an MCP (Model Context Protocol) server, enabling AI coding agents to control VS Code's debugger via DAP (Debug Adapter Protocol). AI agents can start/stop debugging, step through code, set breakpoints, inspect variables, and evaluate expressions. |
| 6 | + |
| 7 | +### Architecture |
| 8 | + |
| 9 | +``` |
| 10 | +AI Agent (Cline/Copilot/Cursor) → MCP/SSE → DebugMCPServer → DebuggingHandler → DebuggingExecutor → VS Code Debug API |
| 11 | +``` |
| 12 | + |
| 13 | +### Key Components |
| 14 | + |
| 15 | +| Component | Responsibility | Docs | |
| 16 | +|-----------|----------------|------| |
| 17 | +| `DebugMCPServer` | MCP server, tool/resource registration | [docs/architecture/debugMCPServer.md](docs/architecture/debugMCPServer.md) | |
| 18 | +| `DebuggingHandler` | Operation orchestration, state change detection | [docs/architecture/debuggingHandler.md](docs/architecture/debuggingHandler.md) | |
| 19 | +| `DebuggingExecutor` | VS Code debug API calls, DAP requests | [docs/architecture/debuggingExecutor.md](docs/architecture/debuggingExecutor.md) | |
| 20 | +| `DebugState` | Debug session state model | [docs/architecture/debugState.md](docs/architecture/debugState.md) | |
| 21 | +| `DebugConfigurationManager` | Launch configs, language detection | [docs/architecture/debugConfigurationManager.md](docs/architecture/debugConfigurationManager.md) | |
| 22 | +| `AgentConfigurationManager` | AI agent auto-configuration | [docs/architecture/agentConfigurationManager.md](docs/architecture/agentConfigurationManager.md) | |
| 23 | + |
| 24 | +## Documentation Maintenance |
| 25 | + |
| 26 | +**IMPORTANT**: Keep `docs/*.md` files up to date when modifying components. These docs should remain high-level: |
| 27 | +- Purpose and motivation |
| 28 | +- Responsibility scope |
| 29 | +- Key concepts and patterns |
| 30 | +- Pointers to relevant code sections |
| 31 | + |
| 32 | +Do NOT duplicate detailed implementation in docs - that information should be inferred from the code itself. |
| 33 | + |
3 | 34 | ## File Header |
4 | | -Include the following header in each source file (adjust comment syntax as needed). |
5 | | -`// Copyright (c) Microsoft Corporation.` |
| 35 | + |
| 36 | +Include in each source file: |
| 37 | +```typescript |
| 38 | +// Copyright (c) Microsoft Corporation. |
| 39 | +``` |
6 | 40 |
|
7 | 41 | ## Build/Lint/Test Commands |
8 | | -- **Compile**: `npm run compile` - Compiles TypeScript to JavaScript in `out/` directory |
9 | | -- **Lint**: `npm run lint` - Runs ESLint on `src/` directory |
10 | | -- **Test**: `npm test` - Runs all tests (compiles + lints first via pretest) |
11 | | -- **Single Test**: Use VSCode Test Explorer or `npm test` (no CLI test filtering available) |
12 | | -- **Watch Mode**: `npm run watch` - Compiles TypeScript in watch mode |
| 42 | + |
| 43 | +| Command | Description | |
| 44 | +|---------|-------------| |
| 45 | +| `npm run compile` | Compile TypeScript to `out/` | |
| 46 | +| `npm run lint` | Run ESLint on `src/` | |
| 47 | +| `npm test` | Run all tests (`src/test/*.test.ts`) | |
| 48 | +| `npm run watch` | Compile in watch mode | |
13 | 49 |
|
14 | 50 | ## Code Style & Conventions |
15 | | -- **TypeScript**: Strict mode enabled, target ES2022, Node16 modules |
16 | | -- **Imports**: Use camelCase/PascalCase naming. Import order: vscode → external → internal (e.g., `./utils/logger`) |
17 | | -- **Naming**: camelCase for variables/functions, PascalCase for classes/interfaces, prefix interfaces with `I` (e.g., `IDebuggingHandler`) |
18 | | -- **Types**: Explicit types preferred, use strict null checks, avoid `any` unless necessary |
19 | | -- **Error Handling**: Use try-catch with descriptive error messages, throw `Error` objects (not literals) |
20 | | -- **Formatting**: Use semicolons, curly braces for all control structures, consistent indentation (tabs) |
21 | | -- **Async**: Use async/await, handle promises properly, implement exponential backoff for retries |
22 | | -- **VSCode API**: Import as `import * as vscode from 'vscode'`, use proper disposal in `context.subscriptions` |
23 | | -- **Logging**: Use `logger` from `./utils/logger` for all logging (info/error/warn) |
24 | | -- **Dependencies**: fastmcp (MCP server), express (HTTP), zod (validation), @modelcontextprotocol/sdk |
25 | | - |
26 | | -## Architecture Notes |
27 | | -- VSCode extension with MCP server for AI agent debugging capabilities |
28 | | -- Main entry: `extension.ts` → activates MCP server and registers commands |
29 | | -- Core: `debuggingHandler.ts` handles debug operations, `debuggingExecutor.ts` executes VSCode debug API calls |
30 | | -- State: `debugState.ts` tracks current debugging session state |
| 51 | + |
| 52 | +- **TypeScript**: Strict mode, ES2022 target, Node16 modules |
| 53 | +- **Imports**: vscode → external packages → internal modules |
| 54 | +- **Naming**: camelCase (variables/functions), PascalCase (classes/interfaces), `I` prefix for interfaces |
| 55 | +- **Types**: Explicit types preferred, strict null checks, avoid `any` |
| 56 | +- **Error Handling**: try-catch with descriptive messages, throw `Error` objects |
| 57 | +- **Formatting**: Semicolons, curly braces for all control structures, tabs for indentation |
| 58 | +- **Async**: async/await, exponential backoff for retries |
| 59 | +- **Logging**: Use `logger` from `./utils/logger` (not `console.log`). Simple wrapper providing `info`, `warn`, `error` methods with consistent formatting. |
| 60 | +- **VS Code API**: Import as `import * as vscode from 'vscode'` |
| 61 | + |
| 62 | +## Key Dependencies |
| 63 | + |
| 64 | +- `fastmcp`: MCP server framework |
| 65 | +- `zod`: Schema validation for tool parameters |
| 66 | +- `@modelcontextprotocol/sdk`: MCP protocol types |
| 67 | +- `express`: HTTP server (used by FastMCP) |
| 68 | + |
| 69 | +## Entry Points |
| 70 | + |
| 71 | +- **Extension activation**: `src/extension.ts` → `activate()` |
| 72 | +- **MCP endpoint**: `http://localhost:{port}/sse` (default port: 3001) |
| 73 | + |
| 74 | +## Configuration |
| 75 | + |
| 76 | +| Setting | Default | Description | |
| 77 | +|---------|---------|-------------| |
| 78 | +| `debugmcp.serverPort` | 3001 | MCP server port | |
| 79 | +| `debugmcp.timeoutInSeconds` | 180 | Operation timeout | |
| 80 | + |
| 81 | +## Documentation Resources |
| 82 | + |
| 83 | +The `docs/` folder contains two types of documentation: |
| 84 | + |
| 85 | +**Component docs** (referenced in Key Components table above): Developer documentation for understanding the codebase architecture. |
| 86 | + |
| 87 | +**AI Agent resources** (served via MCP at runtime): |
| 88 | + |
| 89 | +| File | Purpose | |
| 90 | +|------|---------| |
| 91 | +| `agent-resources/debug_instructions.md` | Core debugging workflow guide for AI agents | |
| 92 | +| `agent-resources/troubleshooting/*.md` | Language-specific debugging tips (Python, JavaScript, Java, C#) | |
| 93 | + |
| 94 | +These resource files are loaded by `DebugMCPServer` and exposed as MCP resources that AI agents can read to learn how to use the debugging tools effectively. |
0 commit comments