Skip to main content
Glama

Analyze Codebase Module Dependency Graph

analyze_code_dependencies
Read-onlyIdempotent

Maps module import graphs, traces symbol call chains, ranks architectural centrality, and detects dead code across polyglot repositories to reveal global dependency structure before refactoring.

Instructions

Analyzes module import graphs, symbol call chains, PageRank graph centrality, and dead code across polyglot source files, distinguishing from 'analyze_change_impact' and 'enforce_architecture_rules' by performing global dependency structure mapping rather than calculating change blast radius or verifying layer boundaries.

Parameters:

  • analysis_type: Structural analysis mode: 'dependencies' builds full inbound/outbound module import graph; 'call_chain' traces deep upstream callers and downstream callees; 'pagerank' computes architectural centrality rankings; 'dead_code' detects unreferenced functions and classes.

  • project_root: Repository root directory path to scan and construct the dependency graph from.

  • target_symbol: Specific function, method, or class name to trace when analysis_type is 'call_chain'; ignored for other modes.

  • file_path: Optional file path to scope module dependency analysis to a single file rather than the entire repository.

Behavior:

  • Mutability: Strictly read-only; inspects source syntax trees without modifying, moving, or deleting files.

  • Idempotency: Deterministic; returns identical graph structures and rankings for the same codebase state.

  • Privacy & Network: 100% offline local parsing for Python, TypeScript, JavaScript, Go, Rust, Java, C#, C++; zero network calls.

  • Performance & Resources: Analyzes 1,000 files in <600ms consuming <60MB RAM; thread-safe.

  • Auth: Zero authentication or cloud credentials required.

  • Return Structure: Emits structured Markdown report detailing adjacency lists, Mermaid call diagrams, PageRank scores, or dead-code candidates.

  • Error Handling: Returns clean warning notices if target_symbol is not found in the AST index or if specified file path is missing.

Usage Guidelines:

  • When to use: Inspect inbound dependents, outbound dependencies, deep symbol call sequences, module importance ranks, or dead code prior to major refactoring.

  • When NOT to use: Do not use for calculating the blast radius score of modifying a specific function (use 'analyze_change_impact' instead); do not use for verifying compliance with layer boundary rules (use 'enforce_architecture_rules' instead).

Returns: Markdown report detailing import graphs, call chains, centrality rankings, or detected dead code.

Tool call template

This tool declares no required parameters. Add optional parameters from the input schema as needed.

{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "tools/call",
  "params": {
    "arguments": {},
    "name": "analyze_code_dependencies"
  }
}

Input Schema

NameRequiredDescriptionDefault
file_pathNoOptional path to a specific file to analyze.
project_rootNoRoot directory of the repository to scan (default: current directory)..
analysis_typeNoType of structural analysis: 'dependencies' for module import/export graph, 'call_chain' for deep caller/callee execution trace, 'pagerank' for architectural backbone centrality, 'dead_code' for unreferenced symbols.dependencies
target_symbolNoTarget class or function name when analysis_type is 'call_chain'.

Output Schema

NameRequiredDescriptionDefault
resultYes

Schema Changelog

Changes observed during successful MCP inspections.

  1. Addedv7.3.2
  2. Removedv7.0.1
  3. Addedv7.0.0

TDQS

A4.8/5.0
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Goes well beyond the annotations by disclosing determinism, 100% offline local parsing, supported languages, concrete performance figures (1,000 files in <600ms, <60MB RAM), thread-safety, zero-auth requirements, and error-handling behavior for missing symbols/paths. The annotations already cover read-only and idempotency, so this extra operational detail is genuine added value.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Front-loaded with purpose and sibling differentiation, then organized into Parameters/Behavior/Usage/Returns with no wasted preamble. Slightly over-full: the return structure is stated twice (under Behavior and again in a final 'Returns' line), and the auth/privacy notes are belabored given the annotation set.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a four-parameter analytical tool with an output schema, nothing material is missing: mode semantics, scoping behavior, error cases, and failure handling are all covered, and the output schema plus the return-format sentence together describe results adequately.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100%, so the baseline is 3; the description earns above that by enumerating the four analysis_type modes with what each produces and by clarifying that target_symbol is only meaningful for 'call_chain' and ignored otherwise, a conditional constraint the schema only partially conveys.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

States a specific verb and resource ('Analyzes module import graphs, symbol call chains, PageRank...') and explicitly distinguishes itself from 'analyze_change_impact' and 'enforce_architecture_rules' by contrasting global dependency mapping against blast-radius and layer-boundary checks.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Has dedicated 'When to use' and 'When NOT to use' sections, and routes the agent to the exact sibling alternative for each excluded case (change impact, architecture rules). The exclusions map to the two most likely confusions among the listed siblings.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.