MCP ts-morph Refactoring Tools
The MCP ts-morph Refactoring Tools server enables automated refactoring and code analysis for TypeScript and JavaScript projects using the ts-morph library. It provides:
Rename Symbols: Rename variables, functions, and classes while automatically updating all references across the project
Rename Files/Folders: Rename filesystem entries and update all related import/export paths
Find References: Locate all usage sites and the definition of a specific symbol within the project
Remove Path Aliases: Convert path aliases (e.g.,
@/components) to relative paths in import/export statementsMove Symbols: Relocate symbols between files while maintaining references
Dry Run: Preview changes before applying them
Test Connection: Verify connection to the MCP server is working correctly
The server integrates with editor extensions like Cursor for seamless refactoring workflows.
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.
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@MCP ts-morph Refactoring Toolsrename the function 'calculateTotal' to 'computeTotal' in src/utils/math.ts"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
MCP ts-morph Refactoring Tools
overview
The MCP server leverages ts-morph to provide refactoring operations for TypeScript and JavaScript codebases, and works with editor extensions such as Cursor to allow AST-based (Abstract Syntax Tree)-based symbol renaming, file/folder renaming, find references, and more.
Related MCP server: TypeScript Rename Helper
Features provided
The MCP server provides the following refactoring features, each of which uses ts-morph to analyze the AST and make changes while maintaining consistency across the project:
Renaming symbols ( rename_symbol_by_tsmorph )
What it does : Globally rename a symbol (function, variable, class, interface, etc.) at a specific position in a specified file across the entire project.
Use case : You want to change the name of a function or variable, but there are many references to it and it would be difficult to change it manually.
Required information :
tsconfig.jsonpath of the project, path of the target file, position of the symbol (line and column), current symbol name, new symbol name
Renaming a file/folder ( rename_filesystem_entry_by_tsmorph )
Feature : Renames multiple specified files and/or folders and automatically updates the paths in all
import/exportstatements in the project.Use cases : When you change file structure and want to modify import paths accordingly. When you want to rename/move multiple files/folders at once.
Required information : project's
tsconfig.jsonpath, array of rename operations (renames: { oldPath: string, newPath: string }[]).remarks :
References are primarily resolved using symbol resolution.
References that contain path aliases (such as
@/) will be updated but converted to relative paths .Imports that reference a directory index file (e.g.
../components) are updated to an explicit file path (e.g.../components/index.tsx) .It also performs a path collision check (duplicates in existing paths and within the operation) before the rename operation.
Note (Execution time): When working with many files and folders at once, or for very large projects, parsing and updating references can take some time.
NOTE (known limitation): Currently, references to default exports of the form
export default Identifier;may not be updated correctly.
Finding references ( find_references_by_tsmorph )
What it does : Finds and lists the definition of a symbol at a particular location in a specified file, as well as all its references throughout the project.
Use case : You want to understand where a function or variable is used. You want to investigate the impact of a refactoring.
Required information : project's
tsconfig.jsonpath, target file path, symbol position (line, column).
Remove a path alias ( remove_path_alias_by_tsmorph )
Function : Replaces path aliases (such as
@/components) inimport/exportstatements in the specified file or directory with relative paths (such as../../components).Use case : You want to make your project more portable or to conform to specific coding standards.
Required information :
tsconfig.jsonpath of the project, path of the file or directory to process.
Moving symbols between files ( move_symbol_to_file_by_tsmorph )
What it does : Moves a specified symbol (function, variable, class, interface, type alias, enum) from the current file to another specified file, automatically updating references (including import/export paths) throughout the project along with the move.
Use case : You want to extract certain functionality into a separate file to reorganize your code.
Required information :
tsconfig.jsonpath of the project, source file path, destination file path, name of the symbol to move, and optionally a symbol kind (declarationKindString) to disambiguate symbols with the same name.NOTE : A symbol's internal dependencies (other declarations used only within that symbol) are moved along with it. Dependencies referenced by other symbols remaining in the source file will remain in the source and will be added as
export(if necessary) and imported in the destination file.Note : symbols that are exported
export defaultcannot be moved with this tool.
environment construction
For users (when using as an npm package)
Add the following settings to mcp.json . By using the npx command, the latest version installed will be automatically used.
{
"mcpServers": {
"mcp-tsmorph-refactor": { // 任意のサーバー名
"command": "npx",
"args": ["-y", "@sirosuzume/mcp-tsmorph-refactor"],
"env": {} // 必要に応じてロギング設定などを追加
}
}
}For developers (for local development and execution)
If you want to run the server locally from source code, you need to build it first.
# 依存関係のインストール (初回のみ)
pnpm install
# TypeScript コードのビルド
pnpm run buildAfter building, you can run it directly in node by setting the following in mcp.json :
{
"mcpServers": {
"mcp-tsmorph-refactor-dev": { // 開発用など、別の名前を推奨
"command": "node",
// プロジェクトルートからの相対パスまたは絶対パス
"args": ["/path/to/your/local/repo/dist/index.js"],
"env": {
// 開発時のデバッグログ設定など
"LOG_LEVEL": "debug"
}
}
}
}Logging Settings (Environment Variables)
The output level and destination of the server operation log can be controlled by the following environment variables. Set them in env block of mcp.json .
LOG_LEVEL: Sets the log verbosity.Available levels:
fatal,error,warn,info(default),debug,trace,silentExample:
"LOG_LEVEL": "debug"
LOG_OUTPUT: Specifies the log output destination.console(default): Logs to standard output. If you are in a development environment (NODE_ENV !== 'production') and havepino-prettyinstalled, the output will be formatted in a pretty way.file: Outputs the log to the specified file. Set this to avoid impacting MCP clients.Example:
"LOG_OUTPUT": "file"
LOG_FILE_PATH: IfLOG_OUTPUTis set tofile, this specifies the absolute path of the log file.Default:
[プロジェクトルート]/app.logExample:
"LOG_FILE_PATH": "/var/log/mcp-tsmorph.log"
Example config (in mcp.json ):
// ... (mcp.json の他の設定)
"env": {
"LOG_LEVEL": "debug", // デバッグレベルのログを
"LOG_OUTPUT": "file", // ファイルに出力
"LOG_FILE_PATH": "/Users/yourname/logs/mcp-tsmorph.log" // ログファイルのパス指定
}
// ...Developer Information
Prerequisites
Node.js (for version, see
.node-versionorvoltafield inpackage.json)pnpm (see
packageManagerfield inpackage.jsonfor version)
set up
Clone the repository and install the dependencies:
git clone https://github.com/sirosuzume/mcp-tsmorph-refactor.git
cd mcp-tsmorph-refactor
pnpm installBuild
Compiles TypeScript code into JavaScript.
pnpm buildThe build artifacts are output to dist directory.
test
Run the unit tests.
pnpm testLinting and formatting
It statically analyzes and formats your code.
# Lintチェック
pnpm lint
# Lint修正
pnpm lint:fix
# フォーマット
pnpm formatUsing the Debugging Wrapper
If you want to check the startup sequence, standard input/output, and error output of the MCP server in detail during development, you can use mcp_launcher.js , which is located in the scripts directory of the project.
This wrapper script launches the original MCP server process ( npx -y @sirosuzume/mcp-tsmorph-refactor ) as a child process and logs the launch information and output to .logs/mcp_launcher.log file in the project root.
How to use:
In the
mcp.jsonfile, changemcp-tsmorph-refactorserver configuration as follows:Set
commandto"node".In
args, specify the path toscripts/mcp_launcher.js(for example,["path/to/your_project_root/scripts/mcp_launcher.js"]). You can also use a path relative to the project root (["scripts/mcp_launcher.js"]).
Example configuration (
mcp.json):{ "mcpServers": { "mcp-tsmorph-refactor": { "command": "node", // scripts/mcp_launcher.js へのパス (プロジェクトルートからの相対パス or 絶対パス) "args": ["path/to/your_project_root/scripts/mcp_launcher.js"], "env": { // 元の環境変数設定はそのまま活かせます // 例: // "LOG_LEVEL": "trace", // "LOG_OUTPUT": "file", // "LOG_FILE_PATH": ".logs/mcp-ts-morph.log" } } // ... 他のサーバー設定 ... } }Restart or reload the MCP client (e.g. Cursor).
Check that the logs are output to
.logs/mcp_launcher.login your project root, and also to the MCP server's own log if configured (e.g..logs/mcp-ts-morph.log).
Using this wrapper can help you diagnose why your MCP server is not starting as expected.
Publishing to npm
This package will be automatically published to npm via a GitHub Actions workflow ( .github/workflows/release.yml ).
Prerequisites
NPM token: Make sure you have an npm access token with public permissions set in your repository's Actions secrets (
Settings>Secrets and variables>Actions) with the nameNPM_TOKEN.Update your version: Before publishing, update the
versionfield inpackage.jsonaccording to Semantic Versioning (SemVer).
How to publish
To trigger the release workflow, use a Git tag push.
How to: Push a Git tag (recommended for releases)
Intended use: Regular version releases (major, minor, patch). This is the recommended standard release process since it provides a clear correspondence between Git history and versions.
Update version: Change
versioninpackage.json(e.g.0.3.0).Commit & Push: Commit the changes to
package.jsonand push them to the main branch.Create tag & push: Creates a Git tag (with
vprefix) that matches the version and pushes it.git tag v0.3.0 git push origin v0.3.0Automation: Pushing a tag triggers the
Release Packageworkflow, which builds, tests, and publishes the package to npm.Verify: Check the status of your workflow in the Actions tab and verify your package on npmjs.com.
Precautions
Version consistency: When triggering on a tag push, the tag name (e.g.
v0.3.0) must exactly matchversion(e.g.0.3.0) inpackage.json, or the workflow will fail.Pre-check: Although your CI workflow includes build and test steps, we recommend running
pnpm run buildandpnpm run testlocally before updating your version to catch potential issues early.
license
This project is released under the MIT license, see the LICENSE file for details.
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Servers
- AlicenseAqualityDmaintenanceProvides code refactoring capabilities for TypeScript/JavaScript and Python through Language Server Protocol integration. Enables renaming symbols, extracting functions, finding references, and moving code between files via natural language commands.52,7576MIT
- AlicenseAqualityCmaintenanceProvides compiler-grade TypeScript symbol renaming and file/directory move planning through the TypeScript Language Service, returning structured edit plans without modifying files.318MIT
- AlicenseAqualityDmaintenanceProvides Python refactoring capabilities via the Rope library, enabling AI agents to perform safe, project-wide code transformations such as renaming symbols, moving modules, and extracting methods.101MIT
- AlicenseAqualityBmaintenanceA TypeScript/JavaScript refactoring MCP server that uses the TypeScript compiler to perform safe, type-aware code transformations such as renaming, extracting functions, and organizing imports across your codebase.48812MIT
Related MCP Connectors
Code intelligence for coding agents: semantic, AST, graph, and full-text search. 279+ languages.
Cross-agent artifact workspace with provenance across Claude Code, Codex, Cursor, LangGraph.
Securely search and manage workspace context files for AI agents and teams.
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
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