set_breakpoint
Pause Node.js processes at specific lines by setting breakpoints using file URLs and line numbers, with optional conditions for precise debugging control.
Instructions
Set a breakpoint in the debugged process. Use full file:// URLs for reliable breakpoint hits.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| condition | No | Optional condition for the breakpoint | |
| file | Yes | File URL or path (use file:///absolute/path/to/file.js for best results) | |
| line | Yes | Line number (1-based) |
Implementation Reference
- src/index.ts:499-557 (handler)The primary handler function for the 'set_breakpoint' tool. It checks for an active debug session, uses the Chrome DevTools Protocol (CDP) Debugger.setBreakpointByUrl to set the breakpoint at the specified file URL and line (converting to 0-based), stores the breakpoint ID in the session's breakpoints map, and returns success or error messages.private async setBreakpoint(args: { file: string; line: number; condition?: string }) { if (!this.debugSession.connected || !this.debugSession.client) { return { content: [ { type: "text", text: "No active debug session. Please attach debugger first.", }, ], isError: true, }; } try { const { Debugger } = this.debugSession.client; // Use CDP to set the breakpoint const result = await Debugger.setBreakpointByUrl({ lineNumber: args.line - 1, // CDP uses 0-based line numbers url: args.file, condition: args.condition }); if (result.breakpointId) { // Store the breakpoint mapping const breakpointKey = `${args.file}:${args.line}`; this.debugSession.breakpoints!.set(breakpointKey, result.breakpointId); return { content: [ { type: "text", text: `Set breakpoint at ${args.file}:${args.line}${args.condition ? ` (condition: ${args.condition})` : ""} - ID: ${result.breakpointId}`, }, ], }; } else { return { content: [ { type: "text", text: `Failed to set breakpoint at ${args.file}:${args.line}`, }, ], isError: true, }; } } catch (error) { return { content: [ { type: "text", text: `Error setting breakpoint: ${error}`, }, ], isError: true, }; } }
- src/index.ts:190-201 (schema)The input schema for the 'set_breakpoint' tool, specifying required 'file' and 'line' parameters with an optional 'condition'.inputSchema: { type: "object", properties: { file: { type: "string", description: "File URL or path (use file:///absolute/path/to/file.js for best results)" }, line: { type: "number", description: "Line number (1-based)" }, condition: { type: "string", description: "Optional condition for the breakpoint" } }, required: ["file", "line"], },
- src/index.ts:187-202 (registration)Registration of the 'set_breakpoint' tool in the ListTools response, including name, description, and input schema.{ name: "set_breakpoint", description: "Set a breakpoint in the debugged process. Use full file:// URLs for reliable breakpoint hits.", inputSchema: { type: "object", properties: { file: { type: "string", description: "File URL or path (use file:///absolute/path/to/file.js for best results)" }, line: { type: "number", description: "Line number (1-based)" }, condition: { type: "string", description: "Optional condition for the breakpoint" } }, required: ["file", "line"], }, },
- src/index.ts:256-257 (registration)Dispatch/registration case in the CallToolRequest handler that routes calls to the setBreakpoint method.case "set_breakpoint": return await this.setBreakpoint(args as { file: string; line: number; condition?: string });