Hướng Dẫn Dùng MCP với Claude: Từng Bước với Ví Dụ GitHub và Slack
Điểm nổi bật
Nhấn để đến mục tương ứng
- 1 Thực tế không hoàn hảo như marketing: PostgreSQL MCP Read-only hoặc read-write access cho PostgreSQL databases. Theo nhận xét từ cộng đồng: "Tạo table users với fields: id, email, created_at". Người dùng thành công học cách biến constraint thành cơ hội, xoay sở thay vì chờ phiên bản hoàn thiện.
- 2 Case thực tế đáng tham khảo ngay: Ví dụ workflow tự động hóa: Prompt đơn: "Check PR #45 trong repo backend-service. Power thực sự của MCP là combine multiple servers. Đây là workflow đã chứng minh hiệu quả từ người dùng thật — adapt cho ngữ cảnh của bạn thay vì copy nguyên.
- 3 Không đơn thuần là khái niệm mới — Mỗi lần bạn hỏi Claude về codebase của mình, bạn phải copy-paste code vào chat. Theo nhận xét từ cộng đồng: "mang thông tin đến Claude,". Sự khác biệt nằm ở cách nó tích hợp vào quy trình làm việc hàng ngày, tạo giá trị tích lũy theo thời gian.
- 4 Mẹo từ power users nên áp dụng ngay: Rate Limiting MCP servers có thể bị gọi nhiều lần trong một conversation. Implement rate limiting để: Protect backend systems khỏi. Chiến lược này đã được kiểm chứng — bạn sẽ thấy khác biệt rõ rệt từ tuần đầu tiên khi áp dụng.
- 5 Khía cạnh quan trọng ít được bàn luận: Host Application Ứng dụng chính mà người dùng interact: Claude Desktop App, Cursor IDE, VS Code với extension. Host là nơi người dùng đặt câu hỏi và nhận kết quả. Nắm được chi tiết này giúp bạn tránh sai lầm phổ biến và khai thác tối đa giá trị từ công cụ.
MCP là gì và tại sao nó thay đổi cách dùng Claude?
Mỗi lần bạn hỏi Claude về codebase của mình, bạn phải copy-paste code vào chat. Mỗi lần muốn Claude check PR status, bạn phải lấy thông tin thủ công rồi paste vào. Với Model Context Protocol (MCP), những việc này không còn cần thiết.
MCP là chuẩn giao thức do Anthropic phát triển, cho phép Claude kết nối trực tiếp với external tools và data sources. Thay vì bạn "mang thông tin đến Claude," Claude tự lấy thông tin cần thiết khi cần.
Codecademy mô tả MCP như "OpenAPI cho AI tools" — tương tự cách OpenAPI chuẩn hóa HTTP APIs, MCP chuẩn hóa cách AI interact với external systems.
Kiến trúc MCP trong 4 thành phần
1. Host Application
Ứng dụng chính mà người dùng interact: Claude Desktop App, Cursor IDE, VS Code với extension. Host là nơi người dùng đặt câu hỏi và nhận kết quả.
2. MCP Client
Connector bên trong host, quản lý kết nối và giao tiếp với MCP servers. Người dùng không interact trực tiếp với client — nó hoạt động transparent trong background.
3. MCP Server
Expose tools và resources cho Claude sử dụng. Mỗi integration có một MCP server riêng: GitHub server expose GitHub API tools, Slack server expose Slack messaging tools, v.v.
4. External Resources
Actual data sources: GitHub repos, Slack workspaces, databases, APIs. MCP server là "translator" giữa Claude và những systems này.
Tutorial 1: Kết nối GitHub MCP
Bước 1: Tạo GitHub Personal Access Token
- Đăng nhập GitHub → Settings
- Developer Settings → Personal access tokens → Tokens (classic)
- Generate new token với scopes:
repo,read:user - Copy token (chỉ hiển thị một lần)
Bước 2: Cấu hình Claude Desktop
- Mở Claude Desktop App
- Vào Settings → Developer tab
- Click "Edit Config" để mở file JSON
Bước 3: Thêm GitHub server configuration
{
"mcpServers": {
"github": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-github"],
"env": {
"GITHUB_PERSONAL_ACCESS_TOKEN": "your_token_here"
}
}
}
}
Bước 4: Restart Claude Desktop
Đóng hoàn toàn và mở lại Claude Desktop. MCP server sẽ khởi động tự động.
Kết quả: Những gì bạn có thể làm ngay
Sau khi setup GitHub MCP, bạn có thể:
- "List all open PRs trong repo my-project"
- "Show me the failing CI checks for PR #42"
- "Create a new branch called feature/user-auth from main"
- "Commit these changes với message 'Fix null pointer exception'"
- "Merge PR #38 sau khi tất cả checks pass"
Tất cả bằng natural language — không cần nhớ git commands hay GitHub CLI syntax.
Tutorial 2: Kết nối Slack MCP
Bước 1: Tạo Slack App
- Vào api.slack.com/apps → Create New App
- Chọn "From scratch," đặt tên app
- Select workspace
- Vào "OAuth & Permissions" → Bot Token Scopes: thêm
chat:write,channels:read,channels:history - Install app vào workspace → copy Bot User OAuth Token
Bước 2: Lấy Workspace ID và Channel ID
-
Workspace ID: Nhìn vào URL Slack workspace:
app.slack.com/client/TXXXXXXXX/— chuỗi bắt đầu bằng T là Workspace ID - Channel ID: Mở channel → More → Copy Link → URL chứa channel ID (bắt đầu bằng C)
Bước 3: Thêm vào config file
{
"mcpServers": {
"github": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-github"],
"env": {
"GITHUB_PERSONAL_ACCESS_TOKEN": "your_github_token"
}
},
"slack": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-slack"],
"env": {
"SLACK_BOT_TOKEN": "xoxb-your-bot-token",
"SLACK_TEAM_ID": "TXXXXXXXX"
}
}
}
}
Restart và verify
Sau khi restart, thử prompt: "Post 'Good morning team!' vào channel #general" — nếu Slack nhận được message, setup thành công.
Workflow thực tế: GitHub + Slack kết hợp
Power thực sự của MCP là combine multiple servers. Ví dụ workflow tự động hóa:
Prompt đơn: "Check PR #45 trong repo backend-service. Nếu tất cả CI checks pass, post summary vào channel #dev-updates trên Slack."
Claude tự động:
- Gọi GitHub MCP để fetch PR #45 và CI status
- Verify tất cả checks pass
- Format PR summary (title, changes, author)
- Gọi Slack MCP để post message vào #dev-updates
Không cần bạn làm gì thêm. Đây là automation không cần viết script.
MCP Servers phổ biến khác
Supabase MCP
Quản lý database bằng natural language:
- "Tạo table users với fields: id, email, created_at"
- "Query 10 users đăng ký trong tuần này"
- "Deploy edge function này lên production"
Supabase MCP có security feature đặc biệt: SQL result wrapper ngăn LLM follow malicious commands ẩn trong data.
PostgreSQL MCP
Read-only hoặc read-write access cho PostgreSQL databases. Ideal cho data analysis workflows: "Show me revenue by customer segment for last quarter."
Google Drive MCP
Search, read, và create documents: "Find all spreadsheets modified this week," "Create a Google Doc với nội dung này."
Puppeteer MCP
Browser automation: "Screenshot homepage của competitor.com," "Extract pricing từ trang này."
Security Best Practices
MCP là công cụ mạnh — và với great power comes great responsibility:
- Minimal permissions: Chỉ grant scopes bạn thực sự cần. Read-only nếu không cần write
- Separate tokens: Dùng dedicated token cho MCP, không share với other applications
- Review actions: Với destructive operations (delete, modify production data), luôn review trước khi confirm
- Rotate tokens thường xuyên: Nếu token bị lộ, revoke ngay và tạo mới
Lưu ý: Nghiên cứu 2025 phát hiện ~2,000 MCP servers public không có authentication. Với production use, luôn setup authentication cho MCP servers của bạn.
Troubleshooting phổ biến
| Vấn đề | Giải pháp |
|---|---|
| MCP server không khởi động | Check console logs trong Claude Desktop, verify npx available trong PATH |
| Permission denied | Check token scopes — grant scopes phù hợp |
| Timeout lỗi | Network issue hoặc rate limiting — retry sau vài phút |
| Config không được apply | Đảm bảo restart hoàn toàn (quit, không chỉ close window) |
Xem thêm về MCP ecosystem tại AI Agent: Tương lai của tự động hóa quy trình và Building Effective Agents với Claude.
Xây Dựng MCP Server Của Riêng Bạn
Nếu bạn có internal tool hoặc database cần kết nối với Claude, bạn có thể xây MCP server của riêng mình. SDK available cho Python và TypeScript/Node.js.
Cấu trúc cơ bản (TypeScript)
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
const server = new Server({ name: 'my-internal-tool', version: '1.0.0' });
server.setRequestHandler('tools/list', async () => ({
tools: [{
name: 'get_customer_data',
description: 'Get customer info by ID',
inputSchema: {
type: 'object',
properties: { customer_id: { type: 'string' } },
required: ['customer_id']
}
}]
}));
const transport = new StdioServerTransport();
await server.connect(transport);
Một khi kết nối, bạn hỏi Claude: "Get customer data for ID 12345" → Claude gọi tool, lấy data từ database của bạn, và trả lời với thông tin thực.
MCP Best Practices Cho Production
Logging và Monitoring
Production MCP servers nên log tất cả tool invocations:
- Tool name, input parameters, timestamp
- Response time và success/failure
- User hoặc session identifier
Logs này giúp debug khi Claude làm gì đó unexpected và provide audit trail cho compliance.
Rate Limiting
MCP servers có thể bị gọi nhiều lần trong một conversation. Implement rate limiting để:
- Protect backend systems khỏi overload
- Prevent accidental data modification loops
- Control costs nếu tool calls charge money (API calls)
Graceful Error Handling
Khi tool fail, trả về descriptive error message — không phải stack trace raw. Claude có thể đọc error message và tự adjust approach:
// Good error response:
{ "error": "Customer ID 12345 not found in database" }
// Bad error response:
{ "error": "TypeError: Cannot read property 'email' of undefined at line 45..." }
Versioning
MCP servers nên version tools explicitly. Khi update tool behavior, bump version và maintain backward compatibility trong ít nhất một version cycle.
Kịch Bản Thực Tế: Developer Workflow Tự Động
Morning Standup Automation
Setup: GitHub MCP + Jira MCP + Slack MCP
Single morning prompt:
"Generate daily standup update:
1. What I did yesterday: Get my GitHub commits from yesterday
2. What I'm doing today: Get my assigned Jira tickets (In Progress)
3. Any blockers: Get PRs waiting for my review more than 24h
Post formatted summary to #standup channel"
Tiết kiệm 10-15 phút mỗi sáng, và standup updates consistently formatted.
PR Review Reminder Workflow
"Check all open PRs in repos [list repos].
Find PRs where:
- Waiting for review more than 48 hours
- Author is someone on my team
Post Slack message to each author with PR link and age"
Release Notes Generator
"Generate release notes for version 2.4.0:
1. Get all merged PRs since last release tag (v2.3.0)
2. Categorize: Features, Bug Fixes, Breaking Changes
3. Format as markdown changelog
4. Create GitHub release draft with these notes"
MCP Patterns: Thiết Kế Tốt và Không Tốt
Pattern Tốt: Granular Tools
Thiết kế tools nhỏ và focused:
// Tốt
get_user_by_email(email)
update_user_role(user_id, role)
delete_user(user_id)
// Không tốt (quá broad)
manage_users(action, params)
Granular tools: Claude có thể chọn đúng tool, và permission model rõ ràng hơn (có thể grant get_user mà không grant delete_user).
Pattern Tốt: Descriptive Tool Descriptions
Tool description là "system prompt" cho tool — càng clear càng tốt:
// Tốt
name: "get_recent_errors",
description: "Retrieve the 10 most recent error logs from production.
Returns: array of {timestamp, level, message, stack_trace}.
Use this when user asks about recent errors or production issues."
// Không tốt
name: "get_errors",
description: "Get errors"
Pattern Tốt: Idempotent Read Operations
Tools chỉ đọc data không cần confirmation. Tools modify data (write, delete) nên có confirmation step hoặc dry-run option.
Cộng Đồng MCP: Tham Gia và Đóng Góp
Tìm MCP Servers
- GitHub: github.com/modelcontextprotocol/servers — official repository
- awesome-mcp-servers: Community-curated list trên GitHub
- MCP Hub: Third-party directories đang nổi lên
Đóng góp
MCP là open-source — nếu bạn build MCP server cho internal tool và có thể public, community sẽ rất appreciate:
- Generalize server để work với các deployments khác
- Add documentation và examples
- Submit PR hoặc create public repo với README rõ ràng
- Share trong MCP community channels
Developer Việt Nam có opportunity đóng góp MCP servers cho Vietnamese-specific services: VNPay, Momo, VNPT, FPT services — những integrations mà global community chưa có.
Nguồn tham khảo
Bai viet co huu ich khong?
Bản quyền thuộc về tác giả. Vui lòng dẫn nguồn khi chia sẻ.





