
LatentGate
io.github.KathanModh259由 GitHub 账号 KathanModh259 发布v1.4.2更新于 Oct 30, 2026
Read large logs, JSON and docs in a fraction of the tokens. Offline, fact-preserving optimizer.
概览
LatentGate 是一个本地 MCP 服务器,在助手读取前压缩日志、JSON、文档和网页,离线且确定性地减少 token 消耗。
- 可以做什么
- 读取文本文件并返回优化后的版本
- 优化对话中已有的文本,可按问题或 token 预算定向压缩,并统计 token 数
- 借助本地 Ollama 模型压缩图片、文本、对话和文档,并查看会话统计
- 在托管 HTTP 模式下抓取网址并返回精简后的可见文本
- 适用场景
- 适合助手需要阅读大体积日志、JSON 转储、长文档或大量重复文本,而上下文或成本成为瓶颈的场景;确定性优化工具无需任何模型或 API 密钥即可使用。
- 运行要求
- 通过 uvx 从 PyPI 包 latent-gate 以 stdio 在本地运行,需要 uv;首次运行会下载依赖,可能超过客户端的启动超时。图片与 compress_* 工具还需要本地 Ollama 服务并预先拉取模型。MCP 服务器本身未声明任何凭据。
安装
在 SourceWeft 中
- 打开 控制台中的 LatentGate,将其添加到工作区。
- 为需要使用其工具的对话启用该服务。
Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。
其他 MCP 客户端
参照 仓库 中的启动说明。
README
LatentGate
Give your AI the signal, not the noise.
An MCP server that shrinks logs, JSON, docs and web pages before your AI reads them — offline, deterministic, in ~3ms, no API key. 66% fewer tokens across a mixed dev corpus; 90%+ on repetitive logs.
[Python 3.10+] [License: Proprietary] [Version] [PRs Welcome] [Ollama] [MCP] [Prometheus] [Grafana] [k6] [Vercel] [CI] [Downloads] [Listed on mcpservers.org]
Use in Claude | Quick Start | Python API | REST API | Monitoring | Load Testing | Deployment | AI Tools | Benchmarks | Contributing
See it work
Try it in your browser → The real optimizer runs on your machine via WebAssembly; nothing you paste is uploaded.
A 400-line error log, read through LatentGate (balanced, measured with tiktoken):
Install it into Claude Code in one line, then ask "read app.log and tell me why orders fail":
What you can rely on: the same input always gives the same output (so provider prompt caching keeps
working); output is never larger than input; code blocks, URLs and quoted strings come back
byte-for-byte; level="lossless" changes nothing but whitespace, JSON formatting and exact duplicates.
What you trade at the default level: runs of near-identical lines are folded to first, last and value
ranges, so individual IDs inside a folded run are not kept. The full corpus, including where it loses
facts, is in Cost Benchmarks and reproducible with latent-gate --optimizer-benchmark.
Works in Claude Code, Claude Desktop, Cursor, Cline, Continue and Zed, free and offline.
Don't want to install anything? The official hosted LatentGate on mcprush also runs where local servers can't, such as claude.ai on the web and mobile. It has a free tier (300 calls a month) and paid plans from $9/month.
The Problem
Every time you send an image or long prompt to GPT-4o / Claude / Gemini, you burn 1,000+ tokens on processing that could happen locally for free.
Features
Use it in Claude
LatentGate plugs into Claude as an MCP server. Its optimizer tools work offline, with no Ollama and no API key — Claude reads big logs, JSON dumps and docs through it and spends a fraction of the context. A 400-line error log goes from 14,400 to ~100 tokens.
Requires uv (uvx fetches LatentGate from PyPI on first run).
The first run downloads dependencies, which can exceed Claude's 30-second MCP startup limit
on a slow connection; run this once beforehand (later starts take ~2s):
Claude Code — plugin (MCP server + a skill that tells Claude when to use it):
Claude Code — MCP server only:
Any agent — from the Agensi marketplace: LatentGate Context Saver is the official skill for Claude Code, Cursor, Codex CLI and 20+ other agents. It sets LatentGate up if it's missing, works with the local and hosted editions, and tells your agent when to use it.
Claude Desktop — add to claude_desktop_config.json and restart:
Then just ask: "Read logs/app.log with latent-gate and tell me why orders fail."
Quick Start
Install
Pull Ollama Models
One-Command Quickstart
This starts everything: Ollama → pulls models → API server → website. See scripts/quickstart.sh for options like --no-pull, --no-website, --port 9000.
CLI Usage
Production Hardening
For API deployments, restrict direct image-path reads to trusted directories:
Benchmark before releases so speed and savings are measured, not guessed:
Python API
Image Query
Text Compression
Batch Processing
Streaming
REST API
Start Server
Endpoints
Example Requests
Async Support
Video Processing
Configuration
Config File
Environment Variables
Save Config
Docker
The docker-compose setup includes:
- latent-gate API server (port 8000)
- Ollama local LLM server (port 11434)
- ollama-init container that auto-pulls required models (profile:
setup) - Prometheus metrics collector on port 9090 (profile:
monitoring) - Grafana dashboard on port 3000 (profile:
monitoring, credentials:admin/latentgate)
Monitoring Stack
Start with monitoring:
Access:
- Grafana: http://localhost:3000 (login:
admin/latentgate) - Prometheus: http://localhost:9090
- Metrics endpoint: http://localhost:8000/metrics
The LatentGate dashboard auto-loads in Grafana with 9 panels covering request rate, latency percentiles (p50/p95/p99), token savings, error rates, pipeline health, and endpoint breakdown.
Customize via environment variables:
GRAFANA_ADMIN— Grafana admin username (default:admin)GRAFANA_PASSWORD— Grafana password (default:latentgate)GRAFANA_ANONYMOUS— Enable anonymous access (default:true)LATENTGATE_ENABLE_METRICS— Enable Prometheus metrics (default:true)
AI Coding Tool Integration (MCP)
LatentGate works as a Model Context Protocol (MCP) server with every major AI coding tool. Your AI assistant automatically compresses images, long prompts, and documents before they reach the cloud model.
Supported Tools
VS Code Extension
Features:
- Right-click any image to compress with LatentGate
- Select text and press
Ctrl+Shift+Alt+Cto compress - Cost dashboard in activity bar
- Auto-configures MCP for Copilot Chat
- Status bar showing token savings
MCP Setup
For Claude, see Use it in Claude. For Cursor, Cline, Continue, Zed and other MCP clients, use the same server command:
Or install it into your environment (pip install "latent-gate[mcp,tokens]") and use
"command": "latent-gate-mcp". Note the command is latent-gate-mcp — plain latent-gate
is the CLI and will not speak MCP. The image and compress_* tools additionally need
ollama pull llava:7b and ollama pull phi3:mini.
See integrations/ folder for detailed setup guides per tool.
Hosted MCP (remote, for gateways like mcprush)
Serves streamable HTTP at /mcp (stateless, so any instance can answer any request) and
/health. Because it's remote, it also works where local MCP servers can't run: claude.ai
on the web and mobile, and any client that only takes a connector URL. The main tool there is
fetch_url_optimized. It fetches a page, JSON API or raw log by URL and returns the visible text,
compacted and deduplicated without a summarizing model. Addresses that aren't public
(localhost, 10.x, cloud metadata) are refused, and that's checked on the live connection, so
DNS tricks don't get around it. In this mode:
read_file_optimized,compress_imageandget_statsare hidden. The first two would read the server's disk, and stats would mix all callers' usage.compress_*tools are listed only whenLATENTGATE_HOSTED_OLLAMA=1(the host runs Ollama).- Each call's input is capped at 2MB.
- With
LATENTGATE_API_KEYset, requests needAuthorization: Bearer <key>. Give the key to your gateway and nobody else, so callers can't bypass the paid plan.
Speed Optimizations
Cost Benchmarks
Image Queries (by provider, estimated)
Estimates from each provider's published image-token formulas versus a ~150-token local description.
Text: measured, reproducible
Deterministic optimizer on built-in realistic inputs, counted with tiktoken (o200k_base).
Facts kept = share of numbers, identifiers, URLs, file names and code preserved verbatim.
Reproduce with latent-gate --optimizer-benchmark (no Ollama or API key needed).
Logs lose individual ids/timestamps when folded (the fold keeps first, last and value ranges), and RAG drops facts from documents irrelevant to the question — both by design.
How it works (safest stage first; see latent_gate/optimizer.py):
- Protect code blocks, inline code, URLs and quoted strings — restored byte-for-byte
- Lossless: whitespace/Unicode cleanup, JSON minification (values untouched), duplicate folding
- Log folding: runs of log lines differing only in numbers/ids → first, last, and ranges
- Filler: pure pleasantries ("Hi!", "Thanks in advance!") and hedging phrases removed
- Selection (only over a budget, or
aggressive): BM25 question-relevance + requirement cues, original order preserved, the user's actual ask is never dropped
Guarantees: output never has more tokens than input; same input → same output (so provider prompt caching keeps working); when a local LLM rewrite is used it must be smaller and keep every fact, otherwise the deterministic result is sent.
Video
Selective decoding skips remote calls for frames similar to the previous one (~2.85x fewer calls on typical footage).
At Scale (10,000 image queries with gpt-4o-mini, estimated)
Cost Tracking
Multi-Language Support
Project Structure
Community
- GitHub Discussions — Feature requests, Q&A, showcases
Contributing
Contributions welcome! See CONTRIBUTING.md.
Development Setup
Run Tests
Priority Areas
- Additional vision model support (Florence-2, InternVL, Qwen-VL)
- Custom similarity plugins for domain-specific use cases
- WebSocket support for real-time streaming
- Advanced cost analytics and optimization suggestions
- Plugin development for specialized industries
- Test coverage improvements
- Documentation and examples
Citation
Inspired by VL-JEPA (Meta FAIR, 2025).
License
Custom Proprietary License — see LICENSE.
Built by Kathan Modh
Process locally. Send smart. Pay less.
来源:README.md,提交 5273d88
工具
0版本历史
2- v1.4.2最新Oct 8, 2026
- v1.3.1Sep 25, 2026
评分
已满足适用检查项的 40%
该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。
- 近 30 天内可连通25 分
请保持端点能够响应 MCP 握手;SourceWeft 每 30 天探测一次。
- 已声明认证方式10 分
请在注册中心条目中声明凭据请求头,或保持端点能够响应探测,以便判定其认证方式。
- 已列出工具15 分
请让服务器在无凭据时响应 tools/list,或发布可在沙箱中无凭据启动的软件包。
- 描述必需15 分
- 图标10 分
- 文档15 分
- 许可证10 分
请在仓库或注册中心条目中声明许可证。