TraceFlow Compress

TraceFlow Compress

Serverless MCP connector for compressing prompts with TraceFlow metrics (tokens, cost, latency, compute, energy, carbon). Provides compression, analysis, routing, and caching tools.

Category
Visit Server

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-mini mode 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 /metrics endpoint.
  • Honest by design: every estimate flagged estimated: true; closed-model params flagged params_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)

  1. Push to GitHub, import into Vercel (Python / Fluid Compute — auto-detected).
  2. Set env vars: CONNECTOR_API_KEY (gates /mcp), optional OPENAI_API_KEY (quality mode), optional UPSTASH_REDIS_REST_URL + _TOKEN (persistent metrics; a local JSON file is used otherwise).
  3. 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).

Recommended Servers

playwright-mcp

playwright-mcp

A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.

Official
Featured
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.

Official
Featured
Local
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
graphlit-mcp-server

graphlit-mcp-server

The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.

Official
Featured
TypeScript
Kagi MCP Server

Kagi MCP Server

An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

Official
Featured
Python
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Exa Search

Exa Search

A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured