set_breakpoint
Pause Node.js code execution at specific lines to inspect variables and debug issues by setting conditional or unconditional breakpoints in files.
Instructions
Set a breakpoint in the debugged process. Use full file:// URLs for reliable breakpoint hits.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| file | Yes | File URL or path (use file:///absolute/path/to/file.js for best results) | |
| line | Yes | Line number (1-based) | |
| condition | No | Optional condition for the breakpoint |
Implementation Reference
- src/index.ts:499-557 (handler)The handler function for the 'set_breakpoint' tool. It checks for an active debug session, then uses the Chrome DevTools Protocol (CDP) Debugger.setBreakpointByUrl to set a breakpoint at the specified file URL and line number (converting to 0-based), optionally with a condition. Stores the breakpoint ID and returns success or error.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:187-202 (schema)Tool registration including name, description, and input schema definition for 'set_breakpoint'.{ 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)Registration of the tool handler dispatch in the CallToolRequest switch statement.case "set_breakpoint": return await this.setBreakpoint(args as { file: string; line: number; condition?: string });