Skip to content

Commit 608a3ed

Browse files
authored
Merge pull request #20 from microsoft/user/oribarilan/docs_and_agentsmd
Docs and AGENTS.md
2 parents 923f603 + 6b12fb8 commit 608a3ed

16 files changed

Lines changed: 693 additions & 30 deletions

AGENTS.md

Lines changed: 87 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,94 @@
11
# Agent Guidelines for DebugMCP
22

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+
334
## 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+
```
640

741
## 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 |
1349

1450
## 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.

docs/debug_instructions.md renamed to docs/agent-resources/debug_instructions.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
⚠️ **CRITICAL INSTRUCTIONS - FOLLOW THESE STEPS:**
44
1. **FIRST:** Use 'add_breakpoint' to set an initial breakpoint at a starting point
5-
1. **THEN:** Optionally use 'add_breakpoint' to set breakpoints at strategic points
6-
2. **THEN:** Use 'start_debugging' tool to start debugging
7-
3. **THEN:** Use repetitively all the other tools to navigate and inspect step by step
8-
3. **FINALLY:** Get to the problematic line to fully understand the root cause. If needed, restart the debug session using restart_debugging.
5+
2. **THEN:** Optionally use 'add_breakpoint' to set breakpoints at strategic points
6+
3. **THEN:** Use 'start_debugging' tool to start debugging
7+
4. **THEN:** Use repetitively all the other tools to navigate and inspect step by step
8+
5. **FINALLY:** Get to the problematic line to fully understand the root cause. If needed, restart the debug session using restart_debugging.
99

1010
## 🚨 ROOT CAUSE ANALYSIS - CRITICAL FRAMEWORK
1111

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# C/C++ Debugging Tips
2+
3+
**C/C++-SPECIFIC GUIDANCE:**
4+
5+
## Prerequisites:
6+
- Use C/C++ extension for VS Code (by Microsoft)
7+
- Ensure GDB or LLDB debugger is installed
8+
- Compile with debug symbols (`-g` flag)
9+
- Set breakpoints in `.c`, `.cpp`, `.cc`, `.h`, `.hpp` files
10+
- Use 'cppdbg' debug configuration type
11+
12+
## C/C++-Specific Best Practices:
13+
- **Compilation:** Always compile with `-g` flag and disable optimizations (`-O0`) for debugging
14+
- **Memory Issues:** Watch for buffer overflows, memory leaks, and dangling pointers
15+
- **Pointers:** Carefully inspect pointer values and dereferenced contents
16+
- **Stack Frames:** Use call stack to trace function calls and local variables
17+
- **Core Dumps:** Enable core dumps for post-mortem debugging of crashes
18+
19+
## Common C++ Debug Configurations:
20+
21+
### GDB (Linux/Windows with MinGW):
22+
```json
23+
{
24+
"type": "cppdbg",
25+
"request": "launch",
26+
"name": "Debug with GDB",
27+
"program": "${fileDirname}/${fileBasenameNoExtension}",
28+
"args": [],
29+
"stopAtEntry": false,
30+
"cwd": "${fileDirname}",
31+
"environment": [],
32+
"externalConsole": false,
33+
"MIMode": "gdb",
34+
"setupCommands": [
35+
{
36+
"description": "Enable pretty-printing for gdb",
37+
"text": "-enable-pretty-printing",
38+
"ignoreFailures": true
39+
}
40+
]
41+
}
42+
```
43+
44+
### LLDB (macOS):
45+
```json
46+
{
47+
"type": "cppdbg",
48+
"request": "launch",
49+
"name": "Debug with LLDB",
50+
"program": "${fileDirname}/${fileBasenameNoExtension}",
51+
"args": [],
52+
"stopAtEntry": false,
53+
"cwd": "${fileDirname}",
54+
"environment": [],
55+
"externalConsole": false,
56+
"MIMode": "lldb"
57+
}
58+
```
59+
60+
## Debugging Tips:
61+
- Use `printf()` or `std::cout` for quick debugging
62+
- Watch for uninitialized variables
63+
- Check array bounds carefully
64+
- Be aware of undefined behavior from pointer arithmetic
65+
- Use address sanitizer (`-fsanitize=address`) to detect memory errors
66+
- Use valgrind for memory leak detection (Linux)
67+
68+
## Common Issues:
69+
- **"Unable to start debugging":** Ensure executable is compiled with debug symbols
70+
- **"No symbol table":** Recompile with `-g` flag
71+
- **Breakpoints grayed out:** Source file doesn't match compiled binary - rebuild
72+
- **Segmentation fault:** Use backtrace to find the crashing line, check pointer operations
73+
- **Optimized away variables:** Compile with `-O0` to disable optimizations
74+
75+
## Memory Debugging:
76+
- **Valgrind:** `valgrind --leak-check=full ./program`
77+
- **Address Sanitizer:** Compile with `-fsanitize=address -fno-omit-frame-pointer`
78+
- **Watch expressions:** Monitor pointer values and array indices during stepping
File renamed without changes.
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Go Debugging Tips
2+
3+
**GO-SPECIFIC GUIDANCE:**
4+
5+
## Prerequisites:
6+
- Use Go extension for VS Code (by Go Team at Google)
7+
- Ensure Delve debugger is installed (`go install github.com/go-delve/delve/cmd/dlv@latest`)
8+
- Set breakpoints in `.go` files
9+
- Use 'go' debug configuration type
10+
- Check GOPATH and GOROOT environment variables
11+
12+
## Go-Specific Best Practices:
13+
- **Build Tags:** Ensure correct build tags are set for debugging
14+
- **Goroutines:** Be aware that goroutines run concurrently - use breakpoints in each goroutine you want to inspect
15+
- **Interfaces:** When debugging interface values, check both the type and value
16+
- **Defer Statements:** Remember deferred functions execute in LIFO order at function return
17+
- **Channels:** Set breakpoints at channel send/receive operations to debug concurrency
18+
19+
## Common Go Debug Configurations:
20+
```json
21+
{
22+
"type": "go",
23+
"request": "launch",
24+
"name": "Launch Package",
25+
"mode": "debug",
26+
"program": "${fileDirname}"
27+
}
28+
```
29+
30+
## Test Debugging:
31+
```json
32+
{
33+
"type": "go",
34+
"request": "launch",
35+
"name": "Launch Test",
36+
"mode": "test",
37+
"program": "${fileDirname}",
38+
"args": ["-test.run", "TestFunctionName"]
39+
}
40+
```
41+
42+
## Debugging Tips:
43+
- Use `fmt.Printf()` or `log.Printf()` for quick debugging
44+
- Watch for `nil` pointer dereferences
45+
- Be aware of value vs pointer receivers on methods
46+
- Check error return values - Go's explicit error handling is a common source of bugs
47+
- Use race detector (`go run -race`) to find data races before debugging
48+
49+
## Common Issues:
50+
- **"could not launch process":** Ensure Delve is installed and in PATH
51+
- **Breakpoints not hit:** Check build mode (debug vs release) and ensure optimizations are disabled
52+
- **Goroutine confusion:** Use the Call Stack panel to switch between goroutines
File renamed without changes.
File renamed without changes.
File renamed without changes.
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# AgentConfigurationManager
2+
3+
## Purpose
4+
5+
Handles automatic configuration of AI coding agents (Cline, GitHub Copilot, Cursor) to connect to the DebugMCP server. Provides a seamless onboarding experience.
6+
7+
## Motivation
8+
9+
For AI agents to use DebugMCP, they need MCP server configuration in their settings files. Rather than requiring users to manually edit JSON files, this manager auto-configures supported agents with the correct SSE endpoint.
10+
11+
## Responsibility
12+
13+
- Detect supported AI agents and their config file paths
14+
- Show post-install popup for agent selection
15+
- Write MCP server configuration to agent settings files
16+
- Handle cross-platform config path differences (Windows, macOS, Linux)
17+
- Track whether onboarding popup has been shown
18+
19+
## Supported Agents
20+
21+
| Agent | Config File | MCP Field |
22+
|-------|-------------|-----------|
23+
| Cline | `cline_mcp_settings.json` | `mcpServers` |
24+
| GitHub Copilot | `mcp.json` | `servers` |
25+
| Cursor | `mcp_settings.json` | `mcpServers` |
26+
27+
## Key Concepts
28+
29+
### Cross-Platform Paths
30+
31+
Config base paths vary by OS:
32+
- **Windows**: `%APPDATA%` (e.g., `C:\Users\X\AppData\Roaming`)
33+
- **macOS**: `~/Library/Application Support`
34+
- **Linux**: `$XDG_CONFIG_HOME` or `~/.config`
35+
36+
### MCP Server Configuration
37+
38+
The configuration written to agent settings:
39+
```json
40+
{
41+
"debugmcp": {
42+
"autoApprove": [],
43+
"disabled": false,
44+
"timeout": 180,
45+
"type": "sse",
46+
"url": "http://localhost:3001/sse"
47+
}
48+
}
49+
```
50+
51+
### Popup State
52+
53+
Uses VS Code's `globalState` to track whether the onboarding popup has been shown, preventing repeated prompts on every activation.
54+
55+
## Key Code Locations
56+
57+
- Class definition: `src/utils/agentConfigurationManager.ts`
58+
- Agent definitions: `getSupportedAgents()`
59+
- Config writing: `addDebugMCPToAgent()`
60+
- Path detection: `getConfigBasePath()`
61+
- Popup logic: `shouldShowPopup()`, `showAgentSelectionPopup()`
62+
63+
## User Flow
64+
65+
1. Extension activates
66+
2. Check if popup was previously shown
67+
3. If not, display multi-select dialog with supported agents
68+
4. For each selected agent, write/update config file
69+
5. Show success message with option to open config file
70+
6. Mark popup as shown
71+
72+
## Commands
73+
74+
- `debugmcp.showAgentSelectionPopup`: Manually trigger agent setup
75+
- `debugmcp.configureAgents`: Alternative manual configuration
76+
- `debugmcp.resetPopupState`: Reset for testing (re-shows popup)

0 commit comments

Comments
 (0)