This MCP server uses ts-morph to provide powerful refactoring operations for TypeScript and JavaScript codebases. It integrates with code editors like Cursor to enable AST-based operations such as renaming symbols, renaming files/folders, and finding references throughout your project.
Add the MCP server configuration to your mcp.json
file:
{
"mcpServers": {
"mcp-tsmorph-refactor": {
"command": "npx",
"args": ["-y", "@sirosuzume/mcp-tsmorph-refactor"],
"env": {}
}
}
}
If you want to run the server locally for development:
# Install dependencies
pnpm install
# Build the TypeScript code
pnpm run build
Then configure your mcp.json
to use the local build:
{
"mcpServers": {
"mcp-tsmorph-refactor-dev": {
"command": "node",
"args": ["/path/to/your/local/repo/dist/index.js"],
"env": {
"LOG_LEVEL": "debug"
}
}
}
}
Control the server's logging through environment variables in the env
block of your mcp.json
:
"env": {
"LOG_LEVEL": "debug",
"LOG_OUTPUT": "file",
"LOG_FILE_PATH": "/Users/yourname/logs/mcp-tsmorph.log"
}
Available options:
LOG_LEVEL
: fatal
, error
, warn
, info
(default), debug
, trace
, silent
LOG_OUTPUT
: console
(default) or file
LOG_FILE_PATH
: Path to log file when LOG_OUTPUT
is set to file
Renames a symbol (function, variable, class, interface, etc.) across the entire project:
{
"method": "rename_symbol_by_tsmorph",
"params": {
"tsconfigPath": "./tsconfig.json",
"filePath": "./src/components/Button.tsx",
"line": 10,
"column": 16,
"currentName": "ButtonProps",
"newName": "CustomButtonProps"
}
}
Renames multiple files and/or folders while updating all import/export paths:
{
"method": "rename_filesystem_entry_by_tsmorph",
"params": {
"tsconfigPath": "./tsconfig.json",
"renames": [
{ "oldPath": "./src/components/Button.tsx", "newPath": "./src/components/CustomButton.tsx" },
{ "oldPath": "./src/utils", "newPath": "./src/helpers" }
]
}
}
Locates all references to a symbol throughout the project:
{
"method": "find_references_by_tsmorph",
"params": {
"tsconfigPath": "./tsconfig.json",
"filePath": "./src/utils/formatDate.ts",
"line": 5,
"column": 14
}
}
Converts path aliases (like @/components
) to relative paths in imports/exports:
{
"method": "remove_path_alias_by_tsmorph",
"params": {
"tsconfigPath": "./tsconfig.json",
"targetPath": "./src/components"
}
}
Moves a symbol to a different file while updating all references:
{
"method": "move_symbol_to_file_by_tsmorph",
"params": {
"tsconfigPath": "./tsconfig.json",
"sourceFilePath": "./src/utils/helpers.ts",
"destinationFilePath": "./src/utils/date-helpers.ts",
"symbolName": "formatDate",
"declarationKindString": "function" // Optional, helps disambiguate symbols with the same name
}
}
For debugging issues with the MCP server, you can use the included wrapper script:
mcp.json
to use the debug wrapper:{
"mcpServers": {
"mcp-tsmorph-refactor": {
"command": "node",
"args": ["path/to/your_project_root/scripts/mcp_launcher.js"],
"env": {
"LOG_LEVEL": "debug"
}
}
}
}
.logs/mcp_launcher.log
for detailed debugging informationTo add this MCP server to Claude Code, run this command in your terminal:
claude mcp add-json "mcp-tsmorph-refactor" '{"command":"npx","args":["-y","@sirosuzume/mcp-tsmorph-refactor"],"env":[]}'
See the official Claude Code MCP documentation for more details.
There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json
file so that it is available in all of your projects.
If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json
file.
To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".
When you click that button the ~/.cursor/mcp.json
file will be opened and you can add your server like this:
{
"mcpServers": {
"mcp-tsmorph-refactor": {
"command": "npx",
"args": [
"-y",
"@sirosuzume/mcp-tsmorph-refactor"
],
"env": []
}
}
}
To add an MCP server to a project you can create a new .cursor/mcp.json
file or add it to the existing one. This will look exactly the same as the global MCP server example above.
Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.
The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.
You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.
To add this MCP server to Claude Desktop:
1. Find your configuration file:
~/Library/Application Support/Claude/claude_desktop_config.json
%APPDATA%\Claude\claude_desktop_config.json
~/.config/Claude/claude_desktop_config.json
2. Add this to your configuration file:
{
"mcpServers": {
"mcp-tsmorph-refactor": {
"command": "npx",
"args": [
"-y",
"@sirosuzume/mcp-tsmorph-refactor"
],
"env": []
}
}
}
3. Restart Claude Desktop for the changes to take effect