freshcrate
Skin:/
Home > MCP Servers > LeanKG

LeanKG

LeanKG: Stop Burning Tokens. Start Coding Lean.

Why this rank:Strong adoptionRecent releaseHealthy release cadence

Description

LeanKG: Stop Burning Tokens. Start Coding Lean.

README

LeanKG

LeanKG

License: MIT Rust crates.io SafeSkill 77/100

Lightweight Knowledge Graph for AI-Assisted Development

LeanKG is a local-first knowledge graph that gives AI coding tools accurate codebase context. It indexes your code, builds dependency graphs, and exposes an MCP server so tools like Cursor, OpenCode, and Claude Code can query the knowledge graph directly. No cloud services, no external databases.

Visualize your knowledge graph with force-directed layout, WebGL rendering, and community clustering.

LeanKG Graph Visualization LeanKG Obsidian

See docs/web-ui.md for more features.


Live Demo

Try LeanKG without installing: https://leankg.onrender.com

leankg web --port 9000

Installation

One-Line Install (Recommended)

curl -fsSL https://raw.githubusercontent.com/FreePeak/LeanKG/main/scripts/install.sh | bash -s -- <target>

Supported targets:

Target AI Tool Auto-Installed
opencode OpenCode AI Binary + MCP + Plugin + Skill + AGENTS.md
cursor Cursor AI Binary + MCP + Skill + AGENTS.md + Session Hook
claude Claude Code Binary + MCP + Plugin + Skill + CLAUDE.md + Session Hook
gemini Gemini CLI Binary + MCP + Skill + GEMINI.md
kilo Kilo Code Binary + MCP + Skill + AGENTS.md
antigravity Google Antigravity Binary + MCP + Skill + GEMINI.md

Examples:

curl -fsSL https://raw.githubusercontent.com/FreePeak/LeanKG/main/scripts/install.sh | bash -s -- cursor
curl -fsSL https://raw.githubusercontent.com/FreePeak/LeanKG/main/scripts/install.sh | bash -s -- claude

Install via Cargo or Build from Source

cargo install leankg && leankg --version
git clone https://github.com/FreePeak/LeanKG.git && cd LeanKG && cargo build --release

Quick Start

leankg init                              # Initialize LeanKG in your project
leankg index ./src                        # Index your codebase
leankg watch ./src                        # Auto-index on file changes
leankg impact src/main.rs --depth 3       # Calculate blast radius
leankg status                             # Check index status
leankg metrics                            # View token savings
leankg web                                # Start Web UI at http://localhost:8080

# Obsidian vault sync
leankg obsidian init                      # Initialize Obsidian vault structure
leankg obsidian push                      # Push LeanKG data to Obsidian notes
leankg obsidian pull                      # Pull annotation edits from Obsidian
leankg obsidian watch                     # Watch vault for changes and auto-pull
leankg obsidian status                    # Show vault status

# Microservice call graph (via Web UI)
leankg web                                # Start Web UI at http://localhost:8080
                                          # Then visit http://localhost:8080/services

See docs/cli-reference.md for all commands.


Claude Code Setup

LeanKG auto-triggers in Claude Code sessions via PreToolUse hooks that route search intents to LeanKG tools instead of native tools.

# Install LeanKG with Claude Code hooks and plugin
leankg setup

# Then restart Claude Code or run:
/reload-plugins

What leankg setup installs:

  • .claude-plugin/ - Plugin manifest for Claude Code validation
  • hooks/ - PreToolUse, SessionStart, PostToolUse hooks
  • Adds leankg@local to enabledPlugins in ~/.claude/settings.json

Auto-trigger behavior:

  • SessionStart hook injects tool selection hierarchy into every session
  • PreToolUse hook nudges toward LeanKG when you use Grep/Read/Bash for code analysis
  • LeanKG returns token-optimized context instead of scanning entire files

How LeanKG Helps

graph LR
    subgraph "Without LeanKG"
        A1[AI Tool] -->|Full codebase context| B1[15,000-45,000 tokens]
        B1 --> A1
    end

    subgraph "With LeanKG"
        A2[AI Tool] -->|Targeted subgraph| C[LeanKG Graph]
        C -->|Context reduction| A2
    end
Loading

Without LeanKG: AI processes full context from files found via grep/search. With LeanKG: AI queries knowledge graph for targeted context. Token reduction varies by task complexity (see benchmark results).


Highlights

  • Auto-Init -- Install script configures MCP, rules, skills, and hooks automatically
  • Auto-Trigger -- Session hooks inject LeanKG context into every AI tool session
  • Token Optimized -- Targeted subgraph retrieval vs full file scanning
  • Impact Radius -- Compute blast radius before making changes
  • Dependency Graph -- Build call graphs with IMPORTS, CALLS, TESTED_BY edges
  • MCP Server -- Expose graph via MCP protocol for AI tool integration
  • Multi-Language -- Index Go, TypeScript, Python, Rust, Java, Kotlin with tree-sitter
  • Android -- Extract XML layouts, resources, and manifest relationships

See docs/architecture.md for system design and data model details.


Supported AI Tools

Tool Auto-Setup Session Hook Plugin
Cursor Yes session-start -
Claude Code Yes session-start Yes
OpenCode Yes - Yes
Kilo Code Yes - -
Gemini CLI Yes - -
Google Antigravity Yes - -
Codex Yes - -

Note: Cursor requires per-project installation. The AI features work on a per-workspace basis, so LeanKG should be installed in each project directory where you want AI context injection.

See docs/agentic-instructions.md for detailed setup and auto-trigger behavior.


Context Metrics

Track token savings to understand LeanKG's efficiency.

leankg metrics --json              # View with JSON output
leankg metrics --since 7d           # Filter by time
leankg metrics --tool search_code   # Filter by tool

See docs/metrics.md for schema and examples.


Update

# Check current version
leankg version

# Update LeanKG binary (kills processes, removes old binary, installs hooks)
leankg update

# Or via install script
curl -fsSL https://raw.githubusercontent.com/FreePeak/LeanKG/main/scripts/install.sh | bash -s -- update

# Obsidian vault sync
leankg obsidian init                      # Initialize Obsidian vault
leankg obsidian push                      # Push LeanKG data to Obsidian notes
leankg obsidian pull                      # Pull annotation edits from Obsidian

Documentation

Doc Description
docs/cli-reference.md All CLI commands
docs/mcp-tools.md MCP tools reference
docs/agentic-instructions.md AI tool setup & auto-trigger
docs/architecture.md System design, data model
docs/web-ui.md Web UI features
docs/metrics.md Metrics schema & examples
docs/benchmark.md Performance benchmarks
docs/roadmap.md Feature planning
docs/tech-stack.md Tech stack & structure
docs/android-extraction.md Android XML & resource extraction

Troubleshooting

Database Lock Error

If you see database is locked (code 5), another LeanKG process is holding the database:

# Kill all leankg and vite processes
leankg-kill

# Or manually
pkill -9 -f "leankg"
pkill -9 -f "vite"

Process Management

leankg proc kill        # Kill all leankg and vite processes
leankg proc status      # Show running leankg/vite processes

Important: Always kill the web server before indexing to avoid database lock conflicts.


Performance Benchmarks

Load Test Results (100K nodes)

Operation Throughput
Insert elements ~57,618 elements/sec
Insert relationships ~67,067 relationships/sec
Retrieve all elements ~418,718 elements/sec
Cache speedup (cold to warm) 345-461x

Run load tests:

cargo test --release load_test -- --nocapture

A/B Benchmark Results

See tests/benchmark/results/clean-benchmark-2026-04-21.md for detailed A/B testing results comparing LeanKG vs baseline code search.


Requirements

  • Rust 1.70+
  • macOS or Linux

License

MIT


Star History

Star History Chart

Release History

VersionChangesUrgencyDate
v0.17.1## What's Changed * fix: use proper CozoDB count aggregation for mcp_status by @linhdmn in https://github.com/FreePeak/LeanKG/pull/41 * support Dart by @MinhDuy-creator in https://github.com/FreePeak/LeanKG/pull/24 * feat: knowledge contribution, versioning, and RBAC via MCP by @linhdmn in https://github.com/FreePeak/LeanKG/pull/44 * feat: LeanKG v2 — Environment Namespacing & Incident Knowledge Layer by @linhdmn in https://github.com/FreePeak/LeanKG/pull/48 * chore(deps): bump rand from 0.8.5 tHigh6/4/2026
v0.17.0## What's Changed * fix: prevent zombie processes with proper graceful shutdown by @linhdmn in https://github.com/FreePeak/LeanKG/pull/39 * fix: prevent self-termination during leankg update by @linhdmn in https://github.com/FreePeak/LeanKG/pull/38 * fix: MCP tool robustness and HTTP auto-index by @linhdmn in https://github.com/FreePeak/LeanKG/pull/40 **Full Changelog**: https://github.com/FreePeak/LeanKG/compare/v0.16.9...v0.17.0 ## What's Changed * fix: prevent zombie processes with proper High5/8/2026
v0.16.9## What's Changed * fix: reduce watcher CPU/RAM by 90%+ with debouncing, DB reuse, and file filtering by @linhdmn in https://github.com/FreePeak/LeanKG/pull/31 * feat: memory-efficient query methods and cache optimizations by @linhdmn in https://github.com/FreePeak/LeanKG/pull/30 * feat: auto-start API server when MCP server starts by @linhdmn in https://github.com/FreePeak/LeanKG/pull/23 * fix: validate required parameters before dispatching to handlers by @linhdmn in https://github.com/FreePeaHigh5/4/2026
v0.16.7## What's Changed * bump: version to v0.16.5 by @linhdmn in https://github.com/FreePeak/LeanKG/pull/22 * feat: Android navigation and Kotlin analysis support by @hossihub in https://github.com/FreePeak/LeanKG/pull/18 * perf: CPU optimization Phase 1 - reduce idle CPU from 61% to <5% by @linhdmn in https://github.com/FreePeak/LeanKG/pull/25 **Full Changelog**: https://github.com/FreePeak/LeanKG/compare/v0.16.5...v0.16.7 ## What's Changed * bump: version to v0.16.5 by @linhdmn in https://githubHigh4/24/2026
v0.16.5## What's Changed * fix: update leankg command to install hooks and remove old skill by @linhdmn in https://github.com/FreePeak/LeanKG/pull/21 **Full Changelog**: https://github.com/FreePeak/LeanKG/compare/v0.16.4...v0.16.5 ## What's Changed * fix: update leankg command to install hooks and remove old skill by @linhdmn in https://github.com/FreePeak/LeanKG/pull/21 **Full Changelog**: https://github.com/FreePeak/LeanKG/compare/v0.16.4...v0.16.5 ## What's Changed * fix: update leankg commandHigh4/20/2026
v0.16.4**Full Changelog**: https://github.com/FreePeak/LeanKG/compare/v0.16.3...v0.16.4 **Full Changelog**: https://github.com/FreePeak/LeanKG/compare/v0.16.3...v0.16.4 **Full Changelog**: https://github.com/FreePeak/LeanKG/compare/v0.16.3...v0.16.4 **Full Changelog**: https://github.com/FreePeak/LeanKG/compare/v0.16.3...v0.16.4High4/20/2026
v0.16.0## What's Changed * feat: allow multiple concurrent MCP server sessions by @linhdmn in https://github.com/FreePeak/LeanKG/pull/17 **Full Changelog**: https://github.com/FreePeak/LeanKG/compare/v0.15.3...v0.16.0 ## What's Changed * feat: allow multiple concurrent MCP server sessions by @linhdmn in https://github.com/FreePeak/LeanKG/pull/17 **Full Changelog**: https://github.com/FreePeak/LeanKG/compare/v0.15.3...v0.16.0 ## What's Changed * feat: allow multiple concurrent MCP server sessions High4/20/2026
v0.15.3## What's Changed * feat: add leankg proc command for process management by @linhdmn in https://github.com/FreePeak/LeanKG/pull/11 * fix: add memory limits and single-instance lock for MCP server by @linhdmn in https://github.com/FreePeak/LeanKG/pull/15 **Full Changelog**: https://github.com/FreePeak/LeanKG/compare/v0.15.2...v0.15.3 ## What's Changed * feat: add leankg proc command for process management by @linhdmn in https://github.com/FreePeak/LeanKG/pull/11 * fix: add memory limits and siHigh4/20/2026
v0.15.2## What's Changed * Fix/mcp multi project routing by @linhdmn in https://github.com/FreePeak/LeanKG/pull/6 * feat: MCP Token Compression & Context Bounds Integration by @nkchuong1607 in https://github.com/FreePeak/LeanKG/pull/9 * feat: Android extraction with view binding and resource relationships by @hossihub in https://github.com/FreePeak/LeanKG/pull/10 * Feature/massive graph by @linhdmn in https://github.com/FreePeak/LeanKG/pull/8 * fix: improve orchestrate tool to resolve module names by @High4/19/2026
v0.15.1## What's Changed * Fix/exclude patterns by @linhdmn in https://github.com/FreePeak/LeanKG/pull/5 **Full Changelog**: https://github.com/FreePeak/LeanKG/compare/v0.15.0...v0.15.1 ## What's Changed * Fix/exclude patterns by @linhdmn in https://github.com/FreePeak/LeanKG/pull/5 **Full Changelog**: https://github.com/FreePeak/LeanKG/compare/v0.15.0...v0.15.1 ## What's Changed * Fix/exclude patterns by @linhdmn in https://github.com/FreePeak/LeanKG/pull/5 **Full Changelog**: https://github.cHigh4/14/2026
v0.15.0## What's Changed * Feature/service calls by @linhdmn in https://github.com/FreePeak/LeanKG/pull/4 **Full Changelog**: https://github.com/FreePeak/LeanKG/compare/v0.14.9...v0.15.0 ## What's Changed * Feature/service calls by @linhdmn in https://github.com/FreePeak/LeanKG/pull/4 **Full Changelog**: https://github.com/FreePeak/LeanKG/compare/v0.14.9...v0.15.0 ## What's Changed * Feature/service calls by @linhdmn in https://github.com/FreePeak/LeanKG/pull/4 **Full Changelog**: https://githuHigh4/14/2026
v0.14.9**Full Changelog**: https://github.com/FreePeak/LeanKG/compare/v0.14.8...v0.14.9 **Full Changelog**: https://github.com/FreePeak/LeanKG/compare/v0.14.8...v0.14.9 **Full Changelog**: https://github.com/FreePeak/LeanKG/compare/v0.14.8...v0.14.9 **Full Changelog**: https://github.com/FreePeak/LeanKG/compare/v0.14.8...v0.14.9Medium4/14/2026
v0.14.7Release v0.14.7 **Full Changelog**: https://github.com/FreePeak/LeanKG/compare/v0.14.6...v0.14.7 **Full Changelog**: https://github.com/FreePeak/LeanKG/compare/v0.14.6...v0.14.7 **Full Changelog**: https://github.com/FreePeak/LeanKG/compare/v0.14.6...v0.14.7 **Full Changelog**: https://github.com/FreePeak/LeanKG/compare/v0.14.6...v0.14.7Medium4/13/2026
v0.14.6Release v0.14.6Medium4/13/2026
v0.12.2## What's Changed * feat: add --dir flag to mcp-stdio command for explicit directory by @linhdmn in https://github.com/FreePeak/LeanKG/pull/39 **Full Changelog**: https://github.com/FreePeak/LeanKG/compare/v0.12.1...v0.12.2 ## What's Changed * feat: add --dir flag to mcp-stdio command for explicit directory by @linhdmn in https://github.com/FreePeak/LeanKG/pull/39 **Full Changelog**: https://github.com/FreePeak/LeanKG/compare/v0.12.1...v0.12.2 ## What's Changed * feat: add --dir flag to mcHigh4/11/2026
v0.10.0## What's Changed * [FR-AUTOINDEX] Auto-Index on DB Write - WriteTracker by @linhdmn in https://github.com/FreePeak/LeanKG/pull/23 * feat: Add context metrics tracking with CLI and seed command by @linhdmn in https://github.com/FreePeak/LeanKG/pull/26 **Full Changelog**: https://github.com/FreePeak/LeanKG/compare/v0.9.4...v0.10.0 ## What's Changed * [FR-AUTOINDEX] Auto-Index on DB Write - WriteTracker by @linhdmn in https://github.com/FreePeak/LeanKG/pull/23 * feat: Add context metrics trackiHigh4/9/2026

Dependencies & License Audit

Loading dependencies...

Similar Packages

ClawCodePersistent agents for Claude Code as a plugin, not a harness. Memory, personality, messaging across WhatsApp, Telegram, and Discord, plus a service mode for 24/7 runs. Imports from OpenClaw.v1.7.4
nodespace-coreLocal-first knowledge base with semantic search for AI coding assistants. Fewer tokens, faster context.v0.1.6
Perplexity-Comet-MCPNo descriptionmain@2026-06-07
google-workspace-mcp-with-scriptNo descriptionmain@2026-06-07
claude-blockerđŸ›Ąī¸ Block distracting websites when Claude Code is in use, ensuring focused work sessions and minimizing interruptions.main@2026-06-07

More from FreePeak

db-mcp-serverA powerful multi-database server implementing the Model Context Protocol (MCP) to provide AI assistants with structured access to databases.

More in MCP Servers

PlanExeCreate a plan from a description in minutes
automagik-genieSelf-evolving AI agent orchestration framework with Model Context Protocol support
agentroveYour own Claude Code UI, sandbox, in-browser VS Code, terminal, multi-provider support (Anthropic, OpenAI, GitHub Copilot, OpenRouter), custom skills, and MCP servers.
ProxmoxMCP-PlusEnhanced Proxmox MCP server with advanced virtualization management and full OpenAPI integration.