Skip to main content
Glama

line_edit

Edit specific lines in files by number or range using replace, delete, or insert actions for targeted modifications without full file replacement.

Instructions

Edit specific lines by number or range

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
fileYesFile to edit
lineNumberNoLine number to edit (1-based)
lineRangeNoLine range (e.g., "10,20" or "5,$")
actionYesAction to perform
contentNoNew content (for replace/insert actions)

Implementation Reference

  • Handler for 'line_edit' tool: destructures input params, constructs appropriate sed command based on action (replace, delete, insert_after, insert_before), executes it with backup, returns success message.
          case 'line_edit': {
            const { file, lineNumber, lineRange, action, content } = args;
            
            if (!existsSync(file)) {
              throw new Error(`File not found: ${file}`);
            }
            
            let sedCmd = 'sed -i.bak ';
            const range = lineRange || `${lineNumber}`;
            
            switch (action) {
              case 'replace':
                sedCmd += `'${range}s/.*/${content}/' '${file}'`;
                break;
              case 'delete':
                sedCmd += `'${range}d' '${file}'`;
                break;
              case 'insert_after':
                sedCmd += `'${range}a\\
    ${content}' '${file}'`;
                break;
              case 'insert_before':
                sedCmd += `'${range}i\\
    ${content}' '${file}'`;
                break;
              default:
                throw new Error(`Unknown action: ${action}`);
            }
            
            await execAsync(sedCmd);
            
            return {
              content: [{
                type: 'text',
                text: `Successfully performed ${action} on line(s) ${range} in ${file}`
              }]
            };
          }
  • Input schema definition for line_edit tool, specifying properties and validation rules.
    inputSchema: {
      type: 'object',
      properties: {
        file: {
          type: 'string',
          description: 'File to edit'
        },
        lineNumber: {
          type: 'number',
          description: 'Line number to edit (1-based)'
        },
        lineRange: {
          type: 'string',
          description: 'Line range (e.g., "10,20" or "5,$")'
        },
        action: {
          type: 'string',
          enum: ['replace', 'delete', 'insert_after', 'insert_before'],
          description: 'Action to perform'
        },
        content: {
          type: 'string',
          description: 'New content (for replace/insert actions)'
        }
      },
      required: ['file', 'action']
  • src/index.ts:144-174 (registration)
    Registration of the 'line_edit' tool in the tools array passed to server.setTools.
    {
      name: 'line_edit',
      description: 'Edit specific lines by number or range',
      inputSchema: {
        type: 'object',
        properties: {
          file: {
            type: 'string',
            description: 'File to edit'
          },
          lineNumber: {
            type: 'number',
            description: 'Line number to edit (1-based)'
          },
          lineRange: {
            type: 'string',
            description: 'Line range (e.g., "10,20" or "5,$")'
          },
          action: {
            type: 'string',
            enum: ['replace', 'delete', 'insert_after', 'insert_before'],
            description: 'Action to perform'
          },
          content: {
            type: 'string',
            description: 'New content (for replace/insert actions)'
          }
        },
        required: ['file', 'action']
      }
    },
  • Help documentation and usage examples for the line_edit tool in the helpContent object.
      line_edit: `line_edit - Line-specific operations
    ==================================
    Edit, delete, or insert at specific line numbers.
    
    Examples:
      // Replace line 10
      line_edit({ file: "list.txt", lineNumber: 10, action: "replace", content: "New line 10" })
      
      // Delete lines 5-15
      line_edit({ file: "data.txt", lineRange: "5,15", action: "delete" })
      
      // Insert after line 1
      line_edit({ file: "imports.js", lineNumber: 1, action: "insert_after", content: "import React from 'react';" })
      
      // Insert before last line
      line_edit({ file: "footer.html", lineRange: "$", action: "insert_before", content: "<!-- Updated -->" })
    
    Ranges:
    - Single line: lineNumber: 42
    - Range: lineRange: "10,20" 
    - To end: lineRange: "5,$"
    `,
Behavior2/5

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

With no annotations provided, the description carries full burden but only states the basic action without disclosing behavioral traits. It doesn't mention permissions needed, whether edits are destructive or reversible, error handling, or side effects like file locking. This is inadequate for a mutation tool with zero annotation coverage.

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 a single, efficient sentence with zero waste. It's front-loaded with the core purpose and appropriately sized for the tool's complexity, making it easy to parse 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?

For a mutation tool with 5 parameters, no annotations, and no output schema, the description is incomplete. It lacks details on behavioral context, error cases, or return values, leaving significant gaps that could hinder correct agent invocation despite the clear purpose and concise structure.

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 fully documents all 5 parameters. The description adds no additional meaning beyond implying line-based targeting, which is already covered by parameter descriptions like 'Line number to edit'. Baseline 3 is appropriate as the schema does the heavy lifting.

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

Purpose4/5

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

The description clearly states the verb ('Edit') and resource ('specific lines'), specifying the target by 'number or range'. It distinguishes from siblings like 'sed_edit' or 'perl_edit' by focusing on line-based editing rather than pattern-based or multi-file operations, though it doesn't explicitly name alternatives.

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 'sed_edit' or 'quick_replace'. The description implies usage for line-specific edits but doesn't specify contexts, prerequisites, or exclusions, leaving the agent to infer based on sibling tool names alone.

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/MikeyBeez/mcp-smalledit'

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