S-10 · TRACK 03 · PATTERNS

MCP & A2A

2 giao thức thống trị 2025: Anthropic MCP (agent ↔ tool/data) + Google A2A (agent ↔ agent). Ch.10 + Ch.15 sách Gulli.

Buổi 10 — Chúng ta sẽ đi qua gì?
🚩

01 · Bài toán N×M

Vì sao cần chuẩn giao thức chung?

🔌

02 · MCP

Host · Client · Server · 3 primitives

🤝

03 · A2A

Agent Card, Task, Artifact, Auth

💻

04 · Thực chiến

Code, security, framework compare

🎯

05 · Takeaways

5 điểm nhớ + homework

01

Bài toán N×M
Ai chuẩn hoá?

Trước MCP/A2A — mỗi tổ chức làm 1 kiểu

Custom integration N×M

• N app AI × M tool/data source = N×M code integration.

• Cursor viết code riêng để đọc GitHub. Claude Desktop viết code riêng để đọc Slack. Redoing everything.

• Team A build Sales Agent, Team B build Support Agent — không nói chuyện được.

• Đổi ecosystem = viết lại từ đầu.

2 giao thức thống nhất

MCP (Anthropic, 11/2024): app AI ↔ tool/data. Viết 1 server — mọi host dùng được.

A2A (Google, 2025): agent ↔ agent. Discovery + handoff structured.

• Ecosystem 1000+ MCP server công khai (GitHub, Slack, Postgres, Playwright, filesystem…).

• Enterprise: mọi team share tool/agent via registry chung.

Analogy: MCP như USB-C cho AI apps — 1 cổng, mọi thiết bị. A2A như SMTP cho agent — giao thức chung để nói chuyện.

02

MCP
Model Context Protocol

Kiến trúc MCP — Host · Client · Server
Host

App AI

Claude Desktop, Cursor, VS Code, ChatGPT desktop. Chạy LLM, quản lý session.

Client

MCP Client

Trong-process của host. Kết nối 1-1 với 1 server. Multiplex nhiều server.

Server

MCP Server

Expose tool/resource/prompt. Bên thứ 3 hoặc self-host (GitHub, Slack, Postgres…).

🔧

Tools

Hàm có side-effect (create, send, run).

📚

Resources

Data read-only (file, DB row, URL).

💬

Prompts

Template messages tái sử dụng.

🔌

Transport

stdio, SSE, HTTP streaming.

Code — MCP server tối giản (Python SDK)
weather_mcp_server.py
from mcp.server.fastmcp import FastMCP

mcp = FastMCP("weather")

# Tool: side-effect / compute
@mcp.tool()
def get_weather(city: str, unit: str = "C") -> dict:
    """Get current weather for a city. Use only when user asks about weather."""
    return weather_api.fetch(city, unit)

# Resource: read-only data
@mcp.resource("weather://forecast/{city}")
def forecast(city: str) -> str:
    return weather_api.forecast_7day(city)

# Prompt: template
@mcp.prompt()
def travel_check(city: str) -> str:
    return f"Nên mang gì khi đi {city}? Kiểm tra thời tiết trước."

if __name__ == "__main__":
    mcp.run(transport="stdio")  # hoặc "sse" cho HTTP
03

A2A
Agent-to-Agent Protocol

4 khái niệm cốt lõi A2A
📋

Agent Card

Manifest JSON tại /.well-known/agent.json: capabilities, auth, endpoint.

📩

Task

Đơn vị công việc gửi giữa agent. Có state (submitted, working, completed).

📄

Artifact

Output có structure của task (file, JSON, image). Stream được.

🔐

Auth

OAuth2, API key, mTLS. Audit trail per turn bắt buộc.

Khác biệt cốt lõi: MCP = 1 host multiplex nhiều tool/data source. A2A = nhiều agent độc lập discovery & handoff nhau.

MCP vs A2A — khi nào cái nào?
Tiêu chí MCP A2A
Kết nối App AI ↔ tool/data Agent ↔ agent
Chủ sở hữu 2 phía Thường cùng org / trusted Có thể khác org
Primitives Tools · Resources · Prompts Agent Card · Task · Artifact
Communication Client-Server, tương đối đồng bộ Multi-turn, async, streaming
Publisher Anthropic (2024) Google (2025)
Nội bộ giống USB-C cho AI SMTP cho agent

Không loại trừ nhau. Enterprise thực tế: Agent giao tiếp bằng A2A, mỗi agent có bộ MCP server riêng để truy tool/data.

04

Thực chiến
Security · Framework · Anti-patterns

Security — đừng nhắm mắt cài MCP server bừa
🔐

Untrusted server

Server nghe stdio ⇒ chạy như user. Cài từ npm bừa = có thể RCE.

🛡

Sandbox

Container / Firecracker VM / gVisor. Least privilege token cho server.

📋

Audit trail

Log mọi tool_call + args + result. Cần cho compliance.

👥

HITL cho risky

Server có action tốn tiền / gửi ngoài ⇒ hỏi user trước (S-11).

Framework support
Nền tảng MCP A2A Ghi chú
Claude Desktop / Code ✅ native Qua subagent Ecosystem lớn nhất
Cursor / VS Code ✅ native MCP first-class
Google ADK ✅ adapter ✅ native A2A publisher
LangGraph / CrewAI Adapter lib Adapter lib Cần integration code
OpenAI Từ 2025 hỗ trợ Assistant API riêng
Anti-patterns

❌ MCP

  • • Cài server không audit ⇒ RCE.
  • • Server đòi quyền quá rộng (root, all-DB).
  • • Không giới hạn số server connect ⇒ context bloat.
  • • Description tool mơ hồ ⇒ model chọn sai.

❌ A2A

  • • Handoff mất context ⇒ agent nhận phải hỏi lại.
  • • Loop giữa 2 agent (A gọi B, B gọi A) ⇒ deadlock.
  • • Không audit trail ⇒ compliance fail.
  • • Trust mọi Agent Card ⇒ phishing agent.
Case VN 🇳🇻 — 5 lĩnh vực MCP mở rộng năng lực
📊

1. Truy vấn DB tự nhiên

Chat với BigQuery/Postgres bằng NL — MCP server SQL sinh query.

🎵

2. Sinh media

Điều phối Imagen, Veo, Chirp qua MCP — 1 host, nhiều engine.

🌐

3. API bên ngoài

Weather, stock, calendar, CRM — wrap tất cả thành MCP server.

📁

4. Filesystem & git

Đọc/ghi file, git ops trực tiếp qua chuẩn MCP local (stdio).

📩

5. Enterprise workflow

Slack, Jira, Notion, Zendesk — wire agent vào ops nội bộ.

🛠

Bonus: FastMCP

Lib Python 20 dòng ⇒ MCP server chạy. Dev experience tốt nhất.

Cơ chế truyền tải: JSON-RPC qua STDIO (local, tương tác trong process) hoặc Streamable HTTP + SSE (từ xa, multi-tenant). Chọn theo trust boundary.

Nguồn: Cẩm nang thực hành HTTM (VN Gulli Ch.10) + Cẩm nang Claude & N8N.

A2A + Multi-Agent thực chiến — Nhân sự số VN
"Nhân sự số" — mô hình VN đặt agent theo chức năng phòng ban (Sales, Marketing, HR, Ops). Mỗi agent = 1 role có tool riêng, giao tiếp qua A2A.
Sales Digital
  • • MCP: CRM, quote gen
  • • A2A: handoff sang Ops khi close
  • • Skill: proposal template
Marketing Digital
  • • MCP: Meta Ads, GA4
  • • A2A: nhận brief từ Sales
  • • Skill: content ops
HR Digital
  • • MCP: HRIS, payroll
  • • A2A: onboarding chain
  • • Skill: interview kit
Ops Digital
  • • MCP: Jira, monitoring
  • • A2A: escalate cho Sales/HR
  • • Skill: incident playbook

Điểm mấu chốt của A2A: Agent Card manifest tại /.well-known/agent.json — giống DNS cho microservice. Không có discovery = không có ecosystem.

Tham chiếu: XÂY DỰNG NHÂN SỰ SỐ AI AGENT + BMAD METHOD (VN).

CLI thực chiến — MCP setup 3 tool

🤖 Claude Code

# Thêm MCP server
claude mcp add filesystem \
  -- npx -y \
    @modelcontextprotocol/\
    server-filesystem \
    /path/to/allowed/dir

# Với env vars
claude mcp add github \
  -e GITHUB_TOKEN=$TOKEN \
  -- npx -y \
    @modelcontextprotocol/\
    server-github

# Liệt kê MCP đã add
claude mcp list

# Xoá
claude mcp remove github

# HTTP MCP server
claude mcp add remote \
  --transport sse \
  https://api.co/mcp

# Trong session
# /mcp → status server

⚡ Cursor

# Config file
# Linux/mac:
~/.cursor/mcp.json
# Windows:
%USERPROFILE%\.cursor\
  mcp.json

# Format tương tự Claude
{
  "mcpServers": {
    "filesystem": {
      "command": "npx",
      "args": [
        "-y",
        "@modelcontext
   protocol/
   server-filesystem",
        "/path"
      ]
    }
  }
}

# Reload: Settings → MCP
# → Refresh servers

💎 Gemini CLI

# Thêm MCP server
gemini mcp add filesystem \
  -- npx -y \
    @modelcontextprotocol/\
    server-filesystem \
    /path/to/dir

# Với scope
gemini mcp add \
  --scope user github \
  -e TOKEN=$T \
  -- npx -y \
    @modelcontextprotocol/\
    server-github

# Liệt kê
gemini mcp list

# HTTP remote
gemini mcp add remote \
  --transport http \
  --url https://api.co/mcp

# Trong session
# /mcp → xem status
# /tools → tool available

Windows path lưu ý: khi truyền path filesystem dùng forward slash (C:/Users/…) hoặc double backslash (C:\\Users\\…) trong JSON.
Ecosystem MCP server có sẵn: server-filesystem · server-github · server-postgres · server-brave-search · server-slack · server-google-drive · server-playwright. Dùng chung format npx cho cả 3 CLI.

05

Takeaways
& homework

5 điều nhớ
1

MCP giải bài toán N×M: 1 server, mọi host dùng được. USB-C cho AI.

2

MCP 3 primitives: Tools (side-effect) · Resources (read-only) · Prompts (template).

3

A2A = giao thức agent ↔ agent. Agent Card + Task + Artifact + Auth.

4

2 giao thức bổ trợ nhau: agent nói A2A, mỗi agent có MCP tool riêng.

5

Security phải là default-on: sandbox, least privilege, audit trail, HITL cho risky action.

Bài tập & chuẩn bị buổi 11
📝

Tự kiểm tra

  • • Chọn 1 internal service, viết MCP server 2-3 tool.
  • • Cài vào Claude Desktop — test tool_use.
  • • Nếu có multi-agent: A2A hay MCP hợp hơn?
📚

Đọc trước

  • • A. Gulli — Ch.10 MCP + Ch.15 A2A.
  • • modelcontextprotocol.io.
  • • Google A2A protocol spec.
🔗

Tài liệu VN

  • Cẩm nang Claude & N8N toàn diện.
  • Khám phá Claude Code.
  • XÂY DỰNG NHÂN SỰ SỐ AI AGENT.
Hết buổi 10

Buổi 11 — Guardrails, HITL & Evaluation
Track 4 — Production. Ch.13 + 18 + 19 sách Gulli.