Refactor MCP
Refactor MCP is a powerful server and CLI tool for code refactoring and search that integrates with MCP clients like Claude Code.
Code Refactoring: Perform regex-based search and replace operations across files, with support for capture groups in replacement patterns for dynamic refactoring.
Code Search: Search for regex patterns in code, returning precise file locations and line numbers.
Advanced Filtering: Refine operations using context patterns (only replacing matches within specific contexts) and file glob patterns to limit scope.
Dual Operation Modes:
MCP Server Mode: Integrate with MCP-compatible clients for programmatic access
CLI Mode: Use directly from command line with features like dry-run (preview changes) and printing matched content
Integrates with ESLint for code quality checks through the npm run lint command
Integrates with Prettier for code formatting through the npm run format command
Built with TypeScript support, using the Model Context Protocol SDK for TypeScript
Provides testing capabilities through Vitest with comprehensive test coverage
Uses Zod schemas for type-safe input validation of parameters passed to the refactoring tools
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., "@Refactor MCPsearch for all console.log statements in the src directory"
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.
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 forreplace_pattern(string) - Replacement pattern (supports capture groups like $1, $2)context_pattern(string, optional) - Only replace matches within this contextfile_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 forcontext_pattern(string, optional) - Filter matches by surrounding contextfile_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)Related MCP server: LSP Tools MCP Server
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@latestCLI 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-runFor Development
# Clone and install dependencies
git clone https://github.com/myuon/refactor-mcp.git
cd refactor-mcp
npm installUsage
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-runThis prevents the shell from interpreting
$1as 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@latestDevelopment
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 testsMCP 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@latestManual 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
Install dependencies:
npm installRun tests:
npm testCheck code quality:
npm run checkBuild:
npm run build
License
MIT
Available Tools
2 toolscode_refactorCode RefactorC
Refactor code by replacing search pattern with replace pattern using regex
| Name | Required | Description | Default |
|---|---|---|---|
| context_pattern | No | Optional context pattern to filter matches | |
| file_pattern | No | Optional file glob pattern to limit search scope | |
| include_capture_groups | No | Include capture groups in the results | |
| include_matched_text | No | Include matched text in the results | |
| replace_pattern | Yes | Replacement pattern (can use $1, $2, etc. for capture groups) | |
| search_pattern | Yes | Regular expression pattern to search for |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions 'refactor code' which implies mutation/write operations, but doesn't specify whether this modifies files in-place, creates backups, requires confirmation, or has any safety mechanisms. It also doesn't describe error handling, performance implications, or what the tool returns. The description is too vague about the actual behavior beyond the basic operation.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
The description is extremely concise at just one sentence that directly states the core functionality. Every word earns its place: 'Refactor code' establishes the action, 'by replacing search pattern with replace pattern' explains the mechanism, and 'using regex' specifies the technology. There's no wasted verbiage or unnecessary elaboration.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
Given this is a mutation tool with 6 parameters, no annotations, and no output schema, the description is insufficiently complete. It doesn't explain what happens after refactoring (e.g., preview vs. apply, success/failure reporting), doesn't mention the optional parameters' purposes, and provides no safety warnings for a tool that modifies code. For a complex refactoring operation, more context is needed.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
Schema description coverage is 100%, so all parameters are documented in the schema. The description adds minimal value beyond the schema by mentioning 'regex' and 'search pattern with replace pattern', which aligns with the schema's 'search_pattern' and 'replace_pattern' parameters. However, it doesn't explain the relationship between parameters or provide usage examples that would help understand how they work together.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description clearly states the verb 'refactor' and the resource 'code', specifying it uses regex patterns for search and replace. It distinguishes from the sibling 'code_search' by indicating this is a modification operation rather than just searching. However, it doesn't specify what kind of refactoring (e.g., renaming, restructuring) or the scope beyond regex replacement.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
The description provides no guidance on when to use this tool versus alternatives. It doesn't mention the sibling 'code_search' tool, nor does it specify scenarios where regex-based refactoring is appropriate versus other refactoring methods. There's no information about prerequisites, limitations, or when not to use it.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
code_searchCode SearchB
Search for code patterns using regex and return file locations with line numbers
| Name | Required | Description | Default |
|---|---|---|---|
| context_pattern | No | Optional context pattern to filter matches | |
| file_pattern | No | Optional file glob pattern to limit search scope | |
| include_capture_groups | No | Include capture groups in the results | |
| include_matched_text | No | Include matched text in the results | |
| search_pattern | Yes | Regular expression pattern to search for |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
With no annotations provided, the description carries the full burden of behavioral disclosure. It states the tool searches and returns results, but lacks details on permissions, rate limits, error handling, or output format beyond file locations and line numbers, leaving gaps for a tool with 5 parameters.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
The description is a single, efficient sentence that front-loads the core purpose and outcome without unnecessary words, making it highly concise and well-structured.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
Given the complexity (5 parameters, no annotations, no output schema), the description is minimal but covers the basic purpose. It lacks details on behavioral traits and output specifics, making it adequate but incomplete for full agent understanding.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
Schema description coverage is 100%, so the schema fully documents all parameters. The description adds no additional meaning beyond what the schema provides, such as examples or usage tips for the parameters, meeting the baseline for high coverage.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description clearly states the specific action ('Search for code patterns using regex') and the resource ('code'), with the outcome ('return file locations with line numbers'). It distinguishes from the sibling tool 'code_refactor' by focusing on search rather than modification.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
No guidance is provided on when to use this tool versus alternatives like 'code_refactor'. The description mentions the search functionality but does not specify scenarios, prerequisites, or exclusions for its use.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections. Dates show when Glama detected each change.
2 tool updates
v1.0.0- First observed
code_refactor - First observed
code_search
TDQS
The two tools have clearly distinct purposes: code_refactor modifies code by replacing patterns, while code_search only finds patterns and returns locations. There is no overlap in functionality, making it impossible to confuse them.
Both tools follow a consistent verb_noun pattern with 'code_' as a prefix and descriptive suffixes ('refactor' and 'search'). The naming is uniform and predictable throughout the set.
With only 2 tools, the server feels thin for a 'Refactor MCP' domain. While the tools cover basic search and replace operations, typical refactoring workflows might require more operations like rename, extract method, or analyze dependencies, leaving the surface incomplete.
The toolset is severely incomplete for a refactoring domain. It lacks essential operations such as renaming identifiers, extracting functions or variables, analyzing code structure, or handling refactoring across multiple files. Agents will face dead ends when attempting complex refactoring tasks.
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Connectors
A comprehensive Model Context Protocol (MCP) server that enables AI assistants to interact with yo…
A Model Context Protocol server for Wix AI tools
The Mercado Pago MCP Server implements the Model Context Protocol to provide AI agents and LLMs with access to Mercado Pago's APIs and tools within compatible development environments. It acts as an intermediary that translates Mercado Pago resources into executable functions (tools) that AI applications can invoke to perform actions and automate flows. The server simplifies integration, enables using documentation to implement or improve code, and optimizes operations through natural language interactions without manual implementations.
An MCP server that gives your AI access to the source code and docs of all public github repos
Related MCP Servers
- AlicenseBqualityFmaintenanceA Model Context Protocol server that provides tools for code modification and generation via Large Language Models, allowing users to create, modify, rewrite, and delete files using structured XML instructions.122MIT
- AlicenseAqualityDmaintenanceA Model Context Protocol server that provides tools to find regex pattern positions in files and list allowed directories, enabling text analysis with LSP-like functionality.211MIT

CodeAlive MCPofficial
AlicenseNot gradedqualityAmaintenanceA Model Context Protocol server that enhances AI agents by providing deep semantic understanding of codebases, enabling more intelligent interactions through advanced code search and contextual awareness.89MIT- AlicenseAqualityBmaintenanceA robust, language-agnostic Model Context Protocol (MCP) server that provides AI coding agents with the ability to edit files surgically via Abstract Syntax Trees (AST) instead of relying on token-heavy, brittle search-and-replace or diff operations.288MIT
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/myuon/refactor-mcp'
If you have feedback or need assistance with the MCP directory API, please join our Discord server