Enables TypeScript-aware file and directory moves within a project by leveraging a persistent tsserver instance to automatically update imports and maintain project integrity.
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., "@ts-refactor-mcpmove src/utils.ts to src/lib/utils.ts and update all imports"
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.
ts-refactor-mcp
TypeScript-aware file refactoring for AI agents via the Model Context Protocol (MCP).
What is this?
An MCP server that enables AI coding agents to move TypeScript files while automatically updating all imports. When you move a file in VS Code, TypeScript's language server updates every import automatically. This tool exposes that same capability to AI agents through MCP.
The problem it solves: AI agents can move files, but they break imports. They either miss updates or waste tokens fixing them manually. This server does it correctly in one atomic operation.
Installation
Or install from source:
MCP Configuration
Add to your MCP client configuration (e.g., Claude Desktop):
Or use the built package:
Available Tools
moveFile
Move a TypeScript file and update all imports automatically.
Input:
Output (when applied):
Output (dry-run):
Example:
warmup
Pre-load a TypeScript project to speed up subsequent operations.
Input:
Output:
Why use this: First operation on a project takes 5-30 seconds while TypeScript loads. Call warmup at session start to pay this cost upfront. Subsequent operations complete in 10-100ms.
How it Works
Persistent tsserver: Keeps TypeScript's language server running between requests
Atomic operations: All import updates succeed or none do—no partial failures
Uses project's TypeScript: Spawns tsserver from your
node_modules/typescriptBattle-tested: Uses the same
getEditsForFileRenameAPI that VS Code uses
Performance
Initial warmup: 5-30 seconds (large projects)
Subsequent moves: 10-100ms
Memory: Persistent tsserver process (~100-500MB depending on project size)
Requirements
Node.js >= 18.0.0
TypeScript project with
tsconfig.jsonTypeScript installed in project's
node_modules
Development
Setup
Run Tests
Build
Project Structure
Architecture Decisions
Persistent tsserver Process
We keep tsserver running between requests. First request pays startup cost (5-30s), subsequent requests are fast (10-100ms). Without persistence, every move would reload the entire project.
Atomic Operations
All edits and the file move happen atomically. Either everything succeeds or nothing changes. This prevents broken intermediate states.
Project's Own TypeScript
We use the TypeScript version from your project's node_modules, not a global install. This ensures refactoring behavior matches your project's TypeScript version.
No State Management
When files change outside our server, we don't track it. If tsserver gets out of sync, call warmup again. Trying to maintain perfect sync is complex and unnecessary—tsserver handles file watching internally.
Limitations
TypeScript only: Requires
tsconfig.json(JavaScript-only projects not supported)One project at a time: One tsserver per tsconfig
No directory moves: Currently only supports single file moves
Cold starts: MCP server restart requires project warmup again
Future Enhancements
Potential future additions (not currently implemented):
moveDirectory: Move entire directories with all filesrenameSymbol: Rename a function/class across filesextractToFile: Move a function to a new fileMulti-root workspace support
JavaScript-only project support
Contributing
Pull requests welcome! Please:
Add tests for new functionality
Ensure all tests pass (
npm test)Follow existing code style
Update documentation
License
MIT
Credits
Built using:
@modelcontextprotocol/sdk - MCP protocol implementation
TypeScript's tsserver - Language service API