# Refactoring MCP Server

Hands your agent Martin Fowler's refactoring catalog: 71+ moves, dry-run previews and smell analysis on the code you point it at.

- MCP server · `type=mcp` · Claude Code, Codex, Cursor, GitHub Copilot, Windsurf (Devin Desktop), Cline, Zed, Gemini CLI · ★ 5
- Author: marshally
- License: MIT · policy=link-only · description only; the file stays with the author
- Source: https://github.com/marshally/mcp-refactoring
- Updated: 2025-11-29
- HTML: https://affpapa.org/en/nevibecode/mcp/refactoring-mcp-server

## What it does

The server registers five tools with your agent. `list_refactorings` returns the available moves and the parameters each one expects. `preview_refactoring` runs a change without touching the file, `apply_refactoring` writes it, `inspect_structure` reports how the code is laid out, and `analyze_code` flags smells and suggests what to do about them.

Targets follow each language's own notation: `src/order.py::Order::calculate_total` for a method, `src/order.py::Order` for a class, and `#L10-L15` to narrow it to a line range. Moves are grouped the way Fowler groups them — composing methods, moving features, simplifying conditionals and so on. Language backends are pluggable. You declare them in `~/.mcp-refactoring/config.toml` with a `command` and an `enabled` flag, and environment variables such as `MCP_REFACTORING_PYTHON_COMMAND` override those settings.

Python 3.10+ is required, plus a language backend — `molting-cli` for Python. No backend means nothing to apply the refactorings with. Python ships first; Ruby, Java and Go are planned.

## Requirements
- Needs: Python and uv (commands run via uvx)

## Install

### Claude Code (native platform)

**Platform CLI**
```bash
claude mcp add mcp-refactoring -- uvx mcp-refactoring
```
uvx runs the command named after the package; if the README names another one, use uvx --from mcp-refactoring <command>

### Codex

**Platform CLI**
```bash
codex mcp add refactoring-mcp-server -- uvx mcp-refactoring
```
uvx runs the command named after the package; if the README names another one, use uvx --from mcp-refactoring <command>

### Cursor

**Config file**
File `.cursor/mcp.json`:
```json
{
    "mcpServers": {
        "refactoring-mcp-server": {
            "command": "uvx",
            "args": [
                "mcp-refactoring"
            ]
        }
    }
}
```
uvx runs the command named after the package; if the README names another one, use uvx --from mcp-refactoring <command>

### GitHub Copilot

**Config file**
File `.vscode/mcp.json`:
```json
{
    "servers": {
        "refactoring-mcp-server": {
            "type": "stdio",
            "command": "uvx",
            "args": [
                "mcp-refactoring"
            ]
        }
    }
}
```
uvx runs the command named after the package; if the README names another one, use uvx --from mcp-refactoring <command>

### Gemini CLI

**Platform CLI**
```bash
gemini mcp add refactoring-mcp-server uvx mcp-refactoring
```
uvx runs the command named after the package; if the README names another one, use uvx --from mcp-refactoring <command>

## When to use it
- see what a refactoring changes before editing files
- pull a method out of a long class the Fowler way
- rename a method across the project without grep
- spot long methods and other smells in a file
- read a class structure before touching it

## Example prompts
- List the Python refactorings in the composing methods category
- Preview extract-method on `src/order.py::Order::calculate#L10-L15` with the name `calculate_tax`
- Apply rename-method to `src/order.py::Order::calc` with the new name `calculate_total`

## Similar
- [dry-refactoring](https://affpapa.org/en/nevibecode/skills/dry-refactoring.md) — skill · 3600 installs
- [refactoring-specialist](https://affpapa.org/en/nevibecode/skills/refactoring-specialist.md) — skill · 747 installs
- [code-refactoring](https://affpapa.org/en/nevibecode/skills/code-refactoring.md) — skill · 546 installs
- [refactoring-patterns](https://affpapa.org/en/nevibecode/skills/refactoring-patterns.md) — skill · 6300 installs
- [codebase-refactoring](https://affpapa.org/en/nevibecode/skills/codebase-refactoring.md) — skill · 613 installs
- [csharp-refactoring](https://affpapa.org/en/nevibecode/skills/csharp-refactoring.md) — skill · 1800 installs

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
