MCP ts-morph Refactoring Tools

Integrations

  • Enables AST-based code refactoring operations for JavaScript files including symbol renaming, file/folder renaming with automatic import path updates, and reference finding.

  • Provides a Node.js-based refactoring server that can be integrated with editor extensions like Cursor to perform code transformations.

  • Provides refactoring capabilities for TypeScript codebases including symbol renaming, finding references, and updating import paths, all performed using AST-based analysis.

MCP ts-morph Refactoring Tools

概要

この MCP サーバーは、ts-morph を利用して TypeScript および JavaScript のコードベースに対するリファクタリング操作を提供します。 Cursor などのエディタ拡張機能と連携し、シンボル名の変更、ファイル/フォルダ名の変更、参照箇所の検索などを AST (Abstract Syntax Tree) ベースで行うことができます。

環境構築

mcp.json に以下のように設定を追加します。

{ "mcpServers": { "mcp-tsmorph-refactor": { // 任意のサーバー名 "command": "node", // TODO: ビルド後のエントリポイントへのパスを指定してください "args": ["/path/to/this/repo/dist/index.js"], "env": {} } } }

提供される機能

この MCP サーバーは以下のリファクタリング機能を提供します。各機能は ts-morph を利用して AST を解析し、プロジェクト全体の整合性を保ちながら変更を行います。

シンボル名の変更 (rename_symbol_by_tsmorph)

  • 機能: 指定されたファイル内の特定の位置にあるシンボル (関数、変数、クラス、インターフェースなど) の名前を、プロジェクト全体で一括変更します。
  • ユースケース: 関数名や変数名を変更したいが、参照箇所が多く手作業での変更が困難な場合。
  • 必要な情報: プロジェクトの tsconfig.json パス、対象ファイルのパス、シンボルの位置 (行・列)、現在のシンボル名、新しいシンボル名

ファイル/フォルダ名の変更 (rename_filesystem_entry_by_tsmorph)

  • 機能: 指定されたファイルまたはフォルダの名前を変更し、プロジェクト内のすべての import/export 文のパスを自動的に更新します。
  • ユースケース: ファイル構成を変更し、それに伴って import パスを修正したい場合。
  • 必要な情報: プロジェクトの tsconfig.json パス、変更前のパス、変更後のパス。
  • 注意: パスエイリアスや相対的なインデックスインポートの更新は不完全な場合があります。変更後に手動確認が必要な場合があります。"."".."@/*等のパスで import している場合、更新されないことがあります。

参照箇所の検索 (find_references_by_tsmorph)

  • 機能: 指定されたファイル内の特定の位置にあるシンボルの定義箇所と、プロジェクト全体でのすべての参照箇所を検索して一覧表示します。
  • ユースケース: ある関数や変数がどこで使われているかを把握したい場合。リファクタリングの影響範囲を調査したい場合。
  • 必要な情報: プロジェクトの tsconfig.json パス、対象ファイルのパス、シンボルの位置 (行・列)。

パスエイリアスの削除 (remove_path_alias_by_tsmorph)

  • 機能: 指定されたファイルまたはディレクトリ内の import/export 文に含まれるパスエイリアス (@/components など) を、相対パス (../../components など) に置換します。
  • ユースケース: プロジェクトの移植性を高めたい場合や、特定のコーディング規約に合わせたい場合。
  • 必要な情報: プロジェクトの tsconfig.json パス、処理対象のファイルまたはディレクトリのパス。

(その他の機能があれば追記)

開発者向け情報

前提条件

  • Node.js (バージョンは .node-version または package.jsonvolta フィールドを参照)
  • pnpm (バージョンは package.jsonpackageManager フィールドを参照)

セットアップ

リポジトリをクローンし、依存関係をインストールします。

git clone https://github.com/sirosuzume/mcp-tsmorph-refactor.git cd mcp-tsmorph-refactor pnpm install

ビルド

TypeScript コードを JavaScript にコンパイルします。

pnpm build

ビルド成果物は dist ディレクトリに出力されます。

テスト

ユニットテストを実行します。

pnpm test

リンティングとフォーマット

コードの静的解析とフォーマットを行います。

# Lintチェック pnpm lint # Lint修正 pnpm lint:fix # フォーマット pnpm format

ライセンス

このプロジェクトは MIT ライセンスの下で公開されています。詳細は LICENSE ファイルをご覧ください。

You must be authenticated.

A
security – no known vulnerabilities
A
license - permissive license
A
quality - confirmed to work

hybrid server

The server is able to function both locally and remotely, depending on the configuration or use case.

Provides TypeScript and JavaScript code refactoring operations using ts-morph, allowing AST-based symbol renaming, file/folder renaming, reference searching, and path alias removal when integrated with editor extensions like Cursor.

  1. 概要
    1. 環境構築
      1. 提供される機能
        1. シンボル名の変更 (rename_symbol_by_tsmorph)
        2. ファイル/フォルダ名の変更 (rename_filesystem_entry_by_tsmorph)
        3. 参照箇所の検索 (find_references_by_tsmorph)
        4. パスエイリアスの削除 (remove_path_alias_by_tsmorph)
      2. 開発者向け情報
        1. 前提条件
        2. セットアップ
        3. ビルド
        4. テスト
        5. リンティングとフォーマット
      3. ライセンス

        Related MCP Servers

        • A
          security
          A
          license
          A
          quality
          TypeScript-based MCP server designed to enhance code editing experiences by providing features such as hover information, code completion, and diagnostics.
          Last updated -
          3
          13
          MIT License
          • Apple
        • A
          security
          A
          license
          A
          quality
          A TypeScript MCP server port of Anthropic's filesystem editing tools, allowing file manipulation via client-approved operations without automated writes to prevent system harm.
          Last updated -
          5
          5
          TypeScript
          MIT License
        • -
          security
          A
          license
          -
          quality
          A TypeScript-based MCP server that provides tools for making precise line-based edits to text files within allowed directories.
          Last updated -
          18
          TypeScript
          MIT License
          • Apple
        • A
          security
          F
          license
          A
          quality
          A TypeScript-based server that visualizes project directory structures in Markdown format, automatically documenting file contents with syntax highlighting and supporting customizable exclusion patterns.
          Last updated -
          1
          3
          2
          TypeScript
          • Linux
          • Apple

        View all related MCP servers

        ID: byunmqla3h