|
| 1 | +# Asynkron.McpDebugger |
| 2 | + |
| 3 | +AI-controlled cooperative debugger via MCP (Model Context Protocol). |
| 4 | + |
| 5 | +Add breakpoints to your C# code that pause execution until an AI (like Claude) resumes them. The AI can inspect the call stack, view source code context, and control program flow. |
| 6 | + |
| 7 | +## How It Works |
| 8 | + |
| 9 | +``` |
| 10 | +┌─────────────────┐ MCP (stdio) ┌─────────────────────────┐ |
| 11 | +│ AI (Claude) │ ◄──────────────────► │ mcpdebugger mcp │ |
| 12 | +└─────────────────┘ └───────────┬─────────────┘ |
| 13 | + │ HTTP |
| 14 | + ┌───────────▼─────────────┐ |
| 15 | + │ mcpdebugger serve │ |
| 16 | + └───────────┬─────────────┘ |
| 17 | + │ HTTP |
| 18 | + ┌───────────▼─────────────┐ |
| 19 | + │ Your Application │ |
| 20 | + │ with DebugBreak calls │ |
| 21 | + └─────────────────────────┘ |
| 22 | +``` |
| 23 | + |
| 24 | +## Installation |
| 25 | + |
| 26 | +### Install the CLI tool (global) |
| 27 | + |
| 28 | +```bash |
| 29 | +dotnet tool install -g Asynkron.McpDebugger |
| 30 | +``` |
| 31 | + |
| 32 | +### Add the client library to your project |
| 33 | + |
| 34 | +```bash |
| 35 | +dotnet add package Asynkron.McpDebugger.Client |
| 36 | +``` |
| 37 | + |
| 38 | +## Quick Start |
| 39 | + |
| 40 | +### 1. Add breakpoints to your code |
| 41 | + |
| 42 | +```csharp |
| 43 | +using Asynkron.McpDebugger.Client; |
| 44 | + |
| 45 | +public class MyService |
| 46 | +{ |
| 47 | + public async Task ProcessOrderAsync(Order order) |
| 48 | + { |
| 49 | + // Async breakpoint - doesn't block threadpool threads |
| 50 | + await DebugBreak.HereAsync(); |
| 51 | + |
| 52 | + // Your code continues after AI resumes... |
| 53 | + await ValidateOrder(order); |
| 54 | + |
| 55 | + // Another breakpoint |
| 56 | + await DebugBreak.HereAsync(); |
| 57 | + |
| 58 | + await ChargeCustomer(order); |
| 59 | + } |
| 60 | +} |
| 61 | +``` |
| 62 | + |
| 63 | +### 2. Start the debug server |
| 64 | + |
| 65 | +```bash |
| 66 | +mcpdebugger serve |
| 67 | +``` |
| 68 | + |
| 69 | +### 3. Configure Claude Code |
| 70 | + |
| 71 | +Add to `~/.claude/settings.json`: |
| 72 | + |
| 73 | +```json |
| 74 | +{ |
| 75 | + "mcpServers": { |
| 76 | + "debugger": { |
| 77 | + "command": "mcpdebugger", |
| 78 | + "args": ["mcp"] |
| 79 | + } |
| 80 | + } |
| 81 | +} |
| 82 | +``` |
| 83 | + |
| 84 | +### 4. Run your application |
| 85 | + |
| 86 | +Your app will pause at each `DebugBreak` call until the AI resumes it. |
| 87 | + |
| 88 | +## API |
| 89 | + |
| 90 | +### Client Library |
| 91 | + |
| 92 | +```csharp |
| 93 | +// Async breakpoint (recommended) - doesn't steal threadpool threads |
| 94 | +await DebugBreak.HereAsync(); |
| 95 | + |
| 96 | +// Sync breakpoint - blocks the current thread |
| 97 | +DebugBreak.Here(); |
| 98 | + |
| 99 | +// Configure server URL (default: http://localhost:5200) |
| 100 | +DebugBreak.Configure("http://localhost:5200"); |
| 101 | + |
| 102 | +// Disable/enable breakpoints |
| 103 | +DebugBreak.Disable(); |
| 104 | +DebugBreak.Enable(); |
| 105 | +``` |
| 106 | + |
| 107 | +### MCP Tools (available to AI) |
| 108 | + |
| 109 | +| Tool | Description | |
| 110 | +|------|-------------| |
| 111 | +| `get_breakpoints` | List all active breakpoints | |
| 112 | +| `get_context` | Get call stack and source code for a breakpoint | |
| 113 | +| `resume` | Resume a specific breakpoint | |
| 114 | +| `resume_all` | Resume all active breakpoints | |
| 115 | + |
| 116 | +### HTTP API (for direct access) |
| 117 | + |
| 118 | +```bash |
| 119 | +# List active breakpoints |
| 120 | +curl http://localhost:5200/status |
| 121 | + |
| 122 | +# Resume a specific breakpoint |
| 123 | +curl -X POST http://localhost:5200/resume/{breakpoint-id} |
| 124 | + |
| 125 | +# Resume all breakpoints |
| 126 | +curl -X POST http://localhost:5200/resume-all |
| 127 | +``` |
| 128 | + |
| 129 | +## CLI Commands |
| 130 | + |
| 131 | +```bash |
| 132 | +mcpdebugger serve [--port 5200] # Start the HTTP debug server |
| 133 | +mcpdebugger mcp [--port 5200] # Start the MCP server (for AI integration) |
| 134 | +mcpdebugger --help # Show help |
| 135 | +``` |
| 136 | + |
| 137 | +## How the Breakpoints Work |
| 138 | + |
| 139 | +The async breakpoint (`HereAsync`) uses `TaskCompletionSource` internally: |
| 140 | +- Your code awaits an HTTP POST to the debug server |
| 141 | +- The server holds the request until the AI calls `resume` |
| 142 | +- No threadpool threads are blocked |
| 143 | + |
| 144 | +The sync breakpoint (`Here`) simply blocks on the HTTP call: |
| 145 | +- The calling thread is blocked until resume |
| 146 | +- Use sparingly to avoid thread starvation |
| 147 | + |
| 148 | +## Building from Source |
| 149 | + |
| 150 | +```bash |
| 151 | +git clone https://github.com/asynkron/Asynkron.McpDebugger.git |
| 152 | +cd Asynkron.McpDebugger |
| 153 | +dotnet build |
| 154 | +``` |
| 155 | + |
| 156 | +## License |
| 157 | + |
| 158 | +MIT |
0 commit comments