Skip to main content
Glama
SiroSuzume

MCP ts-morph Refactoring Tools

by SiroSuzume

move_symbol_to_file_by_tsmorph

Move a top-level symbol (function, variable, class, etc.) between files, automatically rewriting imports/exports and carrying internal-only dependencies.

Instructions

[ts-morph] Move one top-level symbol (function, variable, class, interface, type, enum) from one file to another, carrying its internal-only dependencies and rewriting all imports/exports across the project.

When to use

  • Splitting a large file: move related symbols to a new file one by one.

  • Relocating a helper from a generic utils.ts to a feature-specific module.

  • Prefer this over manual cut-and-paste + import fixing. Manual moves frequently miss re-exports, leave stale imports, or fail to add the new export -- this tool handles all of that via the type checker.

When NOT to use

  • Renaming the file (without moving a single symbol out of it) -> rename_filesystem_entry_by_tsmorph.

  • Renaming a symbol in place -> rename_symbol_by_tsmorph.

  • The symbol you want to move is a export default -> NOT SUPPORTED, refactor it to a named export first.

Critical constraints

  • ONE top-level symbol per call. To move N symbols, invoke the tool N times.

  • Default exports CANNOT be moved. Convert them to named exports beforehand.

  • If multiple top-level declarations share the same name (e.g., function + namespace), pass declarationKindString (e.g., "FunctionDeclaration", "VariableStatement") to disambiguate.

  • Internal dependency rules:

    • Dependencies used ONLY by the moved symbol travel with it.

    • Dependencies also used by other symbols in the source file stay put, gain export if missing, and are imported back into the destination file.

  • All paths (tsconfigPath, originalFilePath, targetFilePath) MUST be absolute.

  • targetFilePath may point to a non-existent file; it will be created.

Tips

  • Run with dryRun: true first when the source file has many co-dependencies to confirm what gets pulled along.

Result

Returns the list of modified (or to-be-modified, in dryRun) file paths, plus status and processing time.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
tsconfigPathYesAbsolute path to the project's tsconfig.json file. Essential for ts-morph.
originalFilePathYesAbsolute path to the file containing the symbol to move.
targetFilePathYesAbsolute path to the destination file. Can be an existing file; if the path does not exist, a new file will be created.
symbolToMoveYesThe name of the single top-level symbol you want to move in this execution.
declarationKindStringNoOptional. The kind of the declaration. Providing this helps resolve ambiguity if multiple symbols share the same name.
dryRunNoIf true, only show intended changes without modifying files.
Behavior5/5

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

No annotations are provided, so the description fully covers behavioral traits: it explains one symbol per call, unsupported default exports, internal dependency handling rules, path requirements (absolute), target file creation, dry run behavior, and ambiguity resolution via declarationKindString. This is comprehensive.

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

Conciseness5/5

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

The description is structured into clear sections: purpose, when/not to use, critical constraints, tips, and result. Every sentence serves a purpose, and the information is front-loaded for quick scanning. There is no redundancy or wasted text.

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?

Given 6 parameters and no output schema, the description covers all necessary aspects: what the tool does, when to use it, constraints, parameter details, and what the result contains. It even explains the internal dependency algorithm. No gaps are evident.

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 coverage is 100% with parameter descriptions. The description adds value beyond the schema by noting that all paths must be absolute, that targetFilePath can be non-existent, and by providing a tip to use dryRun for complex cases. These details enhance parameter understanding.

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 verb (move), the resource (a top-level symbol from one file to another), and the scope (carrying internal-only dependencies and rewriting imports/exports). It distinguishes from sibling tools like rename_filesystem_entry_by_tsmorph and rename_symbol_by_tsmorph, making the purpose unambiguous.

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 provides explicit when-to-use scenarios (splitting large files, relocating helpers) and when-not-to-use (renaming file or symbol, default exports). It also names specific sibling tools as alternatives, giving clear decision criteria.

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

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