Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/), and this

### Fixed
- Standalone CLI breakpoint tools remain usable between debug sessions. Adding, removing, and clearing breakpoints after termination, stopping, disposal, or failed startup no longer try to synchronize with an inactive adapter; saved changes are applied on the next launch (#161).
- A stop in a virtual document now reports its source location. `fileFullPath` is the document URI in the form the breakpoint tools accept, alongside the file name, current line, and following lines.
- `remove_breakpoint` finds a breakpoint in a virtual document whether its URI is written with literal spaces or percent-encoded, and `list_breakpoints` shows the decoded file name.
- `add_breakpoint` and `add_logpoint` accept a virtual document that cannot be opened yet instead of failing. The line is then not checked, and the result says so. Business Central serves a `.dal` source only once its session has stopped, which made it impossible to set a breakpoint there before the first stop.

### Added
- Breakpoint, logpoint, and removal tools now support VS Code virtual-document URIs, including Business Central `al-preview:` `.dal` sources. An optional `workingDirectory` selects the correct workspace when multiple editor windows are open.
- **Claude Code auto-registration** - Claude Code is now offered in the agent selection popup and configured via `~/.claude.json`'s user-scope `mcpServers` field. Claude Desktop connects via its Custom Connector UI instead of a static config file; the README's manual configuration section covers both.

## [2.4.4] - 2026-10-25
Expand Down
23 changes: 20 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ DebugMCP is an MCP server that gives AI coding agents full control over the VS C
| **restart_debugging** | Restart the current debug session; a fresh stop without acknowledgement returns an explicit completion-unconfirmed result, not confirmed success | None |
| **get_debug_status** | Read paused/running/no-session status, the active session ID, and selected-frame details when paused; optionally wait for a pause | `waitForPauseSeconds` (optional, 0-600; bounded by the operation timeout) |
| **get_debug_output** | Read captured output for one session; requires user-enabled capture and at least one filter | `sessionId` (required)<br>`prefix` and/or `category` (required filter; both are ANDed)<br>`cursor` (optional)<br>`limit` (optional, 1-100) |
| **add_breakpoint** | Add a breakpoint at a specific line (optionally conditional) | `fileFullPath` (required)<br>`line` (required, 1-based)<br>`condition` (optional) |
| **add_logpoint** | Add a logpoint that logs a message (instead of pausing) when a line is reached | `fileFullPath` (required)<br>`line` (required, 1-based)<br>`logMessage` (required, `{expr}` interpolated)<br>`condition` (optional) |
| **remove_breakpoint** | Remove a breakpoint from a specific line | `fileFullPath` (required)<br>`line` (required) |
| **add_breakpoint** | Add a breakpoint at a specific line (optionally conditional) | `fileFullPath` (required; path or virtual URI)<br>`workingDirectory` (optional; identifies the window for virtual URIs)<br>`line` (required, 1-based)<br>`condition` (optional) |
| **add_logpoint** | Add a logpoint that logs a message (instead of pausing) when a line is reached | `fileFullPath` (required; path or virtual URI)<br>`workingDirectory` (optional; identifies the window for virtual URIs)<br>`line` (required, 1-based)<br>`logMessage` (required, `{expr}` interpolated)<br>`condition` (optional) |
| **remove_breakpoint** | Remove a breakpoint from a specific line | `fileFullPath` (required; path or virtual URI)<br>`workingDirectory` (optional; identifies the window for virtual URIs)<br>`line` (required) |
| **clear_all_breakpoints** | Remove all breakpoints at once | None |
| **list_breakpoints** | List all active breakpoints | None |
| **list_variable_names** | List names and types of variables in scope, without reading any values | `scope` (optional: 'local', 'global', 'all') |
Expand Down Expand Up @@ -275,6 +275,23 @@ DebugMCP supports debugging for the following languages with their respective VS
| **PHP** | [PHP Debug](https://marketplace.visualstudio.com/items?itemName=xdebug.php-debug) | `.php` | ✅ Fully Supported |
| **Ruby** | [Ruby](https://marketplace.visualstudio.com/items?itemName=Shopify.ruby-lsp) | `.rb` | ✅ Fully Supported |
| **C#/.NET** | [C#](https://marketplace.visualstudio.com/items?itemName=ms-dotnettools.csharp) | `.cs`, `.csproj` | ✅ Fully Supported |
| **AL (Business Central)** | [AL Language](https://marketplace.visualstudio.com/items?itemName=ms-dynamics-smb.al) | `.al`, virtual `.dal` | ✅ Supported with an AL launch configuration |

### Virtual source documents

Breakpoint tools accept native filesystem paths and VS Code virtual-document URIs. This
supports generated or downloaded sources that a language extension exposes without a local
file, including Business Central dependency objects such as
`al-preview://AlLang/.../Table/18/Customer.dal`. When multiple editor windows are open,
pass `workingDirectory` with the virtual URI so DebugMCP routes the operation to the correct
workspace.

When execution stops in a virtual document, the debug state reports the same URI as
`fileFullPath`, so it can be passed back to the breakpoint tools unchanged.

Some debuggers serve a virtual source only once the session has stopped. A breakpoint can
still be set in it beforehand: the line is not validated in that case, and the tool result
says so.

## Configuration

Expand Down
4 changes: 3 additions & 1 deletion docs/architecture/debugMCPServer.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ extension. To avoid debugging the wrong workspace when several windows are open:
operation to that window's `ControlServer`. The target is cached per session so hint-less
follow-ups (step/continue/inspect) reach the same window. If the router window closes,
a worker window takes over the port on retry.
- Breakpoint tools also accept virtual source URIs. A sole registered window is unambiguous;
with multiple windows, callers provide the optional `workingDirectory` routing hint.

`DebugMCPServer` builds one handler **per MCP session** via a handler factory, which is
what lets concurrent agent sessions drive debuggers in different repos simultaneously.
Expand Down Expand Up @@ -142,7 +144,7 @@ error wins:
| `continue_execution` | Continue to next breakpoint |
| `pause_execution` | Interrupt a running program (no breakpoint needed) |
| `restart_debugging` | Restart session |
| `add/remove_breakpoint` | Breakpoint management |
| `add/remove_breakpoint` | Breakpoint management for local paths and virtual source URIs |
| `clear_all_breakpoints` | Remove all breakpoints |
| `list_breakpoints` | List active breakpoints |
| `get_variables_values` | Read the values of specifically named variables |
Expand Down
2 changes: 1 addition & 1 deletion docs/architecture/debugState.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Debugging operations are asynchronous - the debugger takes time to execute and u
| `sessionActive` | `boolean` | Whether a debug session exists, running or stopped |
| `paused` | `boolean \| null` | Observed execution state, or `null` when unobserved |
| `stopSequence` | `number \| null` | Internal executor-local stopped-event marker, independent of frames and source |
| `fileFullPath` | `string \| null` | Full path to current file |
| `fileFullPath` | `string \| null` | Full path to current file, or its URI for a virtual document |
| `fileName` | `string \| null` | Just the filename |
| `currentLine` | `number \| null` | 1-based line number |
| `currentLineContent` | `string \| null` | Content of current line |
Expand Down
7 changes: 7 additions & 0 deletions docs/architecture/debuggingExecutor.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,13 @@ necessarily the physical stop at the top of the stack. The call stack retains
adapter order. If the selected frame is absent from the bounded stack response,
its name and source remain unavailable rather than borrowing top-frame metadata.

A frame's source path may be a native path or a URI. Adapters for virtual
documents (for example Business Central `al-preview:` `.dal` sources) report a
URI; it is opened through its content provider and reported as the canonical
URI string, the same form `getBreakpoints()` uses and the breakpoint tools
accept. `normalizeSourceLocation()` maps a caller-supplied path or URI to that
form, so different spellings of one URI compare equal.

Frame/thread context is populated before source lookup. A missing or unreadable
source does not discard that context or mean that execution is running. Paused
status is also independent of frames: an observed stop with an empty stack still
Expand Down
19 changes: 19 additions & 0 deletions docs/architecture/debuggingHandler.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Debugging is inherently asynchronous - when you step over a line, the debugger t
## Responsibility

- Orchestrate debugging operations (start, stop, step, breakpoints)
- Preserve language-extension virtual source URIs when opening documents and setting breakpoints
- Detect when debugger state has meaningfully changed after commands
- Format debug state into human/AI-readable responses
- Recursively format explicitly requested structs and arrays
Expand Down Expand Up @@ -111,6 +112,24 @@ successful DAP restart response. Actual command failures received before the
result still propagate. A later rejection after an unconfirmed result is logged;
the underlying request is not cancelled. Polling stops when the call returns.

### Virtual source documents

Breakpoint and logpoint locations may be native paths or VS Code virtual-document URIs.
`src/utils/vscodeSourceUri.ts` keeps custom schemes intact instead of converting them into malformed
`file:` URIs. This is required for language-extension sources such as Business Central `.dal`
documents served through the `al-preview:` scheme.

The handler stays host-neutral and does not parse URIs itself; it only uses the text helpers in
`src/utils/sourceUri.ts`, which are also bundled into the standalone CLI. Before looking up a breakpoint
to remove, it asks the executor for the canonical form of the requested location, so a URI
written with a literal space matches the same URI written with `%20`. Breakpoint listings
show the decoded file name.

A breakpoint's line is validated against the source when it can be read. A virtual document
that cannot be opened yet (Business Central serves `.dal` sources only once the session has
stopped) still takes the breakpoint, with a note that the line was not checked; a missing file
on disk remains an error.

### Root Cause Analysis

When debugging stops, the handler prompts AI agents to consider whether they found the root cause or just a symptom, encouraging deeper investigation.
Expand Down
15 changes: 9 additions & 6 deletions src/debugMCPServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,11 +258,12 @@ export class DebugMCPServer {
server.registerTool('add_breakpoint', {
description: 'Set a breakpoint to pause execution at a critical line of code. Breakpoints let you inspect variables and control flow at exact moments.',
inputSchema: {
fileFullPath: z.string().describe('Full path to the file'),
fileFullPath: z.string().describe('Full path or VS Code virtual-document URI of the source file'),
workingDirectory: z.string().optional().describe('Workspace directory used to select the correct VS Code window. Required for a virtual-document URI when multiple windows are open.'),
line: z.number().int().describe('Line number (1-based) where the breakpoint should be set'),
condition: z.string().optional().describe('Optional condition expression. When provided, execution only pauses if this expression evaluates to true at the breakpoint location.'),
},
}, async (args: { fileFullPath: string; line: number; condition?: string }) =>
}, async (args: { fileFullPath: string; workingDirectory?: string; line: number; condition?: string }) =>
this.runTool('add_breakpoint', () => debuggingHandler.handleAddBreakpoint(args)));

// Read captured output
Expand All @@ -281,22 +282,24 @@ export class DebugMCPServer {
server.registerTool('add_logpoint', {
description: 'Add a logpoint: a breakpoint that logs a message instead of pausing execution. Ideal for tracing values across many iterations or hot paths without stopping, or where a hard pause would distort timing. Embed expressions in curly braces to interpolate runtime values, e.g. "user id={user.id}".',
inputSchema: {
fileFullPath: z.string().describe('Full path to the file'),
fileFullPath: z.string().describe('Full path or VS Code virtual-document URI of the source file'),
workingDirectory: z.string().optional().describe('Workspace directory used to select the correct VS Code window. Required for a virtual-document URI when multiple windows are open.'),
line: z.number().int().describe('Line number (1-based) where the logpoint should be set'),
logMessage: z.string().describe('Message to log when the line is reached. Wrap expressions in {curly braces} to interpolate runtime values.'),
condition: z.string().optional().describe('Optional condition expression. When provided, the message is only logged if this expression evaluates to true.'),
},
}, async (args: { fileFullPath: string; line: number; logMessage: string; condition?: string }) =>
}, async (args: { fileFullPath: string; workingDirectory?: string; line: number; logMessage: string; condition?: string }) =>
this.runTool('add_logpoint', () => debuggingHandler.handleAddLogpoint(args)));

// Remove breakpoint tool
server.registerTool('remove_breakpoint', {
description: 'Remove a breakpoint that is no longer needed.',
inputSchema: {
fileFullPath: z.string().describe('Full path to the file'),
fileFullPath: z.string().describe('Full path or VS Code virtual-document URI of the source file'),
workingDirectory: z.string().optional().describe('Workspace directory used to select the correct VS Code window. Required for a virtual-document URI when multiple windows are open.'),
line: z.number().describe('Line number (1-based)'),
},
}, async (args: { fileFullPath: string; line: number }) =>
}, async (args: { fileFullPath: string; workingDirectory?: string; line: number }) =>
this.runTool('remove_breakpoint', () => debuggingHandler.handleRemoveBreakpoint(args)));

// Clear all breakpoints tool
Expand Down
47 changes: 41 additions & 6 deletions src/debuggingExecutor.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
// Copyright (c) Microsoft Corporation.

import * as vscode from 'vscode';
import * as fs from 'node:fs';
import { DebugState, StackFrame } from './debugState';
import { DebugBreakpoint, DebugConfiguration, DebugSessionInfo } from './debugTypes';
import { logger } from './utils/logger';
import { withTimeout } from './utils/withTimeout';
import { getDebugStartupContext, startDebuggingWithDiagnostics } from './utils/debugStartup';
import { DebugSessionTracker } from './utils/debugSessionTracker';
import { DebugOutputBuffer, IDebugOutputQuery } from './utils/debugOutputBuffer';
import { isSourceUri } from './utils/sourceUri';
import { toSourceText, toSourceUri } from './utils/vscodeSourceUri';

/**
* Outcome of dispatching `testing.debugAtCursor`.
Expand Down Expand Up @@ -54,6 +57,8 @@ export interface IDebuggingExecutor {
getActiveFrameId?(): number | undefined;
getDebugOutput?(query: IDebugOutputQuery): ReturnType<DebugOutputBuffer['read']>;
waitForDebugSessionReady(timeoutMs: number, signal?: AbortSignal): Promise<'stopped' | 'terminated' | 'timeout' | 'no-session' | 'attached'>;
getFileLineCount?(fileFullPath: string): Promise<number>;
normalizeSourceLocation?(fileFullPath: string): string;
dispose?(): Promise<void> | void;
}

Expand Down Expand Up @@ -94,6 +99,29 @@ export class DebuggingExecutor implements IDebuggingExecutor {
);
}

/**
* Count the lines of a source file. Virtual documents are read through
* VS Code so their content provider is used; files on disk are read directly.
*/
public async getFileLineCount(fileFullPath: string): Promise<number> {
if (isSourceUri(fileFullPath)) {
const document = await vscode.workspace.openTextDocument(toSourceUri(fileFullPath));
return document.lineCount;
}
const content = await fs.promises.readFile(fileFullPath, 'utf8');
return content.length === 0 ? 0 : content.split(/\r?\n/).length;
}

/**
* The form in which `getBreakpoints` and the debug state report a source
* location, so a caller-supplied path or URI can be compared with them.
* Different spellings of one virtual-document URI (a literal space versus
* `%20`, authority casing) map to the same text.
*/
public normalizeSourceLocation(fileFullPath: string): string {
return toSourceText(toSourceUri(fileFullPath));
}

/**
* Start a debugging session
*/
Expand Down Expand Up @@ -362,7 +390,7 @@ export class DebuggingExecutor implements IDebuggingExecutor {
*/
public async addBreakpoint(fileFullPath: string, line: number, condition?: string, logMessage?: string): Promise<void> {
try {
const uri = vscode.Uri.file(fileFullPath);
const uri = toSourceUri(fileFullPath);
const breakpoint = new vscode.SourceBreakpoint(
new vscode.Location(uri, new vscode.Position(line - 1, 0)),
true,
Expand All @@ -381,7 +409,7 @@ export class DebuggingExecutor implements IDebuggingExecutor {
*/
public async removeBreakpoint(fileFullPath: string, line: number): Promise<void> {
try {
const uri = vscode.Uri.file(fileFullPath);
const uri = toSourceUri(fileFullPath);
const breakpoints = vscode.debug.breakpoints.filter(bp => {
if (bp instanceof vscode.SourceBreakpoint) {
return bp.location.uri.toString() === uri.toString() &&
Expand Down Expand Up @@ -539,9 +567,16 @@ export class DebuggingExecutor implements IDebuggingExecutor {
numNextLines: number
): Promise<void> {
try {
const doc = await vscode.workspace.openTextDocument(vscode.Uri.file(filePath));
// Adapters for virtual documents report a URI in `source.path` (for
// example Business Central's `al-preview:` sources). Treating that
// as a filesystem path would point at a file that does not exist.
const virtualSource = isSourceUri(filePath);
const uri = toSourceUri(filePath);
const doc = await vscode.workspace.openTextDocument(uri);
const zeroBasedLine = Math.max(0, Math.min(line - 1, doc.lineCount - 1));
const fileName = filePath.split(/[/\\]/).pop() || '';
// Report a virtual source in the form the breakpoint tools accept.
const fileFullPath = virtualSource ? toSourceText(uri) : filePath;
const fileName = (virtualSource ? uri.path.split('/') : filePath.split(/[/\\]/)).pop() || '';
const currentLineContent = doc.lineAt(zeroBasedLine).text.trim();

// Collect the next non-empty lines for lookahead context.
Expand All @@ -555,7 +590,7 @@ export class DebuggingExecutor implements IDebuggingExecutor {
lineOffset++;
}

state.updateLocation(filePath, fileName, line, currentLineContent, nextLines);
state.updateLocation(fileFullPath, fileName, line, currentLineContent, nextLines);
} catch (error) {
// Native/library frames or paths VS Code can't open won't resolve to
// a document; degrade gracefully and leave location unset.
Expand Down Expand Up @@ -786,7 +821,7 @@ export class DebuggingExecutor implements IDebuggingExecutor {
.filter((breakpoint): breakpoint is vscode.SourceBreakpoint =>
breakpoint instanceof vscode.SourceBreakpoint)
.map(breakpoint => ({
fileFullPath: breakpoint.location.uri.fsPath,
fileFullPath: toSourceText(breakpoint.location.uri),
line: breakpoint.location.range.start.line + 1,
condition: breakpoint.condition,
logMessage: breakpoint.logMessage
Expand Down
Loading