MCP (Model Context Protocol) is an open protocol that allows AI assistants to connect to external data sources and tools. It acts as a bridge between Claude and services like databases, APIs, file systems, and more.
MCP (Model Context Protocol) là giao thức mở cho phép AI assistant kết nối với các nguồn dữ liệu và công cụ bên ngoài. Nó hoạt động như cầu nối giữa Claude và các dịch vụ như database, API, file system, và nhiều hơn nữa.
With MCP, Claude Code can access realtime information from systems you use, instead of relying only on trained knowledge. This opens up unlimited integration possibilities.
Với MCP, Claude Code có thể truy cập thông tin realtime từ các hệ thống bạn đang sử dụng, thay vì chỉ dựa vào kiến thức được training. Điều này mở ra khả năng tích hợp vô hạn.
MCP servers run as independent processes and communicate with Claude through a standard protocol. Each server provides a set of tools and resources that Claude can use.
MCP servers chạy như các process độc lập và giao tiếp với Claude thông qua giao thức chuẩn. Mỗi server cung cấp một tập các tools và resources mà Claude có thể sử dụng.
Allows Claude to access and manipulate the file system safely, with controlled permissions.
Cho phép Claude truy cập và thao tác với file system một cách an toàn, với các quyền được kiểm soát.
1{2 "mcpServers": {3 "filesystem": {4 "command": "npx",5 "args": ["-y", "@modelcontextprotocol/server-filesystem", "/path/to/allowed/dir"]6 }7 }8}Integrates with GitHub to manage issues, PRs, repositories, and workflows.
Tích hợp với GitHub để quản lý issues, PRs, repositories và workflows.
1{2 "mcpServers": {3 "github": {4 "command": "npx",5 "args": ["-y", "@modelcontextprotocol/server-github"],6 "env": {7 "GITHUB_TOKEN": "ghp_xxxxxxxxxxxx"8 }9 }10 }11}Allows Claude to query PostgreSQL database, view schema, and perform CRUD operations.
Cho phép Claude query database PostgreSQL, xem schema và thực hiện các thao tác CRUD.
1{2 "mcpServers": {3 "postgres": {4 "command": "npx",5 "args": ["-y", "@modelcontextprotocol/server-postgres"],6 "env": {7 "DATABASE_URL": "postgresql://user:pass@localhost:5432/mydb"8 }9 }10 }11}Integrates Slack to read messages, send notifications, and manage channels.
Tích hợp Slack để đọc tin nhắn, gửi thông báo và quản lý channels.
1{2 "mcpServers": {3 "slack": {4 "command": "npx",5 "args": ["-y", "@modelcontextprotocol/server-slack"],6 "env": {7 "SLACK_BOT_TOKEN": "xoxb-xxxxxxxxxxxx"8 }9 }10 }11}MCP servers are configured in Claude Code's settings.json file. You can add multiple servers and Claude will automatically use tools from all configured servers.
MCP servers được cấu hình trong file settings.json của Claude Code. Bạn có thể thêm nhiều server và Claude sẽ tự động sử dụng các tools từ tất cả các server đã cấu hình.
1# Location of settings file:2# macOS/Linux: ~/.claude/settings.json3# Windows: %USERPROFILE%\.claude\settings.json45# Example with multiple servers:6{7 "mcpServers": {8 "filesystem": {9 "command": "npx",10 "args": ["-y", "@modelcontextprotocol/server-filesystem", "."]11 },12 "github": {Bạn có thể sử dụng biến môi trường ($VAR) trong cấu hình để tránh hardcode credentials.
When an MCP server is configured, its tools automatically become available in Claude. You can ask Claude to use them in natural language.
Khi MCP server được cấu hình, các tools của nó sẽ tự động có sẵn trong Claude. Bạn có thể yêu cầu Claude sử dụng chúng bằng ngôn ngữ tự nhiên.
1# With GitHub server configured:2"Create a new issue in the repo for the login bug"34# With PostgreSQL server configured:5"Show me all users who signed up in the last week"67# With Slack server configured:8"Send a message to #dev channel about the deployment"910# Claude will automatically use the appropriate MCP toolsYou can create your own MCP server to integrate with any service. MCP SDK is available for multiple languages.
Bạn có thể tạo MCP server riêng để tích hợp với bất kỳ dịch vụ nào. MCP SDK có sẵn cho nhiều ngôn ngữ.
1// Example: Simple MCP server in TypeScript2import { Server } from "@modelcontextprotocol/sdk/server/index.js";3import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";45const server = new Server({6 name: "my-custom-server",7 version: "1.0.0"8}, {9 capabilities: {10 tools: {}11 }12});When an MCP server has errors, you can debug by viewing logs and testing tools manually.
Khi MCP server gặp lỗi, bạn có thể debug bằng cách xem logs và test tools manually.
1# View MCP server logs2claude --mcp-debug34# Test MCP server directly5npx @modelcontextprotocol/inspector67# List available MCP tools in Claude8/mcp list910# Check MCP server status11/mcp statusKey Takeaways
Điểm Chính
- MCP connects Claude to external data sources and toolsMCP kết nối Claude với nguồn dữ liệu và công cụ bên ngoài
- Servers are configured in ~/.claude/settings.jsonServers được cấu hình trong ~/.claude/settings.json
- Popular servers: filesystem, GitHub, PostgreSQL, SlackServers phổ biến: filesystem, GitHub, PostgreSQL, Slack
- You can create custom MCP servers for any integrationBạn có thể tạo MCP server tùy chỉnh cho bất kỳ tích hợp nào
Practice
Test your understanding of this chapter
What does MCP stand for?
MCP là viết tắt của gì?
MCP servers must be written in JavaScript/TypeScript.
MCP servers phải được viết bằng JavaScript/TypeScript.
Complete the settings.json path for MCP configuration
Hoàn thành đường dẫn settings.json cho cấu hình MCP
~/./settings.json
What components does an MCP server provide?
MCP server cung cấp những thành phần nào?