CodeGraphContext如何将代码仓库转化为AI可查询的知识图谱?
AI Summary (BLUF)
CodeGraphContext is a powerful MCP server and CLI toolkit that transforms local code repositories into queryable graph databases, enabling AI assistants and developers to analyze code relationships, dependencies, and structures through natural language queries or command-line tools.
原文翻译: CodeGraphContext是一个强大的MCP服务器和CLI工具包,可将本地代码仓库转换为可查询的图数据库,使AI助手和开发者能够通过自然语言查询或命令行工具分析代码关系、依赖关系和结构。
引言
将代码仓库转化为AI代理可查询的知识图谱。
Turn code repositories into a queryable graph for AI agents.
CodeGraphContext 是一个强大的 MCP 服务器 和 CLI 工具包,它将本地代码索引到图数据库以图结构存储和查询数据的数据库系统,擅长处理实体间的关系和连接。中,为AI助手和开发者提供上下文。您可以将其作为独立的CLI工具进行全面的代码分析,也可以通过MCP连接到您喜欢的AI IDE,实现AI驱动的代码理解。
A powerful MCP server and CLI toolkit that indexes local code into a graph database to provide context to AI assistants and developers. Use it as a standalone CLI for comprehensive code analysis or connect it to your favorite AI IDE via MCP for AI-powered code understanding.
核心特性
- 代码索引: 分析代码并构建其组件的知识图谱。
Code Indexing: Analyzes code and builds a knowledge graph of its components.
- 关系分析: 查询调用者、被调用者、类层次结构、调用链等。
Relationship Analysis: Query for callers, callees, class hierarchies, call chains and more.
- 预索引包: 使用
.cgc包即时加载知名仓库,无需索引!Pre-indexed Bundles: Load famous repositories instantly with
.cgcbundles - no indexing required! - 实时文件监控: 监控目录变更并自动实时更新图谱 (
cgc watch)。Live File Watching: Watch directories for changes and automatically update the graph in real-time (
cgc watch). - 双模式运行: 既可作为开发者使用的独立 CLI 工具包,也可作为AI代理的 MCP 服务器。
Dual Mode: Works as a standalone CLI toolkit for developers and as an MCP server for AI agents.
- 多语言支持: 完整支持14种编程语言。
Multi-Language Support: Full support for 14 programming languages.
- 灵活的数据库后端: 支持 KùzuDB(Windows默认)、FalkorDB Lite(Unix典型嵌入式默认)、FalkorDB Remote 或 Neo4j。
Flexible Database Backend: KùzuDB (default on Windows), FalkorDB Lite (typical embedded default on Unix when installed), FalkorDB Remote, or Neo4j (all platforms via Docker/native).
支持的编程语言
CodeGraphContext 为以下语言提供全面的解析和分析:
| 图标 | 语言 | 图标 | 语言 | 图标 | 语言 |
|---|---|---|---|---|---|
| 🐍 | Python | 📜 | JavaScript | 🔷 | TypeScript |
| ☕ | Java | 🏗️ | C / C++ | #️⃣ | C# |
| 🐹 | Go | 🦀 | Rust | 💎 | Ruby |
| 🐘 | PHP | 🍎 | Swift | 🎨 | Kotlin |
| 🎯 | Dart | 🐪 | Perl |
每种语言的解析器都会提取函数、类、方法、参数、继承关系、函数调用和导入语句,以构建一个全面的代码图谱将代码元素(如函数、类、方法)及其关系(如调用、继承)表示为图结构的数据模型。。
Each language parser extracts functions, classes, methods, parameters, inheritance relationships, function calls, and imports to build a comprehensive code graph.
数据库选项对比
CodeGraphContext 支持多种图数据库以图结构存储和查询数据的数据库系统,擅长处理实体间的关系和连接。后端以适应不同环境:
| 特性 | KùzuDB | FalkorDB Lite | Neo4j |
|---|---|---|---|
| 典型默认平台 | Windows (嵌入式,安装kuzu后) |
Unix (Python 3.12+,当falkordblite可用时) |
需显式配置 |
| 安装配置 | 零配置 / 嵌入式 | 零配置 / 进程内 | Docker / 外部服务 |
| 支持平台 | 全平台 (Windows原生, macOS, Linux) | 仅Unix (Linux/macOS/WSL) | 全平台 |
| 主要用例 | 桌面、IDE、本地开发 | 特定的Unix开发环境 | 企业级、超大规模图谱 |
| 前置要求 | pip install kuzu |
pip install falkordblite |
Neo4j Server / Docker |
| 性能特点 | ⚡ 极快 | ⚡ 快速 | 🚀 可扩展性强 |
| 数据持久化 | 是 (存储到磁盘) | 是 (存储到磁盘) | 是 (存储到磁盘) |
快速开始
安装核心工具包
pip install codegraphcontext
理解 CodeGraphContext 的两种模式
CodeGraphContext 以 两种模式 运行,您可以单独或同时使用它们:
🛠️ 模式一:CLI 工具包 (独立使用)
将 CodeGraphContext 用作强大的命令行工具包进行代码分析:
- 直接从终端索引和分析代码库
- 查询代码关系、查找死代码、分析复杂度
- 可视化代码图谱将代码元素(如函数、类、方法)及其关系(如调用、继承)表示为图结构的数据模型。和依赖关系
- 适合希望通过CLI命令直接控制的开发者
Use CodeGraphContext as a powerful command-line toolkit for code analysis:
- Index and analyze codebases directly from your terminal
- Query code relationships, find dead code, analyze complexity
- Visualize code graphs and dependencies
- Perfect for developers who want direct control via CLI commands
🤖 模式二:MCP 服务器 (AI驱动)
将 CodeGraphContext 作为 MCP 服务器 供AI助手使用:
- 连接到AI IDE (VS Code, Cursor, Windsurf, Claude, Kiro等)
- 让AI代理使用自然语言查询您的代码库
- 自动进行代码理解和关系分析
- 适合AI辅助开发工作流
Use CodeGraphContext as an MCP server for AI assistants:
- Connect to AI IDEs (VS Code, Cursor, Windsurf, Claude, Kiro, etc.)
- Let AI agents query your codebase using natural language
- Automatic code understanding and relationship analysis
- Perfect for AI-assisted development workflows
两种模式可以同时使用! 安装一次后,即可直接使用CLI命令,或连接到您的AI助手。
You can use both modes! Install once, then use CLI commands directly OR connect to your AI assistant.
安装步骤 (两种模式)
安装:
pip install codegraphcontext数据库设置 (自动)
- KùzuDB (Windows默认): 在Windows、macOS和Linux上原生运行。在Windows上是常见的嵌入式选择;需要时运行
pip install kuzu。KùzuDB (default on Windows): Runs natively on Windows, macOS, and Linux. On Windows it is the usual embedded choice;
pip install kuzuif needed. - FalkorDB Lite (Unix典型默认): 在Unix/macOS/WSL上,当Python 3.12+且
falkordblite可用时,嵌入式后端优先使用FalkorDB Lite;否则使用KùzuDB。FalkorDB Lite (typical default on Unix): When Python 3.12+ and
falkordbliteare available on Unix/macOS/WSL, the embedded backend prefers FalkorDB Lite; otherwise KùzuDB is used. - Neo4j (替代方案): 如需使用Neo4j,或...
Neo4j (Alternative): To use Neo4j instead, or...
- KùzuDB (Windows默认): 在Windows、macOS和Linux上原生运行。在Windows上是常见的嵌入式选择;需要时运行
常见问题(FAQ)
CodeGraphContext 支持哪些编程语言?
它完整支持14种编程语言,包括Python、JavaScript、TypeScript、Java、C/C++、C#、Go、Rust、Ruby、PHP、Swift、Kotlin、Dart和Perl。
CodeGraphContext 的两种运行模式是什么?
它可作为独立的CLI工具包命令行界面工具包,提供代码分析和图数据库操作的命令行工具。供开发者进行代码分析,也可作为MCP服务器模型上下文协议服务器,允许开发者通过标准化接口暴露智能体、工具和其他资源,增强生态兼容性。连接AI IDE(如Cursor、Windsurf),实现AI驱动的代码理解。
CodeGraphContext 支持哪些图数据库以图结构存储和查询数据的数据库系统,擅长处理实体间的关系和连接。?如何选择?
支持KùzuDB(Windows默认)、FalkorDB Lite(Unix嵌入式默认)、FalkorDB Remote和Neo4j。KùzuDB适合本地开发,Neo4j适合企业级大规模图谱。
版权与免责声明:本文仅用于信息分享与交流,不构成任何形式的法律、投资、医疗或其他专业建议,也不构成对任何结果的承诺或保证。
文中提及的商标、品牌、Logo、产品名称及相关图片/素材,其权利归各自合法权利人所有。本站内容可能基于公开资料整理,亦可能使用 AI 辅助生成或润色;我们尽力确保准确与合规,但不保证完整性、时效性与适用性,请读者自行甄别并以官方信息为准。
若本文内容或素材涉嫌侵权、隐私不当或存在错误,请相关权利人/当事人联系本站,我们将及时核实并采取删除、修正或下架等处理措施。 也请勿在评论或联系信息中提交身份证号、手机号、住址等个人敏感信息。