Skip to Content
🛠️ Công cụ AIAntigravityPreviewMCP

MCP (Model Context Protocol)

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ì?

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?

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

MCP hoạt động qua các MCP Servers - các service cung cấp tools và resources cho Agent.

Ví dụ MCP Servers

ServerChức năng
GitHubQuản lý repos, PRs, issues
NotionĐọc/viết Notion documents
DatabaseQuery và update databases
SlackGửi messages, manage channels
LinearProject management

Cấu hình MCP

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

  • Global: ~/.antigravity/mcp.json
  • Project: .antigravity/mcp.json

Sử dụng MCP

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

"Đọc nội dung file README từ repo main-project"

Sử dụng Tools

"Tạo issue mới trên GitHub: 'Fix login bug'"

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

{ "notion": { "command": "npx", "args": ["-y", "@modelcontextprotocol/server-notion"], "env": { "NOTION_API_KEY": "secret_xxxx" } } }

Capabilities:

  • Read pages/databases
  • Create content
  • Update existing pages

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

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

1. Khởi tạo project

npm init -y npm install @modelcontextprotocol/sdk

2. Implement server

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();

3. Đăng ký với Antigravity

{ "my-custom": { "command": "node", "args": ["./my-server.js"] } }

Best Practices

🔐 Bảo mật Credentials

  • Sử dụng environment variables
  • Không commit tokens vào Git
  • Rotate credentials định kỳ

⚡ Performance

  • MCP calls có latency
  • Cache khi có thể
  • Batch related operations

🧪 Testing

  • Test MCP connections trước khi dùng
  • Handle errors gracefully
  • Validate responses

MCP vs Direct API

AspectMCPDirect 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
FlexibilityTrung bìnhCao

Troubleshooting

MCP Server không start

- Kiểm tra command và args - Verify environment variables - Check logs for errors

Connection timeout

- Tăng timeout trong config - Kiểm tra network connectivity - Verify server is running

Permission denied

- Kiểm tra API keys/tokens - Verify scopes và permissions - Check rate limits
Last updated on