Skip to main content
Glama

MCP ts-morph Refactoring Tools

by SiroSuzume

rename_filesystem_entry_by_tsmorph

Renames TypeScript/JavaScript files and folders while automatically updating all import/export paths in the project. Analyzes using tsconfig.json, handles path aliases, and checks for conflicts before applying changes.

Instructions

[Uses ts-morph] Renames one or more TypeScript/JavaScript files and/or folders and updates all import/export paths referencing them throughout the project.

Analyzes the project based on tsconfig.json to find all references to the items being renamed and automatically corrects their paths. Handles various path types, including relative paths, path aliases (e.g., @/), and imports referencing a directory's index.ts ( Checks for conflicts before applying changes.

Usage

Use this tool when you want to rename/move multiple files or folders simultaneously (e.g., renaming util.ts to helper.ts and moving src/data to src/coreData in one operation) and need all the import/export statements referencing them to be updated automatically.

  1. Specify the path to the project's tsconfig.json file. Must be an absolute path.

  2. Provide an array of rename operations. Each object in the array must contain:

    • oldPath: The current absolute path of the file or folder to rename.

    • newPath: The new desired absolute path for the file or folder.

  3. It's recommended to first run with dryRun: true to check which files will be affected.

  4. If the preview looks correct, run with dryRun: false (or omit it) to actually save the changes to the file system.

Parameters

  • tsconfigPath (string, required): Absolute path to the project's root tsconfig.json file. Must be an absolute path.

  • renames (array of objects, required): An array where each object specifies a rename operation with:

    • oldPath (string, required): The current absolute path of the file or folder. Must be an absolute path.

    • newPath (string, required): The new desired absolute path for the file or folder. Must be an absolute path.

  • dryRun (boolean, optional): If set to true, prevents making and saving file changes, returning only the list of files that would be affected. Defaults to false.

  • timeoutSeconds (number, optional): Maximum time in seconds allowed for the operation before it times out. Defaults to 120 seconds.

Result

  • On success: Returns a message listing the file paths modified or scheduled to be modified.

  • On failure: Returns a message indicating the error (e.g., path conflict, file not found, timeout).

Remarks

  • Symbol-based Reference Finding: This tool now primarily uses symbol analysis (identifying exported functions, classes, variables, etc.) to find references across the project, rather than solely relying on path matching.

  • Path Alias Handling: Path aliases (e.g., @/) in import/export statements are updated, but they will be converted to relative paths. If preserving path aliases is crucial, consider using the remove_path_alias_by_tsmorph tool before renaming to convert them to relative paths preemptively.

  • Index File Imports: Imports referencing a directory's index.ts or index.tsx (e.g., import Component from '../components') will be updated to reference the specific index file directly (e.g., import Component from '../components/index.tsx').

  • Known Limitation (Default Exports): Currently, this tool may not correctly update references for default exports declared using an identifier (e.g., export default MyIdentifier;). Default exports using function or class declarations (e.g., export default function myFunction() {}) are generally handled.

  • Performance: Renaming numerous files/folders or operating in a very large project can take significant time due to the detailed symbol analysis and reference updates.

  • Conflicts: The tool checks for conflicts (e.g., renaming to an existing path, duplicate targets) before applying changes.

  • Timeout: Operations exceeding the specified timeoutSeconds will be canceled.

Input Schema

NameRequiredDescriptionDefault
dryRunNoIf true, only show intended changes without modifying files.
renamesYesAn array of rename operations, each with oldPath and newPath.
timeoutSecondsNoMaximum time in seconds allowed for the operation before it times out. Defaults to 120.
tsconfigPathYesAbsolute path to the project's tsconfig.json file.

Input Schema (JSON Schema)

{ "$schema": "http://json-schema.org/draft-07/schema#", "additionalProperties": false, "properties": { "dryRun": { "default": false, "description": "If true, only show intended changes without modifying files.", "type": "boolean" }, "renames": { "description": "An array of rename operations, each with oldPath and newPath.", "items": { "additionalProperties": false, "properties": { "newPath": { "description": "The new desired absolute path for the file or folder.", "type": "string" }, "oldPath": { "description": "The current absolute path of the file or folder to rename.", "type": "string" } }, "required": [ "oldPath", "newPath" ], "type": "object" }, "minItems": 1, "type": "array" }, "timeoutSeconds": { "default": 120, "description": "Maximum time in seconds allowed for the operation before it times out. Defaults to 120.", "exclusiveMinimum": 0, "type": "integer" }, "tsconfigPath": { "description": "Absolute path to the project's tsconfig.json file.", "type": "string" } }, "required": [ "tsconfigPath", "renames" ], "type": "object" }

Other Tools from MCP ts-morph Refactoring Tools

Related Tools

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/SiroSuzume/mcp-ts-morph'

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