Middleman

Middleman

A context refinement MCP server that acts as a proxy to distill large outputs from other MCP servers into concise summaries, reducing token usage and API costs.

Category
访问服务器

README

<div align="center">

<img src="assets/icon (1).png" alt="icon (1).png" width="150" height="150" />

<h1>Middleman: The Context Refiner MCP 🚀</h1> <p><em>Enterprise-grade context distillation for LLMs. Cut API costs by 95%.</em></p>

</div>

Middleman is an enterprise-grade Model Context Protocol (MCP) server designed to act as a "Signal Filter" between messy raw data and expensive LLMs. It gets another MCP output (e.g., Wikipedia) before going to the AI, summarizes it, and sends it to the AI to save tokens.

LicenseMCP Supported

Real-World Impact

Source Data Raw Tokens Middleman Signal Token Reduction Cost Savings
Wikipedia (Full Article) ~25,000 ~800 98.8% 💰💰💰
Reddit Discussion ~15,000 ~600 96% 💰💰💰

✨ Key Features

  • Local File Processing: High-density distillation of local .txt, .log, and .md files.
  • Surgical Focus Query: Tell Middleman exactly what you are looking for (e.g., "Focus only on the technical specs of the Starship engine") to ensure the summary is relevant.
  • XML-Structured Output: Returns data in a strict <summary><core_facts>...</core_facts></summary> schema, optimized for machine-to-machine communication.
  • Built on FastMCP: Robust, Pythonic implementation of the Model Context Protocol.

🛠️ Technical Stack

Component Technology
Runtime Python 3.10+
Protocol MCP (Model Context Protocol)
Primary Engine meta-llama/llama-3.2-3b-instruct:free (via OpenRouter)
Orchestration FastMCP

🚀 Installation & Setup

1. Prerequisites

  • Python 3.10 or higher https://github.com/JithunMethusahan/middleman
  • An OpenRouter API Key

2. Clone and Install

git clone https://github.com/JithunMethusahan/middleman.git
cd middleman
python -m venv venv
source venv/bin/activate  # Windows: venv\Scripts\activate
pip install -r requirements.txt![alt text](image.png)

3. Environment Configuration

Set your API key in your environment:

export OPENROUTER_API_KEY="your_key_here"
# Windows: $env:OPENROUTER_API_KEY="your_key_here"

4. Verify Connection:

Run the included benchmark to ensure the proxy and compressor are working:

python tests/experiment.py

4. Integration with Claude Desktop / Cursor

Add the following to your claude_desktop_config.json:

{
  "mcpServers": {
    "middleman": {
      "command": "/path/to/your/venv/bin/python",
      "args": ["/path/to/middleman/server.py"],
      "env": {
        "OPENROUTER_API_KEY": "sk-or-v1-..."
      }
    }
  }
}

5. Connecting Downstream Tools (The Proxy Gateway)

Middleman is a Universal Proxy. It does not come hardcoded with tools; instead, it "wraps" other MCP servers. You manage these connections via the servers.json file in the root directory.

1. Configure your Tools (servers.json)

Add any MCP-compatible server to this file. Middleman will automatically launch these in the background and intercept their data.

{
  "fetch": {
    "command": "python",
    "args": ["-m", "mcp_server_fetch"]
  },
  "sqlite": {
    "command": "uvx",
    "args": ["mcp-server-sqlite", "--db-path", "test.db"]
  }
}

2. How the AI uses the Gateway

The primary AI (Claude/Cursor) communicates with Middleman via the delegate_and_refine tool. This tool acts as the "Secure Pipe."

Tool Arguments:

1. target_server: The name defined in servers.json (e.g., "fetch").

2. target_tool: The actual tool name on that server (e.g., "fetch" or "query_db").

3. tool_kwargs_json: The arguments for the downstream tool in JSON format.

4. focus_query: The specific signal you want Middleman to extract from the resulting bloat.

3. Example Workflow

When you ask an AI to research a topic, the internal logic looks like this:

AI Call: delegate_and_refine

(target_server="fetch", target_tool="fetch", tool_kwargs_json='{"url": "https://wiki..."}', focus_query="Founding date")

Fetch Server: Downloads 15,000 tokens of raw Wikipedia HTML.

Middleman: Intercepts the 15,000 tokens..

Llama: Extracts the founding date into a 20-token XML block.meta-llama/llama-3.2-3b-instruct:free

AI Result: Receives only the 20-token XML. Token Savings: 99.8%.

Models you can use for free

1. 🦙 Meta (Llama Family)

Meta's open-source models are currently dominating the free tier

meta-llama/llama-3.3-70b-instruct:free (Top pick for general tasks)

meta-llama/llama-3.2-3b-instruct:free (Extremely fast, lightweight)

meta-llama/llama-3.1-405b:free (Huge model, slightly slower)

2. 🌐 Google

google/gemini-2.0-flash-exp:free (Massive 1-Million token context window)

3. 🧠 DeepSeek

deepseek/deepseek-r1:free (Best for deep logical thinking)

🤝 Contributing & Customization

Middleman is designed to be extensible. Want to add support for PDFs, YouTube transcripts, or SQL databases?

  1. Fork the repo.
  2. Add your tool to server.py.
  3. Submit a Pull Request.

For custom enterprise integrations or consulting, contact the author via GitHub Issues.


📄 License

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at: http://www.apache.org/licenses/LICENSE-2.0

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选