Skip to main content
Glama

smart_refactor

DestructiveIdempotent

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
NameRequiredDescriptionDefault
filesYesList of files to search and refactor
oldNameYesThe symbol name to replace
newNameYesThe 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
      }
    });
  • 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']
  • 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'
    ];
Behavior3/5

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

Annotations cover key traits (destructive, idempotent, not read-only, closed-world), so the description adds value by specifying 'renaming symbols across multiple files' and implying intelligence in refactoring. However, it lacks details on error handling, side effects, or rate limits, which would enhance transparency beyond annotations.

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 key details ('renaming symbols across multiple files') without unnecessary words, 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 (destructive refactoring across files) and lack of output schema, the description is adequate but incomplete. It covers the basic operation but omits details on return values, error cases, or advanced usage, leaving gaps for an AI agent to handle effectively.

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%, fully documenting the three parameters. The description adds minimal semantics by implying 'files' are searched and refactored, but doesn't provide extra details like file format constraints or symbol scope, aligning with the baseline for high schema coverage.

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 action ('intelligently refactor code by renaming symbols') and resource ('across multiple files'), making the purpose specific and understandable. However, it doesn't explicitly differentiate from sibling tools like 'complex_find_replace' or 'backup_and_edit', which might offer similar 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 prerequisites, exclusions, or compare to siblings like 'complex_find_replace' for similar tasks, leaving the agent to infer usage context without explicit direction.

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

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