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,$" `,

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