Skip to main content
Glama

MCP Gateway

PyPI version Python License

一个独立的 CLI 网关,将多个 MCP(Model Context Protocol)服务器聚合在单个 HTTP/SSE 端点后面,并具有 Code Mode — 在使用多个 MCP 服务器时,可将 LLM 输入令牌使用量减少高达 92%。

功能

  • 多服务器聚合 — 连接到多个 MCP 服务器(HTTP、SSE、Stdio、Streamable HTTP)并通过单个端点暴露它们

  • Code Mode — 4 个元工具,让 LLM 无需预先加载所有模式即可动态发现和使用工具

  • OAuth 2.0 支持 — 内置 OAuth 流程,支持动态客户端注册(RFC 7591)和令牌存储

  • Hermetic Sandbox — 基于 Starlark 的沙箱,用于安全代码执行

  • MCP 协议兼容 — 适用于 Claude Desktop、Cursor 以及任何兼容 MCP 的客户端

Related MCP server: ToolMux

安装

pip install mcp-gway

或者使用 mise:

mise install
uv sync

快速开始

# Add an MCP server
mcp-gway add youtube --type http --url http://localhost:3001/mcp

# Add a stdio server
mcp-gway add filesystem --type stdio --command npx --args '["-y", "@anthropic/mcp-filesystem"]'

# Add a server requiring OAuth
mcp-gway add supabase --type streamable-http --url https://mcp.supabase.com/mcp

# List all servers
mcp-gway list

# Start the gateway
mcp-gway serve --port 8080

从 Claude Desktop 连接

添加到你的 Claude Desktop 配置(~/Library/Application Support/Claude/claude_desktop_config.json):

{
  "mcpServers": {
    "gateway": {
      "url": "http://localhost:8080/mcp"
    }
  }
}

命令

命令

描述

mcp-gway add

添加 MCP 服务器并生成 .pyi 存根

mcp-gway remove

移除 MCP 服务器

mcp-gway update

更新服务器的工具

mcp-gway list

列出所有已连接的服务器

mcp-gway inspect

显示服务器的工具签名

mcp-gway refresh

刷新连接并重新发现工具

mcp-gway serve

启动网关服务器

Code Mode

连接后,网关会暴露 4 个元工具:

工具

描述

listToolFiles

列出所有可用的 .pyi 存根文件

readToolFile

从存根读取函数签名

getToolDocs

获取工具的详细文档

executeToolCode

在沙箱化的 Starlark 解释器中执行代码

OAuth 认证

对于需要 OAuth 的服务器(例如 Supabase):

# Trigger OAuth flow
mcp-gway refresh supabase --auth

# Or store token manually
mkdir -p ~/.config/mcp-gway/tokens
echo '{"access_token": "YOUR_TOKEN"}' > ~/.config/mcp-gway/tokens/supabase.json

开发

# Install dependencies
mise install
uv sync

# Run tests
uv run pytest -v

# Lint and format
uv run ruff check src/ tests/
uv run ruff format src/ tests/

架构

┌─────────────────────────────────────────────────────────┐
│                    MCP Gateway                          │
├─────────────────────────────────────────────────────────┤
│  CLI (click)     │  HTTP/SSE Server (Starlette)        │
│  - add           │  - POST /mcp (JSON-RPC)             │
│  - remove        │  - GET /mcp (SSE stream)            │
│  - list          │  - POST /mcp/messages               │
│  - refresh       │                                     │
├─────────────────────────────────────────────────────────┤
│  Code Mode (4 meta-tools)     │  Starlark Sandbox      │
│  - listToolFiles               │  - Hermetic execution  │
│  - readToolFile                │  - Server injection    │
│  - getToolDocs                 │                        │
│  - executeToolCode             │                        │
├─────────────────────────────────────────────────────────┤
│  Registry (.pyi files)        │  OAuth2 (RFC 7591)     │
│  - servers/*.pyi               │  - Dynamic registration│
│  - Tool signatures             │  - Token storage       │
└─────────────────────────────────────────────────────────┘
         │                │                │
    ┌────┴────┐      ┌────┴────┐      ┌────┴────┐
    │ Server1 │      │ Server2 │      │ Server3 │
    │ (HTTP)  │      │ (SSE)   │      │ (Stdio) │
    └─────────┘      └─────────┘      └─────────┘

许可证

MIT

Maintenance

ActivityNo data
ResponsivenessUnresponsive

Related MCP Connectors

Related MCP Servers

  • A
    license
    Not graded
    quality
    D
    maintenance
    Aggregates multiple MCP servers into a single endpoint, enabling LLM clients to access tools, resources, and prompts from various backends through one connection.
    9 npm
    MIT
  • A
    license
    B
    quality
    C
    maintenance
    Aggregates multiple MCP servers via a single interface with token optimization and multiple operating modes (Gateway, Meta, Proxy, Search, Code).
    7
    8
    MIT
  • A
    license
    Not graded
    quality
    A
    maintenance
    Centralizes management and routing of multiple MCP servers, exposing them to AI clients via HTTP/SSE endpoints with configurable visibility, sharing, and smart routing.
    1,706 npm
    Apache 2.0
  • A
    license
    Not graded
    quality
    B
    maintenance
    Centralized management and routing of multiple MCP servers via unified Streamable HTTP/SSE endpoints, with granular group visibility, smart routing, and authentication.
    1,706 npm
    Apache 2.0