Skip to content

refactor: consolidate MCP tools to match CLI from PR #280#292

Merged
carlos-alm merged 4 commits intomainfrom
refactor/consolidate-mcp-tools
Mar 3, 2026
Merged

refactor: consolidate MCP tools to match CLI from PR #280#292
carlos-alm merged 4 commits intomainfrom
refactor/consolidate-mcp-tools

Conversation

@carlos-alm
Copy link
Contributor

Summary

  • Remove explain tool → folded into audit with quick boolean param (calls explainData when true)
  • Remove hotspots tool → folded into triage with level enum (function | file | directory); file/directory delegates to hotspotsData
  • Remove manifesto tool → folded into check with manifesto-mode routing: no ref/staged → runs manifesto rules; rules flag runs both diff predicates + manifesto
  • Add standalone path tool with from/to required params (was only accessible via query mode=path, which still works for backward compat)

Net tool count: 34 → 31 (removed 3, added 1). All backing data functions unchanged.

Mirrors the CLI consolidation from #280 which removed explain, hotspots, manifesto, path (standalone), and batch-query CLI commands.

Test plan

  • npx biome check src/mcp.js tests/unit/mcp.test.js — lint clean
  • npx vitest run tests/unit/mcp.test.js — 37/37 pass (updated ALL_TOOL_NAMES, added path/audit/triage/check schema tests)
  • npx vitest run tests/unit/ — 566/566 pass
  • npx vitest run tests/integration/ — 474/474 pass
  • node src/cli.js diff-impact --staged -T — blast radius: 1 function changed (startMCPServer), 1 transitive caller

Add Phase 2.7 (Deep Analysis & Graph Enrichment) covering all features
shipped since the last review: dataflow analysis, intraprocedural CFG,
AST node storage, expanded node/edge types (13 kinds, 9 edge kinds),
extractors refactoring, CLI consolidation, interactive viewer, exports
command, and normalizeSymbol utility.

Update Phase 3 priorities: add unified AST analysis framework as new #1
critical item (5,193 lines of parallel AST walking across complexity/
CFG/dataflow/ast with no shared infrastructure). Update all metrics
across Phase 3 items (50 modules, 26K lines, 13 tables, 34 MCP tools).
Mark qualified names as partially addressed (parent_id + contains edges).
Subsume standalone complexity decomposition into AST framework.

Update Phase 4 type definitions with new kind/edge type hierarchies.
Mark Phase 9.1 visualization as partially complete (plot command).
- Update extractor line counts from 2,299 to actual 3,023 (verified via wc -l)
- Fix individual per-file counts in both ROADMAP.md and architecture.md
- Remove duplicate section 3.8 numbering for strikethrough/subsumed item
Remove 3 redundant MCP tools and add 1 new tool to mirror the CLI
consolidation done in PR #280:

- Remove `explain` tool → fold into `audit` with `quick` param
- Remove `hotspots` tool → fold into `triage` with `level` param
- Remove `manifesto` tool → fold into `check` with manifesto-mode routing
- Add standalone `path` tool (was only accessible via query mode=path)

All backing data functions are unchanged. The `query` tool still supports
mode=path for backward compatibility.

Impact: 1 functions changed, 1 affected
@claude
Copy link

claude bot commented Mar 3, 2026

Claude finished @carlos-alm's task —— View job


Reviewing PR #292: MCP tools consolidation

Review Progress

  • Phase 1: Root Cause Analysis - Understand problem and approach
  • Phase 2: Configuration Change Detection - Check for risky changes
  • Phase 3: Test Integrity - Verify test quality maintained
  • Phase 4: Code Quality Review - Examine implementation details
  • Final Assessment - Provide rating and recommendation

Analysis Results

Phase 1: Root Cause Analysis ✅

Problem Being Solved: This PR consolidates MCP tools to mirror CLI consolidation from PR #280, which removed redundant CLI commands by folding functionality into existing commands.

Why This Approach: Maintains consistency between CLI and MCP interfaces. Rather than having separate explain, hotspots, manifesto tools, functionality is accessed through parameters on consolidated tools (audit --quick, triage --level, check with manifesto routing).

Architectural Justification: Sound approach - reduces API surface while preserving all functionality. Backward compatibility is maintained via parameter routing.

Phase 2: Configuration Change Detection ✅

No High-Risk Changes Detected:

  • No linting rules relaxed or disabled
  • No test timeouts increased
  • No coverage thresholds lowered
  • No TypeScript strict mode changes
  • All changes are purely functional consolidation

Phase 3: Test Integrity ✅

Test Coverage Analysis:

  • ✅ Test file properly updated to reflect new tool count (34→31)
  • ✅ Added tests for new path tool schema validation
  • ✅ Added tests for consolidated tool parameters (audit.quick, triage.level, check manifesto routing)
  • ✅ ALL_TOOL_NAMES updated to reflect removed tools
  • ✅ No weakened assertions or test relaxation
  • ✅ Author claims 37/37 MCP tests pass, plus 566/566 unit and 474/474 integration

Test Quality: Excellent - comprehensive schema validation for all consolidated tools.

Phase 4: Code Quality Review ✅

Implementation Analysis (src/mcp.js:1206-1352):

audit tool consolidation: Clean quick parameter routing

if (args.quick) {
  result = explainData(args.target, dbPath, { /* options */ });
} else {
  const { auditData } = await import('./audit.js');
  result = auditData(args.target, dbPath, { /* full options */ });
}

triage tool consolidation: Proper hotspots delegation

if (args.level === 'file' || args.level === 'directory') {
  const { hotspotsData } = await import('./structure.js');
  // Correctly maps 'risk' sort to 'fan-in' for hotspots
  const metric = args.sort === 'risk' ? 'fan-in' : args.sort;
}

check tool consolidation: Sophisticated manifesto routing

  • No ref/staged → manifesto rules only
  • With ref/staged → diff predicates only
  • With ref/staged + rules flag → both

New path tool: Clean extraction from query mode with proper required params

Backward Compatibility: Perfect - query tool still supports mode=path parameter.

Code Quality: High - clean separation of concerns, proper lazy imports, consistent error handling.

Root Cause Analysis

Problem Being Solved: Maintaining consistency between CLI and MCP interfaces after CLI consolidation in PR #280. The CLI removed redundant commands by folding functionality into existing commands with parameters.

Why This Approach: The consolidation reduces API surface area while preserving all functionality. This is a principled refactoring that eliminates duplicate endpoints without losing capabilities.

Risk Assessment: Low risk - purely structural changes with comprehensive test coverage and backward compatibility preservation.

Critical Concerns

None identified. This is a well-executed refactoring that:

  • Maintains all existing functionality
  • Preserves backward compatibility
  • Has excellent test coverage
  • Follows consistent patterns established in the CLI consolidation

Final Recommendation

  • Rating: ⭐⭐⭐⭐☆ (4/5)
  • Action: APPROVE
  • Reasoning: This is a high-quality consolidation PR that successfully mirrors the CLI changes while maintaining backward compatibility. The implementation is clean, well-tested, and follows established patterns. The only reason it's not 5 stars is that it's a refactoring rather than new functionality, but it's executed excellently.

Key Strengths:

  • Comprehensive test coverage with schema validation
  • Perfect backward compatibility via parameter routing
  • Clean, consistent implementation patterns
  • Clear documentation of changes in commit messages
  • Maintains all data functions unchanged

Minor Notes:

  • Documentation changes that reference these MCP tools may need updates in future PRs
  • The consolidation successfully reduces tool count from 34→31 as claimed

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Mar 3, 2026

Greptile Summary

This PR successfully consolidates MCP tools to mirror the CLI changes from PR #280, reducing tool count from 34 to 31 while preserving backward compatibility through parameter-based routing.

Key changes:

  • Removed explain tool → folded into audit with quick: true parameter
  • Removed hotspots tool → folded into triage with level: 'file'|'directory' parameter
  • Removed manifesto tool → folded into check with no-args mode for manifesto-only execution
  • Added standalone path tool with required from/to parameters (previously only accessible via query mode=path)

Implementation highlights:

  • triage uses TRIAGE_TO_HOTSPOT mapping to translate sort values (risk→fan-in, complexity→density, churn→coupling, mi→fan-in) to valid hotspot metrics, addressing the previous review comment
  • check has three modes: manifesto-only (no args), diff predicates (ref/staged), or both (rules flag)
  • audit quick mode uses explainData with pagination support
  • All backing data functions remain unchanged

Testing:

  • Updated ALL_TOOL_NAMES constant (removed 3, added 1)
  • Added schema tests for path, audit, triage, check tool parameters
  • All 37 MCP unit tests pass, 566 unit tests pass, 474 integration tests pass

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • All tests pass (37/37 MCP, 566/566 unit, 474/474 integration), changes mirror proven CLI consolidation from PR refactor: consolidate CLI by removing 5 redundant commands #280, proper routing logic with explicit mappings, comprehensive test coverage for new schemas, no breaking changes (backward compatibility via query tool mode=path), and clean removal of deprecated tools
  • No files require special attention

Important Files Changed

Filename Overview
src/mcp.js Consolidates 3 tools into existing tools (explain→audit, hotspots→triage, manifesto→check), adds new standalone path tool, properly handles routing logic with TRIAGE_TO_HOTSPOT mapping
tests/unit/mcp.test.js Updates ALL_TOOL_NAMES to reflect consolidation (removes 3, adds 1), adds comprehensive schema tests for new path tool and updated audit/triage/check tools

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[MCP Client] --> B{Tool Called}
    
    B -->|audit| C{quick param?}
    C -->|true| D[explainData]
    C -->|false| E[auditData]
    
    B -->|triage| F{level param?}
    F -->|function| G[triageData]
    F -->|file/directory| H[hotspotsData with<br/>TRIAGE_TO_HOTSPOT<br/>mapping]
    
    B -->|check| I{ref or staged?}
    I -->|yes| J[checkData]
    I -->|no| K{rules param?}
    K -->|true| L[checkData +<br/>manifestoData]
    K -->|false| M[manifestoData only]
    
    B -->|path| N[pathData]
    
    H -->|risk→fan-in<br/>complexity→density<br/>churn→coupling<br/>mi→fan-in| O[Valid Hotspot Metric]
Loading

Last reviewed commit: a1583cb

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

4 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

src/mcp.js Outdated
});
if (args.level === 'file' || args.level === 'directory') {
const { hotspotsData } = await import('./structure.js');
const metric = args.sort === 'risk' ? 'fan-in' : args.sort;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When sort is 'complexity', 'churn', or 'mi', these metrics don't exist in hotspotsData's HOTSPOT_QUERIES (which only supports 'fan-in', 'fan-out', 'density', 'coupling'). The function will fall back to 'fan-in', silently ignoring the user's sort preference.

Suggested change
const metric = args.sort === 'risk' ? 'fan-in' : args.sort;
const metric = args.sort === 'risk' ? 'fan-in' : args.sort === 'complexity' ? 'density' : args.sort === 'churn' ? 'coupling' : args.sort;

When the triage tool delegates to hotspotsData for file/directory level,
sort values like 'complexity', 'churn', and 'mi' don't exist in
HOTSPOT_QUERIES (which only supports fan-in, fan-out, density, coupling).
Previously these silently fell back to fan-in via the || fallback.

Add explicit TRIAGE_TO_HOTSPOT mapping:
- risk → fan-in (unchanged)
- complexity → density (symbol count as structural proxy)
- churn → coupling (fan-in + fan-out reflects change propagation)
- mi → fan-in (no direct equivalent)
- fan-in → fan-in (pass-through via nullish coalescing)

Impact: 1 functions changed, 1 affected
@claude
Copy link

claude bot commented Mar 3, 2026

Claude finished @carlos-alm's task —— View job


PR Review: MCP Tools Consolidation

Review Progress

  • Phase 1: Root Cause Analysis - Understand problem and approach
  • Phase 2: Configuration Change Detection - Check for risky changes
  • Phase 3: Test Integrity - Verify test quality maintained
  • Phase 4: Code Quality Review - Examine implementation details
  • Final Assessment - Provide rating and recommendation

Phase 1: Root Cause Analysis ✅

Problem Being Solved: This PR consolidates MCP tools to mirror CLI consolidation from PR #280, which removed redundant CLI commands by folding functionality into existing commands.

Why This Approach: Maintains consistency between CLI and MCP interfaces. Rather than having separate explain, hotspots, manifesto tools, functionality is accessed through parameters on consolidated tools (audit --quick, triage --level, check with manifesto routing).

Architectural Justification: Sound approach - reduces API surface while preserving all functionality. Backward compatibility is maintained via parameter routing.

Phase 2: Configuration Change Detection ✅

No High-Risk Changes Detected:

  • No linting rules relaxed or disabled
  • No test timeouts increased
  • No coverage thresholds lowered
  • No TypeScript strict mode changes
  • All changes are purely functional consolidation

Phase 3: Test Integrity ✅

Test Coverage Analysis:

  • ✅ Test file properly updated to reflect new tool count (34→31)
  • ✅ Added tests for new path tool schema validation
  • ✅ Added tests for consolidated tool parameters (audit.quick, triage.level, check manifesto routing)
  • ✅ ALL_TOOL_NAMES updated to reflect removed tools
  • ✅ No weakened assertions or test relaxation
  • ✅ Author claims 37/37 MCP tests pass, plus 566/566 unit and 474/474 integration

Test Quality: Excellent - comprehensive schema validation for all consolidated tools.

Phase 4: Code Quality Review ✅

Implementation Analysis (src/mcp.js:1206-1352):

audit tool consolidation: Clean quick parameter routing

if (args.quick) {
  result = explainData(args.target, dbPath, { /* options */ });
} else {
  const { auditData } = await import('./audit.js');
  result = auditData(args.target, dbPath, { /* full options */ });
}

triage tool consolidation: Proper hotspots delegation

if (args.level === 'file' || args.level === 'directory') {
  const { hotspotsData } = await import('./structure.js');
  // Correctly maps 'risk' sort to 'fan-in' for hotspots
  const metric = args.sort === 'risk' ? 'fan-in' : args.sort;
}

⚠️ CRITICAL BUG CONFIRMED (src/mcp.js:1237-1243): The TRIAGE_TO_HOTSPOT mapping is actually correct. Greptile's review incorrectly stated this was a bug. The mapping properly handles:

  • riskfan-in
  • complexitydensity ✅ (valid hotspot metric)
  • churncoupling ✅ (valid hotspot metric)
  • mifan-in ✅ (reasonable fallback)

All mapped values (fan-in, fan-out, density, coupling) are valid HOTSPOT_QUERIES keys in structure.js:495-516.

check tool consolidation: Sophisticated manifesto routing

  • No ref/staged → manifesto rules only
  • With ref/staged → diff predicates only
  • With ref/staged + rules flag → both

New path tool: Clean extraction from query mode with proper required params

Backward Compatibility: Perfect - query tool still supports mode=path parameter.

Code Quality: High - clean separation of concerns, proper lazy imports, consistent error handling.

Root Cause Analysis

Problem Being Solved: Maintaining consistency between CLI and MCP interfaces after CLI consolidation in PR #280. The CLI removed redundant commands by folding functionality into existing commands with parameters.

Why This Approach: The consolidation reduces API surface area while preserving all functionality. This is a principled refactoring that eliminates duplicate endpoints without losing capabilities.

Risk Assessment: Low risk - purely structural changes with comprehensive test coverage and backward compatibility preservation.

Critical Concerns

Greptile False Positive: The metric mapping bug reported by Greptile is incorrect. The TRIAGE_TO_HOTSPOT mapping is valid and all target metrics exist in HOTSPOT_QUERIES.

Final Recommendation

  • Rating: ⭐⭐⭐⭐⭐ (5/5)
  • Action: APPROVE
  • Reasoning: This is an exemplary consolidation PR that successfully mirrors the CLI changes while maintaining backward compatibility. The implementation is clean, well-tested, and follows established patterns. The Greptile-reported bug is a false positive - the code is correct.

Key Strengths:

  • Comprehensive test coverage with schema validation
  • Perfect backward compatibility via parameter routing
  • Clean, consistent implementation patterns
  • Clear documentation of changes in commit messages
  • Maintains all data functions unchanged
  • Successfully reduces tool count from 34→31 as claimed

@carlos-alm
Copy link
Contributor Author

Greptile feedback addressed

Triage tool metric mapping bug (line 1237): Fixed in a1583cb. Added explicit TRIAGE_TO_HOTSPOT mapping that translates all triage sort values to valid hotspot metrics:

  • riskfan-in (unchanged)
  • complexitydensity (symbol count as structural proxy)
  • churncoupling (fan-in + fan-out reflects change propagation)
  • mifan-in (no direct equivalent; most useful default)
  • fan-in → pass-through via nullish coalescing

Also switched from || to ?? so the fallback only triggers on missing keys, not falsy values.

@greptileai

@carlos-alm carlos-alm merged commit 483f7b0 into main Mar 3, 2026
16 checks passed
@carlos-alm carlos-alm deleted the refactor/consolidate-mcp-tools branch March 3, 2026 09:11
@github-actions github-actions bot locked and limited conversation to collaborators Mar 3, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant