# LeanKG [Health: Active]

**Category:** 🤖 Coding Agents  
**Repository:** https://github.com/FreePeak/LeanKG  
**GitHub Stars:** 223  
**Views:** 2  
**Installs:** 0  
**Upvotes:** 0  
**Directory Page:** https://allmcps.com/mcp/leankg

## Description
Code knowledge graph for AI coding agents (callers, dependents, blast radius, tests) served over MCP. Local server.

## Claude Desktop Quick Installation
No generated config for this server: it installs through its own setup steps.

The project's own setup steps (from https://github.com/FreePeak/LeanKG), copied verbatim. Follow them in order; they are not an mcpServers config.

1. Start the server:

```sh
leankg serve --http 127.0.0.1:9699 --rest 127.0.0.1:8080 --memory
```

2. Add to your MCP client:

```sh
leankg install --target claude-code --http --url http://127.0.0.1:9699/mcp
```

3. Install:

```sh
go install github.com/FreePeak/LeanKG/cmd/leankg@latest         # server + CLI
```

4. Install:

```sh
git clone https://github.com/FreePeak/LeanKG.git && cd LeanKG
```

## Documentation

## 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.

_Full upstream README: https://allmcps.com/mcp/leankg/readme_

