Skip to content

[MCP T7] find_path MCP tool #655

@DvirDukhan

Description

@DvirDukhan

Phase 1 ticket T7. Depends on #652 (T4 index_repo).

Context

find_path answers "how does symbol A reach symbol B?" — useful for understanding indirect call chains and refactoring sequences. The underlying operation already exists: Graph.find_paths() (api/graph.py:535-579) and AsyncGraphQuery.find_paths() (api/graph.py:726-745). The CLI command cgraph paths (api/cli.py:317-335) already exposes it. This ticket is a thin async wrapper.

Scope

In:

  • api/mcp/tools/structural.py::find_path(source_id, dest_id, max_paths=10).
  • Wraps AsyncGraphQuery.find_paths() (api/graph.py:726-745).
  • Returns a list of node-sequences, each representing a call path:
    [
      {"path": [{"id":"a","name":"a","label":"Function","file":"...","line":1}, ...]},
      ...
    ]
  • Tests in tests/mcp/test_find_path.py:
    • Unit (mocked graph): assert path serialization shape.
    • Integration: known path against T3 fixture (e.g. entrypoint → service → repo → db) — assert the path exists in the result and has the expected length.
    • No-path case: source and dest with no connecting path returns [], not an error.
    • CLI parity vs cgraph paths: same input → same output.
    • Protocol round-trip.

Out:

  • Path ranking / shortest-path-only mode (deferred).
  • Bidirectional path search.
  • Cross-relation paths beyond the existing find_paths Cypher (CALLS* only).

Files to create / modify

  • api/mcp/tools/structural.py — tool registration
  • new tests/mcp/test_find_path.py

Acceptance criteria

  • Tool registered with FastMCP.
  • Input schema: source_id: str, dest_id: str, max_paths: int = 10.
  • Unit test asserts response shape with mocked graph.
  • Integration test against T3 fixture: find_path(entrypoint, db) returns at least one path that traverses entrypoint → service → repo → db.
  • No-path case (e.g. two disjoint nodes) returns [] — not an exception, not a 404.
  • CLI parity test: cgraph paths <src> <dst> and the MCP tool return the same paths for the same input.
  • Protocol round-trip test.
  • CI workflow [MCP T2] CI workflow with FalkorDB service for MCP tests #649 green.

Dependencies

Out of scope (do NOT do in this PR)

  • Shortest-path-only mode (the existing find_paths returns all paths up to a depth limit).
  • Bidirectional search.
  • Cross-relation paths (only CALLS per the existing implementation).

Notes for the implementer

  • The wrapper should be ~20 lines. Real work is in api/graph.py.
  • max_paths is a safety cap to prevent the agent from blowing the response size on highly-connected graphs. If find_paths already supports a limit param, forward it; otherwise add one.
  • Reuse the protocol-test helper from T4.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestmcpMCP server (model context protocol) work

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions