UBOS Asset Marketplace: MCP Server for ts-morph Refactoring - Revolutionizing Code Management
In the rapidly evolving landscape of software development, maintaining code quality, consistency, and efficiency is paramount. The UBOS Asset Marketplace now features a powerful MCP (Model Context Protocol) Server, equipped with ts-morph refactoring tools, designed to transform how developers manage and refactor TypeScript and JavaScript codebases. This integration not only streamlines development workflows but also ensures that codebases remain maintainable and scalable over time.
What is MCP and Why ts-morph?
At its core, MCP standardizes how applications provide context to Large Language Models (LLMs). The MCP server acts as a crucial bridge, enabling AI models to access and interact with external data sources and tools. This is especially valuable in complex software projects where understanding the codebase’s context is essential for effective refactoring and maintenance.
Ts-morph, a TypeScript compiler API wrapper, provides an abstract syntax tree (AST) representation of TypeScript and JavaScript code. By leveraging ts-morph, the MCP server can perform sophisticated code analysis and transformations with a high degree of precision and safety. This AST-based approach ensures that changes are semantically correct, preserving the integrity of the codebase.
Use Cases: Transforming Development Workflows
The MCP Server with ts-morph refactoring tools addresses several critical use cases in modern software development:
Automated Symbol Renaming: Renaming symbols (variables, functions, classes) across a large project can be a daunting task. The
rename_symbol_by_tsmorphfeature automates this process, ensuring that all references to a symbol are updated consistently, eliminating the risk of errors and inconsistencies.- Scenario: Imagine a function named
getDataneeds to be renamed tofetchDatafor clarity. Manually updating this across hundreds of files would be time-consuming and error-prone. The MCP server automates this, ensuring every instance is correctly updated.
- Scenario: Imagine a function named
Efficient File and Folder Renaming: Restructuring a project often involves renaming and moving files and folders. The
rename_filesystem_entry_by_tsmorphfeature not only renames the files but also updates all import and export statements that reference them. This ensures that the project remains functional after the restructuring.- Scenario: A directory
components/oldis renamed tocomponents/new. The MCP server automatically updates all import statements likeimport X from 'components/old/X'toimport X from 'components/new/X', maintaining the project’s integrity.
- Scenario: A directory
Comprehensive Reference Finding: Understanding where a symbol is used is crucial for debugging and refactoring. The
find_references_by_tsmorphfeature provides a comprehensive list of all references to a given symbol, allowing developers to quickly assess the impact of changes.- Scenario: Before modifying a critical function, developers need to know all the places it is used. This feature provides an exhaustive list, enabling informed decisions.
Streamlined Path Alias Management: Path aliases (e.g.,
@/components) can improve code readability but may hinder portability. Theremove_path_alias_by_tsmorphfeature replaces these aliases with relative paths, making the codebase more portable and compliant with specific coding standards.- Scenario: A project using path aliases needs to be made compatible with a system that doesn’t support them. This feature automates the conversion to relative paths, ensuring compatibility.
Key Features: Powering Code Transformation
The MCP Server offers a suite of features designed to enhance code management and refactoring:
- AST-Based Refactoring: Leveraging ts-morph, the server performs refactoring operations based on the Abstract Syntax Tree (AST) of the code. This ensures semantic correctness and prevents unintended side effects.
- Project-Wide Consistency: Changes are applied consistently across the entire project, maintaining code integrity and reducing the risk of errors.
- Automated Import/Export Updates: When files or folders are renamed, all related import and export statements are automatically updated, saving developers time and effort.
- Path Alias Handling: The server supports path aliases, allowing developers to use them in their code while providing the option to convert them to relative paths when needed.
- Collision Detection: Before renaming files or folders, the server checks for path collisions, preventing errors and ensuring that the operation is safe.
- Performance Optimization: The server is designed to handle large projects efficiently, minimizing the time required for refactoring operations.
Seamless Integration with UBOS Platform
The MCP Server for ts-morph refactoring tools seamlessly integrates with the UBOS platform, providing a comprehensive solution for AI-powered code management. UBOS focuses on bringing AI Agents to every business department. Our platform helps you orchestrate AI Agents, connect them with your enterprise data, build custom AI Agents with your LLM model, and create Multi-Agent Systems.
Integrating the MCP Server into Your Workflow
To begin using the MCP Server, you’ll need to configure it within your mcp.json file. This involves specifying the server’s name, command, arguments, and environment variables. Once configured, the server can be accessed through editors and IDEs that support the MCP protocol, such as Cursor.
Configuration: Add the following configuration to your
mcp.jsonfile:{ “mcpServers”: { “mcp-tsmorph-refactor”: { “command”: “node”, “args”: [“/path/to/this/repo/dist/index.js”], “env”: {} } } }
Usage: Once the server is running, you can use it through your editor or IDE. For example, in Cursor, you can trigger the
rename_symbol_by_tsmorphcommand by selecting a symbol and choosing the “Rename Symbol” option.
For Developers: Extending and Customizing the MCP Server
The MCP Server is designed to be extensible, allowing developers to add new refactoring features and customize existing ones. The server is built using Node.js and ts-morph, making it easy to understand and modify.
To get started with development, follow these steps:
Clone the Repository:
bash git clone https://github.com/sirosuzume/mcp-tsmorph-refactor.git cd mcp-tsmorph-refactor
Install Dependencies:
bash pnpm install
Build the Project:
bash pnpm build
Run Tests:
bash pnpm test
Lint and Format Code:
bash pnpm lint pnpm lint:fix pnpm format
Conclusion: Elevating Code Management with AI
The MCP Server with ts-morph refactoring tools represents a significant advancement in code management and refactoring. By leveraging the power of AI and AST-based analysis, it automates complex tasks, reduces errors, and improves code quality. As part of the UBOS Asset Marketplace, this server empowers developers to build and maintain robust, scalable, and maintainable software projects.
Whether you’re refactoring a large codebase, restructuring a project, or simply trying to improve code quality, the MCP Server provides the tools you need to succeed. Embrace the future of code management with UBOS and the MCP Server for ts-morph refactoring tools.
ts-morph Refactoring Server
Project Details
- SiroSuzume/mcp-ts-morph
- MIT License
- Last Updated: 5/1/2025
Recomended MCP Servers
A Model Context Protocol (MCP) server that enables secure interaction with MySQL databases
makes the jewish library accessible to LLMs through the MCP protocol
这是一个针对于MySQL开发的MCP,该项目旨在帮助用户快速且精确的查询MySQL数据库中的内容
A MCP server for BNB Chain that supports BSC, opBNB, Greenfield, and other popular EVM-compatible networks.
MCP server provide JijModeling Assistant Tools
MCP server that enhances Claude's reasoning capabilities by integrating DeepSeek R1's advanced reasoning engine
A powerful MCP tool for parsing and manipulating MIDI files based on Tone.js. This library leverages the Model...
A browser extension and MCP server that allows you to interact with the browser you are using.
Context7 MCP Server -- Up-to-date code documentation for LLMs and AI code editors





