rename_filesystem_entry_by_tsmorph
Renames a TypeScript/JavaScript file or folder and updates all import/export paths referencing it across the project. Analyzes tsconfig.json
to ensure accurate path corrections. Supports dry-run for previewing changes. Use for consistent renaming with minimal manual intervention.
Instructions
[Uses ts-morph] Renames a single TypeScript/JavaScript file OR FOLDER and updates all import/export paths referencing it throughout the project.
Analyzes the project based on tsconfig.json
to find all references to the file/folder being renamed and automatically corrects its paths. Includes a remark about potential issues with path aliases and relative index imports.
Usage
Use this tool when you want to rename a file (e.g., utils.ts
-> helpers.ts
) or a folder (e.g., src/data
-> src/coreData
) and need all the import
statements in other files that point to it to be automatically updated.
- Specify the path to the project's
tsconfig.json
file. Must be an absolute path. - Specify the current absolute path of the file or folder to rename.
- Specify the new desired absolute path for the file or folder.
- It's recommended to first run with
dryRun: true
to check which files will be affected. - 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. Essential for ts-morph to parse the project. Must be an absolute path. - oldPath (string, required): The current absolute path of the file or folder to rename. 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 ts-morph from making and saving file changes, returning only the list of files that would be affected. Useful for verification. Defaults to false.
Result
- On success: Returns a message containing the list of file paths modified (the renamed file/folder and files with updated imports) or scheduled to be modified if dryRun.
- On failure: Returns a message indicating the error.
Remarks (Added)
- Caution: Updating import/export statements containing path aliases (like
@/
) or relative paths referencing a directory'sindex.ts
(likeimport from '.'
) might be incomplete in the currentts-morph
implementation. Manual verification and correction might be necessary after renaming.
Input Schema
Name | Required | Description | Default |
---|---|---|---|
dryRun | No | If true, only show intended changes without modifying files. | |
newPath | Yes | The new desired absolute path for the file or folder. | |
oldPath | Yes | The current absolute path of the file or folder to rename. | |
tsconfigPath | Yes | Absolute path to the project's tsconfig.json file. |
Input Schema (JSON Schema)
You must be authenticated.
Other Tools from MCP ts-morph Refactoring Tools
Related Tools
- @SiroSuzume/mcp-ts-morph
- @SiroSuzume/mcp-ts-morph
- @bsmi021/mcp-node-omnibus-server
- @SiroSuzume/mcp-ts-morph
- @SiroSuzume/mcp-ts-morph