Skip to main content
Glama

perl_edit

Edit files with Perl one-liners for advanced text modifications. Supports cross-platform file editing, backup creation, and multiline mode for efficient file updates without full replacements.

Instructions

Edit files using Perl one-liners (more powerful than sed, better cross-platform support)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
backupNoCreate backup file
fileYesFile to edit
multilineNoEnable multiline mode (-0777)
scriptYesPerl script (e.g., "s/old/new/g" or "$_ = uc" for uppercase)

Implementation Reference

  • The main handler function for the 'perl_edit' tool. It destructures the input arguments, checks if the file exists, constructs a Perl command with options for backup and multiline processing, executes it using execAsync, and returns a success message.
    case 'perl_edit': { const { file, script, backup = true, multiline = false } = args; if (!existsSync(file)) { throw new Error(`File not found: ${file}`); } const backupExt = backup ? '.bak' : ''; const multilineFlag = multiline ? '-0777 ' : ''; const perlCmd = `perl -i${backupExt} ${multilineFlag}-pe '${script}' '${file}'`; await execAsync(perlCmd); return { content: [{ type: 'text', text: `Successfully edited ${file} using Perl${backup ? ' (backup created as .bak)' : ''}` }] }; }
  • The input schema defining the parameters for the perl_edit tool: file (required string), script (required string), backup (optional boolean, default true), multiline (optional boolean, default false).
    inputSchema: { type: 'object', properties: { file: { type: 'string', description: 'File to edit' }, script: { type: 'string', description: 'Perl script (e.g., "s/old/new/g" or "$_ = uc" for uppercase)' }, backup: { type: 'boolean', default: true, description: 'Create backup file' }, multiline: { type: 'boolean', default: false, description: 'Enable multiline mode (-0777)' } }, required: ['file', 'script']
  • src/index.ts:175-202 (registration)
    The tool registration object for 'perl_edit', including name, description, and inputSchema, added to the tools array for MCP server registration.
    { name: 'perl_edit', description: 'Edit files using Perl one-liners (more powerful than sed, better cross-platform support)', inputSchema: { type: 'object', properties: { file: { type: 'string', description: 'File to edit' }, script: { type: 'string', description: 'Perl script (e.g., "s/old/new/g" or "$_ = uc" for uppercase)' }, backup: { type: 'boolean', default: true, description: 'Create backup file' }, multiline: { type: 'boolean', default: false, description: 'Enable multiline mode (-0777)' } }, required: ['file', 'script'] } },

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