MCP
MCP (Model Context Protocol) là protocol cho phép Antigravity kết nối với các công cụ và dịch vụ bên ngoài.
MCP là gì?
Phần tiêu đề “MCP là gì?”MCP là một open protocol để:
- Kết nối AI agents với external tools
- Cung cấp context từ nhiều nguồn
- Mở rộng khả năng của Agent
Tại sao cần MCP?
Phần tiêu đề “Tại sao cần MCP?”Thay vì Agent phải tự implement mọi integration, MCP cho phép:
- Tái sử dụng các connectors có sẵn
- Standardized cách giao tiếp
- Community-driven development
MCP Servers
Phần tiêu đề “MCP Servers”MCP hoạt động qua các MCP Servers - các service cung cấp tools và resources cho Agent.
Ví dụ MCP Servers
Phần tiêu đề “Ví dụ MCP Servers”| Server | Chức năng |
|---|---|
| GitHub | Quản lý repos, PRs, issues |
| Notion | Đọc/viết Notion documents |
| Database | Query và update databases |
| Slack | Gửi messages, manage channels |
| Linear | Project management |
Cấu hình MCP
Phần tiêu đề “Cấu hình MCP”Cấu trúc config
Phần tiêu đề “Cấu trúc config”{ "mcpServers": { "github": { "command": "npx", "args": ["-y", "@modelcontextprotocol/server-github"], "env": { "GITHUB_TOKEN": "your_token_here" } }, "notion": { "command": "npx", "args": ["-y", "@modelcontextprotocol/server-notion"], "env": { "NOTION_API_KEY": "your_key_here" } } }}Nơi lưu config
Phần tiêu đề “Nơi lưu config”- Global:
~/.antigravity/mcp.json - Project:
.antigravity/mcp.json
Sử dụng MCP
Phần tiêu đề “Sử dụng MCP”Liệt kê Resources
Phần tiêu đề “Liệt kê Resources”Agent có thể liệt kê resources từ MCP server:
"Liệt kê các repos trong GitHub organization của tôi"Đọc Resources
Phần tiêu đề “Đọc Resources”"Đọc nội dung file README từ repo main-project"Sử dụng Tools
Phần tiêu đề “Sử dụng Tools”"Tạo issue mới trên GitHub: 'Fix login bug'"Popular MCP Integrations
Phần tiêu đề “Popular MCP Integrations”GitHub
Phần tiêu đề “GitHub”{ "github": { "command": "npx", "args": ["-y", "@modelcontextprotocol/server-github"], "env": { "GITHUB_TOKEN": "ghp_xxxx" } }}Capabilities:
- List repositories
- Read files
- Create/update PRs
- Manage issues
Notion
Phần tiêu đề “Notion”{ "notion": { "command": "npx", "args": ["-y", "@modelcontextprotocol/server-notion"], "env": { "NOTION_API_KEY": "secret_xxxx" } }}Capabilities:
- Read pages/databases
- Create content
- Update existing pages
PostgreSQL
Phần tiêu đề “PostgreSQL”{ "postgres": { "command": "npx", "args": ["-y", "@modelcontextprotocol/server-postgres"], "env": { "DATABASE_URL": "postgresql://..." } }}Capabilities:
- Query database
- Schema inspection
- Data manipulation
Tạo Custom MCP Server
Phần tiêu đề “Tạo Custom MCP Server”Bạn có thể tạo MCP server riêng:
1. Khởi tạo project
Phần tiêu đề “1. Khởi tạo project”npm init -ynpm install @modelcontextprotocol/sdk2. Implement server
Phần tiêu đề “2. Implement server”import { Server } from '@modelcontextprotocol/sdk/server';
const server = new Server({ name: 'my-custom-server', version: '1.0.0'});
// Define toolsserver.setRequestHandler('tools/list', async () => { return { tools: [ { name: 'my_tool', description: 'Does something useful', inputSchema: { type: 'object', properties: { param: { type: 'string' } } } } ] };});
// Handle tool callsserver.setRequestHandler('tools/call', async (request) => { if (request.params.name === 'my_tool') { // Implementation return { result: 'Success!' }; }});
server.start();3. Đăng ký với Antigravity
Phần tiêu đề “3. Đăng ký với Antigravity”{ "my-custom": { "command": "node", "args": ["./my-server.js"] }}Best Practices
Phần tiêu đề “Best Practices”🔐 Bảo mật Credentials
Phần tiêu đề “🔐 Bảo mật Credentials”- Sử dụng environment variables
- Không commit tokens vào Git
- Rotate credentials định kỳ
⚡ Performance
Phần tiêu đề “⚡ Performance”- MCP calls có latency
- Cache khi có thể
- Batch related operations
🧪 Testing
Phần tiêu đề “🧪 Testing”- Test MCP connections trước khi dùng
- Handle errors gracefully
- Validate responses
MCP vs Direct API
Phần tiêu đề “MCP vs Direct API”| Aspect | MCP | Direct API |
|---|---|---|
| Standardization | ✅ Protocol chung | ❌ Mỗi API khác nhau |
| Reusability | ✅ Community servers | ❌ Phải tự implement |
| Learning curve | ✅ Một lần | ❌ Mỗi API phải học |
| Flexibility | Trung bình | Cao |
Troubleshooting
Phần tiêu đề “Troubleshooting”MCP Server không start
Phần tiêu đề “MCP Server không start”- Kiểm tra command và args- Verify environment variables- Check logs for errorsConnection timeout
Phần tiêu đề “Connection timeout”- Tăng timeout trong config- Kiểm tra network connectivity- Verify server is runningPermission denied
Phần tiêu đề “Permission denied”- Kiểm tra API keys/tokens- Verify scopes và permissions- Check rate limits