Skip to main content
Glama
sourcelens
by Phyzx72

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.

Related MCP server: codegraph-mcp

Install

git clone https://github.com/Phyzx72/sourcelens.git
cd sourcelens
uv venv .venv && source .venv/bin/activate
uv pip install -e .

Requires Python 3.10+.

Run

Stdio (default MCP transport):

sourcelens          # or: python -m sourcelens.server

HTTP (for remote clients):

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

pip install -e '.[dev]'
python -m pytest tests/ -v

License

MIT. See LICENSE.

Available Tools

8 tools
find_importersA

Find files that import the given module/target.

Matches exact or suffix module paths (e.g. "os", "fmt", "utils.foo").

Inputs: target (required).

find_importsC

List what a single file imports, in source order.

Inputs: file (required).

get_file_outlineA

List every symbol declared in a file, in source order.

Use this instead of reading a whole file — it returns the outline (name, kind, line range, signature) so the agent can then pull only the symbol bodies it actually needs.

Inputs: file (required).

get_symbol_sourceA

Fetch a symbol's exact source by id, or by name (+optional file).

Returns the precise byte range from disk (no whole-file read), so an agent gets only the function/class body it needs. Provide symbol_id OR name.

Inputs: file, name, symbol_id.

index_folderA

Index every supported source file under path (absolute or relative).

Walks the tree, parses each file with tree-sitter, and stores symbols + imports in the local SQLite index. Safe to re-run; files are replaced idempotently by path. Returns counts of what was indexed.

Inputs: path (required).

list_languagesA

Return the languages this indexer supports.

Inputs: no named parameters.

search_symbolsA

Search indexed symbols by name substring.

Returns each match with its qualified name, kind, language, file path, and line range. Use get_symbol_source to fetch exact body text. kind filters to e.g. function/class/method; language to python/go/typescript/etc.

Inputs: query (required), kind, limit, language.

statsA

Return index stats: file count, symbol count, per-language breakdown.

Inputs: no named parameters.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    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
    ResponsivenessOutdated data

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      C
      maintenance
      Provides token-efficient code retrieval for coding agents by indexing repositories and enabling ranked snippet search, symbol outlines, and surgical line reads.
      5 npm
      MIT
    • F
      license
      A
      quality
      D
      maintenance
      Provides codebase indexing and retrieval tools that give AI agents token-efficient, query-relevant context packages (symbols, imports, and dependencies) instead of scanning entire repositories.
      6
      -
    • F
      license
      Not graded
      quality
      B
      maintenance
      Provides graph-native code intelligence for coding agents, enabling them to navigate repositories through compact SQLite-backed symbol graphs and retrieve full source only for relevant symbols.
      -