Introduction

In DSH-based agent development, understanding codebase structure, function call relationships, or module dependencies is a common bottleneck. The CodeGraph plugin solves this problem by parsing code into a queryable index.

Plugin Overview

CodeGraph is a code knowledge graph plugin that indexes symbols, call sites, and imports into SQLite, and answers call/dependency questions via a CLI or a stdio MCP tool server.

Core Features

  • Call graph: Supports viewing callers and callees.
  • Dependency graph: Supports viewing module dependencies and dependents.
  • Full-text search: Local full-text search for symbol names, docstrings, and signatures.
  • Impact analysis: Supports transitive closure analysis to view objects affected by modifying a symbol.
  • Incremental indexing: Supports content-hash-based comparison and reparsing only changed files.
  • Visualization export: Supports exporting as Graphviz DOT or JSON.
  • Query cache: The tool server provides a 30-second TTL cache for read-only queries.
  • Parsing engine: Includes two built-in parsing engines: tree-sitter (precise) and a regex scanner (zero-dependency).

Installation and Activation

Install the plugin in DSH:

dsh plugin --profile demo add github:JohnXu22786/codegraph

Typical Usage

The plugin provides two invocation methods: CLI and MCP tool server.

  1. Build the index
    codegraph index
  1. Call relationship query
    codegraph callers services.orders.create_order  # 查询谁调用了该函数
    codegraph callees app.run                       # 查询该函数调用了谁
  1. Dependency relationship query
    codegraph deps services.billing                 # 查询模块依赖
    codegraph dependents services.billing           # 查询谁依赖该模块
  1. Full-text search
    codegraph search 'coupon'                      # 搜索符号名、文档字符串等
  1. Impact analysis
    codegraph impact services.billing.price         # 查询传递调用链
  1. View status and export
    codegraph status                               # 查看索引统计
    codegraph export dot -o graph.dot              # 导出可视化图谱
  1. Start the tool server
    codegraph serve                                # 启动 stdio 工具服务器

Notes

  • Environment requirement: Python ≥ 3.10 is required.
  • Language support: Supports Python, JavaScript, TypeScript, Go, Java, and Rust.
  • Implementation approach: Uses a self-contained implementation with the Python standard library + SQLite and has no mandatory third-party dependencies.
  • Cross-file resolution: Cross-file resolution relies on heuristics, prioritizing exact matches in the same file, import paths, package names, and globally unique names.
  • DSH integration: Loaded through the built-in MCP client in DSH.
  • Node bridge: After installation, the Node bridge exposes tools as tool names such as codegraph_callers and codegraph_callees.
  • Error handling: Read-only tools return an error if no index exists.

Conclusion

CodeGraph provides a structured way to analyze a codebase.