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.
generate_quality_report
What OHM-MCP Refactor does
Architecture, refactoring, tests & metrics in one serverDetect God Objects, circular dependencies, and SOLID violations, then get pattern suggestions and DI refactors with before/after examples.
Use extract_method_ast, dead‑code detection, import
refactoring, safe symbol renaming, and duplication detection to keep
the codebase small, modular, and DRY.
Analyze type‑hint coverage, generate .pyi stubs, and
auto‑create characterization tests so every refactor is guarded by
tests before edits land.
Catch nested loops, repeated work, mutable defaults, and other performance smells, then prioritize by coverage to refactor the riskiest code first.
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.
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.
Safely rename functions, classes, methods, and variables across the entire project with conflict detection and preview‑only mode before applying changes.
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.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"]
}
}
}
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"
]
}
}
}
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"
}
}
}
{
"mcpServers": {
"ohm-mcp-refactor": {
"command": "",
"args": ["/mcp_server.py"],
"cwd": ""
}
}
}
Typical workflows
Everything lives in chat + patch view
generate_characterization_tests → pytest → apply_refactoring → pytest
Lock in current behavior, then let OHM apply changes with backups and
automatic test runs.
detect_code_duplicates → review → extract_method_ast
Extract shared functions from repeated blocks and reduce DRY violations
across the codebase.
analyze_type_hints → follow plan → generate_type_stub
Gradually improve type coverage with prioritized hints and stub files
for legacy modules.
analyze_performance → prioritize_by_coverage → apply fixes
Focus optimization where complexity is high and tests are thin.
refactor_imports → rename_symbol → generate_characterization_tests
Safely move modules, rename public APIs, and verify all call sites and
tests still pass.
generate_quality_report(format="json")
Enforce minimum health scores in CI, block risky PRs, and track debt
reduction over time.
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.
generate_characterization_tests → analyze_type_hints → refactor_imports
Wrap brittle legacy modules with tests, types, and safer imports before
touching behavior.