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 });

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