Skip to main content
Glama

line_edit

Modify specific lines in a file by number or range using actions like replace, delete, or insert. Ideal for precise edits without replacing entire files, enhancing efficiency in file management tasks.

Instructions

Edit specific lines by number or range

Input Schema

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

Implementation Reference

  • Handler implementation for line_edit tool. Uses sed commands based on action (replace, delete, insert_after, insert_before) to edit specific lines or ranges in a file, creating a .bak backup.
    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 the line_edit tool, defining parameters like file, lineNumber/lineRange, action, and content.
    { 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'] } },
  • src/index.ts:278-280 (registration)
    Part of the tools array registration where line_edit is included in server.setTools.
    ] }; });

Other Tools

Related 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