New AI refactoring assistant for your IDE

Ship safer refactors without leaving chat.

OHM MCP Refactor plugs into GitHub Copilot, Cursor, and Cline to analyze your Python code, design refactors, apply them with backups, and run tests—driven by the Model Context Protocol.

Live in your local repo ⚙️ MCP · No cloud data upload 🧪 Test‑first, rollback‑safe refactors
Real‑time IDE integration Host: MCP
GitHub Copilot Chat Cursor IDE Cline (VS Code)
MCP connected
🧠 AST‑based analysis
✅ Dry‑run & rollback
Code Health Snapshot from generate_quality_report
85
Health / 100
📊 Type coverage: 67% 🗑️ Dead code issues: 23 ⚡ Perf hotspots: 6 📋 Duplicated lines: 140 🔁 Safe refactors: Backups + tests

What OHM-MCP Refactor does

Architecture, refactoring, tests & metrics in one server
🏗 Architecture & design God objects · SOLID

Detect God Objects, circular dependencies, and SOLID violations, then get pattern suggestions and DI refactors with before/after examples.

🔧 Code refactoring AST‑true

Use extract_method_ast, dead‑code detection, import refactoring, safe symbol renaming, and duplication detection to keep the codebase small, modular, and DRY.

📊 Type safety & tests

Analyze type‑hint coverage, generate .pyi stubs, and auto‑create characterization tests so every refactor is guarded by tests before edits land.

⚡ Performance hotspots

Catch nested loops, repeated work, mutable defaults, and other performance smells, then prioritize by coverage to refactor the riskiest code first.

🤖 Automated, reversible execution

apply_refactoring runs a dry‑run, creates backups, applies patches, runs tests, and rolls back automatically on failure. show_refactoring_history and rollback_refactoring keep a full audit trail.

📈 Quality dashboard

generate_quality_report emits HTML, Markdown, and JSON dashboards with health score, technical‑debt points, and drill‑down metrics—ready for CI, PRs, and retros.

🧬 Project‑wide symbol ops

Safely rename functions, classes, methods, and variables across the entire project with conflict detection and preview‑only mode before applying changes.

📦 Safer module migrations

Refactor imports when you move or rename modules, keeping all call sites in sync while your test suite and quality reports guard against regressions.

Works where you code

Use the same MCP server across multiple IDEs
GitHub Copilot (VS Code)
Add to .vscode/mcp.json and call tools directly from Copilot Chat with #ohm-mcp-refactor.
{
  "servers": {
    "ohm-mcp-refactor": {
      "command": "python",
      "args": ["${workspaceFolder}/mcp_server.py"]
    }
  }
}
Cursor IDE
Register in Cursor MCP settings using your Python path and mcp_server.py. Tools appear in the AI sidebar.
{
  "mcpServers": {
    "ohm-mcp-refactor": {
      "command": "/path/to/python",
      "args": [
        "${workspaceFolder}/ohm-mcp-refactor/mcp_server.py"
      ]
    }
  }
}
Cline (VS Code)
Configure absolute command and cwd in Cline's MCP servers. Use OHM as your refactoring agent.
{
  "mcpServers": {
    "ohm-mcp-refactor": {
      "command": "/path/to/python",
      "args": ["mcp_server.py"],
      "cwd": "/abs/path/to/ohm-mcp-refactor"
    }
  }
}
Any MCP‑compatible host
Point any MCP‑aware assistant at the same server for a consistent refactoring toolbox across environments.
{
  "mcpServers": {
    "ohm-mcp-refactor": {
      "command": "",
      "args": ["/mcp_server.py"],
      "cwd": ""
    }
  }
}

Typical workflows

Everything lives in chat + patch view
🧪 Safe refactor loop

generate_characterization_tests → pytest → apply_refactoring → pytest
Lock in current behavior, then let OHM apply changes with backups and automatic test runs.

📋 Eliminate duplication

detect_code_duplicates → review → extract_method_ast
Extract shared functions from repeated blocks and reduce DRY violations across the codebase.

📊 Type‑hint migration

analyze_type_hints → follow plan → generate_type_stub
Gradually improve type coverage with prioritized hints and stub files for legacy modules.

⚡ Performance hardening

analyze_performance → prioritize_by_coverage → apply fixes
Focus optimization where complexity is high and tests are thin.

📦 Module & API reshapes

refactor_imports → rename_symbol → generate_characterization_tests
Safely move modules, rename public APIs, and verify all call sites and tests still pass.

📈 CI quality gate

generate_quality_report(format="json")
Enforce minimum health scores in CI, block risky PRs, and track debt reduction over time.

🧵 Large feature refactor

generate_quality_report → plan_refactors → apply_refactoring
Take a whole feature slice, design a sequence of refactors, and apply them with test gates at each step.

🛡️ Legacy code hardening

generate_characterization_tests → analyze_type_hints → refactor_imports
Wrap brittle legacy modules with tests, types, and safer imports before touching behavior.