complex_find_replace
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
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes | Path to the file to perform find and replace on | |
| pattern | Yes | Regular expression pattern to search for | |
| replacement | Yes | Replacement text | |
| options | No | Additional 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 } });
- src/router/operation-router.ts:455-463 (handler)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 }; } }