smart_refactor
Refactor code by renaming symbols across multiple files to maintain consistency and improve readability.
Instructions
Intelligently refactor code by renaming symbols across multiple files
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| files | Yes | List of files to search and refactor | |
| oldName | Yes | The symbol name to replace | |
| newName | Yes | The new symbol name |
Implementation Reference
- src/index.ts:335-362 (registration)Registers the 'smart_refactor' tool with the MCP server, including its description, input schema, and annotations.mcpServer.registerTool({ name: 'smart_refactor', description: 'Intelligently refactor code by renaming symbols across multiple files', inputSchema: { type: 'object', properties: { files: { type: 'array', description: 'List of files to search and refactor' }, oldName: { type: 'string', description: 'The symbol name to replace' }, newName: { type: 'string', description: 'The new symbol name' } }, required: ['files', 'oldName', 'newName'] }, annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: true, openWorldHint: false } });
- src/index.ts:338-354 (schema)Defines the input schema for the 'smart_refactor' tool, specifying parameters for files, oldName, and newName.inputSchema: { type: 'object', properties: { files: { type: 'array', description: 'List of files to search and refactor' }, oldName: { type: 'string', description: 'The symbol name to replace' }, newName: { type: 'string', description: 'The new symbol name' } }, required: ['files', 'oldName', 'newName']
- src/router/operation-router.ts:503-530 (handler)Handler for 'smart_refactor': Searches for oldName regex in affected files using fileSystemManager.findInFile, filters files with matches, and if any, uses editInstanceManager.coordinateMultiFileEdit to replace with newName.case 'smart_refactor': // Use file system to find occurrences, then Edit for precision const searchResults = await Promise.all( operation.affectedFiles.map(file => this.fileSystemManager.findInFile( file, new RegExp(operation.params.oldName, 'g') ) ) ); // If we found occurrences, use Edit to refactor const filesToEdit = operation.affectedFiles.filter((file, index) => searchResults[index].length > 0); if (filesToEdit.length > 0) { return this.editInstanceManager.coordinateMultiFileEdit({ files: filesToEdit, operation: { type: 'replace', params: { pattern: operation.params.oldName, replacement: operation.params.newName } } }); } return { message: 'No occurrences found to refactor' };
- Classifies 'smart_refactor' as a hybrid operation in the analyzeComplexity method.const hybridOperations = [ 'smart_refactor', 'validate_and_edit', 'backup_and_edit', 'atomic_multi_file_edit' ];