remove_instruments
Remove debug instrumentation from code files to clean up after debugging sessions. Specify a file path or clear all instrumented files.
Instructions
Remove debug instruments from files.
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "remove_instruments"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| file | No | Path to file to remove instruments from. If not specified, removes from all instrumented files. |
Implementation Reference
- src/index.ts:209-250 (handler)Executes the remove_instruments tool by removing debug instruments from a specified file or all files, updating both the code via Instrumenter and the session tracking.
case 'remove_instruments': { if (!sessionManager.isActive() || !instrumenter) { return { content: [{ type: 'text', text: 'No active debug session.' }], isError: true, }; } const file = args?.file as string | undefined; if (file) { // Remove from specific file const instruments = sessionManager.getInstrumentsByFile(file); for (const instrument of instruments) { instrumenter.removeInstrument(instrument); sessionManager.removeInstrument(instrument.id); } return { content: [ { type: 'text', text: `Removed ${instruments.length} instrument(s) from ${file}`, }, ], }; } else { // Remove from all files const instruments = sessionManager.getInstruments(); for (const instrument of instruments) { instrumenter.removeInstrument(instrument); } sessionManager.clearInstruments(); return { content: [ { type: 'text', text: `Removed ${instruments.length} instrument(s) from all files`, }, ], }; } } - src/index.ts:83-91 (schema)Defines the input schema for the remove_instruments tool, with an optional 'file' property.
inputSchema: { type: 'object', properties: { file: { type: 'string', description: 'Path to file to remove instruments from. If not specified, removes from all instrumented files.', }, }, }, - src/index.ts:80-92 (registration)Registers the remove_instruments tool in the list returned by ListToolsRequestHandler.
{ name: 'remove_instruments', description: 'Remove debug instruments from files.', inputSchema: { type: 'object', properties: { file: { type: 'string', description: 'Path to file to remove instruments from. If not specified, removes from all instrumented files.', }, }, }, }, - src/instrumenter.ts:40-56 (helper)Instrumenter.removeInstrument: Core logic to remove the specific debug instrumentation code block from the target file by replacing the region with regex.
removeInstrument(instrument: Instrument): boolean { if (!existsSync(instrument.file)) { return false; } const content = readFileSync(instrument.file, 'utf-8'); const regionId = `${REGION_PREFIX}-${instrument.id}`; const newContent = this.removeRegion(content, regionId, instrument.language); if (newContent !== content) { writeFileSync(instrument.file, newContent); return true; } return false; } - src/session.ts:78-83 (helper)SessionManager.removeInstrument: Removes the instrument tracking entry from the session's instruments Map.
removeInstrument(id: string): boolean { if (!this.session) { throw new Error('No active debug session'); } return this.session.instruments.delete(id); }