AI Skill Hub 强烈推荐:代码图谱 是一款优质的MCP工具。已获得 2.3k 颗 GitHub Star,AI 综合评分 8.2 分,在同类工具中表现稳健。如果你正在寻找可靠的MCP工具解决方案,这是一个值得深入了解的选择。
代码图谱 是一款遵循 MCP(Model Context Protocol)标准协议的 AI 工具扩展。通过 MCP 协议,它可以让 Claude、Cursor 等主流 AI 客户端直接访问和操作外部工具、数据源和服务,实现 AI 能力的无缝扩展。无论是文件操作、数据库查询还是 API 调用,都可以通过自然语言在 AI 对话中直接触发,极大提升生产效率。
代码图谱 是一款遵循 MCP(Model Context Protocol)标准协议的 AI 工具扩展。通过 MCP 协议,它可以让 Claude、Cursor 等主流 AI 客户端直接访问和操作外部工具、数据源和服务,实现 AI 能力的无缝扩展。无论是文件操作、数据库查询还是 API 调用,都可以通过自然语言在 AI 对话中直接触发,极大提升生产效率。
# 方式一:通过 Claude Code CLI 一键安装
claude skill install https://github.com/vitali87/code-graph-rag
# 方式二:手动配置 claude_desktop_config.json
{
"mcpServers": {
"----": {
"command": "npx",
"args": ["-y", "code-graph-rag"]
}
}
}
# 配置文件位置
# macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
# Windows: %APPDATA%/Claude/claude_desktop_config.json
# 安装后在 Claude 对话中直接使用 # 示例: 用户: 请帮我用 代码图谱 执行以下任务... Claude: [自动调用 代码图谱 MCP 工具处理请求] # 查看可用工具列表 # 在 Claude 中输入:"列出所有可用的 MCP 工具"
// claude_desktop_config.json 配置示例
{
"mcpServers": {
"____": {
"command": "npx",
"args": ["-y", "code-graph-rag"],
"env": {
// "API_KEY": "your-api-key-here"
}
}
}
}
// 保存后重启 Claude Desktop 生效
<p> <a href="https://code-graph-rag.com"> <img src="https://img.shields.io/badge/Enterprise-Support%20%26%20Services-6366f1" alt="Enterprise Support" /> </a> <a href="https://pepy.tech/projects/code-graph-rag"> <img src="https://static.pepy.tech/personalized-badge/code-graph-rag?period=total&units=INTERNATIONAL_SYSTEM&left_color=BLACK&right_color=GREEN&left_text=downloads" alt="PyPI Downloads" /> </a> </p> </div>
| Language | Status | Extensions | Functions | Classes/Structs | Modules | Package Detection | Additional Features |
|---|---|---|---|---|---|---|---|
| C | Fully Supported | .c | ✓ | ✓ | ✓ | ✓ | Functions, structs, unions, enums, preprocessor includes |
| C++ | Fully Supported | .cpp, .h, .hpp, .cc, .cxx, .hxx, .hh, .ixx, .cppm, .ccm | ✓ | ✓ | ✓ | ✓ | Constructors, destructors, operator overloading, templates, lambdas, C++20 modules, namespaces |
| Java | Fully Supported | .java | ✓ | ✓ | ✓ | - | Generics, annotations, modern features (records/sealed classes), concurrency, reflection |
| JavaScript | Fully Supported | .js, .jsx | ✓ | ✓ | ✓ | - | ES6 modules, CommonJS, prototype methods, object methods, arrow functions |
| Lua | Fully Supported | .lua | ✓ | - | ✓ | - | Local/global functions, metatables, closures, coroutines |
| PHP | Fully Supported | .php | ✓ | ✓ | ✓ | - | Classes, interfaces, traits, enums, namespaces, PHP 8 attributes |
| Python | Fully Supported | .py | ✓ | ✓ | ✓ | ✓ | Type inference, decorators, nested functions |
| Rust | Fully Supported | .rs | ✓ | ✓ | ✓ | ✓ | impl blocks, associated functions |
| TypeScript | Fully Supported | .ts, .tsx | ✓ | ✓ | ✓ | - | Interfaces, type aliases, enums, namespaces, ES6/CommonJS modules |
| Go | In Development | .go | ✓ | ✓ | ✓ | - | Methods, type declarations |
| Scala | In Development | .scala, .sc | ✓ | ✓ | ✓ | - | Case classes, objects |
pyproject.toml to understand external dependenciesrg) (required for shell command text searching)uv package managerollama pull llama3.2
On macOS:
brew install cmake ripgrep
On Linux (Ubuntu/Debian):
sudo apt-get update
sudo apt-get install cmake ripgrep
On Linux (CentOS/RHEL): ```bash sudo yum install cmake sudo dnf install ripgrep
```
cgr is published to PyPI and can be installed system-wide so it works from any target repo without activating a project virtualenv. Install with the treesitter-full (all languages) and semantic (vector search) extras:
```bash
git clone https://github.com/vitali87/code-graph-rag.git
cd code-graph-rag
For basic Python support:
uv sync
For full multi-language support:
uv sync --extra treesitter-full
For development (including tests and pre-commit hooks):
make dev
This installs all dependencies and sets up pre-commit hooks automatically.
This installs Tree-sitter grammars for all supported languages (see Multi-Language Support section).
3. Set up environment variables: ```bash cp .env.example .env
curl -fsSL https://ollama.ai/install.sh | sh
cgr --help
claude mcp add --transport stdio code-graph-rag \
--env TARGET_REPO_PATH=/absolute/path/to/your/project \
--env CYPHER_PROVIDER=openai \
--env CYPHER_MODEL=gpt-4 \
--env CYPHER_API_KEY=your-api-key \
-- uv run --directory /path/to/code-graph-rag code-graph-rag mcp-server
You can build a binary of the application using the build_binary.py script. This script uses PyInstaller to package the application and its dependencies into a single executable.
python build_binary.py The resulting binary will be located in the dist directory.
The Code-Graph-RAG system offers four main modes of operation: 1. Parse & Ingest: Build knowledge graph from your codebase 2. Interactive Query: Ask questions about your code in natural language 3. Export & Analyze: Export graph data for programmatic analysis 4. AI Optimization: Get AI-powered optimization suggestions for your code. 5. Editing: Perform surgical code replacements and modifications with precise targeting.
cgr optimize java \ --reference-document ./ARCHITECTURE.md
> Index this repository
> What functions call UserService.create_user?
> Update the login function to add rate limiting
For detailed setup, see Claude Code Setup Guide.
cgr language add-grammar c-sharp cgr language add-grammar php cgr language add-grammar ruby cgr language add-grammar kotlin
#### Custom Grammar Repositories
For languages hosted outside the standard tree-sitter organization:
bash
```
The new provider-explicit configuration supports mixing different providers for orchestrator and cypher models.
```bash
ORCHESTRATOR_PROVIDER=ollama ORCHESTRATOR_MODEL=llama3.2 ORCHESTRATOR_ENDPOINT=http://localhost:11434/v1
CYPHER_PROVIDER=ollama CYPHER_MODEL=codellama CYPHER_ENDPOINT=http://localhost:11434/v1
#### Option 2: All OpenAI Modelsbash
ORCHESTRATOR_PROVIDER=openai ORCHESTRATOR_MODEL=gpt-4o ORCHESTRATOR_API_KEY=sk-your-openai-key
CYPHER_PROVIDER=openai CYPHER_MODEL=gpt-4o-mini CYPHER_API_KEY=sk-your-openai-key
#### Option 3: All Google Modelsbash
ORCHESTRATOR_PROVIDER=google ORCHESTRATOR_MODEL=gemini-2.5-pro ORCHESTRATOR_API_KEY=your-google-api-key
CYPHER_PROVIDER=google CYPHER_MODEL=gemini-2.5-flash CYPHER_API_KEY=your-google-api-key
#### Option 4: Mixed Providersbash
ORCHESTRATOR_PROVIDER=google ORCHESTRATOR_MODEL=gemini-2.5-pro ORCHESTRATOR_API_KEY=your-google-api-key
CYPHER_PROVIDER=ollama CYPHER_MODEL=codellama CYPHER_ENDPOINT=http://localhost:11434/v1
Get your Google API key from [Google AI Studio](https://aistudio.google.com/app/apikey).
**Install and run Ollama**:bash
cgr start --repo-path /path/to/repo --update-graph \ --batch-size 5000 ```
The system automatically detects and processes files for all supported languages (see Multi-Language Support section).
For active development, you can keep your knowledge graph automatically synchronized with code changes using the realtime updater. This is particularly useful when you're actively modifying code and want the AI assistant to always work with the latest codebase structure.
What it does: - Watches your repository for file changes (create, modify, delete) - Automatically updates the knowledge graph in real-time - Maintains consistency by recalculating all function call relationships - Filters out irrelevant files (.git, node_modules, etc.)
How to use:
Run the realtime updater in a separate terminal:
```bash
cgr optimize javascript --repo-path /path/to/frontend \ --batch-size 5000
**Supported Languages for Optimization:**
All supported languages: `python`, `javascript`, `typescript`, `rust`, `go`, `java`, `scala`, `c`, `cpp`
**How It Works:**
1. **Analysis Phase**: The agent analyzes your codebase structure using the knowledge graph
2. **Pattern Recognition**: Identifies common anti-patterns, performance issues, and improvement opportunities
3. **Best Practices Application**: Applies language-specific best practices and patterns
4. **Interactive Approval**: Presents each optimization suggestion for your approval before implementation
5. **Guided Implementation**: Implements approved changes with detailed explanations
**Example Optimization Session:** Starting python optimization session... ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ The agent will analyze your python codebase and propose specific ┃ ┃ optimizations. You'll be asked to approve each suggestion before ┃ ┃ implementation. Type 'exit' or 'quit' to end the session. ┃ ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
🔍 Analyzing codebase structure... 📊 Found 23 Python modules with potential optimizations
💡 Optimization Suggestion #1: File: src/data_processor.py Issue: Using list comprehension in a loop can be optimized Suggestion: Replace with generator expression for memory efficiency
[y/n] Do you approve this optimization?
**Reference Document Support:**
You can provide reference documentation (like coding standards, architectural guidelines, or best practices documents) to guide the optimization process:
bash
Configuration is managed through environment variables in .env file:
#### Orchestrator Model Configuration - ORCHESTRATOR_PROVIDER: Provider name (google, openai, ollama) - ORCHESTRATOR_MODEL: Model ID (e.g., gemini-2.5-pro, gpt-4o, llama3.2) - ORCHESTRATOR_API_KEY: API key for the provider (if required) - ORCHESTRATOR_ENDPOINT: Custom endpoint URL (if required) - ORCHESTRATOR_PROJECT_ID: Google Cloud project ID (for Vertex AI) - ORCHESTRATOR_REGION: Google Cloud region (default: us-central1) - ORCHESTRATOR_PROVIDER_TYPE: Google provider type (gla or vertex) - ORCHESTRATOR_THINKING_BUDGET: Thinking budget for reasoning models - ORCHESTRATOR_SERVICE_ACCOUNT_FILE: Path to service account file (for Vertex AI)
#### Cypher Model Configuration - CYPHER_PROVIDER: Provider name (google, openai, ollama) - CYPHER_MODEL: Model ID (e.g., gemini-2.5-flash, gpt-4o-mini, codellama) - CYPHER_API_KEY: API key for the provider (if required) - CYPHER_ENDPOINT: Custom endpoint URL (if required) - CYPHER_PROJECT_ID: Google Cloud project ID (for Vertex AI) - CYPHER_REGION: Google Cloud region (default: us-central1) - CYPHER_PROVIDER_TYPE: Google provider type (gla or vertex) - CYPHER_THINKING_BUDGET: Thinking budget for reasoning models - CYPHER_SERVICE_ACCOUNT_FILE: Path to service account file (for Vertex AI)
MEMGRAPH_HOST: Memgraph hostname (default: localhost)MEMGRAPH_PORT: Memgraph port (default: 7687)MEMGRAPH_HTTP_PORT: Memgraph HTTP port (default: 7444)LAB_PORT: Memgraph Lab port (default: 3000)MEMGRAPH_BATCH_SIZE: Batch size for Memgraph operations (default: 1000)TARGET_REPO_PATH: Default repository path (default: .)LOCAL_MODEL_ENDPOINT: Fallback endpoint for Ollama (default: http://localhost:11434/v1)cgr language list-languages
Code-Graph-RAG can run as an MCP (Model Context Protocol) server, enabling seamless integration with Claude Code and other MCP clients.
The agent is designed with a deliberate workflow to ensure it acts with context and precision, especially when modifying the file system.
cgr language remove-language <language-name>
#### Language Configuration
The system uses a configuration-driven approach for language support. Each language is defined in `codebase_rag/language_config.py` with the following structure:
python "language-name": LanguageConfig( name="language-name", file_extensions=[".ext1", ".ext2"], function_node_types=["function_declaration", "method_declaration"], class_node_types=["class_declaration", "struct_declaration"], module_node_types=["compilation_unit", "source_file"], call_node_types=["call_expression", "method_invocation"], ),
#### Troubleshooting
**Grammar not found**: If the automatic URL doesn't work, use a custom URL:bash cgr language add-grammar --grammar-url https://github.com/custom/tree-sitter-mylang
**Version incompatibility**: If you get "Incompatible Language version" errors, update your tree-sitter package:bash uv add tree-sitter@latest ```
Missing node types: The tool automatically detects common node patterns, but you can manually adjust the configuration in language_config.py if needed.
Code-Graph-RAG 是一个强大的代码知识图谱构建与检索增强生成(RAG)系统。它通过解析代码库的结构,将其转化为知识图谱,从而为开发者提供深度的代码理解能力,支持企业级的代码分析与智能交互需求。
本项目具备强大的多语言解析能力,能够深度支持 C、C++ 等语言的函数、类、结构体及模块检测。通过结合代码结构与语义信息,系统可以实现精准���代码索引、关系查询及基于上下文的智能代码分析。
运行本项目需要 Python 3.12+ 环境,并需安装 Docker & Docker Compose 以运行 Memgraph 数据库。此外,系统依赖 cmake 进行编译,使用 ripgrep 进行文本搜索。若使用云端模型需准备 Google Gemini API key,若使用本地模型则需安装 Ollama 并拉取相关模型(如 llama3.2)。
在安装依赖工具时,macOS 用户可以通过 brew 安装 cmake 和 ripgrep;Linux 用户(Ubuntu/Debian)建议使用 apt-get,CentOS/RHEL 用户则使用 yum 或 dnf。请确保在安装过程中正确配置环境,以便顺利构建 pymgclient 等核心依赖。
系统提供五种核心工作模式:1. Parse & Ingest(构建代码知识图谱);2. Interactive Query(通过自然语言询问代码逻辑);3. Export & Analyze(导出图数据进行程序化分析);4. AI Optimization(获取 AI 驱动的代码优化建议);5. Editing(执行精准的代码替换)。您可以直接通过命令行进行索引或针对特定逻辑进行提问。
用户可以通过编辑 .env 文件进行灵活配置。系统支持 provider-explicit 配置模式,允许开发者混合使用不同的模型提供商。例如,您可以配置 ORCHESTRATOR 使用 Ollama 本地模型进行任务编排,而 CYPHER 使用 OpenAI 模型来生成 Cypher 查询语句,实现性能与成本的最佳平衡。
Code-Graph-RAG 可作为 MCP (Model Context Protocol) Server 运行,实现与 Claude Code 及其他 MCP 客户端的无缝集成。系统内置了 Agentic Workflow(智能体工作流),确保 Agent 在执行文件系统修改等操作时具备高度的上下文感知能力与执行精度。
高质量的MCP工具,支持多语言代码分析
AI Skill Hub 为第三方内容聚合平台,本页面信息基于公开数据整理,不对工具功能和质量作任何法律背书。
建议在沙箱或测试环境中充分验证后,再部署至生产环境,并做好必要的安全评估。
✅ MIT 协议 — 最宽松的开源协议之一,可自由商用、修改、分发,仅需保留版权声明。
总体来看,代码图谱 是一款质量优秀的MCP工具,在同类工具中具备一定竞争力。AI Skill Hub 将持续追踪其更新动态,建议收藏备用,结合自身场景选择合适时机引入使用。
| 原始名称 | code-graph-rag |
| Topics | code-analysiscode-understandingpython |
| GitHub | https://github.com/vitali87/code-graph-rag |
| License | MIT |
| 语言 | Python |
收录时间:2026-07-02 · 更新时间:2026-07-02 · License:MIT · AI Skill Hub 不对第三方内容的准确性作法律背书。
选择 Agent 类型,复制安装指令后粘贴到对应客户端