suggest_refactors
suggest_refactors
Section titled “suggest_refactors”Get prioritized, actionable refactoring recommendations based on architecture analysis. This tool identifies specific opportunities to improve your codebase structure, such as breaking cycles, splitting hub modules, fixing layer violations, and reducing coupling.
Parameters
Section titled “Parameters”| Parameter | Type | Required | Description |
|---|---|---|---|
project_path | string | Yes | Absolute or relative path to the project root directory |
edge_filter | string | No | Optional edge filter (reserved for future use) |
Current Response (placeholder)
Section titled “Current Response (placeholder)”Request:
{ "project_path": "."}Response:
Refactoring suggestions require full arxo. Analysis completed: 7 metrics in results.The tool runs the risk preset and confirms analysis completed, but doesn’t return structured refactoring recommendations.
Expected Response (when fully implemented)
Section titled “Expected Response (when fully implemented)”When implemented, this tool will return prioritized refactoring recommendations:
{ "recommendations": [ { "priority": "Critical|High|Medium|Low", "effort": "Low|Medium|High", "category": "string", "title": "string", "description": "string", "evidence": { "modules": ["string"], "metrics": { "key": "value" } }, "steps": ["string"] } ], "recommendations_count": "number"}Recommendation Categories
Section titled “Recommendation Categories”| Category | What it finds |
|---|---|
| Break circular dependencies | Identifies lowest-weight edges to cut (e.g., barrel imports, type-only imports) |
| Split hub modules | Suggests splitting modules with high fan-in + fan-out into smaller, cohesive units |
| Fix layer violations | Recommends dependency inversion or adapter patterns for upward-reaching imports |
| Move misplaced modules | Identifies modules with more connections to neighboring communities |
| Fix unstable dependencies | Suggests extracting interfaces when stable modules depend on unstable ones |
| Refactor high-churn hotspots | Highlights modules that change frequently and are tightly coupled |
Priority Levels
Section titled “Priority Levels”| Priority | When to act |
|---|---|
Critical | Immediate action — blocking issue (e.g., cycles preventing modular compilation) |
High | Address soon — significant technical debt or risk |
Medium | Planned refactoring — improvement opportunity |
Low | Optional — minor improvements or optimizations |
Effort Estimates
Section titled “Effort Estimates”| Effort | Typical scope |
|---|---|
Low | 1-4 hours — single module refactoring |
Medium | 1-3 days — multiple modules, moderate complexity |
High | 1-2 weeks — architectural change, many modules affected |
Expected Examples (when implemented)
Section titled “Expected Examples (when implemented)”Breaking a circular dependency
Section titled “Breaking a circular dependency”{ "priority": "Critical", "effort": "Low", "category": "Break circular dependencies", "title": "Break cycle between auth.ts and session.ts", "description": "A 2-module cycle exists between auth and session. Breaking this cycle will enable modular compilation and reduce coupling.", "evidence": { "modules": ["src/core/auth.ts", "src/core/session.ts"], "metrics": { "scc.max_cycle_size": 2, "ricci_curvature": -0.3 } }, "steps": [ "Extract shared types to src/core/auth-types.ts", "Make session.ts import from auth-types.ts instead of auth.ts", "Verify no cycle with `arxo analyze --preset quick`" ]}Splitting a hub module
Section titled “Splitting a hub module”{ "priority": "High", "effort": "Medium", "category": "Split hub modules", "title": "Split utils.ts (fan-in: 42, fan-out: 18)", "description": "utils.ts is a hub module with excessive dependencies. Split it into focused utilities to reduce coupling.", "evidence": { "modules": ["src/utils/utils.ts"], "metrics": { "centrality.module.max_fan_in": 42, "centrality.module.max_fan_out": 18, "centrality.module.betweenness_max": 0.62 } }, "steps": [ "Extract string utilities to src/utils/string.ts", "Extract array utilities to src/utils/array.ts", "Extract date utilities to src/utils/date.ts", "Update imports across codebase", "Verify betweenness reduced with `arxo analyze --preset quick`" ]}Fixing a layer violation
Section titled “Fixing a layer violation”{ "priority": "High", "effort": "Medium", "category": "Fix layer violations", "title": "Domain layer importing from presentation layer", "description": "Domain logic in src/domain/user.ts imports from src/presentation/formatters.ts, violating layer architecture.", "evidence": { "modules": ["src/domain/user.ts", "src/presentation/formatters.ts"], "metrics": { "layer_violations.violations_count": 1 } }, "steps": [ "Move formatting logic to src/domain/user-formatters.ts", "Update presentation layer to use domain formatters", "Apply Dependency Inversion Principle", "Verify no violations with `arxo analyze --preset ci`" ]}Workaround: Use CLI
Section titled “Workaround: Use CLI”Until this tool is fully implemented in the MCP server, use the CLI:
# Get refactoring recommendationsarxo analyze --preset full --format json > results.json
# Extract refactoring recommendationscat results.json | jq '.results[] | select(.id=="refactoring_recommendations")'Sample CLI output
Section titled “Sample CLI output”{ "id": "refactoring_recommendations", "version": "1.0.0", "values": {}, "findings": [ { "title": "Break cycle between auth.ts and session.ts", "severity": "error", "evidence": [ { "modules": ["src/core/auth.ts", "src/core/session.ts"], "priority": "Critical", "effort": "Low" } ] }, { "title": "Split hub module utils.ts", "severity": "warning", "evidence": [ { "module": "src/utils/utils.ts", "fan_in": 42, "fan_out": 18, "priority": "High", "effort": "Medium" } ] } ]}Workflow (when implemented)
Section titled “Workflow (when implemented)”Use this tool to plan refactoring efforts:
1. get_hotspots → identify problem areas2. suggest_refactors → get prioritized recommendations3. Sort by priority (Critical → High → Medium → Low)4. For each recommendation: a. Assess effort vs impact b. Create refactoring task/ticket c. Implement steps d. Verify improvement with check_cycles or analyze_architecture5. Re-run suggest_refactors to see remaining issuesSee Workflows: Hotspot detection and refactoring for context.
Error Cases
Section titled “Error Cases”| Error | Cause | Solution |
|---|---|---|
missing required parameter: project_path | project_path not provided | Include project_path in request |
Refactoring suggestions require full arxo | MCP server limitation | Use CLI: arxo analyze --preset full |
Performance
Section titled “Performance”- Current: 10-30 seconds (runs
riskpreset) - Expected (when implemented): 30-120 seconds (requires
fullpreset withrefactoring_recommendations)
Related Tools
Section titled “Related Tools”get_hotspots— Find hotspots before getting refactoring suggestionscheck_cycles— Verify cycle-breaking refactoringsanalyze_file_impact— Assess refactoring blast radius
Related Guides
Section titled “Related Guides”- Breaking Cycles — Step-by-step cycle refactoring
- Refactoring Patterns — Common refactoring strategies
- Refactoring Recommendations — Detailed metric documentation
CLI Equivalent (current solution)
Section titled “CLI Equivalent (current solution)”# This is the only way to get full refactoring suggestionsarxo analyze --preset full --format json | jq '.results[] | select(.id=="refactoring_recommendations")'Future Implementation
Section titled “Future Implementation”To fully implement this tool in the MCP server:
- Add
refactoring_recommendationsmetric toarxo-loader - Expose structured recommendation data via the tool
- Support filtering by priority, effort, or category
- Cache recommendations by project state
The metric already exists in the Pro engine — it just needs to be wired into the MCP tool handler.