2 giao thức thống trị 2025: Anthropic MCP (agent ↔ tool/data) + Google A2A (agent ↔ agent). Ch.10 + Ch.15 sách Gulli.
Vì sao cần chuẩn giao thức chung?
Host · Client · Server · 3 primitives
Agent Card, Task, Artifact, Auth
Code, security, framework compare
5 điểm nhớ + homework
• 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.
• 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.
Claude Desktop, Cursor, VS Code, ChatGPT desktop. Chạy LLM, quản lý session.
Trong-process của host. Kết nối 1-1 với 1 server. Multiplex nhiều server.
Expose tool/resource/prompt. Bên thứ 3 hoặc self-host (GitHub, Slack, Postgres…).
Hàm có side-effect (create, send, run).
Data read-only (file, DB row, URL).
Template messages tái sử dụng.
stdio, SSE, HTTP streaming.
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
Manifest JSON tại /.well-known/agent.json: capabilities, auth, endpoint.
Đơn vị công việc gửi giữa agent. Có state (submitted, working, completed).
Output có structure của task (file, JSON, image). Stream được.
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.
| 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.
Server nghe stdio ⇒ chạy như user. Cài từ npm bừa = có thể RCE.
Container / Firecracker VM / gVisor. Least privilege token cho server.
Log mọi tool_call + args + result. Cần cho compliance.
Server có action tốn tiền / gửi ngoài ⇒ hỏi user trước (S-11).
| 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 |
Chat với BigQuery/Postgres bằng NL — MCP server SQL sinh query.
Điều phối Imagen, Veo, Chirp qua MCP — 1 host, nhiều engine.
Weather, stock, calendar, CRM — wrap tất cả thành MCP server.
Đọc/ghi file, git ops trực tiếp qua chuẩn MCP local (stdio).
Slack, Jira, Notion, Zendesk — wire agent vào ops nội bộ.
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.
Đ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).
# 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
# 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
# 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.
MCP giải bài toán N×M: 1 server, mọi host dùng được. USB-C cho AI.
MCP 3 primitives: Tools (side-effect) · Resources (read-only) · Prompts (template).
A2A = giao thức agent ↔ agent. Agent Card + Task + Artifact + Auth.
2 giao thức bổ trợ nhau: agent nói A2A, mỗi agent có MCP tool riêng.
Security phải là default-on: sandbox, least privilege, audit trail, HITL cho risky action.