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
。
提供的功能
该 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-version
或package.json
中的volta
字段) - pnpm(查看
package.json
中的packageManager
字段了解版本)
设置
克隆存储库并安装依赖项:
建造
将 TypeScript 代码编译为 JavaScript。
构建产物输出到dist
目录。
测试
运行单元测试。
代码检查和格式化
它静态分析并格式化您的代码。
执照
该项目根据 MIT 许可证发布。请参阅LICENSE文件以了解详细信息。
Related MCP Servers
- AsecurityAlicenseAqualityTypeScript-based MCP server designed to enhance code editing experiences by providing features such as hover information, code completion, and diagnostics.Last updated -313MIT License
- AsecurityAlicenseAqualityA 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 -55TypeScriptMIT License
- -securityAlicense-qualityA TypeScript-based MCP server that provides tools for making precise line-based edits to text files within allowed directories.Last updated -18TypeScriptMIT License
- AsecurityFlicenseAqualityA 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 -132TypeScript