fittok
An MCP server that filters and compresses context by 80-90% before sending to an LLM, using code knowledge graphs and compression.
README
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)
- 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.
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_contexttool.
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
As an MCP server (recommended — for Claude Code / Cursor)
Add one entry to your client's MCP config:
{ "mcpServers": { "fittok": { "command": "uvx", "args": ["fittok"] } } }
Then ask codebase questions normally. To make it 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 needed)
pip install fittok
fittok index <repo> # optional one-time pre-warm
fittok query <repo> "how does auth work" # prints the relevant code slice
As a library
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
savingsfooter (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 |
false |
Append a 🪙 saved X% footer to answers |
CONTEXT_OPTIMIZER_EMBED_MODEL |
all-MiniLM-L6-v2 |
Embedding model |
CONTEXT_OPTIMIZER_DEVICE |
auto |
auto / cuda / mps / cpu |
CONTEXT_OPTIMIZER_CACHE_DIR |
~/.cache/fittok |
Cache location |
Requirements
Python ≥ 3.10. First run downloads a ~90 MB embedding model. Optional extras:
pip install "fittok[ui]" (graph visualizer), "fittok[gpu]" (torch/CUDA).
License
MIT.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。