Skip to main content
Glama
SiroSuzume

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 (from '.' or from '..'). 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

TableJSON 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.
Behavior5/5

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

With no annotations provided, the description carries full burden and delivers comprehensive behavioral details. It explains the symbol-based reference finding approach, path alias handling (converted to relative paths), index file import updates, known limitations with default exports, performance considerations, conflict checking, and timeout behavior - all crucial for understanding how the tool operates beyond basic functionality.

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 well-structured with clear sections (Usage, Parameters, Result, Remarks) and front-loads the core purpose. While comprehensive, every section adds value - the Remarks section in particular contains critical behavioral information. Some redundancy exists (multiple mentions of absolute paths), but overall the information density is high.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a complex file manipulation tool with no annotations and no output schema, the description provides exceptional completeness. It covers purpose, usage guidelines, detailed behavioral traits, parameter context, success/failure outcomes, limitations, performance characteristics, and sibling tool relationships. The Remarks section alone addresses numerous edge cases and implementation details an agent needs to use this tool effectively.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the baseline is 3. The description adds significant value by explaining the purpose of each parameter in context: why tsconfigPath must be absolute, what renames array contains, the practical use of dryRun for previewing changes, and timeoutSeconds for large operations. It provides concrete examples of rename operations and emphasizes absolute path requirements multiple times.

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: renaming TypeScript/JavaScript files/folders and updating import/export paths using ts-morph. It specifies the scope ('one or more' items, 'throughout the project') and distinguishes from siblings by mentioning the remove_path_alias_by_tsmorph tool for a related but different task.

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

Usage Guidelines5/5

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

The description explicitly states when to use this tool ('when you want to rename/move multiple files or folders simultaneously... and need all import/export statements updated automatically'). It provides a clear alternative (remove_path_alias_by_tsmorph) for preserving path aliases and includes a recommended workflow with dry-run first.

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

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

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