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.
📖 Full command reference → docs/HANDBOOK.md
mcp-name: io.github.likhithreddy/fittok
How it works
codebase ──▶ graphify ──▶ slurp ──▶ readable slice ──▶ LLM answers
(parse) (select) (trim to budget)
- graphify — parses the repo with tree-sitter into a knowledge graph of functions / classes / methods (Python, JS, JSX, TS, TSX, Java, Go, Rust).
- 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).
- 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.
Graphs and embeddings are cached on disk (~/.cache/fittok), keyed by content —
so after a code change only the changed functions re-embed.
Installation
fittok ships as an MCP server, a CLI, and a Python library. It uses
torch for embeddings, so a Python runtime must be present. Pick one runtime
below, then follow the section for your client.
Every config below launches fittok as
uvx fittok. If you chose Python orpipx, swap that forpython -m fittokorpipx run fittokrespectively.
Prerequisites — choose a runtime (one of)
A. uv — recommended (no Python needed on the machine)
curl -LsSf https://astral.sh/uv/install.sh | sh # Linux / macOS
winget install astral-sh.uv # Windows
brew install uv # macOS (Homebrew)
Launch command: uvx fittok — uv provisions its own Python + all deps in
isolation. One static binary, so it's deployable org-wide via MDM/Intune/winget.
B. Python 3.10+ (already on the machine)
python -m pip install fittok # Linux / macOS
py -m pip install fittok # Windows
Launch command: python -m fittok (Windows: py -m fittok).
Managed Linux may reject
pip installwith PEP 668 ("externally-managed-environment") — use option A to avoid it.
C. pipx — isolated, no global install
brew install pipx # macOS
pip install --user pipx && pipx ensurepath # Linux / Windows
Launch command: pipx run fittok.
MCP server — Claude Code
claude mcp add fittok -s user -- uvx fittok
Restart Claude Code → /mcp → confirm fittok is connected, then ask
codebase questions normally.
MCP server — VS Code / GitHub Copilot Chat
code --add-mcp '{"name":"fittok","command":"uvx","args":["fittok"]}'
Or paste into .vscode/mcp.json (workspace) or your user mcp.json:
{ "servers": { "fittok": { "type": "stdio", "command": "uvx", "args": ["fittok"] } } }
Then in Copilot Chat: Agent mode → enable fittok's tools (Configure Tools).
MCP server — GitHub Copilot CLI
copilot mcp add fittok -- uvx fittok
copilot mcp get fittok # verify status + tools
MCP server — Cursor / Windsurf / any MCP client
{ "mcpServers": { "fittok": { "command": "uvx", "args": ["fittok"] } } }
Auto-trigger (optional, every MCP client)
To make fittok fire on every codebase question — without naming it — and stop your client from re-reading files fittok already returned (which would discard the savings), add this one line to your client's instructions file:
"For any codebase question, call fittok first and answer from its output — don't re-read files it already returned code from."
The first half triggers fittok; the second keeps the client from opening the same files afterward. They reinforce each other — one shapes strategy (use fittok), the other stops the double-read. For a stronger, more explicit block:
For any codebase question ("how does X work", "where is Y"):
- Call the fittok MCP tool first, once.
- Answer directly from its
optimized_context— it is the real, authoritative source for that question.- Do NOT read or grep the files fittok already returned code from. That discards the token savings fittok exists to provide.
For the strongest effect, put it in your user-global instructions so it applies to every repo, not just one:
| Client | Instructions file |
|---|---|
| Claude Code | CLAUDE.md (repo) or ~/.claude/CLAUDE.md (user-global) |
| GitHub Copilot | .github/copilot-instructions.md or Copilot user instructions |
| Cursor | .cursor/rules/*.mdc (or .cursorrules) |
| Windsurf | .windsurfrules |
fittok also bakes this rule into every response (an "answer from this, don't re-read" line above the code), so it works even without the snippet above — the snippet just makes it the client's default across all questions.
CLI
cd /path/to/your/repo
uvx fittok index # optional pre-warm (~15s, cached)
uvx fittok query "how does auth work" # LLM answers from relevant code
uvx fittok query "how does auth work" --budget 1500 # cap the slice at 1500 tokens
uvx fittok query "how does auth work" --code # raw relevant code, no LLM
uvx fittok graph # interactive browser graph
uvx fittok graph --query "auth" # graph with relevant nodes highlighted
query sends the relevant code slice to an LLM and streams the answer.
Set one key in your shell and it just works:
export ANTHROPIC_API_KEY="sk-ant-..." # → claude-haiku-4-5 (recommended)
export OPENAI_API_KEY="sk-..." # → gpt-4o-mini (fallback)
Users of Claude Code already have ANTHROPIC_API_KEY set — no extra step needed.
If neither key is set, fittok falls back to --code and prints a setup hint.
graph requires pyvis: uv pip install "fittok[ui]".
Python 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", token_budget=1500)
print(result["optimized_context"]) # the relevant code slice
print(result["savings"]) # token reduction stats
Token savings — honest numbers
On a real Next.js/TS repo (~5k functions), fittok 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 savings footer.
On Opus 4.8, a broad question cost ~84k total tokens without fittok vs ~27k with it — because fittok replaced a 58k-token Explore subagent with one tool call.
How to measure it honestly:
- Use the
🪙 saved X%footer or your API bill (total tokens). - Do not judge by Claude Code's
/contextMessages number — it excludes subagent tokens and is dominated by model reasoning, which fittok doesn't touch.
Configuration
| Variable | Default | Description |
|---|---|---|
ANTHROPIC_API_KEY |
— | Enables LLM answers via claude-haiku-4-5 |
OPENAI_API_KEY |
— | Fallback LLM via gpt-4o-mini |
FITTOK_SHOW_SAVINGS |
true |
🪙 saved X% footer on MCP answers; set 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 |
Full reference: docs/HANDBOOK.md
Requirements
Python ≥ 3.10. First run downloads a ~90 MB embedding model. Optional extras:
uv pip install "fittok[ui]"— graph visualizer (fittok graph)uv pip install "fittok[gpu]"— torch/CUDA for GPU-accelerated embeddings
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fittok-0.5.2.tar.gz.
File metadata
- Download URL: fittok-0.5.2.tar.gz
- Upload date:
- Size: 236.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.27 {"installer":{"name":"uv","version":"0.11.27","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
84fa66c9fbf9a90e7a786527cb3e56f1b73baea9809cfc724e2384d66a0944ab
|
|
| MD5 |
d52503a7545398c869e4aa0ab3847906
|
|
| BLAKE2b-256 |
567b6b6625786b4f1995bfa89e707942667933071f6fb5f4e59ae62ead2cc0c5
|
File details
Details for the file fittok-0.5.2-py3-none-any.whl.
File metadata
- Download URL: fittok-0.5.2-py3-none-any.whl
- Upload date:
- Size: 51.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.27 {"installer":{"name":"uv","version":"0.11.27","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0d9a8accbd8984cc2adf691c8bd0b8f616f632e705ef82e20a10b6d523cade9e
|
|
| MD5 |
0fa1d690873964e2c7fe1ac7873ac9e9
|
|
| BLAKE2b-256 |
e752b02a0c73f2e04e5147b804308793c9f9d5663fc574d8c823645d852d9f2b
|