PluginBench
MCP Server
Active
Apache-2.0

LeanToken MCP Server

io.github.morluto/leantoken

Token-bounded code retrieval for AI agents: find relevant code and keep context windows lean.

What is the LeanToken MCP server?

LeanToken is an MCP server that provides intelligent code discovery and retrieval for coding agents, helping them find relevant code while staying within explicit token budgets. It indexes repositories locally and offers ranked search, file discovery, code structure inspection, and history tracing—all designed to reduce model input tokens by 20–38% compared to broad repository exploration.

LeanToken narrows repository exploration for AI agents by finding and returning only the code that matters. Instead of scanning broad directories or reading whole files, it provides ranked search, compact file discovery, structure inspection without full-file reads, and exact line-range retrieval—all within explicit token budgets. It's built for autonomous triage workflows where agents need evidence-driven context in a single call, then optional follow-ups with minimal token overhead.

How to install LeanToken

Copy-paste configuration for popular MCP clients.

transport: stdio
Config generated by PluginBench — verify against the source before use.
~/Library/Application Support/Claude/claude_desktop_config.json
{
  "mcpServers": {
    "leantoken": {
      "command": "leantoken",
      "args": [
        "mcp"
      ]
    }
  }
}

Tools & capabilities

Tools this server exposes to the agent.

  • leantoken.context — Default materialized first call for autonomous broad triage; optional preview for human or control-plane review with plan_only mode.
  • leantoken.search — Ranked text/regex search over the repository; exhaustive calls can record or reuse complete query coverage.
  • leantoken.files — Compact, ignore-aware path discovery; prefer over find/ls/glob.
  • leantoken.outline — Inspect definitions, signatures, imports, and ranges without whole-file reads.
  • leantoken.read — Read one exact symbol or inclusive line range; prefer over cat/head/sed.
  • leantoken.history — Read, batch-diff, or trace parsed symbols across immutable Git revisions.
  • leantoken.json — Query, summarize, or compare bounded live JSON with paged keys and typed diagnostics.
  • leantoken.receipt_rebase — Carry same-path, same-coordinate, same-hash evidence into a newer completed generation.
  • leantoken.savings — Report observed response accounting, hash suppression, failures, and explicit observation limits.

Use cases

  • Orient autonomous triage in one call by starting with context and using materialized evidence directly, avoiding repeated source resends.
  • Investigate observed failures by providing failure traces and symbols, then following with exact search or read calls for identified owners.
  • Review code changes by using the review workflow with base_revision set to BASE..HEAD and strict_changed_paths enabled.
  • Search ranked code by symbol or text pattern without reading entire files, keeping token usage explicit and bounded.
  • Trace symbol definitions and changes across Git history to understand implementation evolution and dependencies.

LeanToken MCP server FAQ

What is LeanToken?

LeanToken is an MCP server that helps AI coding agents find relevant code efficiently. It indexes repositories locally, provides ranked search and code structure inspection, and returns results within explicit token budgets—reducing model input tokens by 20–38% compared to broad exploration.

Is LeanToken free?

Yes. LeanToken is open-source under MIT OR Apache-2.0 license and available via npm and Cargo.

How do I install LeanToken in Claude or Cursor?

Run `npx leantoken setup` to launch an interactive wizard that detects and configures supported clients (Claude Code, Cursor, OpenCode, Codex, Gemini CLI, Antigravity). Restart the client and verify with `npx leantoken doctor`.

Does LeanToken require authentication or send data to external servers?

No. LeanToken is local-by-default: source is indexed on your machine in a local database, and it is a read-only discovery and retrieval layer. No external authentication or data transmission is required.

What token savings can I expect?

In a controlled 60-run study, LeanToken used 20.1% fewer model input tokens than built-in tools with limited exploration, and 37.6% fewer with broad exploration. Results vary by task; see the measurement methodology in the repository for details.

Can I use LeanToken with my existing agent tools?

Yes. LeanToken works alongside your agent's normal tools for editing, commands, tests, and conversation. It specializes in finding and returning relevant code; agents still handle other workflows.

README (reference)

Source of truth, from the repository.

<div align="center"> <h1>LeanToken</h1>

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
<img src="assets/leantoken-hero-v3.jpg" alt="LeanToken narrowing a large codebase to the files and code an AI agent needs" width="100%">

npm npm downloads Rust 1.95+ License: MIT OR Apache-2.0

Install · Why LeanToken · Tools · CLI · How it works · Docs

</div>

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:

npx leantoken setup
<details> <summary><strong>Setup behavior and safety</strong></summary>

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.

</details>

Restart or reload the configured clients, then verify the connection and first retrieval from a repository:

npx leantoken doctor

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:

npx leantoken savings
<table> <tr> <td width="33%" valign="top"> <strong>Local by default</strong><br><br> Source is indexed on your machine in a local database. LeanToken is a read-only discovery and retrieval layer. </td> <td width="33%" valign="top"> <strong>Explicit token budgets</strong><br><br> Every response has an explicit token limit, so large files cannot take over the request. </td> <td width="33%" valign="top"> <strong>Built for agent workflows</strong><br><br> Find files, search code, inspect structure, read exact ranges, trace history, query JSON, and track token usage through focused tools. </td> </tr> </table> <details> <summary><strong>Advanced setup and version management</strong></summary>

To skip the wizard, select clients explicitly or configure all supported clients:

npx leantoken setup --claude --codex --yes
npx leantoken setup --all --yes

For regular use, --private-runtime is the recommended launcher: it copies the exact package-native executable into LeanToken's versioned application-data directory so clients launch one verified process directly, without persistent npm/Node wrappers. 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:

npx leantoken setup --codex --cursor --dry-run

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:

npx leantoken remove

After private-runtime upgrades, inspect retained versions and preview a reference-safe cleanup before applying it:

npx leantoken runtime list
npx leantoken runtime prune --dry-run
npx leantoken runtime prune --yes

Refresh only existing LeanToken MCP entries after explicitly choosing a new version, or use an older version to roll back:

npx --yes leantoken@latest setup --refresh --yes
npx --yes leantoken@0.1.8 setup --refresh --yes --allow-outdated
</details>

Common agent workflows

LeanToken works best as a small evidence loop rather than a one-shot repository dump:

  1. Orient autonomous triage in one call. Start an uncertain broad task with context and plan_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.
  2. Continue without resending source. Pass the prior receipt_id on the next context call, or pass returned fragment hashes as known_hashes. The response reports exact and overlapping omissions instead of silently charging the same evidence again.
  3. Investigate an observed failure. Use the investigation workflow and provide only directly observed failure_traces, paths, symbols, or test intent in workflow_evidence. Follow with exact search, outline, or read calls for the owners the evidence identifies.
  4. Review a change. Use the review workflow with base_revision set to BASE..HEAD and strict_changed_paths: true. Request a handoff when 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:

Typical repository explorationWith LeanToken
Scan broad directory listingsFind relevant paths in a compact tree
Read whole files to find structureSee definitions and imports without loading the entire file
Send the same code again after each turnAvoid repeating unchanged evidence
Let large files fill the requestKeep returned source within an exact source-token budget and report response overhead separately
Guess which files matterRank likely relevant code for the task

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:

Budget: 1,200 source tokens

Selected evidence:
  src/services/executor.rs        lines 137-147, 251-259
  src/services/reconciliation.rs lines 148-175, 257-272

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

ToolPurpose
leantoken.contextDefault materialized first call for autonomous broad triage; optional preview for human or control-plane review.
leantoken.searchPrefer over grep/rg for ranked search; exhaustive text/regex calls can explicitly record or reuse complete query coverage.
leantoken.filesPrefer over find/ls/glob for compact, ignore-aware path discovery.
leantoken.outlineInspect definitions, signatures, imports, and ranges without whole-file reads.
leantoken.readPrefer over cat/head/sed for one exact symbol or inclusive line range.
leantoken.historyRead, batch-diff, or trace parsed symbols across immutable Git revisions.
leantoken.jsonQuery, summarize, or compare bounded live JSON with paged keys and typed diagnostics.
leantoken.receipt_rebaseExplicitly carry only same-path, same-coordinate, same-hash evidence into a newer completed generation.
leantoken.savingsReport observed response accounting, hash suppression, failures, and explicit observation limits.
<details> <summary><strong>Advanced retrieval controls</strong></summary>

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.

</details>

The catalog stays intentionally small because every tool description and schema also consumes model context.

CLI usage

Run LeanToken directly through npx:

npx leantoken status
npx leantoken savings
npx leantoken doctor
npx leantoken --root /path/to/repo search handle_request

Or use a globally installed binary:

npm install --global leantoken@latest

leantoken --root /path/to/repo index
leantoken --root /path/to/repo search handle_request --mode identifier --max-tokens 800
leantoken --root /path/to/repo context \
  --task "fix request cancellation during shutdown" \
  --budget 2000

Audit an existing redacted experiment or host report without opening a repository index:

leantoken episode audit \
  --adapter multi-agent-suite-v1 \
  --input benchmarks/reports/multi-agent-context-suite-v1-codex-0.144.1.json

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:

leantoken --root /path/to/repo mcp
<details> <summary><strong>Manual MCP client configuration</strong></summary>
{
  "mcpServers": {
    "leantoken": {
      "command": "leantoken",
      "args": ["--root", "/path/to/repo", "mcp"]
    }
  }
}
</details>

For the Cargo distribution, install the published crate and point your MCP client at the resulting executable:

cargo install leantoken --version VERSION
leantoken --root /path/to/repo mcp

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:

cargo install --locked --git https://github.com/morluto/leantoken leantoken

Updating

MCP entries created through npx stay pinned to the exact LeanToken version that configured them. Update existing client integrations explicitly:

npx --yes leantoken@latest setup --refresh --yes

For a globally installed CLI or a CLI installed with Cargo:

leantoken upgrade --check
leantoken upgrade --yes

update is an alias for upgrade. For a project-local npm installation:

npm install leantoken@latest

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:

leantoken cache list
leantoken cache list --summary
leantoken cache list --incompatible-with-current
leantoken cache prune --incompatible-with-current
leantoken cache prune --older-than 30 --dry-run
leantoken cache prune --max-total-bytes 1073741824 --yes

See the usage guide for cache states, pagination, and cleanup safety rules.

How it works

repository
    │
    ▼
file discovery ──► code structure extraction ──► local search index
                                                    │
                                                    ▼
agent request ──► ranked / exact retrieval ──► focused code within a token budget

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:

leantoken --index-include 'src/**' --index-include 'tests/**' index

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

GuideContents
Usage and tool referenceCommands, MCP tools, request options, and examples
Architecture and reliabilityComponents, data flow, storage, and failure behavior
RoadmapCurrent direction and planned work
Development and testingLocal setup, validation, and release workflow
Benchmark methodologyToken-economy measurements and interpretation
Measurement harnessesExperiment, wire-cost, and profiling tools

License

Licensed under either of the following, at your option:

Related MCP servers

REREA logo

REA

Active

Reverse engineer apps and binaries with AI agents—understand features without source code.

357
TypeScript
MIT
View repository →
FLFlameox logo

Flameox

Active

Bounded local runtime evidence for coding agents—profile, benchmark, and analyze artifacts without workspace setup.

34
Python
MIT
View repository →

Local-first GitHub contribution research workbench

3
Go
MIT
View repository →
JAJacobian logo

Jacobian

Active

Executable mathematical vocabulary for AI agents: discover, run, and compose typed operations.

54
Python
MIT
View repository →
CACAN-TAP Verified logo

Free dofollow backlinks for Canadian businesses. Claim, verify, and track NFC tap analytics.

0
JavaScript
MIT
View repository →

GEDCOM CLI and MCP server for AI-assisted family-history research with reviewable changesets.

1
C#
MIT
View repository →