Skip to main content
Glama

complex_find_replace

Destructive

Perform advanced find and replace operations in files using regular expressions with context awareness for precise text manipulation.

Instructions

Perform advanced find and replace operations with context awareness

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYesPath to the file to perform find and replace on
patternYesRegular expression pattern to search for
replacementYesReplacement text
optionsNoAdditional options for the find and replace operation

Implementation Reference

  • src/index.ts:272-303 (registration)
    Registers the complex_find_replace tool with the MCP server, defining its schema and annotations.
    mcpServer.registerTool({
      name: 'complex_find_replace',
      description: 'Perform advanced find and replace operations with context awareness',
      inputSchema: {
        type: 'object',
        properties: {
          path: {
            type: 'string',
            description: 'Path to the file to perform find and replace on'
          },
          pattern: {
            type: 'string',
            description: 'Regular expression pattern to search for'
          },
          replacement: {
            type: 'string',
            description: 'Replacement text'
          },
          options: {
            type: 'object',
            description: 'Additional options for the find and replace operation'
          }
        },
        required: ['path', 'pattern', 'replacement']
      },
      annotations: {
        readOnlyHint: false,
        destructiveHint: true,
        idempotentHint: false,
        openWorldHint: false
      }
    });
  • Handler for complex_find_replace operation: maps it to a 'replace' EditCommand executed by EditInstanceManager.
    case 'complex_find_replace':
      return this.editInstanceManager.executeEditCommand(sessionId, {
        type: 'replace',
        params: {
          pattern: operation.params.pattern,
          replacement: operation.params.replacement,
          options: operation.params.options
        }
      });
  • Implements the 'replace' command execution by sending the replace command to the spawned Edit process stdin.
    case 'goto':
      result = await instance.executeCommand(`goto ${command.params.line} ${command.params.column}`);
  • Classifies complex_find_replace as a 'complex' operation routed to 'edit' executor.
    const complexOperations = [
      'interactive_edit_session',
      'format_code',
      'complex_find_replace',
      'merge_conflicts_resolution',
      'bulk_edit_operation',
      'edit_with_context_awareness'
    ];
  • The executeEditCommand method that dispatches EditCommands, used for complex_find_replace via 'replace'.
    public async executeEditCommand(sessionId: string, command: EditCommand): Promise<EditResult> {
      const instance = this.instances.get(sessionId);
      
      if (!instance) {
        throw new Error(`Edit instance ${sessionId} not found`);
      }
    
      try {
        let result: string;
    
        switch (command.type) {
          case 'open':
            await instance.openFile(command.params.path);
            return { success: true };
    
          case 'close':
            await instance.closeFile(command.params.path);
            return { success: true };
    
          case 'save':
            result = await instance.executeCommand(`save ${command.params.path}`);
            return { success: true, message: result };
    
          case 'edit':
            // This is a simplified approach; in a real implementation, we would need
            // to handle different types of edits (insert, delete, replace, etc.)
            result = await instance.executeCommand(`edit ${JSON.stringify(command.params)}`);
            return { success: true, message: result };
    
          case 'find':
            result = await instance.executeCommand(`find ${command.params.pattern}`);
            return { success: true, message: result };
    
          case 'replace':
            result = await instance.executeCommand(`replace ${command.params.pattern} ${command.params.replacement}`);
            return { success: true, message: result };
    
          case 'goto':
            result = await instance.executeCommand(`goto ${command.params.line} ${command.params.column}`);
            return { success: true, message: result };
    
          default:
            throw new Error(`Unknown command type: ${command.type}`);
        }
      } catch (error: any) {
        return { success: false, message: error.message };
      }
    }
Behavior4/5

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

Annotations indicate destructiveHint=true, readOnlyHint=false, idempotentHint=false, and openWorldHint=false, which the description doesn't contradict. The description adds value by hinting at 'advanced' and 'context awareness' traits not covered by annotations, such as potential for complex pattern matching or contextual modifications, though it could be more explicit about behaviors like file overwriting or error handling.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that front-loads the core purpose without unnecessary words. However, it could be more structured by briefly elaborating on 'context awareness' to improve clarity, but it earns high marks for brevity and directness.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (destructive, non-idempotent, 4 parameters including nested objects) and lack of output schema, the description is minimally adequate. It hints at advanced features but doesn't fully explain the scope of 'context awareness' or potential outcomes, leaving gaps for the agent to infer behavior in a mutation-heavy context.

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 parameters are well-documented in the schema. The description adds no additional semantic details about parameters beyond implying 'advanced' operations, which doesn't enhance understanding of 'path', 'pattern', 'replacement', or 'options'. Baseline 3 is appropriate as the schema carries the burden.

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

Purpose3/5

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

The description states the tool performs 'advanced find and replace operations with context awareness', which gives a general purpose but lacks specificity about what makes it 'advanced' or 'context-aware'. It distinguishes from basic siblings like 'find_in_file' by implying more complexity, but doesn't clearly differentiate from 'smart_refactor' or 'interactive_edit_session' which might also involve find/replace with context.

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 explicit guidance on when to use this tool versus alternatives like 'find_in_file', 'smart_refactor', or 'write_file'. It implies advanced capabilities but doesn't specify scenarios, prerequisites, or exclusions, leaving the agent to guess based on the vague 'context awareness'.

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/mixelpixx/microsoft-edit-mcp'

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