LeanKG logo

LeanKG

Indexes repositories into an access-controlled code graph for agent queries about callers, dependents, impact, tests, and documentation.

Install LeanKG

Run the project’s own setup commands, in order.

Setup steps from the project

LeanKG installs with its own steps rather than a config we can generate, so these are copied as-is. Follow them in order and run the commands in a terminal. Source: github.com

  1. 1. Start the server
    leankg serve --http 127.0.0.1:9699 --rest 127.0.0.1:8080 --memory
    
  2. 2. Add to your MCP client
    leankg install --target claude-code --http --url http://127.0.0.1:9699/mcp
    
  3. 3. Install
    go install github.com/FreePeak/LeanKG/cmd/leankg@latest         # server + CLI
    
  4. 4. Install
    git clone https://github.com/FreePeak/LeanKG.git && cd LeanKG
    

Overview

LeanKG provides AI coding agents with a self-hosted code knowledge graph through MCP. It indexes repositories into SQLite by default, with optional PostgreSQL and pgvector for shared deployments, and exposes import, query, status, and authentication tools. Query responses identify the retrieval rung and index freshness, while access is controlled with bearer tokens and Viewer, Contributor, and Admin roles. Reach for LeanKG when agents need targeted code relationships or impact analysis instead of repeatedly scanning whole files.

Use cases

  • Index a repository for targeted agent code queries
  • Trace callers and dependents before changing a symbol
  • Estimate change impact across imports and calls
  • Retrieve tests and documentation related to code
  • Serve multiple projects through one controlled deployment

Key features

  • Code graph queries over MCP
  • Caller, dependent, and blast-radius analysis
  • Exact, keyword, and optional semantic retrieval
  • SQLite or PostgreSQL with pgvector storage
  • Bearer-token authentication with role floors
  • Stdio and streamable HTTP MCP transports

Security & health

What it can reach and how reliably it runs — from our own checks, not the maintainer’s claims.

ActiveLast checked

Recent health check succeeded.

19/19 checks healthy over the last 45d

Adoption & maintenance

Factual signals from GitHub, npm, and our automated checks — not a rating.

GitHub stars223Stargazers on the source repository.
Last commit6d agoMost recent push to the default branch.
Directory activity2 viewsConfig copies, upvotes, and views on AllMCPs.

How LeanKG works

What LeanKG does

LeanKG gives coding agents a structured view of a repository, including callers, dependents, imports, tests, documentation, and change impact. Agents can request a targeted subgraph rather than repeatedly searching and reading large files. Impact analysis follows contains, calls, and imports relationships with a breadth-first traversal.

The server supports multiple projects. Each request selects the project being queried, allowing one deployment to serve more than one repository. Query results include retrieval metadata and freshness information, so clients can distinguish an exact result from a fallback and identify whether the index may be stale.

How it works

The CLI indexes a repository into a .leankg/leankg.db SQLite database by default. When run from a Git repository, indexing reads objects from the HEAD commit; uncommitted and ignored files are not included. A project can then be exposed to an agent over MCP using either standard input/output or streamable HTTP.

Search uses a retrieval ladder. Exact and keyword matching work without embeddings. Optional semantic search uses embeddings from the configured provider and falls back to available indexed data if vector retrieval is unavailable. Supported embedding providers are local, openai, and deterministic for tests.

LeanKG can also run with PostgreSQL and pgvector for shared, server-scale deployments. Its executable is CGO-free, and a container image is available. HTTP, REST, ConnectRPC, and a web UI are also supported alongside MCP.

Setup and configuration

Install the CLI with Go, index a repository, and add an MCP configuration for the chosen agent:

bash
go install github.com/FreePeak/LeanKG/cmd/leankg@latest
cd your-project
leankg index .
leankg install --target claude-code

The installation command supports JSON-configured targets including claude-code, cursor, codex, gemini, opencode, and omp, plus an xdev YAML target. Restart the client after installation so it loads the MCP entry.

For a shared HTTP process, run leankg serve --http and install an MCP URL ending in /mcp. The HTTP server resolves the project from its working directory unless --project DIR is supplied. GET /health reports readiness. Use leankg doctor to inspect the store path, indexed element and file counts, and the write watermark; --deep enables extended checks.

Set LEANKG_EMBED_PROVIDER when enabling semantic search. A non-loopback HTTP, REST, or RPC listener requires a configured bearer token. The --read-only mode opens the store without migrations and rejects mutating requests.

Tools and capabilities

  • import for importing or updating indexed code data.
  • query for retrieving code-graph context, including relationship and impact information.
  • status for checking index state.
  • authenticate for authentication flows exposed through MCP.
  • Role-based access with Viewer, Contributor, and Admin levels.
  • Bearer tokens that can expire and be revoked.
  • SQLite storage by default, or PostgreSQL with pgvector as an opt-in backend.

Limitations and notes

Indexing from a Git repository uses the HEAD commit, so local uncommitted and ignored files are excluded. Semantic retrieval requires an embedding provider; exact and keyword retrieval do not. Network listeners enforce an exposure guard and refuse non-loopback binds without bearer-token configuration. Read-only mode prevents writes, including mutating MCP operations.

Written by AllMCPs with AI assistance from the project’s README and listing data. How we build listings

Reviews

No reviews yet — be the first to share how it worked for you.

Frequently Asked Questions about LeanKG

LeanKG is an MCP server that connects AI coding agents to a self-hosted code knowledge graph. Its main tools are import, query, status, and authenticate. It indexes repositories and exposes callers, dependents, impact relationships, tests, documentation, retrieval metadata, and freshness information under configurable access controls.

Install LeanKG with Go using `go install github.com/FreePeak/LeanKG/cmd/leankg@latest`, run `leankg index .` in the repository, then use `leankg install --target` for a supported client. Restart the client after installation so it loads the generated MCP configuration.

Yes, LeanKG includes a Cursor installation target. After indexing the repository, run `leankg install --target cursor` and restart Cursor. LeanKG can also serve MCP over HTTP when multiple clients need to connect to one process.

Set `LEANKG_EMBED_PROVIDER` to configure an embedding provider, then run `leankg index` so embeddings are added incrementally. Exact and keyword retrieval work without this setting, and an embedding failure is reported without failing the overall index operation.

Yes, LeanKG supports Viewer, Contributor, and Admin roles, bearer tokens, route-level role requirements, token expiry, and token revocation. Non-loopback HTTP, REST, or RPC listeners require bearer-token configuration, and read-only mode rejects mutating requests.

Related MCP servers

Add a badge to your READMEShow it’s listed — live SVG, Markdown or HTML.

AllMCPs Directory Badge

Full Badge Customizer

Showcase your server listing on GitHub or your project documentation. Embed this dynamic SVG badge to highlight official listing status and live engagement.

Badge Style:
Live Dynamic SVG PreviewLeanKG AllMCPs Directory Badge
Markdown (GitHub README)
[![AllMCPs](https://allmcps.com/api/badge/leankg?style=directory)](https://allmcps.com/mcp/leankg)
HTML Embed
<a href="https://allmcps.com/mcp/leankg"><img src="https://allmcps.com/api/badge/leankg?style=directory" alt="LeanKG on AllMCPs" /></a>