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 重构工具

概述

该 MCP 服务器利用ts-morph为 TypeScript 和 JavaScript 代码库提供重构操作。它与 Cursor 等编辑器扩展配合使用,允许基于 AST 的符号重命名、文件/文件夹重命名和参考查找。

环境搭建

将以下设置添加到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语句中的路径。
  • 用例:您更改文件结构并想相应地修改导入路径。
  • 所需信息:项目的tsconfig.json路径、旧路径、新路径。
  • 注意:路径别名和相对索引导入可能不会完全更新。任何更改后都可能需要手动验证。如果使用诸如"."之类的路径导入、 ".."@/*等,它们可能不会被更新。

查找引用( find_references_by_tsmorph

  • 其作用:查找并列出指定文件中特定位置的符号定义,以及整个项目中的所有引用。
  • 用例:您想知道函数或变量在哪里使用。您想探索重构的范围。
  • 所需信息:项目的tsconfig.json路径、目标文件路径、符号位置(行、列)。

删除路径别名( remove_path_alias_by_tsmorph

  • 功能:将指定文件或目录中的import / export语句中的路径别名(如@/components )替换为相对路径(如../../components )。
  • 用例:您想让您的项目更具可移植性或符合特定的编码标准。
  • 所需信息:项目的tsconfig.json路径,要处理的文件或目录的路径。

(添加任何其他功能)

开发者信息

先决条件

  • Node.js(有关版本,请参阅.node-versionpackage.json中的volta字段)
  • pnpm(查看package.json中的packageManager字段了解版本)

设置

克隆存储库并安装依赖项:

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.

使用 ts-morph 提供 TypeScript 和 JavaScript 代码重构操作,与 Cursor 等编辑器扩展集成时允许基于 AST 的符号重命名、文件/文件夹重命名、引用搜索和路径别名删除。

  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