LeanKG is a lightweight knowledge graph for codebase understanding. It indexes code, builds dependency graphs, calculates impact radius, and exposes everything via MCP for AI tool integration.
Tech Stack: Rust + CozoDB + tree-sitter + MCP
# Index a codebase
cargo run -- init
cargo run -- index ./src
# Calculate impact radius
cargo run -- impact src/main.rs 3
# Start MCP server
cargo run -- serveWhen implementing features, follow: docs/workflow-opencode-agent.md
- Update docs first - PRD (
docs/requirement/prd-leankg.md) → HLD (docs/design/hld-leankg.md) → README - Implement - Follow patterns in
docs/workflow-opencode-agent.md - Build & test -
cargo build && cargo test - Commit -
git commit -m "feat: description"(one feature per commit) - Push -
git pull --rebase && git push - Bump version - Update
versioninCargo.toml - Tag -
git tag -a v<version> -m "Release v<version>" && git push origin v<version>(after version bump)
- NEVER add
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>to commits - NEVER add
🤖 Generated with Claude Codeor similar AI attribution - NEVER add "Generated by" phrases in PR descriptions
cargo build # Build project
cargo test # Run tests
cargo run -- <cmd> # Run CLI commands| File | Purpose |
|---|---|
src/lib.rs |
Module exports |
src/db/models.rs |
Data models (CodeElement, Relationship, BusinessLogic) |
src/graph/query.rs |
Graph query engine |
src/mcp/tools.rs |
MCP tool definitions |
src/mcp/handler.rs |
MCP tool handlers |
src/indexer/extractor.rs |
Code parsing with tree-sitter |
- CodeElement - Files, functions, classes with
qualified_name(e.g.,src/main.rs::main) - Relationship -
imports,calls,tested_by,references,documented_by - BusinessLogic - Annotations linking code to business requirements
Core tools: query_file, get_dependencies, get_dependents, get_impact_radius, get_review_context, find_function, get_call_graph, search_code, generate_doc, find_large_functions, get_tested_by
Doc/Traceability tools: get_doc_for_file, get_files_for_doc, get_doc_structure, get_traceability, search_by_requirement, get_doc_tree, get_code_tree, find_related_docs
See docs/implementation-feature-verification-2026-03-25.md for test results.
Before ANY codebase search/navigation, use LeanKG tools:
mcp_status- check if ready. If not initialized, you MUST runmcp_initpassing the absolute path to the project's.leankgdirectory (e.g.path: "/full/workspace/path/.leankg").- Use tool:
search_code,find_function,query_file,get_impact_radius,get_dependencies,get_dependents,get_tested_by,get_context - Only fallback to grep/read if LeanKG fails
| Task | Use |
|---|---|
| Where is X? | search_code or find_function |
| What breaks if I change Y? | get_impact_radius |
| What tests cover Y? | get_tested_by |
| How does X work? | get_context |
Last updated: 2026-03-26