get_call_graphΒΆ
Generate a call graph showing how functions call each other, detect entry points, and visualize code flow with Mermaid diagrams.
Quick ReferenceΒΆ
get_call_graph(
project_root: str = None, # Project directory
entry_point: str = None, # Starting function
depth: int = 10, # Max traversal depth
include_circular_import_check: bool = True, # Check for circular imports
paths_from: str = None, # Source for path query
paths_to: str = None, # Sink for path query
focus_functions: list = None # Functions to focus on
) -> CallGraphResult
User StoriesΒΆ
| Persona | Story | Tool Value |
|---|---|---|
| π° Alex (First-Timer) | "Visualize how functions call each other" | Understand code flow |
| π₯ David (Team Lead) | "Show team how modules interact" | Architecture clarity |
| π§ Chris (OSS Contributor) | "Trace how MCP tools are implemented" | Implementation patterns |
| π’ Jennifer (Enterprise Architect) | "Trace execution paths across service boundaries" | Distributed system understanding |
ParametersΒΆ
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
project_root | string | No | cwd | Project root directory |
entry_point | string | No | None | Starting function (e.g., "main" or "app.py:main") |
depth | int | No | 10 | Maximum depth to traverse |
include_circular_import_check | bool | No | true | Check for circular imports |
paths_from | string | No | None | Source function for path queries |
paths_to | string | No | None | Sink function for path queries |
focus_functions | list | No | None | Functions to focus subgraph on |
Response SchemaΒΆ
{
"data": {
"nodes": [
{
"id": "string",
"name": "string",
"file": "string",
"line": "integer",
"type": "string",
"is_entry_point": "boolean",
"source_uri": "string"
}
],
"edges": [
{
"source": "string",
"target": "string",
"type": "string",
"context": {
"in_loop": "boolean",
"in_try_block": "boolean",
"in_conditional": "boolean"
},
"confidence": "float"
}
],
"entry_points": ["string"],
"circular_imports": [
{
"cycle": ["string"],
"files": ["string"]
}
],
"paths": [
{
"from": "string",
"to": "string",
"path": ["string"]
}
],
"mermaid_diagram": "string",
"statistics": {
"total_nodes": "integer",
"total_edges": "integer",
"max_depth_reached": "integer"
}
},
"tier_applied": "string",
"max_depth_applied": "integer",
"max_nodes_applied": "integer",
"duration_ms": "integer"
}
ExamplesΒΆ
Basic Call GraphΒΆ
{
"data": {
"nodes": [
{
"id": "main::function::main",
"name": "main",
"file": "main.py",
"line": 10,
"type": "function",
"is_entry_point": true,
"source_uri": "file:///project/src/main.py#L10"
},
{
"id": "services::function::process_data",
"name": "process_data",
"file": "services.py",
"line": 25,
"type": "function",
"is_entry_point": false
},
{
"id": "db::function::save_results",
"name": "save_results",
"file": "db.py",
"line": 15,
"type": "function",
"is_entry_point": false
}
],
"edges": [
{
"source": "main::function::main",
"target": "services::function::process_data",
"type": "calls",
"confidence": 1.0
},
{
"source": "services::function::process_data",
"target": "db::function::save_results",
"type": "calls",
"confidence": 1.0
}
],
"entry_points": ["main::function::main"],
"circular_imports": [],
"mermaid_diagram": "graph TD\n main[main.py:main] --> process_data[services.py:process_data]\n process_data --> save_results[db.py:save_results]",
"statistics": {
"total_nodes": 3,
"total_edges": 2,
"max_depth_reached": 2
}
},
"tier_applied": "community",
"max_depth_applied": 3,
"duration_ms": 145
}
From Specific Entry PointΒΆ
{
"data": {
"nodes": [
{
"id": "routes::function::handle_request",
"name": "handle_request",
"file": "routes.py",
"line": 20
},
{
"id": "auth::function::verify_token",
"name": "verify_token",
"file": "auth.py",
"line": 45
},
{
"id": "handlers::function::process_order",
"name": "process_order",
"file": "handlers.py",
"line": 30
},
{
"id": "db::function::execute_query",
"name": "execute_query",
"file": "db.py",
"line": 10
}
],
"edges": [
{"source": "routes::function::handle_request", "target": "auth::function::verify_token"},
{"source": "routes::function::handle_request", "target": "handlers::function::process_order"},
{"source": "handlers::function::process_order", "target": "db::function::execute_query"}
],
"mermaid_diagram": "graph TD\n handle_request --> verify_token\n handle_request --> process_order\n process_order --> execute_query"
},
"tier_applied": "pro",
"max_depth_applied": 50,
"duration_ms": 230
}
Find Paths Between FunctionsΒΆ
{
"data": {
"paths": [
{
"from": "routes::function::handle_request",
"to": "db::function::execute_query",
"path": [
"routes::function::handle_request",
"handlers::function::process_order",
"db::function::execute_query"
],
"length": 3
},
{
"from": "routes::function::handle_request",
"to": "db::function::execute_query",
"path": [
"routes::function::handle_request",
"services::function::get_data",
"db::function::execute_query"
],
"length": 3
}
],
"total_paths_found": 2
},
"tier_applied": "pro",
"duration_ms": 180
}
Detect Circular ImportsΒΆ
Focus on Specific FunctionsΒΆ
{
"data": {
"nodes": [
{"id": "auth::function::verify_token", "name": "verify_token"},
{"id": "auth::function::check_permissions", "name": "check_permissions"},
{"id": "auth::function::login", "name": "login"},
{"id": "routes::function::protected_route", "name": "protected_route"},
{"id": "db::function::get_user", "name": "get_user"}
],
"edges": [
{"source": "protected_route", "target": "verify_token"},
{"source": "verify_token", "target": "check_permissions"},
{"source": "login", "target": "get_user"}
],
"focus_applied": true
},
"tier_applied": "pro",
"duration_ms": 120
}
Tier LimitsΒΆ
get_call_graph capabilities vary by tier:
| Feature | Community | Pro | Enterprise |
|---|---|---|---|
| Max depth | 3 | 50 | Unlimited |
| Max nodes | 50 | 500 | Unlimited |
| Entry point detection | β | β | β |
| Circular import check | β | β | β |
| Basic Mermaid visualization | β | β | β |
| Advanced visualization | β | β | β Enhanced |
| Path queries (paths_from/paths_to) | β | β | β |
| Focus mode | β | β | β |
| Call context (loops/conditionals) | β | β | β Full |
| Confidence scoring | β | β | β |
| Graph query language | β | β | β |
Community TierΒΆ
- β Generate basic call graphs
- β Entry point detection (main, routes, CLI)
- β Circular import detection
- β Basic Mermaid diagrams
- β οΈ Max depth of 3 - Shallow call graph only
- β οΈ Max 50 nodes - Graph truncated for large codebases
- β No path queries or focus mode
- β No call context or confidence scoring
Pro TierΒΆ
- β All Community features
- β Max depth of 50 - Deep call chain analysis
- β Max 500 nodes - Handle larger codebases
- β Path queries - Find paths from source to sink
- β Focus mode - Extract subgraph around specific functions
- β Call context - Know if calls are in loops/conditionals
- β Confidence scoring - Reliability of each edge
- β Advanced Mermaid - Better visualization with context
Enterprise TierΒΆ
- β All Pro features
- β Unlimited depth - Complete call graph
- β Unlimited nodes - No truncation
- β Graph query language - Custom graph traversals (e.g., "MATCH (n)-[:calls]->(m:function) WHERE m.name CONTAINS 'DB'")
- β Full call context - Complete execution context
- β Source URIs - Click-through to IDE
- β Enhanced visualization - Interactive diagrams
Key Difference: Depth and Query Capabilities - Community: Depth 3, 50 nodes - Quick overview of immediate calls - Pro: Depth 50, 500 nodes, path queries - Trace execution paths for security - Enterprise: Unlimited, query language - Complete call graph analysis
Mermaid DiagramΒΆ
The mermaid_diagram field contains a ready-to-render diagram:
graph TD
main[main.py:main] --> process[services.py:process_data]
main --> validate[validators.py:validate]
process --> save[db.py:save_results]
process --> log[logger.py:log_event] Edge Context (Pro+)ΒΆ
Edges include context about where calls occur:
{
"source": "process_order",
"target": "send_notification",
"context": {
"in_loop": false,
"in_try_block": true,
"in_conditional": true
},
"confidence": 0.95
}
Best PracticesΒΆ
- Start from entry points - Use
entry_pointfor focused analysis - Use path queries for security - Find routes from input to sinks
- Check circular imports - Prevent import errors
- Visualize with Mermaid - Easy to understand graphs
Related ToolsΒΆ
- get_project_map - Project structure overview
- get_graph_neighborhood - K-hop subgraphs
- cross_file_security_scan - Security with graph