mcpField
C
Claude Mcp Server Gateway

Claude Mcp Server Gateway

本地服务
github.com/bzsassonAI 与智能体752 周前更新

关于 Claude Mcp Server Gateway

这是一个面向 Claude Desktop、Claude Code、Cline 和 Roo 的 Python MCP 网关,通过按需加载工具减少启动时载入的工具定义。它将多个后端 MCP 服务汇总为单一入口。

主要功能

  1. 01按需加载 MCP 工具
  2. 02列出已配置服务
  3. 03转发工具调用
  4. 04临时启动后端服务
  5. 05支持多种客户端配置

适用场景

  1. 01减少启动时载入的工具定义
  2. 02按任务调用特定 MCP 服务
  3. 03从单一入口管理多个服务

MCP 相关

网关自身作为单一 MCP 服务,向客户端提供列出服务、加载工具和执行工具的功能;后端 MCP 服务仅在需要时启动,连接为临时连接。

配置

本地服务的配置在各客户端中通用,复制后粘贴到客户端的 MCP 配置文件即可。

暂未收录安装方式

我们还没有获取到这个服务的安装包或远程地址,请按项目 README 中的说明安装。

代码仓库

工具

还没有获取到工具列表

本地服务需要在你的电脑上运行后才能读取工具,维护者暂未提供工具列表。

详细介绍

Claude MCP 服务网关

一个适用于 Claude Desktop、Claude Code、Cline 和 Roo 的 Python MCP 服务网关。它不会在启动时加载所有 MCP 工具,而是按需加载。

适用于: Claude Desktop(应用)、Claude Code(终端)、Cline 和 Roo(VSCode 扩展)

兼容性

平台配置文件支持
Claude Desktopclaude_desktop_config.json是
Claude Code.claude.json 或 .mcp.json是
Cline(VSCode)cline_mcp_settings.json是

MCP 服务的问题

将多个 MCP 服务连接到 Claude 时:

  • GitHub MCP 服务:51 个工具
  • Slack MCP 服务:20 个工具
  • Google Drive MCP:15 个工具
  • Filesystem MCP:12 个工具

光是工具定义就有 100 多个,还没开始使用就已全部加载。每个工具的 JSON 架构都会消耗 token。

这个 Claude MCP 服务网关的功能

网关充当一个包含 3 个工具的 MCP 服务:

  1. list_available_mcps - 显示已配置的 MCP 服务
  2. load_mcp_tools - 从指定的 MCP 服务加载工具
  3. call_mcp_tool - 执行工具

只有 Claude 实际需要时,Model Context Protocol 服务才会启动。

设置

要求
  • Python 3.11+(用于 MCP Python SDK)
  • Claude Desktop、Claude Code 或 Cline/Roo
  • 要使用的 MCP 服务
安装
git clone https://github.com/bzsasson/claude-mcp-server-gateway.git
cd claude-mcp-server-gateway

python3.11 -m venv .venv
source .venv/bin/activate  # Windows: .venv\Scripts\activate

pip install mcp python-dotenv
配置 API 密钥
cp .env.example .env
# Edit .env with your tokens

Claude Desktop MCP 服务配置

添加到 Claude Desktop 配置中:

Mac:~/Library/Application Support/Claude/claude_desktop_config.json
Windows:%APPDATA%\Claude\claude_desktop_config.json
Linux:~/.config/Claude/claude_desktop_config.json

{
  "mcpServers": {
    "gateway": {
      "command": "/path/to/.venv/bin/python",
      "args": ["/path/to/claude-mcp-server-gateway/dcl_wrapper.py"]
    }
  }
}

重启 Claude Desktop。

如何将 MCP 服务添加到 Claude Code

Claude Code MCP 服务设置使用类似的配置,但多一个字段。

用户级配置(所有项目)

编辑 ~/.claude.json:

{
  "mcpServers": {
    "gateway": {
      "type": "stdio",
      "command": "/path/to/.venv/bin/python",
      "args": ["/path/to/claude-mcp-server-gateway/dcl_wrapper.py"]
    }
  }
}
项目级配置

要配置项目专用的 MCP 服务,请在项目根目录下创建 .mcp.json:

{
  "mcpServers": {
    "gateway": {
      "type": "stdio",
      "command": "/path/to/.venv/bin/python",
      "args": ["/path/to/claude-mcp-server-gateway/dcl_wrapper.py"]
    }
  }
}

使用项目范围的服务时,Claude Code 会提示你批准。

替代方式:Claude Code CLI
# Add the gateway using CLI
claude mcp add gateway --scope user \
  --command /path/to/.venv/bin/python \
  -- /path/to/claude-mcp-server-gateway/dcl_wrapper.py

# Verify it's added
claude mcp list

Cline/Roo MCP 服务配置

对于 Cline 和 Roo(VSCode 扩展),MCP 服务网关配置文件位于:

Mac:~/Library/Application Support/Code/User/globalStorage/saoudrizwan.claude-dev/settings/cline_mcp_settings.json
Windows:%APPDATA%/Code/User/globalStorage/saoudrizwan.claude-dev/settings/cline_mcp_settings.json
Linux:~/.config/Code/User/globalStorage/saoudrizwan.claude-dev/settings/cline_mcp_settings.json

{
  "mcpServers": {
    "gateway": {
      "command": "/path/to/.venv/bin/python",
      "args": ["/path/to/claude-mcp-server-gateway/dcl_wrapper.py"],
      "disabled": false
    }
  }
}

更新后重启 VSCode。

工作原理

  1. Claude 启动 - 看到网关(3 个工具)
  2. 你询问 GitHub 相关问题 - Claude 调用 list_available_mcps
  3. Claude 看到 GitHub 可用 - 调用 load_mcp_tools("github")
  4. 网关返回 GitHub 的工具列表
  5. Claude 选择合适的工具 - 调用 call_mcp_tool("github", "search_repositories", {...})
  6. 网关启动 GitHub MCP,运行工具并返回结果

向网关添加 MCP 服务

编辑 dcl_wrapper.py 并将服务添加到 MCP_SERVERS 字典中:

MCP_SERVERS = {
    "your-server": {
        "command": "npx",
        "args": ["-y", "your-mcp-package"],
        "env": {
            "API_KEY": os.getenv("YOUR_API_KEY", "")
        },
        "description": "What it does"
    }
}

当前配置的服务

  • github
  • slack
  • google-drive
  • filesystem
  • postgres
  • memory
  • brave-search

(完整列表请查看 dcl_wrapper.py)

限制

  • 首次使用工具时会有短暂延迟(服务启动)
  • 每个 MCP 服务连接都是临时的
  • 调用之间不保留状态

故障排除

网关未显示
  • 检查配置中的 Python 路径是否指向虚拟环境
  • 确认 dcl_wrapper.py 路径正确
  • 完全重启 Claude Desktop/Code/VSCode
MCP 服务连接错误
  • 检查 .env 文件中的 API 密钥
  • 确认已安装 MCP 服务包
  • 检查网关日志中的错误
Claude Code 特定问题
  • 确保在配置中包含 "type": "stdio"
  • 对于项目配置,在提示时批准
  • 使用 claude mcp list 验证安装

Files

  • dcl_wrapper.py - The gateway server
  • .env - Your API keys
  • requirements.txt - Python dependencies

License

MIT

评论

支持 Markdown

第一次接触 MCP?

从协议是什么,到在客户端里装上第一个服务,这几条回答覆盖了大多数入门问题。

一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。