
LeanToken
io.github.morluto由 GitHub 账号 morluto 发布v0.1.28更新于 Oct 24, 2026
Token-bounded repository context for coding agents over MCP.
概览
LeanToken 为本地代码仓库建立索引,通过 MCP 向编码助手提供受 token 预算约束的代码搜索、结构大纲、精确读取、历史追溯与 JSON 查询。
- 可以做什么
- 查找并排序相关代码路径,在仓库内做文本或正则搜索
- 查看定义、签名、导入与行范围,无需读取整个文件
- 读取指定符号或连续行区间,并在 Git 版本间追踪或对比符号
- 查询、汇总或比较有界的实时 JSON 文件
- 在明确的 token 预算内组装面向任务的上下文,并用回执避免重复发送未变证据
- 报告观测到的 token 用量与哈希抑制情况
- 适用场景
- 适合编码助手在大型或不熟悉的仓库中工作时使用,以减少大范围探索和整文件读取消耗的 token。适用于初步排查、故障调查与变更审查,编辑、构建和测试仍由助手自身工具完成。
- 运行要求
- 以本地 stdio 进程运行,需指定仓库根目录,可通过 npx 或 Cargo 安装的二进制启动。npx 方式需要 Node.js;musl Linux 等其他目标需用 Rust 1.95 或更高版本及 C/C++ 工具链从源码构建。未声明账号、API 密钥或环境变量。
安装
在 SourceWeft 中
- 打开 控制台中的 LeanToken,将其添加到工作区。
- 为需要使用其工具的对话启用该服务。
Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。
其他 MCP 客户端
参照 仓库 中的启动说明。
README
LeanToken
Code intelligence for agents: find the code that matters and keep your context window and tokens lean.
Language: English · 简体中文 · 日本語 · 한국어
- MCP Registry name:
mcp-name: io.github.morluto/leantoken
[npm] [npm downloads] [Rust 1.95+] [License: MIT OR Apache-2.0]
Install · Why LeanToken · Tools · CLI · How it works · Docs
Measured token savings: In a controlled 60-run study, LeanToken used 20.1% fewer model input tokens than the agent's built-in tools with limited repository exploration, and 37.6% fewer than those tools with broad exploration. See exactly how it was measured in the measurement methodology.
Quick start
Add LeanToken to Claude Code, Cursor, OpenCode, Codex, Gemini CLI, or Antigravity:
Setup behavior and safety
Current releases stop setup before writing when npx resolves a stale
project-local or ancestor install, and point to
npx leantoken@latest setup. Older releases that predate this check can be
bootstrapped directly with that versioned command.
The interactive setup wizard preselects supported clients it detects; you can change that selection before continuing. It then shows the exact configuration paths and MCP launcher and asks for a separate final confirmation. Automation never treats detection as consent. An npx-based setup pins the exact LeanToken version that ran setup, so restarting a client cannot silently move to a newer release.
Global setup never stores the repository where setup happened. OpenCode gets a workspace-relative working directory; other supported clients launch LeanToken from the workspace cwd selected by the host. If a host instead starts it from the home directory or a filesystem root, LeanToken refuses to index that broad root by default.
Restart or reload the configured clients, then verify the connection and first retrieval from a repository:
Try a broad task such as: Find the code related to request cancellation before
editing. LeanToken helps the agent start with leantoken.context, while its
normal tools remain available for edits, builds, and tests.
Inspect LeanToken's observed repository-local token accounting:
Advanced setup and version management
To skip the wizard, select clients explicitly or configure all supported clients:
For regular use, --private-runtime is the recommended launcher: it copies the
exact package-native executable into an application-data directory named by
version and full BLAKE3 digest, so clients launch one verified process directly,
without persistent npm/Node wrappers. Different source builds of one version
can coexist. setup --refresh --private-runtime pins the current exact artifact;
other referenced artifacts stay usable. It remains opt-in so the zero-install
path does not add an application-data write. Preview its path and digest with
--dry-run.
Automation never treats detection as consent: --yes requires explicit client
flags, --all, or --refresh for entries already managed by LeanToken. Preview
the same resolved plan without changing files:
Setup adds the leantoken MCP entry plus a small owned discovery skill only in
the directories used by the selected hosts: Claude Code uses ~/.claude, while
Codex and the other supported hosts use ~/.agents. The skill advertises
routing metadata; it does not duplicate tool schemas, add rules, or install
shell hooks. Setup marks new MCP launchers as managed and refuses to replace a
same-name manual entry unless you review the dry-run and pass
--force-unmanaged. Remove the owned integration with:
After private-runtime upgrades, inspect retained artifacts and preview a reference-safe cleanup before applying it:
Refresh only existing LeanToken MCP entries after explicitly choosing a new version, or use an older version to roll back:
Common agent workflows
LeanToken works best as a small evidence loop rather than a one-shot repository dump:
- Orient autonomous triage in one call. Start an uncertain broad task with
contextandplan_only: false, then use the materialized evidence directly. Make at most one focused follow-up only when coverage identifies a concrete missing implementation or regression-test owner. - Continue without resending source. Pass the prior
receipt_idon the next context call, or pass returned fragment hashes asknown_hashes. The response reports exact and overlapping omissions instead of silently charging the same evidence again. - Investigate an observed failure. Use the
investigationworkflow and provide only directly observedfailure_traces, paths, symbols, or test intent inworkflow_evidence. Follow with exactsearch,outline, orreadcalls for the owners the evidence identifies. - Review a change. Use the
reviewworkflow withbase_revisionset toBASE..HEADandstrict_changed_paths: true. Request ahandoffwhen another agent needs a compact manifest of selected hashes, changed paths, assumptions, and completed validations without copied source bodies.
This one-call contract is for autonomous repository triage, not a limit on
implementation agents. Human review and control-plane flows can still preview
expensive or high-risk retrieval with plan_only: true before materializing.
The repeated multi-agent context suite
found that an iterative LeanToken profile used 50.9% more total input than thin
native, while the frozen one-context-plus-optional-one-search profile saved
20.1% and had 15/20 path-set successes. Those results cover four pinned triage
tasks; they do not prove a universal implementation workflow.
Explicit focus constraints are contracts. When a request supplies
focus_paths, exact focus_symbols, and
minimum_fragments_per_focus_path, LeanToken generates candidates within the
documented per-file bounds and reports a coverage failure when distinct ranges
cannot satisfy the minimum. Explain-profile plans and materialized responses
also identify the bounded allocation boundary that generated, reserved,
selected, or suppressed each focus candidate without changing ranking.
Why LeanToken
Most agents start by searching widely and reading whole files. LeanToken narrows that work in stages:
Your coding agent still handles editing, commands, tests, and conversation. LeanToken finds and returns the code those tasks need.
LeanToken does not create one giant prompt file. It answers focused searches and reads as the agent needs them.
Example
For a task like fix request cancellation during shutdown, an illustrative bounded result might look like this:
The agent receives these ranges instead of both full files. If the budget is too small, the response also says what was left out. Paths, scores, receipts, JSON, and MCP transport wrappers are not part of this source-token budget; see token accounting for the measured boundaries.
Available tools
Advanced retrieval controls
Every index-backed retrieval tool, including receipt_rebase, accepts
consistency: "reconcile_working_tree" when completed edits must be reconciled
before the query. The default,
"indexed_generation", returns the latest completed index generation without
scanning or waiting for filesystem changes; it is not a Git revision boundary.
leantoken.history reads immutable Git objects and leantoken.json reads exact
live files, so neither accepts an index consistency mode. To constrain context
to immutable history, pass BASE..HEAD as leantoken.context.base_revision
with strict_changed_paths: true.
For autonomous broad triage, set plan_only: false and use the materialized
evidence directly. Reserve plan_only: true for human or control-plane review
before expensive or high-risk retrieval: it returns bounded ranked candidate
metadata without source fragments or receipt mutation. After approval, repeat
the same request with plan_only: false. Set response_profile: "compact" for
the smallest fail-loud response, keep the default "balanced" shape, or use
"explain" for bounded individual omissions, facets, and diff evidence. The
response reports the resolved choice as effective_response_profile.
The catalog stays intentionally small because every tool description and schema also consumes model context.
CLI usage
Run LeanToken directly through npx:
Or use a globally installed binary:
Audit an existing redacted experiment or host report without opening a repository index:
The default projection is Markdown; add global --json for the stable
normalized JSON schema. The auditor is local, bounded, and read-only with
respect to its input. It retains artifact hashes, not raw prompts, source, tool
arguments, or tool outputs.
npm install leantoken installs the command in the current project's
node_modules/.bin; it does not add leantoken to the shell PATH. Invoke a
project-local install through npx leantoken, a package script, or
./node_modules/.bin/leantoken.
Run the MCP server manually over stdio:
Manual MCP client configuration
For the Cargo distribution, install the published crate and point your MCP client at the resulting executable:
The official MCP Registry entry is io.github.morluto/leantoken. Registry
clients that support Cargo packages can install the matching leantoken
version and use the mcp command shown above.
Installation options
The npm package includes native binaries for:
- macOS on ARM64 and x64
- glibc Linux on ARM64 and x64
- Windows on x64
Installation does not run lifecycle scripts or download an executable from a postinstall hook. Other targets, including musl Linux, must build from source. Install Rust 1.95 or later and a native C/C++ toolchain, then run:
Updating
MCP entries created through npx stay pinned to the exact LeanToken version
that configured them. Update existing client integrations explicitly:
For a globally installed CLI or a CLI installed with Cargo:
update is an alias for upgrade. For a project-local npm installation:
Pinned MCP entries never silently move to @latest. If the exact package is not
available locally or online, startup fails rather than selecting another version.
Updating the CLI does not change existing MCP entries. See the
usage guide for rollbacks, cache management, and version details.
Cache management
Inspect local repository caches or preview cleanup before applying it:
See the usage guide for cache states, pagination, and cleanup safety rules.
How it works
LeanToken indexes source once, then serves compact paths, ranked matches, structural outlines, exact source ranges, and task-specific context. It avoids resending unchanged evidence across turns.
Dependency-heavy workspaces can opt into a separate, cache-identified first-party index without changing the default whole-repository behavior:
Status and every retrieval disclose whether the active index is full or scoped, so an empty scoped result is never presented as whole-repository absence. See the usage guide for bounds, cache identity, and MCP registration examples.
LeanToken's goal is to return the code an agent needs with fewer input tokens.
Documentation
License
Licensed under either of the following, at your option:
来源:README.md,提交 5cfab83
工具
0版本历史
1- v0.1.28最新Sep 16, 2026
评分
已满足适用检查项的 50%
该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。
- 近 30 天内可连通25 分
请保持端点能够响应 MCP 握手;SourceWeft 每 30 天探测一次。
- 已声明认证方式10 分
请在注册中心条目中声明凭据请求头,或保持端点能够响应探测,以便判定其认证方式。
- 已列出工具15 分
请让服务器在无凭据时响应 tools/list,或发布可在沙箱中无凭据启动的软件包。
- 描述必需15 分
- 图标10 分
- 文档15 分
- 许可证10 分