cachepin
Supports OpenAI API traffic as an upstream target, applying lossless prompt-cache optimization and keep-alive proxying for OpenAI models.
Exposes a Prometheus-compatible /metrics endpoint for monitoring proxy, cache, and routing telemetry.
This server does not currently have a deployable release on Glama. Follow the repository's setup instructions to install and configure it for your MCP client, including any required credentials and local dependencies.
cachepin
Pin your prefix. Stop burning 15×–40× on broken multi-agent LLM prompt caches.
Zero-dependency Rust + AVX2 / ARM64 NEON multi-agent prompt-cache compiler, exact $O(M^2 K)$ mixed-TTL breakpoint optimizer, TTFT-triggered single-flight thundering-herd coalescer, HTTP/1.1 keep-alive proxy, and replication-aware Shadow-KV radix router. ~1.1 MB binary · 0 external crates · 100% lossless · works with Anthropic, OpenAI, vLLM, SGLang, Claude Code, Codex, and MCP.
Interactive browser playground & swarm billing simulator: pgg898200-ship-it.github.io/cachepin
Why Multi-Agent Prompt Caches Collapse
In late-2026 LLM economics, a cached token read costs 0.05× on Anthropic Opus/Sonnet 5.5 and OpenAI GPT-5.6+ (20× cheaper), and 0.025× on Anthropic Fable 5.1 (40× cheaper). Yet multi-agent coding and research swarms routinely fall to 2%–20% cache hit rates because a single differing byte at token 50 invalidates the entire 50,000-token KV prefix after it:
Non-deterministic tool & schema key order across MCP servers and language runtimes.
Volatile tokens injected early (ISO-8601 timestamps, UUIDs,
req_*/trace_*/session_*IDs).All-Gather collective prefix shattering (arXiv:2604.03143): $N$ agents ingest the same shared repo files or peer summaries in different orders.
Cold-start thundering herds: 32 subagents spawn simultaneously on the same cold prefix and pay 32 redundant cache writes.
Eviction-regime routing cliffs on self-hosted vLLM/SGLang clusters: single-home prefix routers pile bursts onto one GPU and regress P99 TTFT when working sets exceed fleet KV capacity.
cachepin fixes all five losslessly — without dropping or rephrasing a single token. It stacks orthogonally on top of lossy prompt compressors (caveman, context-mode).
Related MCP server: promptopt
30-Second Quickstart
# Option A: Install prebuilt release binary (Linux/macOS x86_64 & ARM64, SHA-256 verified)
curl -fsSL https://raw.githubusercontent.com/pgg898200-ship-it/cachepin/main/scripts/install.sh | sh
# Option B: Homebrew / Nix / Docker / Offline Cargo build (0 external crates)
brew install --HEAD pgg898200-ship-it/cachepin/cachepin # Homebrew tap
nix run github:pgg898200-ship-it/cachepin -- --version # Nix Flake
docker run -i --rm ghcr.io/pgg898200-ship-it/cachepin:latest mcp
cargo build --release # 100% offline, 0 cratesRun Immediately (Zero Config Needed)
# 1. Audit your real local Claude Code (~/.claude/projects) & Codex (~/.codex/sessions) logs
cachepin audit --auto
cachepin audit --claude-code
cachepin audit --codex
# 2. Pinpoint the exact byte where two prompts shatter KV caching + counterfactual recovery
cachepin diff agent_a.json agent_b.json
# 3. Drop-in HTTP/1.1 keep-alive reverse proxy for Cloud APIs or multi-GPU vLLM/SGLang fleets
cachepin proxy --upstream https://api.anthropic.com --port 47820
ANTHROPIC_BASE_URL=http://127.0.0.1:47820 claude
# Live dark-mode telemetry: http://127.0.0.1:47820/dashboard | Prometheus: /metrics
# 4. Native stdio MCP server, Claude Code Plugin, Universal .mcpb Extension, or Agent Skill
cachepin mcp
# Claude Code Plugin: /plugin marketplace add pgg898200-ship-it/cachepin && /plugin install cachepin
# Cross-agent skill : npx skills add pgg898200-ship-it/cachepinOr embed directly in Python (zero dependencies via ctypes + libcachepin.so):
from cachepin import CachePin
with CachePin(mode="swarm") as cp:
optimized = cp.optimize_dict(request_payload, tenant="team-alpha", provider="anthropic")Architecture
flowchart LR
A["Multi-Agent Swarm<br/>(N concurrent agents)"] --> B["Pass 1-4 Prefix Compiler<br/>AVX2/NEON JSON + Tool Sort + Bijective Hoist + All-Gather"]
B --> C["TTFT Single-Flight Coalescer<br/>1 Leader -> N-1 Followers wake on 200 OK headers"]
C --> D["Tenant-Isolated Radix Tree<br/>+ Exact O(M^2 K) Mixed-TTL DP (1h before 5m)"]
D --> E{"Upstream Mode"}
E -->|Cloud API| F["Anthropic / OpenAI<br/>(Verified TLS + zero-buffer SSE + usage reconciliation)"]
E -->|Self-Hosted Fleet| G["Shadow-KV Adaptive-Replication Router<br/>(1.16 us/route + HTTP/1.1 keep-alive pool)"]
G --> H["vLLM / SGLang GPU Fleet"]Reproducible Benchmarks
Every number below is generated directly on this machine (Intel Xeon, AVX2, 2 vCPUs, rustc 1.100, Node.js v22.23, Python 3.12) and saved verbatim in benchmarks/results.json. Reproduce everything with ./scripts/verify.sh, or run standalone paper reproductions (benchmarks/repro_all_gather_2604_03143.py, benchmarks/repro_thundering_herd.py, benchmarks/repro_vllm_eviction_cliff.py).
[LIVE-CPU]: Direct wall-clock measurements on live CPU execution & loopback TCP sockets.[SIM-TRACE]: Deterministic discrete-event workload & 8-GPU cluster replays under late-2026 provider pricing.
1. Cross-Language Matched Controls (18.5 KiB Multi-Agent Request) [LIVE-CPU]
Runtime | Compile P50 | Compile P99 | LCP Diff Throughput | CLI Cold Start |
| 84.2 µs | 138.4 µs | 42.56 GB/s | 2.53 ms |
| 392.9 µs | 828.1 µs | 39.13 GB/s | — |
Node.js 22 (V8 JIT control) | 290.3 µs | 1,233.9 µs | 0.85 GB/s | 56.54 ms |
Python 3.12 (stdlib control) | 1,876.3 µs | 2,096.4 µs | 0.02 GB/s | 35.96 ms |
Speedup ( | 22.3× / 3.45× | 15.1× / 8.91× | 2,108× / 50.3× | 14.2× / 22.4× |
Note:
cachepinRust executes strictly more work than the Node/Python controls (adding All-Gather frequency-bucket alignment, SipHash-2-4 tenant KDF, 18-block prefix hashing, SIMD BPE token estimation, and config-trap guard), yet beats Node.js 22 V8 by 3.45× at P50 and 8.91× at P99. On ARM64 (Apple Silicon / AWS Graviton),cachepinautomatically dispatches native ARM64 NEON (simd: neon), verified natively in CI onubuntu-24.04-arm.
2. Core Native Kernels & Live Reverse Proxy [LIVE-CPU]
Kernel / Live Measurement | Measured Value | Evidence |
AVX2 Longest-Common-Prefix Diff ( | 42.56 GB/s |
|
Exact $O(M^2 K)$ Mixed-TTL DP Breakpoint Solver (16 blocks) | 8.04 µs P50 / 27.85 µs P99 |
|
Shadow-KV Adaptive-Replication Route Decision (8 backends) | 1.16 µs P50 / 2.35 µs P99 |
|
Live Loopback HTTP/1.1 Keep-Alive Proxy Added Overhead | 0.22 ms P50 ( |
|
32-Agent Live Cold-Start Thundering Herd (Cache Writes) | 32 → 1 writes (-96.88%) |
|
3. Multi-Agent Prefix Recovery & Exact DP Savings [SIM-TRACE]
Workload (Anthropic Opus 5.5: | Raw Baseline | After | Improvement |
32-Agent Coding Swarm (Tool/Key Drift + Volatile IDs + Docs) | 2.24% hit | 98.44% hit | -93.50% cost (15.39× cheaper) |
16-Agent All-Gather Collective Rounds (arXiv:2604.03143) | 19.61% hit | 98.61% hit | -93.43% cost |
64-Agent Branching Tree (Mixed | Uncached / Naive 1-BP | Exact DP | -88.51% vs uncached / -88.59% vs naive 1-BP |
4. 8-GPU vLLM Eviction-Regime Routing (48 Prefixes, Zipf-1.25 Bursts) [SIM-TRACE]
Routing Policy | Fleet KV Hit % | P50 TTFT | P99 TTFT | Mean TTFT | Auto-Replications |
Round-Robin | 51.1% | 136.6 ms | 443.0 ms | 137.3 ms | 366 |
Least-Loaded | 52.6% | 106.0 ms | 376.0 ms | 119.1 ms | 355 |
Consistent-Hash | 96.1% | 16.8 ms | 351.6 ms | 72.9 ms | 0 |
SingleHome-2xDivert (Ranvier-style) | 66.9% | 14.4 ms | 413.0 ms | 89.7 ms | 180 |
| 87.5% | 12.8 ms | 260.0 ms | 37.1 ms | 66 |
cachepin cuts P99 TTFT by 37.0% vs single-home 2×-divert and 30.9% vs Least-Loaded, and cuts Mean TTFT by 2.42× vs single-home 2×-divert and 3.21× vs Least-Loaded, while deciding routes in 1.16 µs P50.
Comparison Against Existing Tools
Capability |
|
|
|
|
100% lossless (zero eval degradation) | Yes (proven bijection) | No (lossy prose/output trim) | Yes | Yes |
Multi-agent All-Gather prefix alignment | Yes | No | No | No |
Exact $O(M^2 K)$ mixed | Yes (enforces A/B/C rule) | No | No | No |
TTFT single-flight thundering-herd coalescer | Yes ( | No | No | No |
Cloud APIs (Anthropic/OpenAI) + vLLM/SGLang | Both | Cloud/client | Anthropic only | vLLM only |
Eviction-regime adaptive KV replication | Yes ( | No | No | No (+eviction cliff) |
Runtime footprint & SIMD | ~1.1 MB binary, AVX2 + NEON, 0 deps | Node / plugin | Node proxy | C++20 Seastar + Docker |
Native MCP + Python FFI + CLI Diff & Audit | All built-in | MCP/Skill | Proxy only | Router only |
When You Do NOT Need cachepin
Short prompts (
< 512tokens): Below provider minimum cacheable prefix thresholds (cachepinautomatically passes these through unchanged withbelow_min_tokens).Single-turn, zero-reuse one-off queries: If a system prompt or context is never reused within 5–60 minutes, caching adds a 1.25× write surcharge without future read hits (our DP solver detects
expected_hits == 0and places 0 breakpoints).Single-agent workloads already at
>95%cache hit rate: Runcachepin audit --autofirst — if your raw hit rate is already>95%, you don't need another proxy in your stack.
Verification & Safety Guarantees
Run the complete verification gate (zero-dependency check, 64 Rust unit/property tests under -D warnings, 12-vector adversarial red-team & live integration suite, and cross-language matched-control benchmarks):
./scripts/verify.shVerified guarantees (tested in tests/adversarial_suite.py, cargo test --release, and native ARM64 NEON CI):
Prompt-injection sentinel safety: Literal
⟦cp:v1⟧/⟦cp:esc:strings in untrusted inputs are escaped bijectively (reconstruct_lossless(hoist(s)) == sfor all UTF-8 strings).Strict cross-tenant isolation: Every block hash, radix namespace, and single-flight coalescer key is derived via per-tenant SipHash-2-4 KDF — zero cross-tenant cache sharing or probing.
RFC 8259 DoS resistance: Strict
MAX_DEPTH = 128parser guard, full UTF-16 surrogate pair validation, zerounwrap()in production paths, panic-safecatch_unwindFFI boundary.Anthropic mixed-TTL compliance: Emitted breakpoints strictly satisfy
<= 4and all1hmarkers preceding all5mmarkers.Fail-open RAII coalescing: Leader errors, disconnects, or panics immediately wake parked followers (
Drop for LeaderGuard).Zero-buffering keep-alive pooling & provider usage reconciliation: Plain HTTP upstreams reuse warm TCP sockets cleanly across requests while reconciling provider-reported
cache_read_input_tokens/cache_creation_input_tokens/cached_tokensafter client flush.
Documentation & Registry Links
Interactive Playground & Explorer: pgg898200-ship-it.github.io/cachepin
Official MCP Registry identifier:
mcp-name: io.github.pgg898200-ship-it/cachepindocs/ALGORITHMS.md— Formal mathematical specification of all 5 mechanismsdocs/INTEGRATIONS.md— Drop-in setup for Claude Code, Codex, Anthropic, OpenAI, vLLM/SGLang, MCP, and Python SDKSKILL.md— Agent-first declarative skill manifest (npx skills add pgg898200-ship-it/cachepin)llms.txt— Concise machine-readable repository index for AI coding agents
License
Dual-licensed under MIT OR Apache-2.0. See LICENSE.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
This server cannot be deployed
Maintenance
Related MCP Connectors
AI routing, memory, guardrails, and governance. Routes across Claude, GPT, Gemini.
Multi-agent coordination outside your LLM context: dedupe parallel work, per-agent budgets, handoff
One MCP endpoint for Claude, GPT & Gemini: 100+ tools + no-code connectors + agent workers.
AI model routing on your own vendor keys: pick the best model per prompt, or route and run it.
Related MCP Servers
- AlicenseBqualityDmaintenanceRoute prompts intelligently across Claude, Gemini, and GPT-4o, automatically picking the best model for every task while minimizing token cost.532 npmMIT
- AlicenseNot gradedqualityCmaintenanceEnables local, offline prompt compression, smart asking when needed, and routing to the cheapest capable model to save tokens and costs for terminal AI agents.1MIT
- AlicenseNot gradedqualityCmaintenanceEnables autonomous context window management, prompt caching, token optimization, and real-time observability for AI coding agents across multiple IDEs, reducing token costs and improving performance.Apache 2.0
- FlicenseNot gradedqualityNot gradedmaintenanceEnables dynamic, intent- and budget-aware routing of queries across 70+ LLMs by balancing cost and latency through Pareto-optimal model selection. Integrates with MCP clients like Claude Desktop and Cursor for automated multi-model execution.-