MCP là gì?
Định nghĩa
MCP (Model Context Protocol) là một open-source standard cho phép kết nối AI applications với external systems. MCP cung cấp cách chuẩn hóa để AI agents truy cập data sources, tools, và workflows.
Analogy: USB-C cho AI
USB-C cho devices:
- Standardized connector
- Power delivery
- Data transfer
- Works across devices
MCP cho AI:
- Standardized protocol
- Tool execution
- Data access
- Works across AI platformsVấn đề MCP giải quyết
Before MCP
AI Agent trong "sandbox":
┌─────────────────────┐
│ AI Agent │
│ - No file access │
│ - No database │
│ - No APIs │
│ - Limited context │
└─────────────────────┘Problems:
- ❌ Cannot read local files
- ❌ Cannot query databases
- ❌ Cannot call external APIs
- ❌ Cannot integrate with existing systems
- ❌ Each AI platform has different integration
After MCP
MCP enables:
┌─────────────┐ MCP ┌─────────────────┐
│ AI Agent │◄────────►│ External Systems│
│ │ │ • Databases │
│ • Claude │ │ • Files │
│ • Cursor │ │ • APIs │
│ • ChatGPT │ │ • Tools │
└─────────────┘ └─────────────────┘Benefits:
- ✅ Standardized access to external systems
- ✅ Security model built-in
- ✅ Works across AI platforms
- ✅ Rich ecosystem of servers
- ✅ Extensible and customizable
MCP trong AI Ecosystem
Position trong Stack
┌─────────────────────────┐
│ AI Applications │
│ (Claude, Cursor, etc.) │
└────────────┬────────────┘
│ MCP Protocol
┌────────────▼────────────┐
│ MCP Servers │
│ • Database servers │
│ • File servers │
│ • API servers │
│ • Custom servers │
└────────────┬────────────┘
│
┌────────────▼────────────┐
│ External Systems │
│ • MongoDB │
│ • PostgreSQL │
│ • File systems │
│ • REST APIs │
└─────────────────────────┘Comparison với các protocols khác
| Protocol | Purpose | Scope | AI-specific |
|---|---|---|---|
| HTTP/REST | Web APIs | General | No |
| gRPC | Microservices | General | No |
| WebSocket | Real-time | General | No |
| LSP | Language services | Development | Partial |
| MCP | AI context | AI-specific | ✅ Yes |
Core Concepts
1. Client
AI application sử dụng MCP:
- Claude Desktop
- Cursor IDE
- Custom AI applications
- Enterprise AI platforms
2. Server
Cung cấp functionality qua MCP:
- Database servers
- File servers
- API servers
- Custom business logic servers
3. Transport
Cách client và server communicate:
- stdio: Standard input/output (default)
- HTTP: HTTP-based communication
- Custom: Custom transport protocols
4. Protocol
JSON-RPC 2.0 based protocol:
- Standardized message format
- Capability negotiation
- Error handling
- Extensibility
MCP Components Deep Dive
Tools
Definition: Functions AI có thể actively gọi
Characteristics:
- AI decides khi nào dùng
- Can modify external systems
- Return results cho AI
- Can be chained together
Examples:
javascript
// Database query tool
{
"name": "query_database",
"description": "Execute SQL query",
"inputSchema": {
"type": "object",
"properties": {
"query": {"type": "string"},
"database": {"type": "string"}
}
}
}
// File write tool
{
"name": "write_file",
"description": "Write content to file",
"inputSchema": {
"type": "object",
"properties": {
"path": {"type": "string"},
"content": {"type": "string"}
}
}
}Resources
Definition: Passive data sources cho context
Characteristics:
- Read-only access
- Provide context cho AI
- Can be subscribed to for updates
- AI cannot modify
Examples:
javascript
// File resource
{
"uri": "file:///path/to/config.json",
"name": "Configuration File",
"description": "Application configuration",
"mimeType": "application/json"
}
// Database schema resource
{
"uri": "mongodb://localhost/users/schema",
"name": "Users Collection Schema",
"description": "Schema definition for users collection",
"mimeType": "application/json"
}Prompts
Definition: Pre-built instruction templates
Characteristics:
- Guide AI behavior
- Combine tools và resources
- User-controlled
- Reusable templates
Examples:
javascript
// Data analysis prompt
{
"name": "analyze_database",
"description": "Analyze database and provide insights",
"arguments": [
{
"name": "database_schema",
"description": "Database schema resource",
"required": true
},
{
"name": "analysis_goal",
"description": "What to analyze",
"required": true
}
]
}Use Cases
1. Database Integration
AI Agent: "Show me all users who signed up last week"
MCP Server:
- Connect to database
- Execute query
- Return results2. File System Access
AI Agent: "Read the configuration file and update the timeout"
MCP Server:
- Read config file (resource)
- Update file (tool)
- Confirm changes3. API Integration
AI Agent: "Create a new user in Stripe"
MCP Server:
- Call Stripe API (tool)
- Handle authentication
- Return user ID4. Development Workflow
AI Agent: "Run tests and fix any failures"
MCP Server:
- Run tests (tool)
- Read test results (resource)
- Fix code (tool)
- Rerun tests (tool)MCP vs Custom Integrations
Custom Integration (trước MCP)
javascript
// Custom Claude plugin
class ClaudePlugin {
async connectToDatabase() {
// Custom implementation
// Hard-coded for Claude
// No standardization
}
async readFile() {
// Custom implementation
// Security concerns
// Limited functionality
}
}
// Custom Cursor plugin
class CursorPlugin {
async connectToDatabase() {
// Different implementation
// Different API
// Duplication of effort
}
}MCP Integration (sau MCP)
javascript
// Single MCP server
class DatabaseMCPServer {
async listTools() {
return [
{
name: "query",
description: "Execute database query"
}
];
}
async callTool(name, args) {
if (name === "query") {
return await this.executeQuery(args.query);
}
}
}
// Works with Claude, Cursor, ChatGPT, etc.
// Standardized protocol
- Single implementation
- Consistent behavior
- Security built-inMCP Philosophy
1. Standardization
- Cùng protocol cho tất cả AI platforms
- Consistent behavior
- Reduced development effort
2. Security First
- Authentication và authorization
- Permission model
- Audit trail
3. Extensibility
- Easy to add new servers
- Custom business logic
- Community contributions
4. Interoperability
- Cross-platform compatibility
- Mixed server environments
- Gradual adoption
MCP Timeline
2024 Q1: Anthropic introduces MCP
2024 Q2: Open source protocol
2024 Q3: First servers released
2024 Q4: Major IDE integrations
2025 Q1: Enterprise adoption
2025 Q2: Ecosystem growthKey Players
Maintainers
- Anthropic (creator)
- OpenAI (contributor)
- Block (contributor)
- Linux Foundation (host)
Major Implementations
- Claude Desktop (native)
- Cursor IDE (native)
- MongoDB (official server)
- Community servers (100+)
Adoption
- 50+ AI applications support MCP
- 200+ MCP servers available
- Growing enterprise adoption
Summary
MCP là:
- ✅ Standard protocol cho AI integration
- ✅ Solves real problems với AI agents
- ✅ Growing ecosystem
- ✅ Production-ready
MCP không phải là:
- ❌ Magic solution cho tất cả problems
- ❌ Replacement cho existing protocols
- ❌ Only for databases
- ❌ Limited to specific AI platforms
Core value:
"MCP enables AI agents to safely and effectively interact with external systems through a standardized protocol"
Tiếp theo: 2. Kiến trúc MCP → Hiểu sâu về cách MCP hoạt động