Skip to content

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

β†’ See all user stories

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ΒΆ

Generate a call graph for the src directory
{
  "project_root": "/project/src"
}
codescalpel get-call-graph src/
{
  "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ΒΆ

Show the call graph starting from the handle_request function in routes.py
{
  "project_root": "/project/src",
  "entry_point": "routes.py:handle_request",
  "depth": 5
}
codescalpel get-call-graph src/ \
  --entry-point "routes.py:handle_request" \
  --depth 5
{
  "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ΒΆ

Find all call paths from handle_request to execute_query
{
  "project_root": "/project/src",
  "paths_from": "routes.py:handle_request",
  "paths_to": "db.py:execute_query"
}
codescalpel get-call-graph src/ \
  --paths-from "routes.py:handle_request" \
  --paths-to "db.py:execute_query"
{
  "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ΒΆ

Check the project for circular imports
{
  "project_root": "/project/src",
  "include_circular_import_check": true
}
codescalpel get-call-graph src/ --include-circular-import-check
{
  "data": {
    "circular_imports": [
      {
        "cycle": ["models", "services", "models"],
        "files": ["models.py", "services.py"]
      }
    ],
    "has_circular_imports": true,
    "suggestion": "Consider using lazy imports or restructuring modules"
  },
  "tier_applied": "community",
  "duration_ms": 95
}

Focus on Specific FunctionsΒΆ

Show the call graph around the authentication functions
{
  "project_root": "/project/src",
  "focus_functions": ["verify_token", "check_permissions", "login"]
}
codescalpel get-call-graph src/ \
  --focus-functions "verify_token,check_permissions,login"
{
  "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

β†’ See tier comparison

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ΒΆ

  1. Start from entry points - Use entry_point for focused analysis
  2. Use path queries for security - Find routes from input to sinks
  3. Check circular imports - Prevent import errors
  4. Visualize with Mermaid - Easy to understand graphs