mcp-unify

mcp-unify

Unifies multiple MCP servers behind a single endpoint with lazy loading, auto-cleanup, Python plugins, and role-based filtering.

Category
访问服务器

README

mcp-unify

PyPI License Python

Unify multiple MCP servers behind a single endpoint. Lazy loading, auto-cleanup, Python plugins, role-based filtering.

The Problem

If you use Claude Code or any MCP client with 3+ servers, you get:

  • Multiple subprocesses (~50MB each)
  • Duplicated config
  • No centralized control
  • No way to add custom Python tools without a full MCP server

The Solution

mcp-unify runs one process that proxies N MCP servers on-demand:

Claude Code / MCP Client
  │
  ▼
mcp-unify (1 process)
  ├─ [plugin] Python @tool functions     ← in-process, 0 overhead
  ├─ [lazy]   filesystem-server          ← subprocess spawned on first call
  ├─ [lazy]   github-server              ← subprocess spawned on first call
  └─ [lazy]   playwright                 ← subprocess spawned on first call
      ↑
      5 min idle → auto-kill

Install

pip install mcp-unify

Quick Start

1. Create gateway.yaml

servers:
  filesystem:
    command: npx
    args: ["-y", "@modelcontextprotocol/server-filesystem", "/tmp"]

  github:
    command: npx
    args: ["-y", "@modelcontextprotocol/server-github"]
    env:
      GITHUB_TOKEN: "${GITHUB_TOKEN}"
    enabled: false

idle_timeout: 300

2. Run

stdio (for Claude Code):

mcp-unify stdio --config gateway.yaml

SSE (for remote clients):

mcp-unify serve --config gateway.yaml --port 8765

3. Add to Claude Code

{
  "mcpServers": {
    "gateway": {
      "command": "mcp-unify",
      "args": ["stdio", "--config", "/path/to/gateway.yaml"]
    }
  }
}

Python Plugins

Add custom tools with zero boilerplate:

from mcp_gateway import tool

@tool(description="Add two numbers")
def add(a: float, b: float) -> float:
    return a + b

Reference in your config:

plugins:
  - module: my_tools.calculator

Or register programmatically:

from mcp_gateway import MCPGateway

gw = MCPGateway()
gw.register_tool(add)
await gw.serve_stdio()

Sync functions run via asyncio.to_thread(). Async functions run natively. Schemas are auto-generated from type hints.

Role-Based Filtering

Control which tools each client sees:

roles:
  admin: null        # all tools
  readonly: ["filesystem_*", "gateway_status"]
  developer: ["github_*", "filesystem_*", "gateway_*"]

Set the role via environment variable:

MCP_GATEWAY_ROLE=readonly mcp-unify stdio

Uses glob patterns — filesystem_* matches all tools from the filesystem server.

How It Works

  1. Lazy Loading: Servers aren't started until a tool is called. Each server gets a _<name>_connect placeholder tool. Calling it spawns the subprocess and discovers real tool schemas via session.list_tools().

  2. Auto-Cleanup: A background task checks every 60s and kills server subprocesses idle for longer than idle_timeout (default: 5 min).

  3. Real Schemas: Tool schemas are discovered from the actual server via the MCP SDK, not hardcoded. You always get accurate inputSchema.

  4. Plugin Tools: Python functions decorated with @tool run in the gateway process. Type hints are introspected to generate JSON Schema automatically.

API

from mcp_gateway import MCPGateway, tool

# From YAML
gw = MCPGateway.from_config("gateway.yaml")

# Programmatic
gw = MCPGateway()
gw.register_tool(my_function, name="my_tool", description="...")

# Serve
await gw.serve_stdio()    # stdio mode
await gw.serve_sse()      # SSE mode on :8765

# Context manager
async with MCPGateway() as gw:
    await gw.serve_stdio()

CLI

mcp-unify serve [--config FILE] [--host HOST] [--port PORT]
mcp-unify stdio [--config FILE]
mcp-unify list  [--config FILE]

Config discovery: --config > ./gateway.yaml > ./mcp-unify.yaml

Requirements

  • Python >= 3.10
  • mcp >= 1.0.0
  • starlette >= 0.27.0
  • uvicorn >= 0.23.0
  • pyyaml >= 6.0

License

MIT

推荐服务器

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 模型以安全和受控的方式获取实时的网络信息。

官方
精选