Skip to main content
Glama
Phyzx72
by Phyzx72
README.md
# sourcelens

**Token-efficient local code retrieval as an MCP server.** Index a codebase once with tree-sitter AST parsing, then query exact symbols — functions, classes, methods — instead of re-reading whole files into your context window.

Built from scratch, MIT-licensed. No paid license, no network, local-first.

## Why

Reading whole files to find one function is a token incinerator. `sourcelens` parses source into an AST once, stores each symbol's name, kind, qualified name, signature, and exact byte offsets, then serves precise bodies on demand. Pull only the function you need — not the 800-line module around it.

## Install

```bash
git clone <this-repo> sourcelens
cd sourcelens
uv venv .venv && source .venv/bin/activate
uv pip install -e .
```

Requires Python 3.10+.

## Run

Stdio (default MCP transport):

```bash
sourcelens          # or: python -m sourcelens.server
```

HTTP (for remote clients):

```bash
SOURCELENS_HTTP=1 SOURCELENS_PORT=8766 sourcelens
```

The index is a SQLite file at `~/.sourcelens/index.db` by default. Override with `SOURCELENS_DB=/path/to/index.db`.

## Tools

| Tool | What it does |
|------|--------------|
| `index_folder(path)` | Walk + parse every supported file, store symbols + imports |
| `search_symbols(query, kind?, language?)` | Find symbols by name substring |
| `get_symbol_source(id? / name?+file?)` | Fetch a symbol's exact body (byte-precise, no whole-file read) |
| `get_file_outline(file)` | List all symbols in a file, source order |
| `find_importers(target)` | Which files import a module |
| `find_imports(file)` | What a file imports |
| `stats()` | Index counts + per-language breakdown |
| `list_languages()` | Supported languages |

## Supported languages

Python (`.py`), JavaScript (`.js/.jsx`), TypeScript (`.ts/.tsx`), Go (`.go`), Rust (`.rs`), C/C++ (`.c/.h/.cpp/.hpp`).

## Usage pattern (the whole point)

1. `index_folder("/path/to/repo")` — once.
2. `search_symbols("handle_request")` — find it.
3. `get_symbol_source(name="handle_request")` — get *only* that function's body.

Never `Read` a whole file to find one symbol again.

## Tests

```bash
python -m pytest tests/ -v
```

## License

MIT. See `LICENSE`.

TDQS

A3.7/5.0

Scored across 8 tools

Disambiguation4/5

每个工具都有明确的资源+动作组合,但 find_importers 和 find_imports 的名称几乎相同,功能互为反向,可能造成误选。其余工具如 search_symbols 与 get_symbol_source 通过描述清楚区分。

Naming Consistency4/5

大多数工具遵循 snake_case 的 动词_名词 模式,如 search_symbols、get_symbol_source、find_importers。但 stats 是纯名词,且动词在 list/index/search/get/find 之间不统一,存在轻微不一致。

Tool Count5/5

8 个工具覆盖了索引、统计、符号搜索、源码获取、文件大纲和依赖分析,每个工具都有明确用途,没有冗余,范围对于代码索引服务器非常合适。

Completeness4/5

核心工作流(索引、查询符号、查看文件大纲、分析导入关系)覆盖完整。缺少显式的索引删除或清理操作,但 index_folder 的幂等重跑可以在一定程度上替代更新,代理也能通过重新索引绕过。

Maintenance

ActivityMaintained
ResponsivenessNo issues