Skip to content

feat(mcp): impact_analysis tool — variable-depth Cypher (T6)#680

Draft
DvirDukhan wants to merge 1 commit into
dvirdukhan/mcp-t5-t7-t8-query-toolsfrom
dvirdukhan/mcp-t6-impact-analysis
Draft

feat(mcp): impact_analysis tool — variable-depth Cypher (T6)#680
DvirDukhan wants to merge 1 commit into
dvirdukhan/mcp-t5-t7-t8-query-toolsfrom
dvirdukhan/mcp-t6-impact-analysis

Conversation

@DvirDukhan
Copy link
Copy Markdown

Implements T6 (#654) — the only structural tool with no pre-existing AsyncGraphQuery backing. Inlines a variable-depth [:CALLS*1..depth] Cypher with DISTINCT for cycle safety.

Stacked on:

Tool

impact_analysis(symbol_id, project, branch=None, direction='IN', depth=3):

  • direction='IN' → transitive upstream callers ("what breaks if I change X?").
  • direction='OUT' → transitive callees ("what does X reach?").
  • depth clamped to [1, IMPACT_MAX_DEPTH=10]. Above-cap values are silently clamped so agents can ask for "very deep" without erroring.
  • Cycles handled via Cypher DISTINCT — no manual visited-set, no infinite loop.

Tests

tests/mcp/test_impact_analysis.py — 9 tests:

  • Unit: _clamp_depth normalization + garbage rejection; direction validation; tool registered on the MCP app.
  • Integration: upstream of db and downstream of entrypoint match contract entries in expected.yaml; depth=1 excludes the 3-hop entrypoint.
  • Cycle safety: throwaway A↔B + C→A graph; DISTINCT guarantees no duplicates and termination.
  • JSON serialisability.

Full MCP suite: 34 passed in 22.7s.

Out of scope

Per the ticket: cross-rel traversal (only CALLS in v1), ranking, cross-branch / cross-repo impact.

Closes #654.

Adds the only MCP tool with no pre-existing AsyncGraphQuery backing,
inlining a [:CALLS*1..depth] traversal with DISTINCT for cycle safety.

api/mcp/tools/structural.py
- impact_analysis(symbol_id, project, branch, direction='IN', depth=3)
- direction='IN' returns transitive upstream callers (what breaks if
  you change this symbol); direction='OUT' returns transitive callees.
- depth is clamped to [1, IMPACT_MAX_DEPTH=10]; values above 10 are
  silently clamped, not rejected, so agents can ask for "very deep"
  without worrying about the cap.
- _clamp_depth helper accepts int / stringified int, rejects bool /
  None / non-numeric strings.
- Direction must be 'IN' or 'OUT'; raises before issuing the query.

tests/mcp/test_impact_analysis.py (9 tests)
- Unit: _clamp_depth normalization + garbage rejection; direction
  validation; tool registered on the MCP app.
- Integration vs the sample-project fixture: upstream(db) and
  downstream(entrypoint) match the expected.yaml contract; depth=1
  from db excludes the 3-hop entrypoint.
- Cycle safety: throwaway A-B + C-A graph; DISTINCT ensures no
  duplicates and the query terminates.
- JSON serialisability.

tests/mcp/fixtures/expected.yaml
- New impact section with upstream_includes_any_of for db and
  downstream_includes_any_of for entrypoint.

Out of scope (per ticket): cross-rel traversal (CALLS only for v1),
ranking, cross-branch / cross-repo impact.

Closes #654.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 27, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 6bd0749a-c07d-4063-9290-32fc673a0c20

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch dvirdukhan/mcp-t6-impact-analysis

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant