developer-tools

Refactor

myuon

by myuon

Refactor enables regex-based code refactoring for bulk search-and-replace, pattern matching, and large-scale code transf

Provides regex-based code refactoring capabilities for bulk search-and-replace operations across file systems with pattern matching, context filtering, and glob-based file discovery to enable large-scale code transformations and migrations.

github stars

6

0 commentsdiscussion

Both formats append explainx.ai attribution and the canonical URL for this MCP server listing.

Context-aware replacementsSupports capture groups in regex patternsGlob-based file filtering

best for

  • / Large-scale codebase migrations and refactoring
  • / Renaming functions or variables across multiple files
  • / Updating import statements and API calls
  • / Code cleanup and standardization tasks

capabilities

  • / Search for code patterns using regex across files
  • / Replace code patterns with capture group support
  • / Filter operations by file type using glob patterns
  • / Apply changes only within specific code contexts
  • / Find exact line numbers for pattern matches

what it does

Performs regex-based search and replace operations across multiple files in your codebase. Helps automate large-scale code refactoring and migrations with pattern matching and context filtering.

about

Refactor is a community-built MCP server published by myuon that provides AI assistants with tools and capabilities via the Model Context Protocol. Refactor enables regex-based code refactoring for bulk search-and-replace, pattern matching, and large-scale code transf It is categorized under developer tools. This server exposes 2 tools that AI clients can invoke during conversations and coding sessions.

how to install

You can install Refactor in your AI client of choice. Use the install panel on this page to get one-click setup for Cursor, Claude Desktop, VS Code, and other MCP-compatible clients. This server runs locally on your machine via the stdio transport.

license

MIT

Refactor is released under the MIT license. This is a permissive open-source license, meaning you can freely use, modify, and distribute the software.

readme

refactor-mcp

A Model Context Protocol (MCP) server that provides powerful refactoring tools for Coding Agents. It can run in two modes:

  • MCP Server Mode (default): Integrates with MCP-compatible clients like Claude Code
  • CLI Mode: Direct command-line usage for standalone refactoring tasks

Features

This MCP server implements two main tools to assist with code refactoring:

🔧 code_refactor

Performs regex-based search and replace operations across files with advanced filtering capabilities.

Parameters:

  • search_pattern (string) - Regular expression pattern to search for
  • replace_pattern (string) - Replacement pattern (supports capture groups like $1, $2)
  • context_pattern (string, optional) - Only replace matches within this context
  • file_pattern (string, optional) - Glob pattern to limit files (e.g., *.js, src/**/*.ts)

Example:

// Replace foo() calls with bar() calls
code_refactor("foo\((.+)\)", "bar($1)")

// Before: let k = foo(1,2,3);
// After:  let k = bar(1,2,3);

Context-aware refactoring:

// Only replace "legacy_sdk" within import statements
code_refactor("legacy_sdk", "brand_new_sdk", "import")

🔍 code_search

Searches for regex patterns and returns file locations with precise line numbers.

Parameters:

  • search_pattern (string) - Regular expression pattern to search for
  • context_pattern (string, optional) - Filter matches by surrounding context
  • file_pattern (string, optional) - Glob pattern to limit search scope

Example:

code_search("foo\(.+\)")

// Result:
// ./src/utils.js (line: 15)
// ./src/helpers.ts (lines: 23-27)

Installation

Quick Start

MCP Server Mode (for Claude Code and other MCP clients):

# Install globally for MCP integration
npm install -g @myuon/refactor-mcp

# Or use with npx (recommended for MCP clients)
npx @myuon/refactor-mcp@latest

CLI Mode (for direct command-line usage):

# Search for patterns
npx @myuon/refactor-mcp@latest cli search -p "function.*\(" -f "src/**/*.js"

# Refactor with preview
npx @myuon/refactor-mcp@latest cli refactor -s "const (\w+)" -r "let \$1" --dry-run

For Development

# Clone and install dependencies
git clone https://github.com/myuon/refactor-mcp.git
cd refactor-mcp
npm install

Usage

CLI Mode

You can use the refactor tools directly from the command line by adding cli after the main command:

# Search for patterns
refactor-mcp cli search -p "function (.*) \{" -f "src/**/*.ts"

# Search with matched content display
refactor-mcp cli search -p "function (.*) \{" -f "src/**/*.ts" --print

# Refactor with dry-run (preview changes)
refactor-mcp cli refactor -s "const (\w+) = " -r "let \$1 = " --dry-run

# Refactor with matched content display
refactor-mcp cli refactor -s "const (\w+) = " -r "let \$1 = " --print --dry-run

# Refactor with file pattern
refactor-mcp cli refactor -s "old_function" -r "new_function" -f "src/**/*.js"

# Context-aware refactoring
refactor-mcp cli refactor -s "legacy_sdk" -r "new_sdk" -c "import" -f "src/**/*.ts"

CLI Commands:

  • search - Search for code patterns
    • -p, --pattern <pattern> - Regular expression pattern to search for
    • -c, --context <context> - Optional context pattern to filter matches
    • -f, --files <files> - Optional file glob pattern to limit search scope
    • --print - Print matched content to stdout
    • --matched - Show only matched text with capture groups
  • refactor - Refactor code with regex replacement
    • -s, --search <search> - Regular expression pattern to search for
    • -r, --replace <replace> - Replacement pattern (supports $1, $2, etc.)
    • -c, --context <context> - Optional context pattern to filter matches
    • -f, --files <files> - Optional file glob pattern to limit search scope
    • --dry-run - Preview changes without modifying files
    • --print - Print matched content and replacements to stdout

Important Notes:

  • When using capture groups in replacement patterns on the command line, escape the dollar sign: \$1, \$2, etc.
  • Example: refactor-mcp cli refactor -s "const (\w+) = " -r "let \$1 = " --dry-run
  • This prevents the shell from interpreting $1 as a shell variable

MCP Server Mode (Default)

By default, refactor-mcp runs as an MCP server via stdio transport:

# Run as MCP server (default mode)
refactor-mcp

# Or explicitly with npx
npx @myuon/refactor-mcp@latest

Development

npm run dev          # Run server in development mode
npm run dev:cli      # Run CLI in development mode with arguments
npm run cli          # Run CLI directly (for testing)
npm run build        # Build for production
npm start            # Run built server (MCP mode)

Code Quality

npm run check        # Run all quality checks
npm run lint         # Run ESLint
npm run format       # Format code with Prettier
npm test             # Run tests

MCP Integration

This server uses the Model Context Protocol to communicate with compatible clients. It runs via stdio transport and can be integrated into any MCP-compatible environment.

Claude Code Integration

For Claude Code users, you can easily add this MCP server with:

claude mcp add refactor npx @myuon/refactor-mcp@latest

Manual Configuration

Add to your MCP client configuration:

{
  "mcpServers": {
    "refactor-mcp": {
      "command": "npx",
      "args": ["@myuon/refactor-mcp@latest"]
    }
  }
}

Alternative Configuration (Local Installation)

{
  "mcpServers": {
    "refactor-mcp": {
      "command": "refactor-mcp"
    }
  }
}

Architecture

  • Framework: Model Context Protocol SDK for TypeScript
  • Runtime: Node.js with ES modules
  • Validation: Zod schemas for type-safe input validation
  • File Operations: Native fs module with glob pattern matching
  • Testing: Vitest with comprehensive test coverage

Contributing

  1. Install dependencies: npm install
  2. Run tests: npm test
  3. Check code quality: npm run check
  4. Build: npm run build

License

MIT

FAQ

What is the Refactor MCP server?
Refactor is a Model Context Protocol (MCP) server profile on explainx.ai. MCP lets AI hosts (e.g. Claude Desktop, Cursor) call tools and resources through a standard interface; this page summarizes categories, install hints, and community ratings.
How do MCP servers relate to agent skills?
Skills are reusable instruction packages (often SKILL.md); MCP servers expose live capabilities. Teams frequently combine both—skills for workflows, MCP for APIs and data. See explainx.ai/skills and explainx.ai/mcp-servers for parallel directories.
How are reviews shown for Refactor?
This profile displays 36 aggregated ratings (sample rows for discoverability plus signed-in user reviews). Average score is about 4.6 out of 5—verify behavior in your own environment before production use.

Use Cases

Extended AI Capabilities

Add new capabilities to Claude beyond text generation

Example

Access external data sources, execute code, interact with tools and services

Transform Claude from chatbot to action-taking agent

Context Enhancement

Provide Claude with access to relevant context and data

Example

Load project documentation, access knowledge bases, query databases

Get more accurate, context-aware responses

Workflow Automation

Automate multi-step workflows combining AI and external tools

Example

Research → Summarize → Create document → Send notification

Complete complex tasks end-to-end without manual steps

Implementation Guide

Prerequisites

  • Claude Desktop 0.7.0+ or Cursor IDE with MCP support
  • Basic understanding of MCP architecture and capabilities
  • Access credentials for integrated services (if required)
  • Willingness to experiment and iterate on configuration

Time Estimate

15-60 minutes depending on server complexity

Installation Steps

  1. 1.Install MCP server: npm install -g [package-name] or via GitHub
  2. 2.Add server configuration to ~/.claude/mcp.json
  3. 3.Provide required credentials and configuration
  4. 4.Restart Claude Desktop to load new server
  5. 5.Test basic functionality with simple prompts
  6. 6.Explore capabilities and experiment with use cases
  7. 7.Document successful patterns for reuse

Troubleshooting

  • MCP server not loading: Check config syntax, verify installation
  • Connection errors: Check network, firewall, credentials
  • Feature not working: Read server docs, check required parameters
  • Performance issues: Monitor resource usage, check for network latency
  • Conflicts with other servers: Check port assignments, namespace collisions

Best Practices

✓ Do

  • +Read server documentation thoroughly before setup
  • +Start with simple use cases to validate functionality
  • +Test in non-production environment first
  • +Monitor resource usage and performance
  • +Keep servers updated for bug fixes and new features
  • +Document configuration for team members
  • +Use environment variables for sensitive configuration

✗ Don't

  • Don't grant overly permissive access to MCP servers
  • Don't skip reading security considerations in docs
  • Don't expose sensitive data without proper controls
  • Don't run untrusted MCP servers without code review
  • Don't ignore error messages—investigate root cause

💡 Pro Tips

  • Combine multiple MCP servers for powerful workflows
  • Create custom MCP servers for your specific needs
  • Share successful configurations with team
  • Use MCP inspector for debugging
  • Join MCP community for tips and troubleshooting

Technical Details

Architecture

Model Context Protocol standardizes how AI hosts (Claude, Cursor) communicate with external tools and data sources through server implementations.

Protocols

  • Model Context Protocol (MCP)
  • JSON-RPC 2.0
  • stdio or HTTP transport

Compatibility

  • Claude Desktop
  • Cursor IDE
  • Custom MCP clients

When to Use This

✓ Use When

Use when you need Claude to access external data, execute actions, or integrate with tools. Best for extending AI capabilities beyond conversation.

✗ Avoid When

Avoid when native integrations exist (use official APIs directly), for real-time critical systems, or when security/compliance requires zero external dependencies.

Integration

  • Tool composition: Chain multiple MCP tools in workflows
  • Context augmentation: Provide AI with relevant external data
  • Action delegation: Let AI execute tasks on external systems
  • Bidirectional sync: Keep AI context and external systems in sync

Discussion

Product Hunt–style comments (not star reviews)
  • No comments yet — start the thread.

List & Promote Your MCP Server

Share your MCP server with the developer community

GET_STARTED →
MCP server reviews

Ratings

4.636 reviews
  • Amina Mehta· Dec 20, 2024

    Refactor is among the better-indexed MCP projects we tried; the explainx.ai summary tracks the official description.

  • Ira Ndlovu· Dec 8, 2024

    Refactor has been reliable for tool-calling workflows; the MCP profile page is a good permalink for internal docs.

  • Dhruvi Jain· Dec 4, 2024

    Strong directory entry: Refactor surfaces stars and publisher context so we could sanity-check maintenance before adopting.

  • Tariq Jain· Dec 4, 2024

    Strong directory entry: Refactor surfaces stars and publisher context so we could sanity-check maintenance before adopting.

  • Maya Khanna· Nov 27, 2024

    Refactor is a well-scoped MCP server in the explainx.ai directory — install snippets and categories matched our Claude Code setup.

  • Oshnikdeep· Nov 23, 2024

    Refactor is among the better-indexed MCP projects we tried; the explainx.ai summary tracks the official description.

  • Layla Jackson· Nov 23, 2024

    Refactor is among the better-indexed MCP projects we tried; the explainx.ai summary tracks the official description.

  • Yusuf Tandon· Nov 3, 2024

    Useful MCP listing: Refactor is the kind of server we cite when onboarding engineers to host + tool permissions.

  • Yusuf Gupta· Oct 22, 2024

    Refactor reduced integration guesswork — categories and install configs on the listing matched the upstream repo.

  • Yusuf Lopez· Oct 18, 2024

    We wired Refactor into a staging workspace; the listing’s GitHub and npm pointers saved time versus hunting across READMEs.

showing 1-10 of 36

1 / 4