
LeanKG
by FreePeak·★ 188·综合分 50
LeanKG 是一个轻量级知识图谱,通过索引代码库并通过 MCP 暴露给 AI 开发工具,显著减少 token 消耗。
概述
LeanKG 是一个基于 Rust 的本地知识图谱,专为 AI 编程工具提供准确的代码库上下文。它索引代码文件,构建依赖关系图,并通过 MCP 服务器使 AI 工具(如 Cursor、OpenCode 和 Claude Code)能够直接查询知识图谱。系统提供影响半径计算、依赖关系图可视化、令牌优化和多语言支持等功能。与基于云的解决方案不同,LeanKG 本地运行,无需外部数据库依赖,解决了 AI 工具处理完整代码库上下文时的高 token 消耗问题。
试试问 AI
装完之后,这里有 7 个你可以让 AI 做的事:
什么时候选它
当您需要一个本地自托管知识图谱来提高 AI 编程工具在代码库上下文中的准确性,且不希望依赖云服务时,选择 LeanKG。
什么时候不要选它
如果您需要基于云的协作功能或需要写入知识图谱的权限,不要选择 LeanKG,因为它主要是一个只读系统。
此 server 暴露的工具
从 README 抽取出 12 个工具search_codeSearch for code patterns or specific implementations in the knowledge graph
find_dependenciesFind dependencies between code elements and analyze impact radius
get_element_infoRetrieve detailed information about a specific code element
detect_clustersIdentify functional code communities and clusters in the codebase
trace_featureTrace feature implementation across the codebase
annotate_codeAdd annotations to code elements for better context
export_graphExport the knowledge graph in various formats
analyze_qualityAnalyze code quality and find oversized functions
get_metricsView token savings and context reduction metrics
detect_changesDetect changes in codebase and classify risk level
run_commandExecute shell commands with RTK compression to save tokens
register_repoRegister a new repository for multi-repo context management
可对比工具
安装
安装
一键安装(推荐)
curl -fsSL https://raw.githubusercontent.com/FreePeak/LeanKG/main/scripts/install.sh | bash -s -- <target>支持的目标包括:cursor、claude、opencode、kilo、antigravity、gemini、codex
通过 Cargo 安装
cargo install leankg && leankg --versionClaude Code 集成
# 安装 Claude Code 钩子
leankg setup
# 重启 Claude Code 或运行:
/reload-plugins配置
LeanKG 在设置过程中创建 MCP 配置。手动设置请参阅 docs/mcp-tools.md 了解 MCP 服务器配置。
FAQ
- LeanKG 支持哪些 AI 工具?
- LeanKG 支持 Cursor、Claude Code、OpenCode、Kilo Code、Gemini CLI、Google Antigravity 和 Codex,集成程度包括自动设置、会话钩子和插件。
- LeanKG 如何减少 token 消耗?
- LeanKG 构建知识图谱,使 AI 工具可以查询特定子图,而不是处理完整代码库上下文,将 token 消耗从 15,000-45,000 减少到相关代码。
- LeanKG 是基于云的吗?
- 不是,LeanKG 是本地优先的解决方案,完全在您的机器上运行,无需云服务或外部数据库依赖。
LeanKG 对比
最后更新于 · 由 README + GitHub 公开数据自动生成。