lens
Provides token-efficient code retrieval for coding agents by indexing repositories and enabling ranked snippet search, symbol outlines, and surgical line reads.
README
🔎 lens
Token-efficient code & doc retrieval for agents.
The biggest token sink for a coding agent is reading whole files to find a few relevant lines. lens fixes that: index a repo once, then search for ranked snippets, get a symbol outline of a file, or do a surgical line read — pulling just enough context instead of the whole file.
Part of tools-for-agents. Zero dependencies — Node standard library + built-in node:sqlite with FTS5 (BM25 ranking).
Why
| Without lens | With lens |
|---|---|
Read a 600-line file to find one function → ~6k tokens |
lens_search "parse auth header" → ~300 tokens of the exact snippets |
| Read a file just to learn its structure | lens_outline → a symbol map, ~100 tokens |
| Re-read whole files after each edit | incremental reindex touches only changed files |
CLI
node src/cli.js index . # build the index (incremental on re-run)
node src/cli.js search "websocket reconnect" -k 6 --tokens 1500 --glob 'src/*'
node src/cli.js outline src/server.js # symbol map, no full read
node src/cli.js read src/server.js 40 80 # surgical line range
node src/cli.js stats # index stats
Index location is ./.lens/index.db (override with LENS_DB).
MCP server (for agents)
{
"mcpServers": {
"lens": { "command": "node", "args": ["/abs/path/to/lens/mcp/mcp-server.js"],
"env": { "LENS_DB": "/abs/path/to/repo/.lens/index.db" } }
}
}
Tools
| Tool | Use it to… |
|---|---|
lens_index |
Index / refresh a path (incremental: only changed files re-read). |
lens_search |
Get ranked snippets within a token budget — use instead of reading files. |
lens_outline |
Get a file's symbol map (functions/classes/headings) with line numbers. |
lens_read |
Read an exact line range. |
lens_map |
List indexed files + language breakdown. |
lens_stats |
Index statistics. |
How it works
- Walks a tree (skipping
node_modules,.git, build dirs, binaries, huge files). - Chunks each file into overlapping line windows and stores them in an FTS5 virtual table.
searchruns an FTS5MATCHranked by bm25, then fills results up to a token budget (≈4 chars/token).outlineis regex-based per language (js/ts, py, go, rust, java, ruby, sql, markdown…).indexis incremental — files unchanged since last index (by mtime) are skipped.
MIT licensed.
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
Neon Database
MCP server for interacting with Neon Management API and databases
E2B
Using MCP to run code via e2b.
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.