网关MCP服务器
   
智能地将MCP请求路由到多个后端服务器。
🎯 主要特点
🚀 绕过工具限制
- 挑战:MCP客户端通常对一次可以加载的工具数量有限制
- 解决方案:mcpware仅公开2个路由工具,同时提供对无限后端工具的访问
- 结果:通过单一网关连接到GitHub(50多种工具)、数据库等!
🔧 其他好处
- 单一入口点 适用于多个MCP服务器
- 自动化流程管理 用于后端服务器
- 基于Docker 隔离和部署
快速开始
# Clone the repository
git clone https://github.com/delexw/mcpware.git
cd mcpware
# Build the Docker image
docker build -t mcpware . --no-cache
# Configure MCP client (see Installation section)然后按照所示配置MCP客户端 安装 部分。
原理
mcpware作为Docker容器运行,它:
- 通过stdio接收MCP客户端的请求
- 将它们路由到相应的后端MCP服务器(也在Docker中运行)
- 将响应返回给MCP客户端
重要:后端服务器可以使用任何命令(docker, npx, node, python等等)。在Docker中运行mcpware时,后端使用本地命令,如 npx 或 node 将在mcpware容器内执行。
安装
先决条件
- 码头工人
- MCP客户端(光标等)
使用MCP客户端进行设置
- 克隆此存储库:
git clone https://github.com/delexw/mcpware.git
cd mcpware- 在中配置后端
config.json(见下面的配置部分)
- 设置环境变量:
1. 复制示例文件: cp env.example .env 1. 编辑 .env 根据您的实际值:
GITHUB_PERSONAL_ACCESS_TOKEN=your_github_token_here
BUILDKITE_API_TOKEN=your_buildkite_token_here
# Add other environment variables as needed- 添加到MCP客户端配置:
注: 您可以将机密或令牌直接配置到mcpware中 config.json
配置(直接运行Docker):
{
"mcpServers": {
"mcpware": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"-v",
"/path/to/mcpware/config.json:/app/config.json:ro",
"-v",
"/var/run/docker.sock:/var/run/docker.sock",
"--env-file",
"/path/to/mcpware/.env",
"mcpware"
]
}
}
}重要:
- 替换 /path/to/mcpware 带有克隆存储库的绝对路径 - Docker套接字挂载(/var/run/docker.sock)mcpware需要启动基于Docker的后端,否则您不需要
为什么要挂载Docker套接字?
- mcpware需要为后端MCP服务器启动Docker容器(如 ghcr.io/github/github-mcp-server) - Docker套接字挂载允许mcpware与Docker通信 - 没有这个挂载,mcpware无法启动作为Docker容器运行的后端服务器
特定于平台的Docker套接字配置
网关需要访问Docker套接字才能启动后端容器。安装路径因平台而异:
为什么需要Docker套接字访问? mcpware充当启动后端MCP服务器的进程管理器。当后端被配置为作为Docker容器运行时(例如。, ghcr.io/github/github-mcp-server),mcpware需要:
- 创建并启动Docker容器
- 管理其生命周期(停止/重新启动)
- 通过stdio与他们沟通
没有Docker套接字访问,mcpware无法启动基于Docker的后端,并将因权限错误而失败。
快速检查
运行此脚本检查Docker配置:
python scripts/check_docker_socket.pyLinux/macOS/WSL2
无需更改。默认配置有效:
volumes:
- /var/run/docker.sock:/var/run/docker.sockWindows(本机容器)
更新Docker套接字路径:
{
"mcpServers": {
"mcpware": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"-v",
"/path/to/mcpware/config.json:/app/config.json:ro",
"-v",
"//./pipe/docker_engine://./pipe/docker_engine",
"--env-file",
"/path/to/mcpware/.env",
"mcpware"
]
}
}
}注意不同的Docker套接字路径: //./pipe/docker_engine 而不是 /var/run/docker.sock
检查你的Docker类型
要验证您在Windows上使用的是哪个Docker后端:
docker version --format '{{.Server.Os}}'linux=WSL2/H-V-后端(使用默认配置)windows=Windows容器(使用覆盖文件)
配置
创建一个 config.json 使用后端服务器:
{
"backends": {
"github": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-github"],
"env": {
"GITHUB_PERSONAL_ACCESS_TOKEN": "${GITHUB_PERSONAL_ACCESS_TOKEN}"
},
"description": "GitHub MCP Server",
"timeout": 60
},
"database": {
"command": "docker",
"args": ["run", "-i", "--rm", "bytebase/dbhub", "--transport", "stdio"],
"description": "Database MCP Server"
}
}
}配置说明:
- 后端命令可以是任何可执行文件(
docker,npx,node,python等等) - 使用时
docker命令,确保Docker套接字已挂载(请参阅安装说明)
看 config.example.json 更多后端示例(数据库、API等)。
用法
网关公开了两个主要工具:
使用工具
将工具调用路由到特定的后端服务器。
参数:
backend_server:后端服务器的名称server_tool:要调用的工具的名称tool_arguments:要传递给工具的参数
例子:
{
"backend_server": "github",
"server_tool": "create_issue",
"tool_arguments": {
"owner": "myorg",
"repo": "myrepo",
"title": "New issue",
"body": "Issue description"
}
}discover_backend_tools
发现可用的后端及其工具。
参数:
backend_name:(可选)要查询的特定后端
与其他MCP服务器一起使用mcpware
mcpware旨在与MCP客户端配置中的其他MCP服务器协同工作。你可以:
- 使用mcpware作为网关 适用于多个后端服务器
- 将一些MCP服务器分开 用于直接访问
- 混搭 根据您的需求
混合配置示例:
{
"mcpServers": {
"mcpware": {
"command": "docker",
"args": [
"run", "-i", "--rm",
"-v", "/path/to/mcpware/config.json:/app/config.json:ro",
"-v", "/var/run/docker.sock:/var/run/docker.sock",
"--env-file", "/path/to/mcpware/.env",
"mcpware"
]
},
"redis-direct": {
"command": "docker",
"args": ["run", "--rm", "-i", "-e", "REDIS_HOST=localhost", "mcp/redis"]
}
}
}这使您能够:
- 需要路由时,通过mcpware访问多个服务器
- 当您需要专用访问时,直接连接到特定服务器
- 根据您的工作流程组织MCP服务器
发展
先决条件
请确保您已安装Python 3.10+:
python --version # Should show Python 3.10 or higher开发设置
- 克隆存储库:
git clone https://github.com/delexw/mcpware.git
cd mcpware- 创建虚拟环境(推荐):
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate- 安装开发依赖项:
pip install -r requirements.txt发展依赖性
该项目使用最小的依赖关系。所有核心功能都是使用Python标准库实现的。
测试依赖关系 (包含在requirements.txt中):
pytest-测试框架pytest-asyncio-异步测试支持pytest-cov-代码覆盖率报告
可选开发工具 (必要时单独安装):
# Code formatting
pip install black isort
# Linting
pip install flake8 pylint mypy
# Development convenience
pip install pytest-watch # Auto-run tests on file changes本地运行
# Run the gateway server
python gateway_server.py --config config.json
# Run with debug logging
python gateway_server.py --config config.json --log-level DEBUG代码的风格
在提交之前格式化代码:
# Format with black (if installed)
black src/ tests/ gateway_server.py
# Sort imports (if installed)
isort src/ tests/ gateway_server.py
# Run linting (if installed)
flake8 src/ tests/ gateway_server.py --max-line-length=120运行测试
# Run all tests
pytest
# Run with coverage report
pytest --cov=src --cov=gateway_server --cov-report=html
# Run specific test file
pytest tests/test_config.py
# Run tests in watch mode (requires pytest-watch)
pytest-watch码头工人
使用Docker构建和运行:
# Build the image
docker build -t mcpware .
# Run interactively (for testing)
docker run -it --rm \
-v $(pwd)/config.json:/app/config.json:ro \
-v /var/run/docker.sock:/var/run/docker.sock \
-e GITHUB_PERSONAL_ACCESS_TOKEN \
mcpware
# Run with specific config file
docker run -it --rm \
-v /path/to/your/config.json:/app/config.json:ro \
-v /var/run/docker.sock:/var/run/docker.sock \
-e GITHUB_PERSONAL_ACCESS_TOKEN \
mcpware环境变量
网关支持在后端配置中替换环境变量。将这些设置在您的 .env 文件:
# Example .env file
GITHUB_PERSONAL_ACCESS_TOKEN=ghp_xxxxxxxxxxxxx
ANTHROPIC_API_KEY=sk-ant-xxxxxxxxxxxxx
# Add other tokens as needed引用的环境变量 config.json 使用 ${VAR_NAME} 语法将被自动替换。
测试
该项目包括综合单元和集成测试。
运行测试
- 安装测试依赖项:
pip install -r requirements.txt- 运行所有测试:
pytest- 运行覆盖率测试:
pytest --cov=src --cov=gateway_server --cov-report=html- 运行特定的测试模块:
pytest tests/test_config.py
pytest tests/test_backend.py
pytest tests/test_protocol.py- 在监视模式下运行测试:
pytest-watch许可证
麻省理工学院

