ข้ามไปที่เนื้อหา

Production AI Agents Need an MCP Gateway

MCP server สองตัวรันอยู่ใน notebook ของ developer ไม่มีปัญหาอะไร แต่พอเป็นสี่สิบตัวกระจายอยู่ใน production agent แถมต้องจัดการ auth token, audit trail และเพดานค่าใช้จ่าย เรื่องไม่ง่ายแล้ว Model Context Protocol ชนะเรื่อง wire format ไปเรียบร้อย ส่วนเรื่อง deploy ยังไม่มีใครตอบได้ชัด ทางที่จะพาคุณรอดเกินไตรมาสที่สองของ production มีทางเดียว คือมอง MCP เป็น L7 protocol ตัวหนึ่งเหมือนตัวอื่น แล้ววาง gateway ไว้ข้างหน้า

MCP ในปี 2026 จริง ๆ แล้วคืออะไร

Model Context Protocol (MCP) คือ protocol บน JSON-RPC ที่ให้ LLM agent เรียกใช้ tool, resource และ prompt ด้วยวิธีมาตรฐานเดียวกัน spec ล่าสุดคือเวอร์ชัน 2026-07-28 ออกวันที่ 2026-07-28 ตอนนี้ agent framework เจ้าใหญ่ใช้ MCP กันหมดแล้ว1

Agent ทุกวันนี้ส่วนใหญ่สร้างบน OpenAI Agents SDK v0.22.0, Anthropic SDK v1.4.0 หรือ LangGraph 1.x ซึ่งทุกตัวมี MCP client อยู่ข้างในเหมือนกัน Agent หนึ่งตัวต่อกับ MCP server ได้ N ตัว (filesystem, GitHub, Slack, Postgres, internal API) ผ่าน stdio, HTTP หรือ SSE2

Agent ตัวเดียวคุยกับ MCP server ไม่กี่ตัวยังไหว แต่ถ้า agent ยี่สิบตัวคุยกับ server สี่สิบตัว ใช้ credential ชุดเดียวกัน แย่ง rate limit กัน แล้วยังต้องผ่าน audit อีก แบบนี้ไม่รอด

ทำไม MCP ต้องมี gateway

เหตุผลที่ HTTP ขาด Envoy, nginx หรือ Kong ไม่ได้ กำลังเกิดซ้ำกับ MCP ทันทีที่ MCP ออกจาก laptop ไปใช้งานจริง จะเจอ 5 ปัญหานี้:

ปัญหา ไม่มี gateway แล้วพังตรงไหน
Auth fan-out Agent ทุกตัวถือ OAuth token ของทุก server พอ revoke ไปตัวเดียว ต้องนั่งไล่ rotate อีกชั่วโมง
Per-tenant access Marketing agent ไม่ควรเรียก HR MCP ได้ แต่ไม่มีอะไรกันไว้
Rate limiting Model ไม่รู้ว่าควรหยุดตรงไหน เลยยิง GitHub MCP ไป 1000 RPM
Observability Agent ไหนเรียก tool ไหน ใช้ prompt อะไร เสีย token ไปเท่าไหร่ ไม่มีใครตอบได้
Versioning Slack MCP server ออก breaking change มา agent 12 ตัวแดงพร้อมกัน

ไม่มีอะไรใหม่เลย ปัญหาพวกนี้เราเคยแก้มาแล้วกับ HTTP, gRPC และ GraphQL ถึง wire format จะเป็น JSON-RPC over stdio ปัญหาฝั่ง operation ก็ยังเหมือนเดิม

Open-source gateway สองตัวที่น่าใช้จริงในปี 2026

Docker MCP Gateway - v0.43.3, 2026-07-16

MCP Gateway ของ Docker มาพร้อม Docker Desktop MCP Toolkit (Docker Desktop 4.59 ขึ้นไป) ตัว gateway รัน MCP server แต่ละตัวเป็น Docker container ดูแล lifecycle ให้ แล้วเปิด Gateway URL เดียวให้ MCP client ทุกตัวต่อเข้ามา4

# Configure a server from the catalog
docker mcp server configure --server github --env GITHUB_TOKEN_FILE=/run/secrets/gh

# Run the gateway
docker mcp gateway run --port 8811 --secrets-from docker-desktop

# Every MCP client connects to http://localhost:8811

จุดที่ทำได้ดี:

  • Container isolation แยก MCP server แต่ละตัวไว้คนละ container
  • Secrets management ผ่าน Docker Desktop ไม่ต้องยัด token ไว้ใน env var
  • OAuth flow มีให้ในตัว สำหรับ MCP ที่ต้องใช้
  • Dynamic tool discovery — agent เห็น capability ของทุก server ที่ตั้งค่าไว้รวมกันในที่เดียว
  • Catalog model — ลง server จาก Docker MCP Catalog ได้เหมือนลง package

จุดที่ยังไม่ตอบโจทย์:

  • ออกแบบมาให้ใช้บนเครื่องตัวเองเป็นหลัก ถ้าจะขึ้น production ต้องยก pattern นี้ไปทำบน cluster เอง
  • ไม่มี multi-tenant RBAC มาในตัว คิดไว้แค่คนเดียวใช้บนเครื่องเดียว
  • ไม่มีช่องให้เขียน policy-as-code (OPA, Cedar ฯลฯ)

Agentgateway - v1.5.0, 2026-08-27, Apache-2.0

Agentgateway เป็น proxy ที่เข้ากับ ecosystem ของ CNCF ได้ดี สร้างมาเพื่อ agentic protocol โดยเฉพาะ คือ MCP และ A2A ของ Google ใช้กับ framework ไหนก็ได้ และประกาศตัวชัดว่าจะเป็น connectivity layer ที่ AI agent ยังขาดอยู่5

ใน README เขียนจุดประสงค์ไว้ตรง ๆ:

Agentgateway เป็น open source proxy ที่สร้างบน AI-native protocol (MCP และ A2A) ใส่เข้าไปแล้วได้ security, observability และ governance ทันที ครอบคลุมทั้ง agent-to-LLM, agent-to-tool และ agent-to-agent ใช้ได้กับทุก framework และทุก environment

พูดง่าย ๆ ก็คือ "Envoy สำหรับ AI agent" แนวคิด control-plane-as-data เหมือนกัน (ใช้ Gateway API CRD แบบ kgateway) observability ก็แบบที่คุ้นมือ ต่างกันตรงที่ resource model เข้าใจ tool และ resource แทนที่จะเป็น HTTP path

Feature Docker MCP Gateway Agentgateway
License Apache-2.0 Apache-2.0
เหมาะกับ Local dev, prod ที่มี tenant เดียว Prod ที่มีหลาย agent บน Kubernetes
MCP routing Server ละ container, endpoint เดียว Policy ราย tool/ราย server ผ่าน Gateway API
Observability Stdout + Docker log OTLP มาในตัว, tool-call span แบบ structured
Authentication Docker Desktop secrets store OAuth 2.0 / OIDC / JWT ราย tool
Multi-tenant ทำได้จำกัด รองรับเต็มที่
รองรับ A2A ไม่รองรับ รองรับ
ความ mature นิ่งแล้วสำหรับใช้บน desktop 2025 → 2026, ~4.7k star

เลือกคร่าว ๆ แบบนี้: ใช้ Docker MCP Gateway ตอน local development และ production ที่มีทีมเดียว เปลี่ยนไปใช้ Agentgateway เมื่อมี agent workload หลายตัว มีหลาย tenant และทีม ops ทำงานแบบ Gateway API-first อยู่แล้ว

Reference architecture

Pattern ที่ทีม production ส่วนใหญ่ใช้แล้วรอดในปี 2026:

                    ┌──────────────────────┐
                    │  Agent Runtimes      │
                    │  - OpenAI Agents SDK │
                    │  - Anthropic SDK     │
                    │  - LangGraph         │
                    └──────────┬───────────┘
                               │ MCP-over-HTTP/SSE
                               ▼
                    ┌──────────────────────┐
                    │   MCP Gateway        │
                    │  ┌────────────────┐  │
                    │  │ Authn / Authz  │  │
                    │  │ Rate limit     │  │
                    │  │ Tool registry  │  │
                    │  │ Policy engine  │  │
                    │  │ OTLP exporter  │  │
                    │  └────────────────┘  │
                    └──────────┬───────────┘
                               │
        ┌──────────────┬───────┴────────┬──────────────┐
        ▼              ▼                ▼              ▼
   ┌────────┐    ┌────────┐       ┌────────┐      ┌────────┐
   │ GitHub │    │ Slack  │       │ Postgres│     │ Custom │
   │ MCP    │    │ MCP    │       │ MCP     │     │ MCP    │
   └────────┘    └────────┘       └────────┘      └────────┘

Agent ทุกตัวคุยกับ gateway อย่างเดียว ส่วน MCP server ทุกตัวต้องเข้าผ่าน gateway เท่านั้น ผลคือคุณมีจุดเดียวไว้บังคับ policy จุดเดียวไว้เก็บ telemetry และจุดเดียวไว้สลับหรือเปลี่ยน version ของ server

Gateway ควรคุมอะไรบ้าง

ในปี 2026 มี 5 เรื่องที่คุ้มลงแรงทำ ทุกข้อเป็น policy ที่ช่วยจับ incident ที่เกิดขึ้นจริงใน production ไม่ใช่แค่กันไว้ตามทฤษฎี

1. Authentication และ authorization ราย tool

Wire format ของ MCP มี primitive 3 ตัว คือ tools, resources และ prompts ทั้งสามตัวควรเขียน policy คุมได้โดยตรง ตัวอย่าง spec ที่ใช้ได้จริง:

# gateway-policies.yaml
policies:
  - name: hr-tools-rbac
    match: { tool: "hr.*" }
    allow: { teams: ["people-ops", "engineering-managers"] }
    deny: { teams: ["contractors"] }
    audit: true

  - name: github-write-rate-limit
    match: { tool: "github.create_issue", tool: "github.merge_pr" }
    rate_limit: { rps: 5, burst: 10 }
    require_approval: true

  - name: postgres-read-only
    match: { tool: "postgres.*" }
    allow_methods: ["SELECT", "EXPLAIN"]
    deny_methods: ["INSERT", "UPDATE", "DELETE", "DROP"]

แนวทาง security ของ MCP ที่ Anthropic เขียนไว้พูดชัดว่า implementation MUST คุม consent, authorization flow, access control และ data protection ไว้ที่ขอบของ protocol3 ขอบที่ว่านี้ก็คือ gateway นั่นเอง

2. Rate limit และเพดานค่าใช้จ่ายราย tenant

Model ที่วน loop ไม่หยุดเรียก tool ตัวเดียวได้ถึง 10,000 ครั้งใน session เดียว ที่แพงไม่ใช่ LLM token แต่เป็นค่า API ของ tool ถ้ายิง third-party API ที่ 1,000 RPM ทั้งวัน บิลออกมา $5,000 ได้เลย จุดที่คุมเพดานนี้ได้มีที่เดียวคือ gateway

# OpenTelemetry counter for cost per tool
from opentelemetry import metrics
meter = metrics.get_meter("mcp-gateway")
cost = meter.create_counter("mcp.tool.cost_usd")

@tool.invocation
async def track_and_call(req, call):
    est_cost = estimate_cost(req.tool, req.arguments)
    cost.add(est_cost, {"tool": req.tool, "tenant": req.tenant})
    if cost_above_quota(req.tenant, req.tool):
        raise QuotaExceeded()
    return await call(req)

3. กรอง tool result

MCP server ส่งทุกอย่างที่ upstream API ตอบกลับมาให้ agent ตรง ๆ ถ้าเป็น GET /users/me ก็ไม่เป็นไร แต่ถ้า tool คือ "ดึง customer record" แล้ว agent ที่เรียกมาจากอีกทีม เรื่องใหญ่แน่

ให้กรองที่ gateway อย่าไปหวังให้ model กรองเอง ตัด field ที่เป็น PII ออก redact secret และทิ้ง row ที่อยู่นอก policy scope ของ tenant ที่ request เข้ามา

4. Audit logging

มีสองคำถามที่ยังไงก็ต้องโดนถาม:

  • "เมื่อวานตอน 14:23 ทำไม agent ไปทำ X?"
  • "Tool ของ agent ตัวนี้เห็นข้อมูลอะไรไปบ้าง?"

ถ้ามี audit log ที่ gateway ตอบได้ทั้งสองข้อด้วย query เดียว ทุก tool call ควรเก็บ:

  • ใครเรียก (agent ตัวไหน, run ID อะไร, agent ทำงานแทน user คนไหน)
  • ชื่อ tool และเวอร์ชัน
  • Argument (redact field ที่เป็น secret ตั้งแต่ตอน ingest)
  • ขนาด result, status, latency
  • Trace correlation ID ที่โยงไปหา OTel span ตัวแม่

ส่ง log เข้า observability backend ที่มีอยู่แล้ว ไม่ต้องสร้าง tool ใหม่

5. กัน prompt injection ตั้งแต่ที่ขอบ

MCP spec เตือนไว้ตรง ๆ ว่าพึ่งแค่ protocol ไม่พอ:

MCP บังคับหลัก security เหล่านี้ในระดับ protocol ไม่ได้ คนที่ implement จึง SHOULD ใส่ consent และ authorization flow, access control และ data protection ที่รัดกุมไว้ใน application เอง

Tool result ของ MCP กลับไปเป็น context ของ model เท่ากับว่าอะไรก็ตามที่ upstream tool ส่งกลับมา จะกลายเป็นส่วนหนึ่งของ prompt ทันที gateway จึงต้องมอง tool result เป็น untrusted input แล้วใช้ policy redaction และ validation แบบเดียวกับที่ใช้กับข้อความที่ดึงมาจากเว็บใน LLM pipeline อื่น ๆ

Pattern ที่ใช้ได้จริง:

def guard_tool_result(tool_name, result):
    # Strip anything that looks like an injected instruction
    sanitized = redact_injection_attempts(result)
    # Cap result size to prevent context stuffing
    return truncate(sanitized, max_tokens=2000)

Self-hosted vs hosted: จะ deploy แบบไหนดี

ในปี 2026 มีวิธี deploy ที่ใช้ได้จริงอยู่ 3 แบบ:

แบบ ค่าใช้จ่าย ความยากในการดูแล ใช้ตอนไหน
Local Docker MCP Gateway ไม่มีค่า infra ไม่ต้องดูแล Dev, ใช้คนเดียว
Sidecar ในทุก agent pod เพิ่มตามจำนวน agent ต้องไล่ rollout ทีละ agent ทีมภายในที่ไว้ใจกันได้
Central gateway หลัง service mesh Control plane ชุดเดียวใช้ร่วมกัน Upgrade ที่เดียวจบ Production หลายทีม

แบบที่ scale ได้จริงมีแค่ central gateway รอให้ต้องเปลี่ยน auth ครั้งแรกก่อน แล้วจะเข้าใจ

ตัวอย่าง production deployment บน Kubernetes ที่ใช้ได้:

# gateway-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata: { name: mcp-gateway }
spec:
  replicas: 3
  selector:
    matchLabels: { app: mcp-gateway }
  template:
    metadata:
      labels: { app: mcp-gateway }
      annotations:
        prometheus.io/scrape: "true"
    spec:
      containers:
        - name: gateway
          image: ghcr.io/agentgateway/agentgateway:v1.5.0
          args: ["run", "--config", "/etc/gateway/config.yaml"]
          ports:
            - { containerPort: 8811 }
          volumeMounts:
            - { name: cfg, mountPath: /etc/gateway }
          env:
            - name: OTEL_EXPORTER_OTLP_ENDPOINT
              value: "http://otel-collector.observability:4317"
            - name: OTEL_SERVICE_NAME
              value: "mcp-gateway"
          resources:
            requests: { cpu: "1", memory: 2Gi }
            limits: { cpu: "4", memory: 4Gi }
        - name: oauth-proxy
          image: ghcr.io/oauth2-proxy/oauth2-proxy:v7.6.0
          # OIDC validation for agent identity
      volumes:
        - name: cfg
          configMap: { name: gateway-config }

มี 3 จุดที่ควรสังเกต:

  • Replica 3 ตัว อยู่หลัง service เพื่อ HA ตอนนี้ gateway อยู่ใน critical path แล้ว ต้องดูแลให้สมกับที่เป็นจุดตาย
  • OTLP exporter ตั้งเป็น env หลักตั้งแต่แรก ที่ทำทั้งหมดนี้ก็เพื่อรวม observability ไว้ที่เดียว ต่อให้เรียบร้อยตั้งแต่วันแรก
  • OAuth proxy sidecar ไว้ยืนยันตัวตนของ agent agent ส่ง JWT ของ service account มา แล้ว proxy เอาไปตรวจกับ IdP ของคุณ

เริ่มต้นแบบทำได้จริง

ถ้าจะเริ่มวันนี้:

  • สำรวจการใช้ MCP ก่อน ถามทุกทีมว่าใช้ MCP server ตัวไหน agent ตัวไหน credential อะไร องค์กรส่วนใหญ่เจอว่าใช้จริงเยอะกว่าที่คิดไว้ 3-4 เท่า
  • เลือก gateway มาตัวเดียว ช่วง dev หรือ prod ระยะแรกใช้ Docker MCP Gateway พอมี agent workload ตั้งแต่ 3 ตัว หรือ tenant ตั้งแต่ 2 ราย ค่อยไป agentgateway
  • วาง identity-aware proxy ไว้หน้า gateway ใช้ OIDC หรือ mTLS แยกตัวตนราย agent ไม่ใช่ราย pod
  • ต่อ OTLP ตั้งแต่วันแรก เก็บ 3 signal คือ tool call rate, tool call latency และขนาด tool call result ตั้ง alert ที่สองตัวแรก ตัวที่สามทำเป็น chart ไว้ดู
  • ตั้ง policy เป็น default-deny MCP server หรือ tool ใหม่ต้องได้รับอนุมัติก่อน ถึงจะเรียกผ่าน gateway ได้
  • เริ่มจาก tenant เดียว ลองย้าย MCP traffic ของทีมเดียวมาผ่าน gateway ก่อน แล้วค่อยย้ายทุกทีม
  • Audit-log ทุกอย่าง ส่งเข้า SIEM หรือ observability backend ที่มีอยู่ ไม่ต้องทำระบบใหม่

อะไรไม่ควรเอาไปไว้หลัง gateway

มี 3 อย่างที่ไม่ควรเอาเข้า MCP gateway:

  1. งานที่ latency ต้องต่ำระดับไม่กี่มิลลิวินาที MCP gateway บวก overhead เพิ่มหลักสิบมิลลิวินาที ถ้า trading strategy ต้องการ tool call ที่เร็วกว่า 10ms ให้เรียกตรง อย่าผ่าน gateway
  2. State ของ browser session ที่ login ไว้แล้ว MCP ออกแบบมาให้ backend agent เรียก tool อย่าพยายามดัดมันไปทำ browser automation ไปใช้ browser-control primitive ที่ทำมาเพื่องานนี้ดีกว่า
  3. Internal script ที่ใช้ครั้งเดียวทิ้ง ถ้ามี agent ตัวเดียวคุยกับ MCP server ตัวเดียว และไม่มีแผนจะขยาย gateway ก็เป็นแค่ overhead รอให้มี agent ตัวที่สองก่อนค่อยใส่

Summary

  • MCP ชนะเรื่อง wire format ไปแล้ว ที่ยังไม่จบคือเรื่อง deploy
  • ถ้ามี agent หลายตัวและ server หลายตัว central MCP gateway เป็นทางเดียวที่คุม auth, rate limit, audit และ policy ได้ครบ
  • Docker MCP Gateway v0.43.3 เหมาะกับ local และ prod ที่มีทีมเดียว Agentgateway v1.5.0 เหมาะกับ prod แบบ multi-tenant ที่รันบน Kubernetes
  • ต่อ OTLP ตั้งแต่วันแรก ไม่ต้องสร้าง observability backend ใหม่เพื่องานนี้
  • ให้ gateway มอง tool result เป็น untrusted input MCP spec เองก็บอกชัดว่าพึ่งแค่ protocol ไม่พอ
  • เริ่มจากสำรวจของที่มีอยู่ ไม่ใช่เริ่มจากวาด architecture ทีมส่วนใหญ่เจอว่าใช้ MCP เยอะกว่าที่คิด 3-4 เท่า
  • Gateway อยู่ใน critical path ทำ HA และวาง identity-aware proxy ตั้งแต่วันแรก

ใช้ MCP โดยไม่มี gateway ก็เหมือนใช้ HTTP โดยไม่มี nginx ช่วงแรกก็ใช้ได้ แต่พอวันที่พัง คุณจะไม่รู้แล้วว่าใครเรียกอะไรไปบ้าง


มีคำถามหรืออยากคุยต่อ? ติดต่อผมได้ทาง LinkedIn, X หรือ email


  1. Model Context Protocol, 2026-07-28 release — ตรวจ release tag และวันที่ของ spec แล้วเมื่อ 2026-07-21 ↩

  2. Model Context Protocol, Architecture — โครงแบบ client-host-server บน JSON-RPC 2.0 มี resource, tool และ prompt เป็น primitive ↩

  3. Model Context Protocol, Security Best Practices — consent, authorization, access control และ data protection เป็นหน้าที่ของคน implement protocol ไม่ได้รับประกันให้ ↩

  4. Docker, MCP Gateway — Apache-2.0, ~1.5k star; tag ล่าสุด v0.43.3 (2026-07-16); gateway แบบ binary เดียว รัน MCP server เป็น Docker container และเปิด URL เดียวให้ client แต่ละตัว ↩

  5. Agentgateway, README — Apache-2.0, ~4.7k star; release ล่าสุด v1.5.0 (2026-08-27); proxy สไตล์ Envoy ที่ทำมาเพื่อ MCP และ A2A โดยเฉพาะ ↩

Discussion

Have thoughts on this post? Share them below — questions, corrections, or your own experience are all welcome.