microsoft/mcp-gateway

MCP Gateway is a reverse proxy and management layer for MCP servers, enabling scalable, session-aware stateful routing and lifecycle management of MCP servers in Kubernetes environments.

MCP Gateway – 什麼是 MCP Gateway

MCP Gateway 是一個為 Model Context Protocol (MCP) 打造的開源反向代理與管理層。它運行在 Kubernetes 集群中,並提供兩個主要平面:

  • Control plane – 一組 REST APIs,讓你可以 建立、更新、列出與刪除 MCP 伺服器實例(稱為 adapters)以及提供額外功能的 tools。當提供 Azure Cognitive Services 端點時,控制平面也可以選擇性地管理 agentssessions(LLM 驅動的工作流)。
  • Data plane – 一個無狀態的反向代理,負責將傳入的 MCP 流量路由至適當的伺服器。它提供 session‑aware routing(所有具有相同 session_id 的請求都會前往同一個 pod)以及一個 Tool Gateway Router,能動態地將工具呼叫轉發至正確的 tool container。

此閘道器是為企業級部署設計的:它整合了 Azure Entra ID 以進行 bearer‑token 驗證與角色型存取控制 (RBAC),內建了 React 管理入口網站,並可以透過 Docker/Kubernetes 在本地端進行部署,或使用一鍵式 Azure 範本進行部署。


Core Concepts

Concept What It Means
MCP Server (Adapter) 一個實作 Model Context Protocol 的 container,本質上是一個 LLM 可以進行通訊的串流式 HTTP 端點。
Tool 一個已註冊的服務 (container) ,實作了特定的 MCP‑tool 定義 (name, input schema, execution endpoint)。
Tool Gateway Router 一個位於閘道器後方的 MCP 伺服器;它會檢查傳入的 MCP 請求,查找工具定義,並將呼叫轉發至正確的 tool container。
Session‑aware routing 保證所有帶有相同 session_id 的呼叫都會命中同一個後端 pod,從而保留狀態化互動。
Agents & Sessions (preview) 可選的 LLM 驅動 agents,可以呼叫已註冊的 tools (以及一些內建的 bash/file tools)。Sessions 會透過 Server‑Sent Events 串流事件。

Key Features

  • RESTful control‑plane API 用於管理 adapters, tools, agents, 和 sessions (CRUD, status, logs)。
  • Authentication & RBAC 使用 Azure Entra ID (讀/寫角色 mcp.admin, mcp.engineer, 等)。
  • Stateless reverse proxy 搭配分佈式 session store,提供生產等級的擴展性。
  • Dynamic tool routing – 註冊一個新工具後,router 會自動將呼叫導向至該工具。
  • Built‑in management portal (/portal/) 用於視覺化 CRUD、日誌檢查,以及瀏覽器內的 JSON‑RPC 測試控制台。
  • Kubernetes‑native deployment (StatefulSets, headless services) 以及簡單的本地 Docker-K8s 部署路徑。
  • Optional LLM agents 可以呼叫 tools 與內建的 bash/file 工具,並具備沙盒風格的安全性限制。
  • Support for both local and remote MCP servers – 你可以代理現有的 MCP 端點。

Typical Use Cases

  1. Enterprise AI platform – 在單一閘道器後方託管許多 MCP-compatible LLM 後端 (例如:Copilot, custom models),由閘道器處理驗證、路由與生命週期管理。
  2. Tool‑as‑a‑service – 註冊領域特定的工具 (weather, finance, code execution) 一次,讓任何 MCP client 都可以呼叫 them,而不需要硬編碼端點。
  3. Multi‑tenant development sandbox – 開發者可以透過 API 建立隔離的 adapters/tools,在本地端測試,然後推廣至生產環境。
  4. LLM‑driven agents – 建立能編排多個工具 (例如:檢索數據、執行腳本、寫入文件) 的 agents,並透過 VS Code 的 Copilot chat 進行展示。
  5. Observability & governance – 在受規管的環境中,為所有 MCP 流量提供集中化的日誌、遙測與角色型存取控制。

Quick‑Start Summary (Local)

  1. Prerequisites – 安裝 .NET 8 SDK, Docker Desktop (含 Kubernetes), 以及本地 Docker registry。

  2. Build images – 編譯 sample MCP server 與 sample tool,並將 them push 到 localhost:5000

  3. Publish gateway images – 執行 dotnet publish 並使用提供的 publish profile 來產生 gateway 與 tool‑router containers。

  4. Deploy – 應用 deployment/k8s/local-deployment.yml 並進行 port‑forward 服務 (kubectl port-forward … 8000:8000)。

  5. Create an adapter – POST 到 /adapters 並附帶 JSON { "name": "mcp-example", "imageName": "mcp-example", "imageVersion": "1.0.0" }

  6. Register a tool | POST 到 /tools 並附帶一個 tool 定義 (例如:weather tool) 及其 container image。

  7. Connect a client – 將 VS Code 的 MCP config 指向 http://localhost:8000/adapters/<name>/mcp 以進行直接伺服器存取取,或指向 http://localhost:8000/mcp 以進行 tool routing。

  8. (Optional) Enable agents – 在 FoundrySettings 區塊中加入 Azure Cognitive Services 端點,並透過 /agents/n/s/sessions APIs 建立 agents/sessions。


Where to Find More

  • OpenAPI specopenapi/mcp-gateway.openapi.json (可匯入 Postman, Swagger UI, 等)
  • Management portal sourceportal/README.md
  • Entra ID role configuration guidedocs/entra-app-roles.md
  • Sample server implementationssample-servers/mcp-example/sample-servers/tool-example/ Quickly check the Azure deployment guide – 「Deploy to Azure」章節,包含一鍵式範本與 Entra ID 設定步驟。

Bottom line: MCP Gateway 為任何 Model Context Protocol 服務提供了一個生產等級、Kubernetes-native 的門面,處理驗證、session-affinity、動態工具路由與可選的 LLM-agent 編排——這一切都透過一個乾淨的 REST API 與現成的 UI。

相關

  • 專案
  • 專案
  • 專案
  • 專案
  • 專案