Skip to main content
Glama

smart_refactor

DestructiveIdempotent

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'
    ];
Behavior4/5

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

Annotations provide key hints: destructiveHint=true (indicating changes), idempotentHint=true (safe to retry), readOnlyHint=false (not read-only), and openWorldHint=false (limited scope). The description adds value by specifying 'intelligently' (implying smart matching) and 'across multiple files' (scope), which aren't covered by annotations. It doesn't contradict annotations, as 'refactor' aligns with destructive and non-read-only hints, and it provides useful context beyond the structured data.

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 front-loads the core action ('Intelligently refactor code') and specifies the method ('by renaming symbols across multiple files'). There is no wasted verbiage, and every word contributes to understanding the tool's purpose, making it highly concise and well-structured.

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 (refactoring across files with destructive changes), annotations cover safety and idempotency, but there's no output schema. The description lacks details on return values, error handling, or what 'intelligently' entails (e.g., language-specific rules). It's adequate as a high-level overview but incomplete for full operational understanding, especially without output information, warranting a mid-range score.

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%, with clear descriptions for 'files', 'oldName', and 'newName'. The description adds minimal semantics by implying 'intelligently' might affect how symbols are matched, but it doesn't elaborate on parameter usage (e.g., file formats, symbol types). Since the schema does the heavy lifting, a baseline score of 3 is appropriate, as the description doesn't significantly enhance parameter understanding beyond what's already documented.

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 verb ('refactor') and resource ('code by renaming symbols across multiple files'), making the purpose evident. It distinguishes from siblings like 'format_code' or 'find_in_file' by focusing on intelligent refactoring with symbol renaming across files. However, it doesn't explicitly differentiate from 'complex_find_replace' or 'backup_and_edit', which might have overlapping functionality, preventing a perfect score.

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. It doesn't mention when-not to use it (e.g., for simple single-file edits) or name specific siblings like 'complex_find_replace' or 'backup_and_edit' as alternatives. Without such context, users might struggle to choose appropriately among the available 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/mixelpixx/microsoft-edit-mcp'

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