Skip to main content
Glama

add_instrument

Insert debug instrumentation at a specified line to log variable values during execution for debugging purposes.

Instructions

Add a debug instrument at a specific line in a file. The instrument will log variable values when executed.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
fileYesPath to the file to instrument (relative to working directory)
lineYesLine number where to insert the instrument (1-indexed)
captureNoVariable names to capture and log

Implementation Reference

  • Main handler for the 'add_instrument' tool. Validates active session, parses input arguments, creates instrument using SessionManager, inserts code using Instrumenter, and returns success message with details.
    case 'add_instrument': {
      if (!sessionManager.isActive() || !instrumenter) {
        return {
          content: [{ type: 'text', text: 'No active debug session. Start one first with start_debug_session.' }],
          isError: true,
        };
      }
    
      const file = args?.file as string;
      const line = args?.line as number;
      const capture = (args?.capture as string[]) || [];
    
      if (!file || !line) {
        return {
          content: [{ type: 'text', text: 'Missing required parameters: file and line' }],
          isError: true,
        };
      }
    
      const instrument = sessionManager.addInstrument({ file, line, capture });
      instrumenter.addInstrument(instrument);
    
      return {
        content: [
          {
            type: 'text',
            text: `Instrument added!\n\nID: ${instrument.id}\nFile: ${instrument.file}\nLine: ${line}\nCapturing: ${capture.length > 0 ? capture.join(', ') : '(no variables)'}\n\nThe instrument will log data when that line is executed.`,
          },
        ],
      };
    }
  • src/index.ts:56-79 (registration)
    Tool registration in the listTools response, including name, description, and input schema.
    {
      name: 'add_instrument',
      description: 'Add a debug instrument at a specific line in a file. The instrument will log variable values when executed.',
      inputSchema: {
        type: 'object',
        properties: {
          file: {
            type: 'string',
            description: 'Path to the file to instrument (relative to working directory)',
          },
          line: {
            type: 'number',
            description: 'Line number where to insert the instrument (1-indexed)',
          },
          capture: {
            type: 'array',
            items: { type: 'string' },
            description: 'Variable names to capture and log',
            default: [],
          },
        },
        required: ['file', 'line'],
      },
    },
  • Input schema defining parameters for the add_instrument tool: file (string, required), line (number, required), capture (array of strings, optional).
    inputSchema: {
      type: 'object',
      properties: {
        file: {
          type: 'string',
          description: 'Path to the file to instrument (relative to working directory)',
        },
        line: {
          type: 'number',
          description: 'Line number where to insert the instrument (1-indexed)',
        },
        capture: {
          type: 'array',
          items: { type: 'string' },
          description: 'Variable names to capture and log',
          default: [],
        },
      },
      required: ['file', 'line'],
    },
  • SessionManager.addInstrument: Creates Instrument instance with resolved file path, detected language, generates ID, stores in session's instruments Map, returns the instrument.
    addInstrument(options: InstrumentOptions): Instrument {
      if (!this.session) {
        throw new Error('No active debug session');
      }
    
      const language = this.detectLanguage(options.file);
      const instrument: Instrument = {
        id: `dbg-${randomUUID().slice(0, 8)}`,
        file: resolve(this.workingDirectory, options.file),
        line: options.line,
        language,
        capture: options.capture,
        createdAt: Date.now()
      };
    
      this.session.instruments.set(instrument.id, instrument);
      return instrument;
    }
  • Instrumenter.addInstrument: Reads target file, validates line number, generates language-specific instrument code, inserts it before the specified line, writes back to file.
    addInstrument(instrument: Instrument): void {
      if (!existsSync(instrument.file)) {
        throw new Error(`File not found: ${instrument.file}`);
      }
    
      const content = readFileSync(instrument.file, 'utf-8');
      const lines = content.split('\n');
    
      if (instrument.line < 1 || instrument.line > lines.length + 1) {
        throw new Error(`Line ${instrument.line} is out of range (file has ${lines.length} lines)`);
      }
    
      const code = this.generateInstrumentCode(instrument);
      const codeLines = code.split('\n');
    
      // Insert at the specified line (1-indexed, so line 5 means insert before index 4)
      lines.splice(instrument.line - 1, 0, ...codeLines);
    
      writeFileSync(instrument.file, lines.join('\n'));
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries full burden. It mentions the instrument 'will log variable values when executed', which hints at runtime behavior, but lacks details on permissions, side effects (e.g., file modification), error handling, or execution context. For a mutation tool with zero annotation coverage, this is inadequate.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is two concise sentences with zero waste, front-loading the core action and purpose. Every word earns its place, making it easy to scan and understand quickly.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (mutating files for debugging) and lack of annotations or output schema, the description is incomplete. It doesn't cover behavioral aspects like how the instrument works, what 'log' means, or interaction with sibling tools, leaving significant gaps for an AI agent to infer usage.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents all parameters (file, line, capture). The description adds minimal value beyond the schema by implying the instrument logs variable values, which relates to the 'capture' parameter, but doesn't provide additional syntax or format details. Baseline 3 is appropriate when the schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action ('Add a debug instrument'), resource ('at a specific line in a file'), and purpose ('will log variable values when executed'). It distinguishes from siblings like 'list_instruments' or 'remove_instruments' by focusing on creation rather than querying or deletion.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance is provided on when to use this tool versus alternatives like 'start_debug_session' or 'remove_instruments'. The description implies usage for debugging but doesn't specify prerequisites, exclusions, or contextual recommendations relative to sibling tools.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/iarmankhan/agentic-debugger'

If you have feedback or need assistance with the MCP directory API, please join our Discord server