MCP Refactoring
Enables LLMs to apply Martin Fowler's 71+ refactoring patterns to codebases through a pluggable, language-agnostic architecture. Supports previewing and applying refactorings, analyzing code smells, and inspecting code structure with safe-by-default operations.
README
mcp-refactoring
<!-- mcp-name: io.github.marshally/mcp-refactoring -->
An MCP (Model Context Protocol) server that exposes Martin Fowler's refactoring catalog to LLMs through a pluggable, language-agnostic architecture.
Features
- 71+ Refactorings: Full implementation of Martin Fowler's refactoring catalog
- Pluggable Architecture: Support for multiple languages (Python first, Ruby/Java/Go planned)
- Safe by Default: Preview mode shows changes before applying
- LLM-Optimized: TOON output format for token efficiency
Installation
# Using uvx (recommended)
uvx mcp-refactoring
# Using pip
pip install mcp-refactoring
# Using pipx
pipx install mcp-refactoring
Requirements
- Python 3.10+
- A language backend (e.g.,
molting-clifor Python)
Install the Python backend:
pip install molting-cli
Claude Desktop Configuration
Add to your Claude Desktop config:
{
"mcpServers": {
"refactoring": {
"command": "uvx",
"args": ["mcp-refactoring"]
}
}
}
Available Tools
list_refactorings
List available refactorings with their parameter contracts.
list_refactorings(language="python", category="composing_methods")
preview_refactoring
Preview what changes a refactoring would make (dry-run).
preview_refactoring(
refactoring="extract-method",
target="src/order.py::Order::calculate#L10-L15",
params={"name": "calculate_tax"}
)
apply_refactoring
Apply a refactoring to the codebase.
apply_refactoring(
refactoring="rename-method",
target="src/order.py::Order::calc",
params={"new_name": "calculate_total"}
)
inspect_structure
Get structural information about code.
inspect_structure(path="src/order.py", depth="method")
analyze_code
Analyze code for smells and suggest refactorings.
analyze_code(path="src/order.py", smells=["long-method"])
Target Specification
Each language uses its native conventions:
Python
src/order.py::Order::calculate_total # Method
src/order.py::Order::calculate_total#L10-L15 # Line range
src/order.py::Order # Class
Configuration
Create ~/.mcp-refactoring/config.toml:
[backends.python]
enabled = true
command = "molting"
[backends.ruby]
enabled = false
command = "molting-rb"
Environment variable overrides:
MCP_REFACTORING_PYTHON_COMMAND=/path/to/molting
MCP_REFACTORING_PYTHON_ENABLED=true
Refactoring Categories
Based on Martin Fowler's catalog:
- Composing Methods: extract-method, inline-method, etc.
- Moving Features: move-method, extract-class, etc.
- Organizing Data: encapsulate-field, replace-type-code, etc.
- Simplifying Conditionals: decompose-conditional, guard-clauses, etc.
- Simplifying Method Calls: rename-method, add-parameter, etc.
- Dealing with Generalization: pull-up-method, extract-interface, etc.
Development
# Clone the repository
git clone https://github.com/marshally/mcp-refactoring.git
cd mcp-refactoring
# Install in development mode
pip install -e ".[dev]"
# Run tests
pytest
# Run linter
ruff check .
# Run type checker
mypy src/
License
MIT License - see LICENSE for details.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。