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, interface, type, or enum) from one file to another, automatically carrying its internal-only dependencies and rewriting all imports and exports across the project.

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?

With no annotations provided, the description fully carries the burden. It discloses critical behaviors: internal dependency rules (carries only internal deps, leaves shared ones with export), path requirements (must be absolute), creation of non-existent target file, and dry-run support. Covers all significant behavioral traits.

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?

Description is well-structured with sections, bullet points, and clear headings. Immediately states core functionality, then provides usage guidelines, constraints, tips, and result. Every sentence earns its place; no redundancy.

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?

Despite no output schema and 6 parameters, the description thoroughly explains the tool's behavior, constraints, and expected result (list of modified files). Includes a tip to use dryRun first. Everything an agent needs to invoke correctly is present.

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

Parameters3/5

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

Schema description coverage is 100%, so baseline is 3. The description adds some extra context (e.g., 'Essential for ts-morph' for tsconfigPath, 'disambiguate' for declarationKindString) but mostly restates schema, providing moderate added value.

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: moving a top-level symbol between files while rewriting imports/exports. It distinguishes from sibling tools by naming them explicitly (e.g., rename_filesystem_entry_by_tsmorph, rename_symbol_by_tsmorph) and noting when not to use this tool.

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?

Includes explicit 'When to use' and 'When NOT to use' sections with clear context and alternatives, such as renaming a file or renaming a symbol. Also warns about unsupported default exports, guiding the agent correctly.

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