Lybrary,a persistent AST-aware code memory for AI agents(MCP server pip install)

vibhudixit_301 pts0 comments

GitHub - vibhu-dixit/lybrary: Living structure-aware code memory for AI coding agents Β· GitHub

/" data-turbo-transient="true" />

Skip to content

Type / to search

Sign in<br>Sign upAppearance settings

You signed in with another tab or window. Reload to refresh your session.<br>You signed out in another tab or window. Reload to refresh your session.<br>You switched accounts on another tab or window. Reload to refresh your session.

Dismiss alert

{{ message }}

vibhu-dixit

lybrary

Public

Notifications<br>You must be signed in to change notification settings

Fork

Star

main

BranchesTags

Go to file

CodeOpen more actions menu

Folders and files<br>NameNameLast commit message<br>Last commit date<br>Latest commit

History<br>1 Commit<br>1 Commit

.github/workflows

.github/workflows

lybrary

lybrary

tests

tests

.gitignore

.gitignore

CHANGELOG.md

CHANGELOG.md

README.md

README.md

pyproject.toml

pyproject.toml

View all files

Repository files navigation

🧠 lybrary

Living structure-aware code memory for AI coding agents.

pip install lybrary

The problem

Every time an AI agent starts a session, it re-reads your codebase from scratch.

agent: let me grep for auth logic...<br>agent: reading src/auth/middleware.py...<br>agent: reading src/auth/jwt.py...<br>agent: reading src/auth/session.py...<br>agent: reading src/utils/crypto.py...<br>↳ 4,000 tokens burned before writing a single line.

On a large codebase this happens dozens of times per session. Tokens wasted. Context filled. Same files read over and over.

The solution

lybrary gives your agent a persistent memory it can query instead of reading files.

agent: memory_query("authentication flow")<br>↳ 3 chunks returned. 180 tokens. Done.

It indexes your repo using real AST boundaries, keeps the index fresh automatically, and exposes it as an MCP server that any AI IDE connects to natively.

✨ Features

🌳 AST-aware chunking<br>tree-sitter parses your code β€” never splits a function in half

⚑ Background daemon<br>watches for file changes, re-indexes only what changed

πŸ” Semantic search<br>vector search with token-budget packing

πŸ”Œ MCP server<br>works with Kiro, Cursor, Claude Desktop, Windsurf out of the box

πŸ“¦ Fully local<br>no cloud, no API keys, embeddings run on your machine

🐍 Pure pip install<br>Python 3.11–3.14, no PyTorch, no compilation needed

Supported languages: Python Β· JavaScript Β· TypeScript Β· TSX Β· Go Β· Rust Β· Java Β· C Β· C++

πŸš€ Quick start

pip install lybrary

cd /path/to/your/repo<br>lybrary init<br>lybrary start # builds index + starts background daemon<br>lybrary query "authentication flow"

After lybrary start, the daemon keeps running even after you close the terminal. File changes are picked up automatically β€” only affected chunks are re-indexed.

πŸ”Œ MCP integration

Add to your MCP config (Kiro, Cursor, Claude Desktop, Windsurf):

"mcpServers": {<br>"lybrary": {<br>"command": "lybrary",<br>"args": ["mcp"]

Your agent now has three tools:

Tool<br>What it does

memory_query<br>Semantic search β€” returns ranked chunks with full source, file path, and line numbers

memory_status<br>Reports daemon state, chunk count, and tracked files

memory_update<br>Triggers incremental or full re-index, optionally scoped to specific files

Agents should call memory_query before reading any files.<br>This replaces multi-file reads with a single targeted query β€” cutting token usage by 80–90% on large codebases.

πŸ–₯️ CLI reference

Command<br>Description

lybrary init<br>Create .lybrary/ and default config

lybrary start<br>Index (if needed) + start persistent daemon

lybrary stop<br>Stop the daemon

lybrary status<br>Show running state, chunk count, tracked files

lybrary index<br>Force (re)index

lybrary query<br>Semantic search over the memory

lybrary logs<br>View / follow daemon log

lybrary mcp<br>Start MCP server (stdio transport)

πŸ—οΈ How chunking works

your file<br>tree-sitter parser<br>AST definition nodes ← functions, classes, methods, interfaces<br>β”œβ”€β”€ class Foo ──────────► chunk: entire class body<br>β”‚ β”œβ”€β”€ def bar ───────► chunk: method bar (its own chunk too)<br>β”‚ └── def baz ───────► chunk: method baz (its own chunk too)<br>└── module-level ────────► chunk: imports, constants, top-level statements

Each chunk gets a context header and is embedded with MiniLM-L6-v2 via ONNX Runtime β€” fast, local, no GPU needed.

πŸ—‚οΈ Architecture

.lybrary/<br>β”œβ”€β”€ config.toml # model, chunk size, ignore patterns<br>β”œβ”€β”€ index.db # SQLite: chunks + float32 vector blobs<br>β”œβ”€β”€ file_hashes.json # content-hash map for incremental updates<br>β”œβ”€β”€ daemon.pid<br>└── daemon.log

Indexer β€” tree-sitter β†’ AST chunks β†’ fastembed / ONNX Runtime embeddings

Store β€” SQLite + numpy (cosine similarity via batched dot product, no external vector DB)

Daemon β€” watchdog file watcher + debounce + incremental re-chunk/embed

MCP β€” FastMCP server over stdio

πŸ—ΊοΈ Roadmap

AST chunker (multi-language, cAST-style)

Incremental indexing via content hashes

Background daemon + file watcher (Windows + Unix)

CLI (init / start / stop / status / index / query / logs / mcp)

MCP server (memory_query, memory_status,...

lybrary daemon chunk files agent file

Related Articles