Skip to main content
Glama

smart_refactor

Rename symbols across multiple files to maintain code consistency during refactoring.

Instructions

Intelligently refactor code by renaming symbols across multiple files

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filesYesList of files to search and refactor
oldNameYesThe symbol name to replace
newNameYesThe new symbol name

Implementation Reference

  • Handler implementation for 'smart_refactor' tool. Searches for oldName in specified files using filesystem manager's findInFile, identifies files with matches, then performs coordinated multi-file replacement to newName using edit instance manager's coordinateMultiFileEdit. Returns message if no occurrences.
    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' };
  • src/index.ts:336-362 (registration)
    Registers the 'smart_refactor' tool with the MCP server within registerHybridTools function. Includes description, input schema validating files array, oldName and newName strings, and annotations indicating destructive nature.
    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 } });
  • Input schema definition for 'smart_refactor' tool, requiring array of files and strings oldName, 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'] },
  • Categorizes 'smart_refactor' as a hybrid operation in analyzeComplexity method, routing it to medium complexity handling.
    const hybridOperations = [ 'smart_refactor', 'validate_and_edit', 'backup_and_edit', 'atomic_multi_file_edit' ];

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