|
|
MCP Gateway Pattern - Aggregating Multiple Servers
Author: Venkata Sudhakar
In production systems, tools are spread across many MCP servers - one for databases, one for cloud storage, one for notifications, and so on. Connecting an agent to each server individually creates complex configuration. The MCP Gateway pattern solves this by building a single gateway server that proxies tool calls to the appropriate backend MCP server, giving agents one endpoint for all tools.
ShopMax India runs separate MCP servers for inventory (Spanner), customer data (AlloyDB), notifications (Pub/Sub), and jobs (Cloud Tasks). The MCP Gateway aggregates all of these into one server so the main ShopMax ADK agent has a single connection point and one unified tool list covering all operations.
The below example shows an MCP Gateway that starts multiple child MCP servers as subprocesses and forwards tool calls to the correct backend based on tool name prefixes.
It gives the following output,
# Agent connects to gateway - sees all tools from all backends:
Available tools:
[inventory] query_inventory, update_stock
[customer] search_customer, log_return_request
[notify] send_notification, broadcast_alert
[jobs] enqueue_job, check_job_status
# Agent calls inventory tool through gateway:
Tool: query_inventory({city: "Hyderabad", category: "Laptops"})
-> Gateway routes to inventory backend
-> Returns: [{"product_id": "LAP005", "name": "Asus VivoBook 15", "stock": 23}]
# Agent calls customer tool through gateway:
Tool: search_customer({query: "Ravi Kumar"})
-> Gateway routes to customer backend
-> Returns: [{"customer_id": "C-7731", "name": "Ravi Kumar", "city": "Hyderabad"}]
Deploy the MCP Gateway as a Cloud Run service so backend MCP servers run as sidecar containers in the same pod, keeping inter-server communication local and fast. Add a tool registry with health checks so the gateway can skip unavailable backends and surface partial tool lists rather than failing entirely. Use tool name prefixes consistently across all backend servers to make routing transparent and debuggable.
|
|