Infrastructure / MCP
NGINX 1.31.5:依 JSON 請求內容路由 MCP,Control API 必須鎖 UNIX Socket
NGINX 1.31.5 將 predicate location、提早讀取 request body、原生 JSON 欄位解析與 Control API 帶入開源核心,讓 MCP/GraphQL 共用端點可依方法分流;Control API 無內建驗證,必須隔離。
2026年9月3日2 分鐘閱讀👁 5
NGINX 1.31.5 × MCP Gateway
同一個 /mcp 端點,也能先看 JSON method 再決定送去哪個後端
NGINX 1.31.5 把 predicate locations、client_body_early_read、原生 JSON 解析與 Control API 帶進開源核心,讓 API、GraphQL 與 MCP 流量不必只靠 URL path 分流。
四個關鍵能力
| 能力 | 用途 | MCP/Agent 平台價值 |
|---|---|---|
Predicate variables in location | 用任意已求值變數作為 location 條件 | 可依 header、網段、憑證或 JSON 欄位選 upstream |
client_body_early_read | 在 location matching 前讀取並緩衝 body | 先看到 MCP method/tools/call 再分流 |
| Native JSON parsing | 用 json_set 把 JSON key/nested field 放進 NGINX 變數 | 不必為基本 payload 路由額外依賴 Lua/njs |
| Control API | 查詢 process/config,並以 JSON 回傳 reload 結果 | CI/CD 可同步知道 reload 是否成功 |
概念範例:
client_body_early_read on;
json_set $json_method $request_body "method";
# 實際上線前應依官方完整文件驗證語法與版本
location $json_method {
# 依 tools/call、resources/read 等操作套用 upstream、限流或拒絕規則
}