MCP (Model Context Protocol) + Agent — สอน Setup ฉบับสมบูรณ์
ถ้าคุณใช้ Claude หรือ AI Agent ในการทำงานอยู่แล้ว และเคยสงสัยว่า "ทำไม AI บางตัวถึงสามารถอ่านไฟล์ เปิด Browser ดึงข้อมูลจาก Database ได้เอง?" คำตอบคือ MCP — Model Context Protocol
ปี 2024 Anthropic ประกาศ MCP เป็น open standard ที่เปลี่ยนเกมวิธีที่ AI Agent เชื่อมต่อกับโลกภายนอก และตั้งแต่นั้นมา ระบบนิเวศรอบๆ MCP เติบโตอย่างรวดเร็วจนวันนี้มี MCP Server ให้ใช้หลายร้อยตัว ตั้งแต่ GitHub, Postgres, Slack ไปจนถึง Notion
บทความนี้จะสอนคุณตั้งแต่ต้น ว่า MCP คืออะไร ทำงานยังไง และ Setup ยังไงให้ Agent ของคุณฉลาดขึ้นทันที
1. MCP คืออะไร — Open Standard จาก Anthropic 2024
Model Context Protocol (MCP) คือ open protocol มาตรฐานสำหรับให้ AI Model เชื่อมต่อกับ external data sources และ tools ได้อย่างสม่ำเสมอ
Anthropic ปล่อย MCP เป็น open source ในเดือนพฤศจิกายน 2024 พร้อมกับ spec ที่เปิดให้ทุกคนสร้าง MCP Server ได้เอง โดยไม่ต้องรอ Anthropic
ก่อน MCP มีอยู่ ปัญหาคือ:
- ทุก AI ทุกเจ้าเชื่อมกับ tools คนละวิธีกัน (แตก fragmentation)
- Developer ต้องเขียน integration ใหม่ทุกครั้งที่เปลี่ยน AI model
- ไม่มีวิธีมาตรฐานในการ expose context ให้ AI
MCP แก้ปัญหาเหล่านี้ด้วยการกำหนด protocol เดียวที่ใช้ได้กับทุก AI client ที่ support MCP ไม่ว่าจะเป็น Claude Desktop, Cursor, Continue, Zed หรือ application อื่นๆ ที่ implement spec เดียวกัน
สำหรับใครที่กำลังศึกษา AI Agent ภาษาไทย MCP คือ layer สำคัญที่ทำให้ Agent ทำงานกับข้อมูลจริงได้
2. ทำไม MCP ถึงเหมือน USB-C ของ LLM Tools
คำอุปมาที่โด่งดังที่สุดในวงการคือ MCP เหมือน USB-C
ก่อนมี USB-C โลกมี connector หลายร้อยแบบ — Micro USB, Mini USB, Lightning, proprietary connector ต่างๆ และอุปกรณ์แต่ละชิ้นต้องใช้สาย cable คนละแบบ
USB-C เปลี่ยนทุกอย่างด้วย standard connector เดียวที่ใช้ได้กับทุกอุปกรณ์ ไม่ว่าจะเป็น laptop, phone, monitor, keyboard
MCP ทำสิ่งเดียวกันกับ AI tools:
| ปัญหาเดิม | MCP แก้ด้วย |
|---|---|
| ทุก AI ต้องเขียน integration แยก | Protocol เดียวใช้ได้ทุกที่ |
| Tools ทำงานกับ AI model เดียวเท่านั้น | Server หนึ่งตัว ใช้กับหลาย AI clients |
| เปลี่ยน AI ต้อง rewire ทุก integration | เปลี่ยน client ได้โดยไม่แตะ server |
| ไม่มีมาตรฐานด้าน security | MCP spec กำหนด permission model ชัดเจน |
ผลลัพธ์คือ ecosystem ที่เติบโตเร็วมาก ปัจจุบันมี MCP Server ให้ใช้ฟรีหลายร้อยตัว และใครก็สามารถสร้าง MCP Server ใหม่ได้ในเวลาไม่กี่ชั่วโมง
หัวใจสำคัญที่ทำให้ MCP ต่างจากแนวทางเก่าๆ คือ interoperability — ทำครั้งเดียว ใช้ได้ทุกที่
3. Architecture: Client / Server / Transport
ก่อน setup ต้องเข้าใจ architecture ของ MCP ก่อน ซึ่งประกอบด้วย 3 ส่วนหลัก:
MCP Host / Client
คือ application ที่ผู้ใช้โต้ตอบด้วย ตัวอย่างเช่น:
- Claude Desktop — desktop app จาก Anthropic
- Cursor — AI-powered code editor
- Continue — VS Code extension สำหรับ AI coding
- Zed — modern code editor ที่ support MCP
Client ทำหน้าที่เชื่อมต่อกับ MCP Server และส่ง context ที่ได้ไปให้ LLM ใช้ในการตอบสนอง
MCP Server
คือ service ที่ expose data และ tools ให้ client เรียกใช้ได้ MCP Server แต่ละตัวสามารถ provide:
- Resources — ข้อมูลที่อ่านได้ (files, database records, API responses)
- Tools — actions ที่ AI เรียกใช้ได้ (create file, query DB, send request)
- Prompts — template prompts ที่ reusable
Transport Layer
MCP support transport หลายแบบ:
- stdio — communicate ผ่าน stdin/stdout (เหมาะกับ local server)
- HTTP + SSE — สำหรับ remote server ผ่าน network
สำหรับ Multi-Agent System ที่ซับซ้อน HTTP transport ให้ความยืดหยุ่นมากกว่า แต่สำหรับการเริ่มต้น stdio transport ง่ายกว่าและไม่ต้องมี network setup
[Claude Desktop / Cursor / Continue]
↕ MCP Protocol (stdio / HTTP)
[MCP Server: Filesystem / GitHub / Postgres / Custom]
↕ Native APIs / SDKs
[Real World: Files / Git Repos / Databases / APIs]
4. สอน Setup MCP Server แรก
มาเริ่ม setup MCP Server ตัวแรกกันเลย ใช้ Filesystem MCP Server ซึ่งเป็นตัวง่ายที่สุดและ official จาก Anthropic
Prerequisites
# ต้องมี Node.js 18+ หรือ Python 3.10+
node --version # v18.0.0 หรือสูงกว่า
python --version # Python 3.10 หรือสูงกว่า
Option A: TypeScript/Node.js (แนะนำสำหรับ Beginners)
Step 1: Install Filesystem MCP Server
# ติดตั้งผ่าน npm โดยตรง (ไม่ต้อง clone repo)
npx -y @modelcontextprotocol/server-filesystem /path/to/your/folder
แค่นี้ก็รัน server ได้แล้ว แต่เราต้อง configure ให้ Claude Desktop รู้จักด้วย
Step 2: Configure Claude Desktop
เปิดไฟล์ config ของ Claude Desktop:
# macOS
open ~/Library/Application\ Support/Claude/claude_desktop_config.json
# Windows
# C:\Users\<username>\AppData\Roaming\Claude\claude_desktop_config.json
เพิ่ม configuration นี้:
{
"mcpServers": {
"filesystem": {
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-filesystem",
"/Users/yourname/Documents",
"/Users/yourname/Projects"
]
}
}
}
เปลี่ยน path ให้ตรงกับ folder ที่คุณต้องการให้ Claude เข้าถึง แล้ว restart Claude Desktop
Step 3: ทดสอบ
เปิด Claude Desktop แล้วลองถามว่า "ช่วยอ่านไฟล์ README.md ใน Projects ให้หน่อย" — ถ้า setup ถูกต้อง Claude จะสามารถอ่านไฟล์จริงได้
Option B: Python Server
สำหรับคนที่ถนัด Python SDK ก็ available เช่นกัน:
pip install mcp
ตัวอย่าง Python MCP Server อย่างง่าย:
from mcp.server import Server
from mcp.server.stdio import stdio_server
from mcp.types import Tool, TextContent
app = Server("my-first-mcp")
@app.list_tools()
async def list_tools():
return [
Tool(
name="get_weather",
description="ดึงข้อมูลอากาศ",
inputSchema={
"type": "object",
"properties": {
"city": {"type": "string", "description": "ชื่อเมือง"}
},
"required": ["city"]
}
)
]
@app.call_tool()
async def call_tool(name: str, arguments: dict):
if name == "get_weather":
city = arguments["city"]
# ใส่ logic จริงตรงนี้
return [TextContent(type="text", text=f"อากาศใน {city}: 28°C แดดจ้า")]
if __name__ == "__main__":
import asyncio
asyncio.run(stdio_server(app))
5. เชื่อมกับ Claude Desktop, Cursor, Continue
MCP Server ตัวเดียวใช้ได้กับหลาย client ตามหลัก USB-C ที่พูดถึง
Claude Desktop
ตาม Step 2 ข้างต้น — แก้ไขไฟล์ claude_desktop_config.json
สามารถเพิ่มหลาย server พร้อมกันได้:
{
"mcpServers": {
"filesystem": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-filesystem", "/Users/yourname"]
},
"github": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-github"],
"env": {
"GITHUB_PERSONAL_ACCESS_TOKEN": "your_token_here"
}
}
}
}
Cursor
Cursor support MCP ตั้งแต่ version 0.43 ขึ้นไป เปิด Settings → MCP แล้วเพิ่ม server config แบบเดียวกัน หรือแก้ไขไฟล์ ~/.cursor/mcp.json
{
"mcpServers": {
"filesystem": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-filesystem", "/your/project/path"]
}
}
}
เมื่อ setup แล้ว Cursor Agent จะสามารถ read/write ไฟล์โปรเจกต์ได้โดยตรง แทนที่จะต้อง paste โค้ดทีละส่วน
Continue (VS Code Extension)
Continue เป็น open source AI coding assistant ที่ support MCP ผ่าน config ไฟล์ ~/.continue/config.json:
{
"mcpServers": [
{
"name": "filesystem",
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-filesystem", "/workspace"]
}
]
}
ถ้ากำลังศึกษา Claude Agent SDK การผสม Continue กับ MCP ทำให้ workflow การเขียนโค้ดเร็วขึ้นมาก เพราะ AI เข้าถึง codebase ได้โดยตรง
6. ตัวอย่าง MCP Server ที่ใช้บ่อย
Filesystem Server
{
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-filesystem", "/allowed/path"]
}
ใช้ทำอะไรได้บ้าง:
- อ่านและเขียนไฟล์ใน directory ที่กำหนด
- ค้นหาไฟล์ตาม pattern
- ดู directory structure
- เหมาะสำหรับ: Document management, Code review, Config file editing
GitHub Server
{
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-github"],
"env": {
"GITHUB_PERSONAL_ACCESS_TOKEN": "ghp_xxxxxxxxxxxx"
}
}
ใช้ทำอะไรได้บ้าง:
- ดู issues และ pull requests
- สร้าง/อัพเดท issues
- อ่าน repository content
- จัดการ branches
- เหมาะสำหรับ: Project management, Code review automation, Issue triage
PostgreSQL Server
{
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-postgres",
"postgresql://username:password@localhost:5432/mydb"
]
}
ใช้ทำอะไรได้บ้าง:
- Query ข้อมูลจาก database โดยตรง
- ดู schema และ table structure
- สร้าง reports จากข้อมูลจริง
- เหมาะสำหรับ: Data analysis, Business reporting, DB exploration
MCP Servers ยอดนิยมอื่นๆ
| Server | ทำอะไร | Install |
|---|---|---|
| Slack | ส่ง/อ่านข้อความ Slack | @modelcontextprotocol/server-slack |
| Google Drive | จัดการ Google Docs/Sheets | @modelcontextprotocol/server-gdrive |
| Puppeteer | Browser automation | @modelcontextprotocol/server-puppeteer |
| Brave Search | Web search | @modelcontextprotocol/server-brave-search |
| Memory | Persistent memory สำหรับ AI | @modelcontextprotocol/server-memory |
สำหรับข้อมูลเพิ่มเติมเกี่ยวกับ MCP ecosystem ดูได้ที่บทความ MCP Model Context Protocol ที่อธิบาย deep dive ด้าน spec
7. สร้าง Custom MCP Server สำหรับธุรกิจ
ส่วนที่น่าสนใจที่สุดคือการสร้าง Custom MCP Server สำหรับ use case เฉพาะของธุรกิจคุณ
Use Case ตัวอย่าง: CRM MCP Server
สมมติว่าธุรกิจคุณมีระบบ CRM ที่ต้องการให้ AI เข้าถึงข้อมูลลูกค้าได้:
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import {
CallToolRequestSchema,
ListToolsRequestSchema,
} from "@modelcontextprotocol/sdk/types.js";
const server = new Server(
{ name: "crm-server", version: "1.0.0" },
{ capabilities: { tools: {} } }
);
// ลงทะเบียน tools ที่ AI จะเรียกใช้ได้
server.setRequestHandler(ListToolsRequestSchema, async () => ({
tools: [
{
name: "get_customer",
description: "ดึงข้อมูลลูกค้าจาก CRM",
inputSchema: {
type: "object",
properties: {
customer_id: { type: "string", description: "ID ลูกค้า" }
},
required: ["customer_id"]
}
},
{
name: "search_customers",
description: "ค้นหาลูกค้าจากชื่อหรืออีเมล",
inputSchema: {
type: "object",
properties: {
query: { type: "string", description: "คำค้นหา" }
},
required: ["query"]
}
},
{
name: "create_note",
description: "บันทึก note สำหรับลูกค้า",
inputSchema: {
type: "object",
properties: {
customer_id: { type: "string" },
note: { type: "string" }
},
required: ["customer_id", "note"]
}
}
]
}));
// Handle tool calls
server.setRequestHandler(CallToolRequestSchema, async (request) => {
const { name, arguments: args } = request.params;
switch (name) {
case "get_customer": {
// เรียก CRM API จริง
const customer = await fetchCustomerFromCRM(args.customer_id);
return {
content: [{ type: "text", text: JSON.stringify(customer, null, 2) }]
};
}
case "search_customers": {
const results = await searchCRM(args.query);
return {
content: [{ type: "text", text: JSON.stringify(results, null, 2) }]
};
}
case "create_note": {
await addNoteToCRM(args.customer_id, args.note);
return {
content: [{ type: "text", text: "บันทึก note เรียบร้อย" }]
};
}
default:
throw new Error(`Unknown tool: ${name}`);
}
});
// Start server
const transport = new StdioServerTransport();
await server.connect(transport);
Deploy Custom Server
สำหรับ production deployment:
# Build TypeScript
npm run build
# เพิ่มใน claude_desktop_config.json
{
"mcpServers": {
"crm": {
"command": "node",
"args": ["/path/to/crm-server/dist/index.js"],
"env": {
"CRM_API_URL": "https://your-crm.example.com",
"CRM_API_KEY": "your_secret_key"
}
}
}
}
Ideas สำหรับธุรกิจไทย
- E-commerce: MCP Server เชื่อมกับ WooCommerce / Shopify ให้ AI ดูออร์เดอร์ จัดการสต็อก
- HR: เชื่อมกับระบบ HR ให้ AI ช่วยตอบคำถาม policy วันลา
- Finance: เชื่อมกับ ERP ให้ AI สร้าง financial report อัตโนมัติ
- Customer Service: เชื่อมกับ ticketing system ให้ AI ดู history ลูกค้าก่อนตอบ
ใครที่กำลังสร้าง AI Agent สำหรับธุรกิจในไทย MCP เป็น foundational layer ที่ทำให้ Agent มี access ข้อมูลจริงได้โดยไม่ต้อง hard-code
8. Tips และ Best Practices
Security
- กำหนด path ที่ Filesystem server เข้าถึงได้อย่าง specific (ไม่ใช่
/ทั้งหมด) - เก็บ API keys ใน environment variables ไม่ใส่ตรงๆ ใน config
- Review permissions ของ MCP Server ก่อน install
Performance
- ใช้ caching ใน custom server ถ้า data ไม่ได้ update บ่อย
- จำกัด scope ของ tools ให้แคบที่สุดเท่าที่จำเป็น
- Monitor usage เพราะ AI อาจเรียก tool ซ้ำได้
Debugging
# ดู logs ของ Claude Desktop
# macOS
tail -f ~/Library/Logs/Claude/mcp*.log
# ทดสอบ server โดยตรงจาก command line
echo '{"jsonrpc":"2.0","id":1,"method":"tools/list"}' | node dist/index.js
เมื่อไหรควรใช้ MCP vs ไม่ใช้
ใช้ MCP เมื่อ:
- ต้องการให้ AI เข้าถึง data source เฉพาะบ่อยๆ
- ต้องการ reuse integration กับหลาย AI client
- ทีมมีหลายคนต้องการ access data เดียวกันผ่าน AI
ไม่จำเป็นต้องใช้ MCP เมื่อ:
- ทำ one-off task ที่ paste ข้อมูลตรงๆ ก็พอ
- ข้อมูลเปลี่ยนแปลงไม่บ่อยและ context window เพียงพอ
สรุป: MCP เปลี่ยน AI Agent จาก "คุยเก่ง" เป็น "ทำงานได้จริง"
MCP ไม่ใช่แค่ feature เสริม — มันคือ infrastructure ที่ทำให้ AI Agent สามารถทำงานกับโลกจริงได้
สิ่งที่ต้อง remember:
- MCP = open standard จาก Anthropic — ทำครั้งเดียวใช้ได้กับทุก client
- Architecture ง่ายๆ: Client ↔ MCP Server ↔ Data/Tools
- เริ่มด้วย official servers (Filesystem, GitHub, Postgres) ก่อน
- เมื่อ confident แล้วค่อยสร้าง Custom Server สำหรับ use case ของตัวเอง
- Security first — กำหนด scope ให้แคบ อย่าให้ access มากเกินจำเป็น
สำหรับ developer และธุรกิจที่ต้องการใช้งาน MCP Agent อย่างจริงจัง ทักษะ MCP กลายเป็นหนึ่งใน skills ที่ market ต้องการมากที่สุดในปี 2026
พร้อมยกระดับ AI Agent ของคุณ?
AI Unlocked เปิดสอน MCP, Claude Agent SDK, Multi-Agent System และอีกมากมาย ให้เรียนรู้แบบ hands-on กับ use case จริง
อ่านเพิ่มเติม:
เขียนโดย
AI Unlocked Team
บทความอื่นๆ ที่น่าสนใจ

AI ทำ Music Video — รวม 5 เครื่องมือฟรี
AI ทำ Music Video ฟรีได้จริง! รวม 5 เครื่องมือ Suno, Runway, Kaiber, Hailuo, Pika พร้อม workflow sync ภาพ-เพลง ลดต้นทุนได้ถึง 90% ไม่ต้องมีทักษะตัดต่อ
เรียน AI ใน 30 วัน — Plan สำหรับคนงานยุ่ง
เรียน AI 30 วัน ได้จริงไหม? Plan วันละ 1 ชม. สำหรับคนทำงานยุ่ง ตั้งแต่ Foundation ถึง Portfolio — เริ่มต้นได้เลยวันนี้ ดู Pricing
เรียน AI เชียงใหม่ ราคาถูกที่สุด — 5 ทางเลือก
รวม 5 ทางเลือกเรียน AI เชียงใหม่ ราคาถูก งบ 0–5,000 บาท พร้อม path เริ่มฟรี → ลงทุน paid และเปรียบคุณภาพ vs ราคาที่คุ้มจริง
