TypeScript Refactoring MCP server

Enables AI to perform complex TypeScript/JavaScript refactoring operations like renaming symbols, moving code between files, and updating import paths through ts-morph's powerful code transformation capabilities.
Back to servers
Setup instructions
Provider
SiroSuzume
Release date
May 01, 2025
Language
JavaScript
Stats
9 stars

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.

Installation

Using the NPM Package

Add the MCP server configuration to your mcp.json file:

{
  "mcpServers": {
    "mcp-tsmorph-refactor": {
      "command": "npx",
      "args": ["-y", "@sirosuzume/mcp-tsmorph-refactor"],
      "env": {}
    }
  }
}

Running from Source

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"
      }
    }
  }
}

Logging Configuration

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

Usage

Rename Symbol

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"
  }
}

Rename Files or Folders

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" }
    ]
  }
}

Find References

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
  }
}

Remove Path Aliases

Converts path aliases (like @/components) to relative paths in imports/exports:

{
  "method": "remove_path_alias_by_tsmorph",
  "params": {
    "tsconfigPath": "./tsconfig.json",
    "targetPath": "./src/components"
  }
}

Move Symbol to Another File

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
  }
}

Debug Options

For debugging issues with the MCP server, you can use the included wrapper script:

  1. Update your 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"
      }
    }
  }
}
  1. Restart your MCP client
  2. Check the log file at .logs/mcp_launcher.log for detailed debugging information

How to install this MCP server

For Claude Code

To 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.

For Cursor

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.

Adding an MCP server to Cursor globally

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": []
        }
    }
}

Adding an MCP server to a project

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.

How to use the MCP server

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.

For Claude Desktop

To add this MCP server to Claude Desktop:

1. Find your configuration file:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json
  • Linux: ~/.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

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later