Giới thiệu
Model Context Protocol (MCP) — do Anthropic phát triển — là chuẩn mở giúp agent kết nối với bất kỳ data source hoặc tool nào một cách thống nhất. Thay vì viết custom integration cho mỗi tool, bạn implement MCP Server một lần và mọi MCP-compatible client đều dùng được.
1. MCP Architecture
┌──────────────┐ ┌──────────────┐ ┌──────────────┐
│ MCP Client │◄───►│ MCP Server │◄───►│ Data Source │
│ (Agent/IDE) │ │ (Your code) │ │ (DB/API/FS) │
└──────────────┘ └──────────────┘ └──────────────┘
2. Build MCP Server
from mcp.server import Server
from mcp.types import Tool
server = Server("my-tools")
@server.tool("query_database")
async def query_db(sql: str) -> str:
"""Execute read-only SQL query."""
result = await db.execute(sql)
return json.dumps(result)
@server.tool("search_github")
async def search_github(query: str, repo: str) -> str:
"""Search code in a GitHub repository."""
...
Tóm tắt
- MCP = USB-C cho AI — chuẩn kết nối universal
- Client/Server architecture: agent là client, tools là servers
- Tool discovery: agent tự biết có tools nào available
- Ecosystem: 1000+ MCP servers có sẵn
Bài tập
- Build MCP Server cho SQLite database
- Build MCP Server cho GitHub API (search repos, read files)
- Connect agent tới 3+ MCP Servers cùng lúc
- So sánh custom tool vs MCP tool: development experience