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

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à 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

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 hoạt động qua các MCP Servers - các service cung cấp tools và resources cho Agent.

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
{
"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"
}
}
}
}
  • Global: ~/.antigravity/mcp.json
  • Project: .antigravity/mcp.json

Agent có thể liệt kê resources từ MCP server:

"Liệt kê các repos trong GitHub organization của tôi"
"Đọc nội dung file README từ repo main-project"
"Tạo issue mới trên GitHub: 'Fix login bug'"
{
"github": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-github"],
"env": {
"GITHUB_TOKEN": "ghp_xxxx"
}
}
}

Capabilities:

  • List repositories
  • Read files
  • Create/update PRs
  • Manage issues
{
"notion": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-notion"],
"env": {
"NOTION_API_KEY": "secret_xxxx"
}
}
}

Capabilities:

  • Read pages/databases
  • Create content
  • Update existing pages
{
"postgres": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-postgres"],
"env": {
"DATABASE_URL": "postgresql://..."
}
}
}

Capabilities:

  • Query database
  • Schema inspection
  • Data manipulation

Bạn có thể tạo MCP server riêng:

Terminal window
npm init -y
npm install @modelcontextprotocol/sdk
import { Server } from '@modelcontextprotocol/sdk/server';
const server = new Server({
name: 'my-custom-server',
version: '1.0.0'
});
// Define tools
server.setRequestHandler('tools/list', async () => {
return {
tools: [
{
name: 'my_tool',
description: 'Does something useful',
inputSchema: {
type: 'object',
properties: {
param: { type: 'string' }
}
}
}
]
};
});
// Handle tool calls
server.setRequestHandler('tools/call', async (request) => {
if (request.params.name === 'my_tool') {
// Implementation
return { result: 'Success!' };
}
});
server.start();
{
"my-custom": {
"command": "node",
"args": ["./my-server.js"]
}
}
  • Sử dụng environment variables
  • Không commit tokens vào Git
  • Rotate credentials định kỳ
  • MCP calls có latency
  • Cache khi có thể
  • Batch related operations
  • Test MCP connections trước khi dùng
  • Handle errors gracefully
  • Validate responses
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
- Kiểm tra command và args
- Verify environment variables
- Check logs for errors
- Tăng timeout trong config
- Kiểm tra network connectivity
- Verify server is running
- Kiểm tra API keys/tokens
- Verify scopes và permissions
- Check rate limits