Skip to main content
Glama
qckfx

Tree-Hugger-JS MCP Server

by qckfx

rename_identifier

Renames JavaScript/TypeScript identifiers throughout code while avoiding strings and comments. Use to refactor function, variable, or class names with preview option for safety.

Instructions

Intelligently rename all occurrences of an identifier throughout the code. Avoids renaming in strings/comments.

Examples: • Refactor function names: rename_identifier('fetchData', 'fetchUserData') • Improve variable names: rename_identifier('data', 'userData') • Update class names: rename_identifier('Manager', 'UserManager') • API consistency: rename_identifier('getUserInfo', 'fetchUserInfo') • Preview first: rename_identifier('oldName', 'newName', {preview: true}) • Legacy code update: rename_identifier('XMLHttpRequest', 'fetch')

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
oldNameYesCurrent identifier name to find and replace
newNameYesNew identifier name (should be valid JavaScript identifier)
previewNoReturn preview only without applying changes (default: false). Always preview first for safety.

Implementation Reference

  • The main handler function that performs the rename operation using tree-hugger-js transform API. Handles preview mode, updates AST and source code, records in transform history, and returns result or preview.
    private async renameIdentifier(args: { oldName: string; newName: string; preview?: boolean }) {
      if (!this.currentAST) {
        return {
          content: [{
            type: "text",
            text: "No AST loaded. Please use parse_code first.",
          }],
          isError: true,
        };
      }
    
      try {
        const transformed = this.currentAST.tree.transform()
          .rename(args.oldName, args.newName);
    
        const result = transformed.toString();
        
        if (!args.preview) {
          this.currentAST.sourceCode = result;
          this.currentAST.tree = parse(result);
          this.currentAST.timestamp = new Date();
        }
    
        const transformResult: TransformResult = {
          operation: "rename_identifier",
          parameters: { oldName: args.oldName, newName: args.newName },
          preview: result.slice(0, 500) + (result.length > 500 ? '...' : ''),
          timestamp: new Date(),
        };
        
        this.transformHistory.push(transformResult);
    
        return {
          content: [{
            type: "text",
            text: `${args.preview ? 'Preview: ' : ''}Renamed "${args.oldName}" to "${args.newName}"\n\n${args.preview ? 'Preview:\n' : 'Result:\n'}${result}`,
          }],
        };
      } catch (error) {
        return {
          content: [{
            type: "text",
            text: `Error renaming identifier: ${error instanceof Error ? error.message : String(error)}`,
          }],
          isError: true,
        };
      }
    }
  • Input schema defining parameters oldName (string, required), newName (string, required), preview (boolean, optional) for the rename_identifier tool.
    inputSchema: {
      type: "object",
      properties: {
        oldName: {
          type: "string",
          description: "Current identifier name to find and replace"
        },
        newName: {
          type: "string", 
          description: "New identifier name (should be valid JavaScript identifier)"
        },
        preview: {
          type: "boolean",
          description: "Return preview only without applying changes (default: false). Always preview first for safety."
        }
      },
      required: ["oldName", "newName"],
    },
  • src/index.ts:281-302 (registration)
    Tool registration in ListToolsRequestSchema handler, including name, detailed description with examples, and input schema.
    {
      name: "rename_identifier", 
      description: "Intelligently rename all occurrences of an identifier throughout the code. Avoids renaming in strings/comments.\n\nExamples:\n• Refactor function names: rename_identifier('fetchData', 'fetchUserData')\n• Improve variable names: rename_identifier('data', 'userData')\n• Update class names: rename_identifier('Manager', 'UserManager')\n• API consistency: rename_identifier('getUserInfo', 'fetchUserInfo')\n• Preview first: rename_identifier('oldName', 'newName', {preview: true})\n• Legacy code update: rename_identifier('XMLHttpRequest', 'fetch')",
      inputSchema: {
        type: "object",
        properties: {
          oldName: {
            type: "string",
            description: "Current identifier name to find and replace"
          },
          newName: {
            type: "string", 
            description: "New identifier name (should be valid JavaScript identifier)"
          },
          preview: {
            type: "boolean",
            description: "Return preview only without applying changes (default: false). Always preview first for safety."
          }
        },
        required: ["oldName", "newName"],
      },
    },
  • src/index.ts:431-432 (registration)
    Dispatcher case in CallToolRequestSchema handler that routes the tool call to the renameIdentifier method.
    case "rename_identifier":
      return await this.renameIdentifier(args as { oldName: string; newName: string; preview?: boolean });
Behavior3/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It effectively describes key behaviors: it renames identifiers intelligently (avoiding strings/comments), supports a preview mode for safety, and applies changes throughout the code. However, it lacks details on permissions needed, error handling, or rate limits, which are important for a mutation tool.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is appropriately sized and front-loaded with a clear purpose statement, followed by relevant examples that earn their place by illustrating usage scenarios. However, the list of examples is somewhat lengthy and could be more streamlined without losing clarity.

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 as a mutation tool with no annotations and no output schema, the description is moderately complete. It covers purpose, usage examples, and key behaviors but lacks details on return values, error conditions, or integration with sibling tools, leaving some gaps for an AI agent to infer.

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%, so the schema already documents all parameters (oldName, newName, preview). The description adds minimal value beyond the schema by mentioning that newName 'should be valid JavaScript identifier' and emphasizing preview for safety, but does not provide additional syntax or format details. Baseline 3 is appropriate as the schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose with specific verbs ('rename all occurrences of an identifier throughout the code') and distinguishes it from siblings by focusing on identifier renaming rather than analysis, insertion, or transformation. It explicitly mentions what it avoids (renaming in strings/comments), which further clarifies its scope.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides clear context for when to use this tool through multiple examples (e.g., refactoring function names, improving variable names, updating class names, API consistency, legacy code updates). It implicitly suggests usage for code refactoring tasks but does not explicitly state when not to use it or name specific alternatives among siblings.

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/qckfx/tree-hugger-js-mcp'

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