MCP Tools for Querying Code Relationships in code-review-graph

The code-review-graph repository provides FastMCP-based query_graph and supporting tools that expose graph-based queries to find function callers, callees, and associated tests through specific pattern arguments.

The code-review-graph project implements a Model Context Protocol (MCP) server that surfaces the entire codebase as a queryable graph. For developers tracing execution flow or identifying test coverage, the repository ships specialized MCP tools for querying code relationships that resolve symbols and traverse the underlying GraphStore without manual navigation.

Core MCP Tool: query_graph

The primary interface for relationship exploration is the query_graph tool defined in code_review_graph/tools/query.py. This tool accepts a pattern argument that determines which relationship to inspect, along with a target symbol that can be specified as a qualified name, file path, or Java-style FQN.

According to the source code, the supported relationship patterns are declared in the _QUERY_PATTERNS dictionary (lines 25-33) and include:

  • callers_of – Returns all functions that invoke the target function
  • callees_of – Returns all functions called by the target function
  • tests_for – Returns test nodes (direct or indirect) that exercise the target symbol

The query_graph implementation validates the pattern against _QUERY_PATTERNS, resolves the target symbol, walks the GraphStore, and returns a structured response containing matching nodes, a summary string, and pagination metadata (lines 28-46).

Supporting MCP Tools for Code Analysis

Beyond query_graph, the repository exposes complementary MCP tools in code_review_graph/tools/query.py:

get_impact_radius

The get_impact_radius tool analyzes the blast radius of changed files by traversing caller/callee relationships up to a specified depth. This is essential for understanding indirect effects after code modifications (lines 6-14).

semantic_search_nodes

The semantic_search_nodes tool performs fuzzy or semantic lookup of nodes by name or keyword. Results can be piped into query_graph for precise relationship queries when you need to resolve ambiguous symbol names (lines 94-102).

traverse_graph_func

For free-form exploration, traverse_graph_func executes BFS or DFS traversals starting from a node discovered via semantic search, allowing custom path exploration beyond predefined patterns (lines 165-173).

list_graph_stats and find_large_functions

Additional utilities include list_graph_stats for high-level graph metrics like node counts and language breakdown (lines 75-82), and find_large_functions for identifying refactoring candidates based on code size (lines 38-45).

Practical Code Examples

These examples demonstrate how to invoke the MCP tools directly from Python. In production workflows, you would typically invoke these through a FastMCP client over stdio or HTTP; the functions are also importable for unit testing.

Find Callers of a Function

from code_review_graph.tools.query import query_graph

result = query_graph(
    pattern="callers_of",
    target="utils.py::process_data",
    detail_level="standard",
    max_results=20,
)

print(result["summary"])
for node in result["results"]:
    print(f"Caller: {node['qualified_name']} ({node['file_path']})")

Find Callees of a Function

from code_review_graph.tools.query import query_graph

result = query_graph(
    pattern="callees_of",
    target="services/order_service.py::create_order",
    detail_level="standard",
)

print(result["summary"])
for node in result["results"]:
    print(f"Callee: {node['qualified_name']} ({node['file_path']})")

List Tests for a Symbol

from code_review_graph.tools.query import query_graph

result = query_graph(
    pattern="tests_for",
    target="models/user.py::User",
    detail_level="standard",
)

print(result["summary"])
for test in result["results"]:
    kind = "Indirect" if test.get("indirect") else "Direct"
    print(f"{kind} test: {test['qualified_name']} ({test['file_path']})")

Combine Semantic Search with Relationship Queries

from code_review_graph.tools.query import semantic_search_nodes, query_graph

# Resolve ambiguous symbol names first

search = semantic_search_nodes(query="order", kind="Function")
best = search["results"][0]
qualified = best["qualified_name"]

# Then query relationships

callers = query_graph(pattern="callers_of", target=qualified)
print(callers["summary"])

Calculate Change Impact Radius

from code_review_graph.tools.query import get_impact_radius

impact = get_impact_radius(
    changed_files=["services/payment.py"],
    max_depth=3,
    detail_level="standard",
)

print(impact["summary"])

Key Implementation Files

The MCP tool surface is implemented across these source files:

Summary

  • The query_graph MCP tool is the primary interface for querying code relationships, supporting callers_of, callees_of, and tests_for patterns defined in code_review_graph/tools/query.py.
  • Target resolution handles qualified names, file paths, and Java-style FQNs automatically.
  • get_impact_radius provides blast-radius analysis for changed files by traversing relationship depths.
  • semantic_search_nodes enables fuzzy symbol resolution before precise relationship queries.
  • All tools are registered with the FastMCP server in code_review_graph/main.py and available via stdio or HTTP transports.

Frequently Asked Questions

How do I query all functions that call a specific method in code-review-graph?

Use the query_graph MCP tool with the callers_of pattern. Pass the target function as a qualified name (e.g., module.py::function_name) or file path. The tool resolves the symbol against the GraphStore and returns all incoming call relationships.

What is the difference between query_graph and get_impact_radius?

query_graph answers specific relationship questions (who calls X, what does X call, what tests cover X) for a single target symbol. get_impact_radius analyzes the downstream and upstream effects of multiple changed files, calculating indirect impact through caller/callee chains up to a configurable depth.

Can I search for symbols by partial name before querying relationships?

Yes. Use the semantic_search_nodes tool to perform fuzzy or semantic lookup by keyword, then extract the qualified_name from the results to use as the target parameter in query_graph. This workflow handles ambiguous symbol names gracefully.

Where are the MCP tool definitions registered for client access?

All MCP tools are registered in code_review_graph/main.py, which initializes the FastMCP server. This makes the tools available to any MCP client including CLI tools, VS Code extensions, or custom scripts communicating over stdio or HTTP.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →