MCP ts-morph Refactoring Tools

find_references_by_tsmorph

Analyze a TypeScript project to locate the definition and all references of a symbol by specifying its position in a file. Essential for understanding the impact of refactoring changes.

Instructions

[Uses ts-morph] Finds the definition and all references to a symbol at a given position throughout the project.

Analyzes the project based on tsconfig.json to locate the definition and all usages of the symbol (function, variable, class, etc.) specified by its position.

Usage

Use this tool before refactoring to understand the impact of changing a specific symbol. It helps identify where a function is called, where a variable is used, etc.

  1. Specify the absolute path to the project's tsconfig.json.
  2. Specify the absolute path to the file containing the symbol you want to investigate.
  3. Specify the exact position (line and column) of the symbol within the file.

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.
  • targetFilePath (string, required): The absolute path to the file containing the symbol to find references for. Must be an absolute path.
  • position (object, required): The exact position of the symbol to find references for.
    • line (number, required): 1-based line number.
    • column (number, required): 1-based column number.

Result

  • On success: Returns a message containing the definition location (if found) and a list of reference locations (file path, line number, column number, and line text).
  • On failure: Returns a message indicating the error.

Input Schema

NameRequiredDescriptionDefault
positionYesThe exact position of the symbol.
targetFilePathYesAbsolute path to the file containing the symbol.
tsconfigPathYesAbsolute path to the project's tsconfig.json file.

Input Schema (JSON Schema)

{ "$schema": "http://json-schema.org/draft-07/schema#", "additionalProperties": false, "properties": { "position": { "additionalProperties": false, "description": "The exact position of the symbol.", "properties": { "column": { "description": "1-based column number.", "type": "number" }, "line": { "description": "1-based line number.", "type": "number" } }, "required": [ "line", "column" ], "type": "object" }, "targetFilePath": { "description": "Absolute path to the file containing the symbol.", "type": "string" }, "tsconfigPath": { "description": "Absolute path to the project's tsconfig.json file.", "type": "string" } }, "required": [ "tsconfigPath", "targetFilePath", "position" ], "type": "object" }

You must be authenticated.

Other Tools from MCP ts-morph Refactoring Tools

Related Tools

ID: byunmqla3h