✨ From vibe coding to vibe deployment. UBOS MCP turns ideas into infra with one message.

Learn more

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:

  1. Automated Symbol Renaming: Renaming symbols (variables, functions, classes) across a large project can be a daunting task. The rename_symbol_by_tsmorph feature 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 getData needs to be renamed to fetchData for 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.
  2. Efficient File and Folder Renaming: Restructuring a project often involves renaming and moving files and folders. The rename_filesystem_entry_by_tsmorph feature 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/old is renamed to components/new. The MCP server automatically updates all import statements like import X from 'components/old/X' to import X from 'components/new/X', maintaining the project’s integrity.
  3. Comprehensive Reference Finding: Understanding where a symbol is used is crucial for debugging and refactoring. The find_references_by_tsmorph feature 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.
  4. Streamlined Path Alias Management: Path aliases (e.g., @/components) can improve code readability but may hinder portability. The remove_path_alias_by_tsmorph feature 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.

  1. Configuration: Add the following configuration to your mcp.json file:

    { “mcpServers”: { “mcp-tsmorph-refactor”: { “command”: “node”, “args”: [“/path/to/this/repo/dist/index.js”], “env”: {} } } }

  2. 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_tsmorph command 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:

  1. Clone the Repository:

    bash git clone https://github.com/sirosuzume/mcp-tsmorph-refactor.git cd mcp-tsmorph-refactor

  2. Install Dependencies:

    bash pnpm install

  3. Build the Project:

    bash pnpm build

  4. Run Tests:

    bash pnpm test

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

Featured Templates

View More
Verified Icon
AI Agents
AI Chatbot Starter Kit
1336 8300 5.0
Customer service
Service ERP
126 1188
Customer service
AI-Powered Product List Manager
153 867
AI Agents
AI Video Generator
252 2007 5.0
AI Engineering
Python Bug Fixer
119 1433

Start your free trial

Build your solution today. No credit card required.

Sign In

Register

Reset Password

Please enter your username or email address, you will receive a link to create a new password via email.