Skip to Content

MCP Hosts

Khái niệm cơ bản

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.


Nhiệm vụ của Host

1. Discovery & Lifecycle Management

  • Đọc config file để biết servers nào khả dụng
  • Khởi động/dừng server processes
  • Reconnect khi server crash

2. Permission Management

  • Hỏi user: “Claude muốn đọc file X. Cho phép?”
  • Quản lý consent cho từng server/tool

3. Context Injection

  • Lấy data từ servers
  • Inject vào context window của LLM
  • Quản lý token budget

4. Tool Orchestration

  • Nhận tool calls từ LLM
  • Route đến đúng server
  • Trả kết quả về LLM

Các Host phổ biến

HostStatusĐặc điểm
Claude Desktop✅ ProductionHost đầu tiên, config bằng JSON
Zed Editor✅ ProductionIDE với MCP tích hợp
Cursor🔄 BetaPopular AI code editor
Gemini CLI🔄 BetaGoogle’s AI in terminal
Continue.dev✅ ProductionVS Code extension
BeeAI (IBM)✅ ProductionEnterprise solution

Claude Desktop Config

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" } } } }

Zed Editor Config

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

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

Host Responsibilities Flow

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, ...)

Bài tập thực hành

Mục tiêu

Thêm 2 servers vào Claude Desktop.

Bước thực hiện

  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”

Tóm tắt

Khái niệmÝ nghĩa
HostApp quản lý MCP connections
Config fileJSON định nghĩa servers
PermissionUser approve mỗi action
OrchestrationRoute tool calls đến servers

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

Last updated on