Skip to main content
Glama

sed_multifile

Apply sed patterns to multiple files matching a glob pattern to make targeted text replacements across your codebase or documents.

Instructions

Apply sed pattern to multiple files matching a glob pattern

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
patternYesSed pattern to apply
filePatternYesFile glob pattern (e.g., "*.ts", "src/**/*.js")
directoryNoStarting directory for search.
backupNoCreate backup files

Implementation Reference

  • Handler implementation for sed_multifile tool. Locates files using 'find' with the given glob pattern, applies the sed pattern via 'perl -i -pe' to each matching file (with optional .bak backups), collects results, and returns a processing summary.
    case 'sed_multifile': {
      const { pattern, filePattern, directory = '.', backup = true } = args;
      
      // Use find to get files matching pattern
      const findCmd = `find ${directory} -name "${filePattern}" -type f`;
      const { stdout: files } = await execAsync(findCmd);
      
      if (!files.trim()) {
        return {
          content: [{
            type: 'text',
            text: `No files found matching pattern: ${filePattern}`
          }]
        };
      }
      
      const fileList = files.trim().split('\n');
      const results = [];
      
      for (const file of fileList) {
        try {
          const backupExt = backup ? '.bak' : '';
          const sedCmd = `perl -i${backupExt} -pe '${pattern}' '${file}'`;
          await execAsync(sedCmd);
          results.push(`✓ ${file}`);
        } catch (error) {
          results.push(`✗ ${file}: ${error.message}`);
        }
      }
      
      return {
        content: [{
          type: 'text',
          text: `Processed ${fileList.length} files:\n${results.join('\n')}`
        }]
      };
    }
  • src/index.ts:67-94 (registration)
    Registration of the sed_multifile tool in the ListTools response, including name, description, and input schema definition.
    {
      name: 'sed_multifile',
      description: 'Apply sed pattern to multiple files matching a glob pattern',
      inputSchema: {
        type: 'object',
        properties: {
          pattern: {
            type: 'string',
            description: 'Sed pattern to apply'
          },
          filePattern: {
            type: 'string',
            description: 'File glob pattern (e.g., "*.ts", "src/**/*.js")'
          },
          directory: {
            type: 'string',
            default: '.',
            description: 'Starting directory for search'
          },
          backup: {
            type: 'boolean',
            default: true,
            description: 'Create backup files'
          }
        },
        required: ['pattern', 'filePattern']
      }
    },
  • Input schema definition for sed_multifile tool, specifying parameters like pattern, filePattern, directory, and backup options.
    inputSchema: {
      type: 'object',
      properties: {
        pattern: {
          type: 'string',
          description: 'Sed pattern to apply'
        },
        filePattern: {
          type: 'string',
          description: 'File glob pattern (e.g., "*.ts", "src/**/*.js")'
        },
        directory: {
          type: 'string',
          default: '.',
          description: 'Starting directory for search'
        },
        backup: {
          type: 'boolean',
          default: true,
          description: 'Create backup files'
        }
      },
      required: ['pattern', 'filePattern']
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions the core action but doesn't describe important behavioral traits: whether this is a destructive operation (implied by 'Apply sed pattern' but not explicit), what happens on errors, whether it shows previews before applying changes, or any rate limits. The description is minimal and lacks critical context for safe usage.

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 that directly states the tool's purpose without unnecessary words. It's appropriately sized and front-loaded with the core functionality, 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?

Given the complexity of a batch text-editing tool with no annotations and no output schema, the description is inadequate. It doesn't explain what the tool returns (e.g., success/failure status, modified file list), error handling, or safety considerations like the backup parameter's effect. For a potentially destructive operation, more context is needed.

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 fully documents all 4 parameters. The description doesn't add any parameter-specific semantics beyond what's in the schema—it doesn't explain how the pattern interacts with filePattern or directory, or clarify backup behavior. This meets the baseline for high schema coverage.

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 action ('Apply sed pattern') and target ('to multiple files matching a glob pattern'), providing a specific verb+resource combination. However, it doesn't explicitly distinguish this tool from sibling tools like sed_edit or quick_replace, which likely have overlapping functionality for text editing.

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?

The description provides no guidance on when to use this tool versus alternatives like sed_edit, quick_replace, or perl_edit. It mentions the scope ('multiple files matching a glob pattern') but doesn't specify when this batch operation is preferred over single-file edits or other text processing 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/MikeyBeez/mcp-smalledit'

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