Skip to main content

MCP server exposing Martin Fowler's refactoring catalog to LLMs

Project description

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-cli for 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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mcp_refactoring-0.1.0.tar.gz (29.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mcp_refactoring-0.1.0-py3-none-any.whl (29.4 kB view details)

Uploaded Python 3

File details

Details for the file mcp_refactoring-0.1.0.tar.gz.

File metadata

  • Download URL: mcp_refactoring-0.1.0.tar.gz
  • Upload date:
  • Size: 29.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for mcp_refactoring-0.1.0.tar.gz
Algorithm Hash digest
SHA256 11ff158b0c628735bdaf86d773f4c64e7d36159e1c16819c6ceb7fc55e15c498
MD5 55d18ab18aeb45a58450ddef69b8f2d6
BLAKE2b-256 97db02cc40621bf3cfa47f46e4a1ad930c8d04bb70de78f8439caaef51be631b

See more details on using hashes here.

File details

Details for the file mcp_refactoring-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for mcp_refactoring-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ee6dc061225d02f5fdf00832ce5c025604f32dd8fa474756271a2e20b5780424
MD5 608134751a78b3f98ab558ce27c78763
BLAKE2b-256 a8326da37451b9f51eada506067decbd841d51093d77103eb85a3359254db59c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page