Skip to main content
Glama
SiroSuzume

MCP ts-morph Refactoring Tools

by SiroSuzume

change_signature_by_tsmorph

Add, remove, or reorder parameters in a function and automatically update all call sites across the project using type-checked refactoring.

Instructions

[ts-morph] Add, remove, or reorder parameters of a function/method/arrow-function and propagate the matching argument changes to every call site in the project.

When to use

  • Adding a required parameter to a function with many callers (LLM single-edit reliably misses some — this tool guarantees every call site is updated via the type checker).

  • Removing or reordering parameters of a function that is imported, re-exported, or accessed through a method chain.

  • Inserting a context-like first parameter (ctx, logger, etc.) into existing helpers.

When NOT to use

  • Renaming a parameter — use rename_symbol_by_tsmorph on the parameter identifier instead.

  • Changing only the parameter's type annotation without changing arity — edit the source file directly.

  • Moving the function to another file — use move_symbol_to_file_by_tsmorph.

Critical constraints

  • position must point at the function's name identifier (1-based line/column). For const foo = () => {}, point at foo; for class C { foo() {} }, point at foo.

  • functionName must match the identifier text at that position (sanity check).

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

  • Spread arguments (fn(...args)) at call sites cause the operation to fail when a change would modify arguments. Refactor those callers manually first, or limit changes to trailing optional/defaulted parameters with no argumentForCallers.

  • Operations apply sequentially; later operations see the parameter list produced by earlier ones.

Operation semantics

  • add: Inserts a parameter at index (default: end). If argumentForCallers is provided, that exact text is inserted at the same index in every call site. If omitted, callers are left untouched (use only for trailing optional / defaulted parameters).

  • remove: Removes the parameter at index. Each call site with at least that many arguments drops the corresponding one. Calls passing fewer arguments are left untouched.

  • reorder: Rebuilds the parameter list and every call site according to newOrder. Fails if any call site does not pass exactly that many arguments (no way to safely reorder omitted optionals).

Tips

  • Run with dryRun: true first when the function has many callers to preview the impacted files.

  • For adding multiple parameters at once, list multiple add operations; their index values refer to the parameter list after prior operations in the same call have been applied.

Result

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

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
tsconfigPathYesPath to the project's tsconfig.json file.
targetFilePathYesPath to the file containing the function declaration.
positionYesExact position of the function name identifier.
functionNameYesName of the function/method at that position.
changesYesOrdered list of signature operations to apply. See the tool description for semantics.
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, the description fully discloses behaviors: constraints for position and functionName, spread argument failure, sequential operation effects, operation semantics, and dryRun mode. It also details edge cases like call site argument dropping for remove operations.

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?

Structured with clear sections (when to use, when not, critical constraints, operation semantics, tips, result). Every sentence earns its place; no redundancy. Front-loaded with core verb and purpose.

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 tool with 6 parameters, nested changes array, and no output schema, the description covers return format (modified file paths, status, processing time), failure cases (spread arguments), and sequential operation behavior. It is complete for effective use.

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

Parameters5/5

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

Although schema coverage is 100%, the description enriches every parameter with context: position pointing to name identifier, functionName as sanity check, changes array semantics (add/remove/reorder), argumentForCallers usage, and index ordering after prior operations. This goes far beyond schema definitions.

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 opens with a precise verb: 'Add, remove, or reorder parameters of a function/method/arrow-function and propagate the matching argument changes to every call site.' This clearly distinguishes it from sibling tools like rename_symbol_by_tsmorph or move_symbol_to_file_by_tsmorph.

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 'When to use' and 'When NOT to use' sections explicitly lay out scenarios and alternatives (e.g., rename_symbol_by_tsmorph for renaming, direct editing for type-only changes, move_symbol_to_file_by_tsmorph for file moves). This provides excellent guidance.

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