Bỏ qua để đến nội dung

MCP Hosts

Tưởng tượng Host như “ngôi nhà” của AI…

  • AI (LLM) là người ở trong nhà
  • MCP Servers là các dịch vụ bên ngoài (điện, nước, internet…)
  • Host là ngôi nhà kết nối tất cả lại

Host = Ứng dụng nơi user tương tác với AI, đồng thời quản lý kết nối đến MCP Servers.


  • Đọc config file để biết servers nào khả dụng
  • Khởi động/dừng server processes
  • Reconnect khi server crash
  • Hỏi user: “Claude muốn đọc file X. Cho phép?”
  • Quản lý consent cho từng server/tool
  • Lấy data từ servers
  • Inject vào context window của LLM
  • Quản lý token budget
  • Nhận tool calls từ LLM
  • Route đến đúng server
  • Trả kết quả về LLM

Host Status Đặc điểm
Claude Desktop ✅ Production Host đầu tiên, config bằng JSON
Zed Editor ✅ Production IDE với MCP tích hợp
Cursor 🔄 Beta Popular AI code editor
Gemini CLI 🔄 Beta Google’s AI in terminal
Continue.dev ✅ Production VS Code extension
BeeAI (IBM) ✅ Production Enterprise solution

File: ~/Library/Application Support/Claude/claude_desktop_config.json

{
"mcpServers": {
"filesystem": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-filesystem", "/Users/me/docs"]
},
"postgres": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-postgres"],
"env": {
"DATABASE_URL": "postgresql://user:pass@localhost/mydb"
}
},
"github": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-github"],
"env": {
"GITHUB_TOKEN": "ghp_xxxx"
}
}
}
}

File: ~/.config/zed/settings.json

{
"context_servers": {
"filesystem": {
"command": {
"path": "npx",
"args": ["-y", "@modelcontextprotocol/server-filesystem", "/path/to/project"]
}
}
}
}

User Query
┌──────────────────────────────────────────────┐
│ HOST │
│ │
│ 1. Check available servers │
│ 2. Inject server capabilities into prompt │
│ 3. Send to LLM │
│ │
│ ┌─────────────────────────────────┐ │
│ │ LLM │ │
│ │ "I want to call tool X..." │ │
│ └─────────────────────────────────┘ │
│ │
│ 4. Parse tool call request │
│ 5. Ask user permission (if needed) │
│ 6. Route to correct server │
│ 7. Get result │
│ 8. Inject result, continue conversation │
└──────────────────────────────────────────────┘
MCP Servers (filesystem, postgres, ...)

Thêm 2 servers vào Claude Desktop.

  1. Mở config file Claude Desktop
  2. Thêm Filesystem server (đọc folder dự án)
  3. Thêm Memory server (để Claude nhớ thông tin)
{
"mcpServers": {
"project": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-filesystem", "/path/to/your/project"]
},
"memory": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-memory"]
}
}
}
  1. Restart Claude
  2. Test:
    • “Nhớ tên tôi là Phúc”
    • “Tên tôi là gì?”
    • “Đọc file README trong project”

Khái niệm Ý nghĩa
Host App quản lý MCP connections
Config file JSON định nghĩa servers
Permission User approve mỗi action
Orchestration Route tool calls đến servers

Bài tiếp theo: MCP Clients - Giao thức kết nối.