MCP (Model Context Protocol) là gì — 'USB-C' cho AI kết nối mọi tool
MCP là chuẩn mở Anthropic launch tháng 11/2024 — cho phép AI (Claude, ChatGPT, Cursor) kết nối với mọi tool/data/service qua 1 interface chung. Hiểu MCP để tích hợp Google Drive, Slack, GitHub, custom API vào Claude trong 5 phút thay vì code custom integration tuần.
Mục lục bài viết(24)

Sơ đồ thành phần MCP — AI host (Claude Desktop, Cursor, Claude Code) chứa MCP Client. Client kết nối nhiều MCP Server qua protocol chuẩn (JSON-RPC). Mỗi server expose: Tools (function AI gọi), Resources (data AI đọc), Prompts (template AI dùng). 1 client + nhiều server = 1 AI host có sức mạnh hàng trăm tool. Nguồn: Wikimedia Commons (CC BY-SA 4.0).
Hiểu đơn giản nhất
Tưởng tượng AI là một người trợ lý mới vào công ty. Bạn muốn họ làm việc với:
- Email công ty (Gmail)
- Slack messages
- Google Drive files
- Database
- GitHub repo
- Lịch Google Calendar
Cách 1 — Trước MCP: Bạn phải code 6 integration riêng cho AI. Mỗi cái 100-500 dòng code, học doc Gmail API, Slack API, Drive API... Mất 2-4 tuần.
Cách 2 — Với MCP: Mỗi service có sẵn MCP server (community hoặc official). Bạn add vào config Claude:
{
"mcpServers": {
"gmail": { "command": "npx", "args": ["mcp-server-gmail"] },
"slack": { "command": "npx", "args": ["mcp-server-slack"] },
"drive": { "command": "npx", "args": ["mcp-server-gdrive"] }
}
}Restart Claude. Xong. AI giờ biết list email, send Slack, read Drive — qua 1 chuẩn duy nhất.
MCP = Model Context Protocol = "USB-C cho AI".
| Khái niệm | Đời thực | MCP |
|---|---|---|
| MCP Server | Thiết bị USB-C (đèn, ổ cứng, monitor) | Service expose tool/data |
| MCP Client | Lap có cổng USB-C | AI host (Claude Desktop, Cursor) |
| Protocol | Chuẩn USB-C (đầu cắm, voltage) | JSON-RPC + structured tool defs |
| Tools | Tính năng chính (sạc, gửi data) | Function AI có thể gọi |
| Resources | File trong ổ cứng | Data AI có thể đọc |
| Prompts | Macro phím tắt | Template prompt sẵn |
Tại sao bạn cần biết
- Mở rộng AI từ "chatbot" thành "agent thật". AI biết đọc email + tạo task + push code là productivity x10.
- Tiết kiệm 80-90% code integration. 1 dòng config thay vì 200 dòng custom code.
- Vendor-neutral. MCP server viết 1 lần, chạy với Claude/ChatGPT/Cursor đều được.
- Hiểu landscape AI agent 2026. MCP là tầng foundation cho agent ecosystem — biết MCP = biết hướng phát triển AI app.
- Build SaaS có MCP server = differentiate. 2026 customer chọn SaaS có MCP support để AI họ dùng access được. Strategic moat.
Anatomy của MCP
MCP server expose 3 loại thứ:
1. Tools — function AI gọi
{
name: "send_email",
description: "Send email via Gmail",
inputSchema: {
type: "object",
properties: {
to: { type: "string", description: "Recipient email" },
subject: { type: "string" },
body: { type: "string" }
},
required: ["to", "subject", "body"]
}
}AI thấy tool định nghĩa → biết gọi với param gì → server execute → return result.
2. Resources — data AI đọc
{
uri: "drive://folder/123",
name: "Q4 Marketing Plan",
mimeType: "text/markdown"
}AI có thể read_resource("drive://folder/123") → fetch content. Khác Tool ở chỗ: Resource là data tĩnh, Tool là action.
3. Prompts — template prompt AI sử dụng
{
name: "code_review",
description: "Review code changes for security + style",
arguments: [
{ name: "diff", description: "Git diff to review", required: true }
]
}User trong Claude Desktop chọn "code_review" → AI tự fill template + apply.
MCP server phổ biến 2026
Official (Anthropic team)
| Server | Use case |
|---|---|
mcp-server-filesystem | Read/write local files (scoped path) |
mcp-server-git | Git operations (commit, diff, log) |
mcp-server-sqlite | Query SQLite DB |
mcp-server-postgres | Query Postgres DB |
mcp-server-puppeteer | Browse web, screenshot, scrape |
mcp-server-fetch | HTTP fetch URL với conversion to markdown |
mcp-server-time | Get current time, timezone |
mcp-server-memory | Persistent key-value memory across sessions |
Community popular
| Server | Use case |
|---|---|
context7 | Live docs lookup cho 1000+ library (React, Next.js, Drizzle...) |
github | Issue/PR management, repo search |
slack | Read/send messages, list channels |
notion | Read/edit pages, query DB |
exa | Web search semantic |
firecrawl | Web scraping + extract structured data |
playwright | Browser automation testing |
youtube-transcript | Get transcript của video |
chatgpt-imagegen | Image generation qua OpenAI DALL-E |
Custom (vietcodex.com đang dùng)
| Server | Vai trò |
|---|---|
google-flow-bridge | Call Google Flow API gen image (custom Patchright + Xvfb) |
chatgpt-imagegen | DALL-E proxy với auth + retry logic riêng |
Setup MCP với Claude Desktop
Bước 1: Cài Claude Desktop
claude.ai/download — desktop app cho Mac/Windows.
Bước 2: Edit config file
File: ~/Library/Application Support/Claude/claude_desktop_config.json (Mac) hoặc %APPDATA%\Claude\claude_desktop_config.json (Windows).
{
"mcpServers": {
"filesystem": {
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-filesystem",
"/Users/yourname/Documents"
]
},
"github": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-github"],
"env": {
"GITHUB_PERSONAL_ACCESS_TOKEN": "ghp_xxxxxxxxx"
}
},
"context7": {
"command": "npx",
"args": ["-y", "@upstash/context7-mcp"]
}
}
}Bước 3: Restart Claude Desktop
App load MCP server tự động khi start. Icon 🔌 trong UI hiện server đã connect.
Bước 4: Use trong conversation
You: "List file trong Documents/projects, đọc file README.md"
Claude: [calls filesystem.list_directory → list_files → read_text_file]
"Đây là 12 file..."
Claude tự biết khi nào gọi tool nào dựa trên user query.
Tự viết MCP server — quickstart
TypeScript SDK đơn giản nhất:
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import { z } from "zod";
const server = new Server(
{ name: "vietcodex-tools", version: "1.0.0" },
{ capabilities: { tools: {} } }
);
// Define tool: get order status
server.setRequestHandler("tools/list", async () => ({
tools: [
{
name: "get_order_status",
description: "Get vietcodex.com order status by order number",
inputSchema: {
type: "object",
properties: {
order_number: { type: "string", description: "vd: VC2026000001" }
},
required: ["order_number"]
}
}
]
}));
// Handle tool call
server.setRequestHandler("tools/call", async (request) => {
if (request.params.name === "get_order_status") {
const { order_number } = request.params.arguments as { order_number: string };
const order = await fetch(`https://vietcodex.com/api/orders/${order_number}`)
.then(r => r.json());
return {
content: [{ type: "text", text: JSON.stringify(order) }]
};
}
throw new Error("Unknown tool");
});
// Connect via stdio
const transport = new StdioServerTransport();
await server.connect(transport);Lưu file server.js, build với tsc, add vào Claude config với command: "node", args: ["/path/to/server.js"]. Done.
MCP transport — stdio vs Streamable HTTP
Stdio (local subprocess)
- AI host spawn server qua command line
- Communicate qua stdin/stdout
- ✅ Đơn giản, no network setup
- ✅ Security: chạy local process, không expose network
- ❌ Chỉ work khi server và client cùng machine
Khi dùng: filesystem, git, sqlite, local script — server cần local resource access.
Streamable HTTP (remote)
- Server expose HTTP endpoint
- Client POST request, server stream response
- ✅ Server có thể chạy remote (SaaS hosted)
- ✅ Multi-tenant support
- ✅ OAuth flow built-in (Q1 2026 standard)
- ❌ Cần host + manage server uptime
Khi dùng: SaaS integration (Notion, Slack, GitHub) — server hosted bởi vendor.
Ví dụ thực tế: vietcodex.com workflow với MCP
Khi tôi viết bài wiki này, Claude Code có ~5 MCP server active:
1. filesystem (scoped vietcodex-app/) — đọc/ghi file MDX
2. github — push code lên repo
3. context7 — lookup docs Next.js/Drizzle
4. chatgpt-imagegen — gen hero image
5. exa — web search latest info
Workflow gen 1 bài wiki:
User: "Viết bài về MCP cho cluster ai-coding"
Claude internally:
[Tool: filesystem.list_directory("content/wiki/ai-coding/")]
→ list 11 existing files, decide MCP slug
[Tool: exa.search("MCP Model Context Protocol 2026")]
→ fetch 5 latest articles for context
[Tool: context7.resolve-library-id("@modelcontextprotocol/sdk")]
[Tool: context7.query-docs("MCP server typescript example")]
→ get up-to-date code example
[Tool: filesystem.write_file("content/wiki/ai-coding/mcp-la-gi.mdx", "...")]
→ save MDX
[Response to user] "Done — file created at..."
5 MCP server = 5 superpower. Không có MCP, mỗi tool cần code wrapper custom riêng.
Quy tắc bảo mật MCP
| Risk | Mitigation |
|---|---|
| Server malicious đọc file ngoài scope | Limit filesystem server vào folder cụ thể, không full disk |
| Server send data ra ngoài | Audit network access, dùng firewall outbound |
| Prompt injection qua tool response | Sanitize string trước khi inject vào AI context |
| Token leak qua server local | Lưu API key trong env var, không hardcode |
| Server không trust source | Chỉ cài từ npm official @modelcontextprotocol/* hoặc github trusted |
Anthropic publish MCP security advisory Q1 2026 — đọc trước khi cài community server.
Cái gì có thể sai
| Vấn đề | Triệu chứng | Cách fix |
|---|---|---|
| Server không start | Claude hiện ❌ icon next to server name | Check log: ~/Library/Logs/Claude/mcp-server-<name>.log |
| Tool không gọi được | AI nói "tôi không có tool đó" | Restart Claude Desktop sau khi edit config |
| Server crash khi gọi nhiều lần | Memory leak hoặc race condition | Check server stderr, fix code |
| Permission denied filesystem | Folder ngoài scope đã grant | Add folder vào args path |
| GitHub MCP rate-limited | API token thiếu scope hoặc PR spam | Tạo personal access token mới với đúng scope |
| Vietnamese trong response broken | UTF-8 encoding issue trong server | Set process.stdout.write với encoding utf8 |
| 2 server cùng tên collision | Cùng tool name trong 2 server | Rename trong config |
Tóm tắt 1 dòng
MCP (Model Context Protocol) = "USB-C cho AI" — chuẩn mở Anthropic launch 11/2024 cho phép AI kết nối tool/data/service qua 1 protocol chung. MCP Server expose Tools + Resources + Prompts. MCP Client (Claude Desktop, Cursor, ChatGPT) consume nhiều server đồng thời. Setup 5 phút thay vì 2-4 tuần code custom. SDK TypeScript/Python ~50 dòng cho server cơ bản. Transport: stdio (local), Streamable HTTP (remote). Adoption nhanh 2025-2026, > 300 server official + community. Cài chỉ trust source.
Đọc tiếp
- Context Window + Token economics — MCP tool defs ăn token, cần optimize
- AI Coding là gì — MCP là tầng foundation cho AI agent 2026
- Claude Code, Cursor, GitHub Copilot — so sánh 3 tool — cả 3 đều support MCP
- Prompt Engineering — cách nói chuyện với AI — MCP tool description = prompt engineering inline