TraceFlow Compress
Serverless MCP connector for compressing prompts with TraceFlow metrics (tokens, cost, latency, compute, energy, carbon). Provides compression, analysis, routing, and caching tools.
README
TraceFlow Compress
A serverless prompt-compression MCP connector that compresses prompts fast and returns TraceFlow-style metrics — tokens, cost, latency, compute-load, energy, and carbon — where every number is either measured or a clearly-labeled estimate. See SPEC.md for the full design.
Built around the TraceFlow whitepaper's Prompt Intelligence + token/cost/ compute/energy/carbon layer (the buildable slice — no GPU hardware required).
Highlights
- Fast + serverless: default heuristic compression is pure Python (~3 ms,
no model, no API key). Optional
gpt-4o-minimode for higher quality. - MCP connector: exposes 5 tools + a metrics resource over streamable HTTP.
- TraceFlow metrics: token/cost/latency (measured) + energy/carbon/GPU-load (estimated, labeled). GPU intent preserved via a compute-load model, not faked.
- Live dashboard + public
/metricsendpoint. - Honest by design: every estimate flagged
estimated: true; closed-model params flaggedparams_known: false.
Quick start (local)
pip install -r requirements.txt
python demo.py # try the core on a sample
python eval/run_eval.py # measured eval over sample prompts
pytest tests/ # test suite
python mcp_server.py # run the MCP server over stdio
uvicorn api.index:app --port 8000 # run the HTTP server + dashboard
# → open http://localhost:8000/ (dashboard) and /mcp (connector)
MCP tools
| Tool | Purpose |
|---|---|
compress_prompt(text, target_ratio?, quality?, target_model?, use_cache?) |
Compress + full metrics. target_model="auto" routes by complexity |
route_prompt(text) |
Recommend a small/large model by complexity + cost transparency |
analyze_prompt(text) |
Tokens, fillers, redundancy (no compression) |
estimate_savings(text, calls_per_day?, target_model?) |
Projected monthly cost/carbon savings |
get_metrics() |
Aggregate TraceFlow metrics incl. cache hit rate |
get_top_prompts(n?) |
Most compressible prompts seen |
detect_anomalies() |
AIOps: flag low-compression / token / cost spikes (IQR baseline) |
Resource: metrics://summary.
Each compress_prompt result also carries distributed-trace spans (§2.2) —
measured sub-step timings (route, cache_lookup, compress, token_metrics,
estimates).
Semantic caching (§8.2) & multi-model routing (§8.4)
- Cache — two-tier, serverless-friendly: exact (normalized hash) + similarity
(lexical-cosine,
TF_CACHE_THRESHOLD, default 0.92) so near-identical prompts reuse a prior compression. Namespaced by (ratio, quality, model). Per warm instance. Hit rate is shown on the dashboard. - Routing —
route_prompt/target_model="auto"scores prompt complexity (reasoning verbs, code, structure, length) and picks a small vs large model, with per-model cost estimates so the choice is transparent.
Deploy (serverless, Vercel)
- Push to GitHub, import into Vercel (Python / Fluid Compute — auto-detected).
- Set env vars:
CONNECTOR_API_KEY(gates/mcp), optionalOPENAI_API_KEY(quality mode), optionalUPSTASH_REDIS_REST_URL+_TOKEN(persistent metrics; a local JSON file is used otherwise). - Add to Claude via connector settings →
https://<app>.vercel.app/mcp.
Metrics dashboard: https://<app>.vercel.app/.
Metrics reference
| Measured (real) | Estimated (labeled) |
|---|---|
| tokens in/out/saved, reduction % | cost saved (USD) |
| latency (ms) | energy saved (Wh) |
| CPU time, peak RAM | carbon saved (g CO₂) |
| fillers removed, redundancy % | GPU-ms load + reduction % (2×params×tokens) |
Layout
core/ compression + intelligence + estimates + metrics store
mcp_server.py FastMCP tools/resource
api/index.py serverless ASGI entrypoint (MCP + dashboard + /metrics + auth)
dashboard/ static metrics page
eval/ measured evaluation
tests/ unit tests
Reused from the Prompt Compression Agent
tiktoken counting, the filler list + analysis logic, the metrics dataclass pattern, and the OpenAI wiring (for the optional LLM path).
推荐服务器
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 模型以安全和受控的方式获取实时的网络信息。