English | 简体中文
mcp-gateway is a lightweight MCP aggregation proxy. It merges multiple backend MCP Servers into a single unified endpoint, exposing one MCP service externally while preserving tool namespace isolation to prevent name collisions across backends.
- Aggregate multiple backend MCP Servers behind one endpoint
- Backend transport support:
stdio/sse/streamable-http - Gateway transport support:
stdio/sse/streamable-http - Built-in HTTP management API:
/health,/servers,/tools - Managed with
uvfor virtual environments and dependencies
uv sync --extra devThis will:
- Create a
.venvvirtual environment - Install development dependencies
- Resolve and lock dependency versions
Current pinned MCP Python SDK version: mcp==1.27.1.
uv run python main.py --config ./examples/config/servers.jsonuv run python main.py --transport sse --config ./examples/config/sse-backend.jsonDefault listen address: http://127.0.0.1:8080/sse
uv run python main.py --transport streamable-http --config ./examples/config/streamable-http-backend.jsonDefault listen address: http://127.0.0.1:8080/mcp
Configuration files use a unified format:
{
"mcpServers": {
"server-name": {
"transport": "stdio | sse | streamable-http",
"command": "python",
"args": ["./server.py"],
"url": "http://127.0.0.1:9000/sse",
"headers": {
"Authorization": "Bearer ..."
}
}
}
}{
"mcpServers": {
"calculator": {
"transport": "stdio",
"command": "python",
"args": ["./tests/tools/calculator.py"]
},
"echo": {
"transport": "stdio",
"command": "python",
"args": ["./tests/tools/echo_server.py", "--name", "echo"]
}
}
}See: examples/config/servers.json
{
"mcpServers": {
"remote-echo": {
"transport": "sse",
"url": "http://127.0.0.1:9090/sse"
}
}
}See: examples/config/sse-backend.json
{
"mcpServers": {
"remote-echo": {
"transport": "streamable-http",
"url": "http://127.0.0.1:9091/mcp"
}
}
}See: examples/config/streamable-http-backend.json
The gateway rewrites tool names using the pattern:
<server_name>.<tool_name>
For example:
calculator.addcalculator.multiplyremote-echo.ping
This allows safe aggregation of multiple backends that may expose tools with identical names.
When the gateway runs in sse or streamable-http mode, it additionally exposes:
GET /healthGET /serversPOST /serversDELETE /servers/{name}GET /tools
The POST /servers request body follows the same format as the main configuration file.
main.py
src/mcp_gateway/
examples/config/
tests/
Where:
- main.py — unified entry point
- src/mcp_gateway/app.py — gateway lifecycle and HTTP service
- src/mcp_gateway/clients.py — backend connection management
- src/mcp_gateway/proxy.py — MCP request routing and aggregation
uv run pytest -qCurrent test coverage:
- Proxy tool aggregation and routing
- SSE gateway transport
- Streamable HTTP gateway transport
- Streamable HTTP backend connectivity
Note: On Windows sandbox environments, process-level
stdioend-to-end tests are automatically skipped due to named pipe permission restrictions. The logic layer is still covered by unit tests.