Skip to main content

MCP server that retrieves the most relevant source code for a query, within a token budget

Project description

fittok

Retrieve only the relevant source code for a question — instead of the model reading whole files — so an LLM answers codebase questions on a small, focused slice of context. Less input = fewer tokens, lower cost, faster answers.

Works three ways from one install: an MCP server, a CLI, and a Python library — plus a Claude Code plugin that injects context automatically.


How it works

codebase ──▶ graphify ──▶ slurp ──▶ readable slice ──▶ LLM answers
             (parse)      (select)   (trim to budget)
  1. graphify — parses the repo with tree-sitter into a knowledge graph of functions / classes / methods (Python, JS, JSX, TS, TSX, Java, Go, Rust).
  2. slurp — scores every node against the question with **semantic embeddings
    • TF-IDF + PageRank**, then selects only the genuinely relevant nodes via a relevance cliff (no budget-padding with noise).
  3. readable output — returns the actual source code of those nodes, top-ranked in full and the supporting tail as signatures, trimmed to a budget. The model answers directly from it.

Note: an earlier design compressed the slice with LLMLingua, but that produced unreadable token-salad the model ignored (then re-read the files). fittok returns real, readable code instead. LLMLingua remains available only as the standalone compress_context tool.

Graphs and embeddings are cached on disk (~/.cache/fittok), keyed by content — so after a code change only the changed functions re-embed.


Install & use

fittok runs through uv — one tool for everything below, with no manual pip install. Install it once:

brew install uv                                  # macOS
# or any OS:  curl -LsSf https://astral.sh/uv/install.sh | sh

As an MCP server (recommended — Claude Code / Cursor / Windsurf)

Claude Code — one command:

claude mcp add fittok -- uvx fittok      # add -s user to enable it in every project

Restart Claude Code, then run /mcp to confirm fittok shows connected.

Cursor / Windsurf / any MCP client — add to its MCP config:

{ "mcpServers": { "fittok": { "command": "uvx", "args": ["fittok"] } } }

Then ask codebase questions normally. To make fittok trigger without mentioning it, add one line to your client's CLAUDE.md:

"For any codebase question, call fittok first and answer from its output."

As a CLI (no MCP, no install — uvx fetches + runs it)

cd /path/to/your/repo
uvx fittok index                       # optional one-time pre-warm (path defaults to cwd)
uvx fittok query "how does auth work"  # prints the relevant code slice

As a library

uv add fittok            # in a uv project   (or:  uv pip install fittok  in a venv)
from fittok import optimize
result = optimize("/path/to/repo", "how does authentication work")
print(result["optimized_context"])

First query on a repo auto-indexes (~15s once, cached); after that it's instant.


Token savings — honest numbers

fittok cuts the input/exploration cost of a codebase question. On a real Next.js/TS repo (~5k functions) it returns a ~1.5–3.5k-token slice instead of the model reading 15–20k+ tokens of files — an ~80–90% reduction on input, deterministic and reported in the tool's savings footer.

How to measure it honestly:

  • ✅ Use the savings footer (e.g. 84% — 2,494 vs 15,631 tokens) or your API bill (total tokens — which counts the subagent crawls fittok avoids).
  • ⚠️ Do not judge by Claude Code's /context "Messages" number — it excludes subagent tokens and is dominated by the model's own reasoning, which fittok doesn't touch. On thorough models the real saving (e.g. ~84k → ~27k total tokens, by avoiding an Explore subagent) is invisible there but clear on the bill.

Where it shines: broad / multi-file questions, large files, unfamiliar repos, and thorough models that would otherwise explore heavily. On a tiny question a capable model can answer from one small file, so the win is marginal there.


Configuration (env vars)

Variable Default Purpose
FITTOK_SHOW_SAVINGS true Append a 🪙 saved X% footer to answers; set to false to disable
FITTOK_EMBED_MODEL all-MiniLM-L6-v2 Embedding model
FITTOK_DEVICE auto auto / cuda / mps / cpu
FITTOK_CACHE_DIR ~/.cache/fittok Cache location

Requirements

Python ≥ 3.10. First run downloads a ~90 MB embedding model. Optional extras: uv pip install "fittok[ui]" (graph visualizer), "fittok[gpu]" (torch/CUDA).

License

MIT.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fittok-0.3.4.tar.gz (452.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fittok-0.3.4-py3-none-any.whl (44.0 kB view details)

Uploaded Python 3

File details

Details for the file fittok-0.3.4.tar.gz.

File metadata

  • Download URL: fittok-0.3.4.tar.gz
  • Upload date:
  • Size: 452.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.5

File hashes

Hashes for fittok-0.3.4.tar.gz
Algorithm Hash digest
SHA256 1e83bfb63bba226f9b0b52d4bfccf5c324bbfeabfd2f4fc165efb8825f22f52b
MD5 ecb5516c072cc998034eecc935c49b94
BLAKE2b-256 8afa7abebb8fc84e2360ef1fddf6a708da152f330e05aa76591a567862d4ebb9

See more details on using hashes here.

File details

Details for the file fittok-0.3.4-py3-none-any.whl.

File metadata

  • Download URL: fittok-0.3.4-py3-none-any.whl
  • Upload date:
  • Size: 44.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.5

File hashes

Hashes for fittok-0.3.4-py3-none-any.whl
Algorithm Hash digest
SHA256 b79d9c466c083a7bc79aef7834215cf4566d92cbee2d93b43defadedae1f5104
MD5 32e51e96840e5303f7b665f668b8bc3d
BLAKE2b-256 326b02074d24539d5dd2e8d1f0efa292c8737eba2d397a61b5ceeaa9a20a3cb1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page