
Sophon
io.github.lacausecrypto由 GitHub 账号 lacausecrypto 发布v0.5.4更新于 Oct 24, 2026
Honest token economics for MCP agents. 68% tokens saved, zero-ML Rust binary.
发布方自己的服务:Sophon Consulting
概览
一个本地运行的 Rust MCP 服务器,通过确定性压缩提示词、对话历史、文件读取和命令输出,为编码代理减少 token 消耗。
- 可以做什么
- Sophon 通过 stdio 提供 11 个 MCP 工具,用于压缩代理发送给模型的文本。compress_prompt 只保留长提示词中与查询相关的部分,compress_history 生成摘要、事实和近期窗口,compress_output 用 21 个领域过滤器清理命令 stdout/stderr 的噪声。其他工具负责文件读写增量、重复样板片段编码、token 计数、会话节省统计以及按查询排序的代码库摘要。它在查询时不依赖嵌入模型或 API 密钥,以单个本地二进制文件运行。
- 适用场景
- 适合编码代理工作流中重复读取文件、冗长命令输出和不断增长的对话历史占主要 token 开销的场景,尤其是配合 Claude Code、Cursor 或 Cline 使用。它叠加在服务商提示缓存或记忆系统之前,而不是替代它们。不适用于高召回率的对话记忆、大规模文档的多跳推理、OCR 或 PDF 版面处理,以及非常小的输入。
- 运行要求
- 作为本地进程通过 stdio 启动,可通过 npm 包 mcp-sophon 安装(postinstall 会下载适用于 macOS arm64/x64、Linux arm64/x64 或 Windows x64 的预编译二进制文件),也可用 Rust 1.75+ 从源码构建。可选功能需要额外的构建参数。可选环境变量包括 SOPHON_MEMORY_PATH、SOPHON_RETRIEVER_PATH、SOPHON_HYBRID、SOPHON_ROLLING_SUMMARY、SOPHON_CHUNK_TARGET、SOPHON_EMBEDDER 和 SOPHON_LLM_CMD。未声明身份验证。
安装
在 SourceWeft 中
- 打开 控制台中的 Sophon,将其添加到工作区。
- 为需要使用其工具的对话启用该服务。
Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。
其他 MCP 客户端
参照 仓库 中的启动说明。
README
Sophon
Deterministic context compression for MCP agents. One Rust binary. Zero ML at query time. Reproducible benchmarks, real-data measurements.
[npm version] [npm total downloads] [GitHub release] [CI] [License: MIT] [Rust 1.75+] [MCP] [Tests]
Sophon is a deterministic context layer for agents speaking the Model Context Protocol. It compresses prompts, conversation memory, code digests, file deltas, and shell output — without an embedding model at query time, without a GPU, and without API keys.
Single 5.2 MB Rust binary. MCP-native. cl100k_base-accurate. Default build pulls no Python, no ML weights, no network.
What it does, in 30 seconds
11 MCP tools total (full table below).
Real numbers — measured on this repo's own dev cycle
We built four independent benches that each capture a different chunk of an agent's tool traffic. All four run against this repo's actual git history + working tree on the operator's machine. Reproducible byte-for-byte by anyone with cargo build --release.
real_session_holistic.py runs all four sub-benches with --json, parses them, and produces the weighted blend. Default weights reflect this repo's observed shape; pass --weights "history=0.4,..." to model your own workload.
USD economy on Claude Opus 4.7
Pass
--model sonnetor--model haikutoreal_session_deep_dive.pyif you're re-pricing for a cheaper tier.
Where each dimension falls short (we say it ourselves)
- history measures only what
gitcaptures (commits + diffs) — typically ~5-10 % of a real session's tool traffic. The 94.6 % is the upper bound, not the typical case. - shell mixes commands that compress well (
git diff95 %) with commands that don't (gh repo view --jsonadds tokens, −9 %). 84.4 % is a real-world average, not a curated highlight. - filereads uncovered that
compress_prompton raw source files compresses by budget cap, not by query routing — same file with 3 different queries → identical output. Section detection only fires on structured input (Markdown headers, XML tags). Documented inline in the bench. - search depends entirely on YOUR repo's state. A repo with no TODOs gets 0 % on
grep TODO.
The blended 84.7 % is napkin-math from a linear weighted average across four real measurements. Not a cherry-picked synthetic. Run the benches yourself to verify.
Other reproducible benchmarks (synthetic, on-thesis)
Why Sophon — "in front of X"
Sophon is not a memory platform, a recall system, an OCR stack, or a replacement for provider-side caching. It's a deterministic compressor that slots in front of whatever memory / cache / code-nav layer you already use, and attacks the tokens those layers can't.
In front of Anthropic / OpenAI prompt caching
Provider caching handles the static half of a request — system prompt, tool definitions, reused documents. It doesn't touch the dynamic half (growing conversation history, tool outputs). Sophon compresses exactly that half. The two stack cleanly.
+24 % tokens / +49 % $ saved on top of prompt caching on a 25-turn Claude session — because the uncached dynamic block is billed at 10× the cached rate. See
sophon_plus_prompt_caching.py.
In front of mem0 / Letta / Zep / Graphiti
Memory systems retrieve the right memories. Sophon shrinks what gets sent to the LLM after retrieval. If mem0 returns 2 kB of raw memories, compress_prompt keeps only the sections the query actually references.
Honest caveat: on very short retrieved blocks (< ~200 tokens) Sophon's wrapper adds overhead and you should pass through. The bench reports this directly.
In front of Claude Code / Cursor / Cline
Primary use case. Every repeat file read becomes a read_file_delta; every shell command output goes through compress_output; every repeated boilerplate block gets a fragment_cache token. Install transparently with sophon hook install --agent claude --global.
In front of a RAG pipeline
navigate_codebase produces a PageRanked repo digest that a RAG retriever would otherwise spend expensive embedding calls to build. Tree-sitter / regex symbol extraction over 11 languages, sub-second.
When NOT to use Sophon
- Long-form conversational recall above 80 % — Sophon caps at ~40 % on LOCOMO and we don't chase it. Run mem0 / Letta / Zep for recall, then optionally pipe their output through Sophon.
- Multi-hop reasoning on massive documents — that's HippoRAG or GraphRAG.
- OCR / PDF layout — out of scope. Use Docling / Marker / Unstructured upstream.
- Very small inputs (< ~200 tokens) — Sophon's section scaffolding can cost more than it saves.
Quick start
Install via npm (recommended)
The postinstall script downloads the right prebuilt binary for your platform from the GitHub Releases page. Supported: macOS arm64/x64, Linux arm64/x64, Windows x64.
Build from source
Optional features:
Requires Rust 1.75+.
Wire it into an MCP client
Most clients accept this snippet (Claude Desktop, Claude Code, Cursor, Cline, Continue):
Run sophon doctor to print the right config path for your client.
Recommended runtime setup
Quick CLI
Programmatic (one-shot JSON-RPC)
What the binary ships
11 MCP tools, all stdio:
Binary sizes by feature set:
MCP protocol: 2025-06-18. notifications/cancelled actually drops the response (since v0.5.4). Structured JSON-RPC error codes (-32000..-32099 reserved for Sophon). Infallible dispatcher — a malformed request can't kill the stdio loop.
Filesystem confinement (opt-in)
For clients running untrusted prompts, set SOPHON_ALLOWED_ROOT to an existing workspace directory. read_file_delta, write_file_delta, and navigate_codebase reject resolved paths outside this directory. By default, trusted local integrations retain unrestricted filesystem access. This is a path-level defense, not a hardened OS sandbox: although known symlinks and dangling symlinks are checked, a concurrent actor who can modify directory links may swap a path between authorization and the subsequent file operation (TOCTOU). Do not expose these tools to hostile users with write access to the same filesystem; use operating-system isolation for strict security boundaries. New files require an existing parent directory when confinement is enabled.
Configuration
Run sophon doctor to see every SOPHON_* env var currently set with validation warnings. Full catalogue (24 flags) lives in runtime_flags.rs. The flags worth knowing:
Deprecated v0.4.0 recall-chasing flags — SOPHON_HYDE, SOPHON_FACT_CARDS, SOPHON_ENTITY_GRAPH, SOPHON_ADAPTIVE, SOPHON_LLM_RERANK, SOPHON_TAIL_SUMMARY, SOPHON_REACT, SOPHON_GRAPH_MEMORY, SOPHON_MULTIHOP_LLM — chase LOCOMO recall, an axis we no longer optimise. Still functional but sophon doctor flags them. Removed in a future major.
Honest limitations
The full list lives in BENCHMARK.md § 8. Headlines:
- LOCOMO conversational recall caps at ~40 %. mem0 / HippoRAG hit 80-90 % with neural retrieval at query time — we chose determinism + sub-100 ms p99 instead. Pipe mem0 in front of Sophon if you need that recall.
- HashEmbedder is keyword-bound. "favorite food" ↔ "weakness for ginger snaps" doesn't match. Activate BGE (
SOPHON_EMBEDDER=bge) for semantic recall — costs +25 MB binary + model load. - No multimodal ingestion. Images / PDFs / audio out of scope. Run Docling / Marker / Unstructured upstream.
- Rolling summary doesn't help on small sessions. When the un-summarised tail fits the budget, the rolling cache is a no-op. Useful for long-running sessions with
SOPHON_LLM_CMDset. - Some commands don't compress.
gh repo view --jsonadds tokens,git log --onelinesaves 0.4 %. Sophon's job isn't to compress already-compact output — it's to compress redundant verbose output. The benches name the gaps explicitly.
Project layout
Contributing
PRs welcome. Run the test suite:
Every benchmark claim is reproducible — pointers to the scripts live in BENCHMARK.md. If a number doesn't reproduce on your machine, open an issue.
Particularly welcome:
- TypeScript bindings (Python bindings ship in
sophon-py/) ghfamily filter (gh run list,gh pr list,gh repo view --json) — the bench shows this is currently a gapSOPHON_EMBEDDER_CMDshell-out plugin pattern (mirror ofSOPHON_LLM_CMD) for Voyage / OpenAI / Cohere- Multi-repo
real_session_holistic.pyruns against popular open-source repos
License
MIT. See LICENSE.
来源:README.md,提交 e4bc0b4
工具
0版本历史
1- v0.5.4最新Sep 16, 2026
评分
已满足适用检查项的 50%
该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。
- 近 30 天内可连通25 分
请保持端点能够响应 MCP 握手;SourceWeft 每 30 天探测一次。
- 已声明认证方式10 分
请在注册中心条目中声明凭据请求头,或保持端点能够响应探测,以便判定其认证方式。
- 已列出工具15 分
请让服务器在无凭据时响应 tools/list,或发布可在沙箱中无凭据启动的软件包。
- 描述必需15 分
- 图标10 分
- 文档15 分
- 许可证10 分