MCP 学习路径:从零基础到精通
MCP 学习路径:从零基础到精通
本学习路径面向零基础读者,帮助你一步步系统掌握 MCP。无需任何 AI 或协议背景!
🎯
学习目标:完成本路径后,你将理解 MCP 核心概念,会使用现成服务器,并能构建自己的定制集成。
🗺️ 学习路径总览
flowchart TD
A["🎓 阶段1:理解<br/>(1-2 小时)"] --> B["🔧 阶段2:使用<br/>(2-3 小时)"]
B --> C["👨💻 阶段3:构建<br/>(4-6 小时)"]
C --> D["🚀 阶段4:精通<br/>(持续)"]
A --> A1["什么是 MCP?"]
A --> A2["为什么重要?"]
A --> A3["关键概念"]
B --> B1["安装 Claude Desktop"]
B --> B2["连接第一个服务器"]
B --> B3["探索服务器库"]
C --> C1["构建简单服务器"]
C --> C2["添加自定义工具"]
C --> C3["处理真实数据"]
D --> D1["生产部署"]
D --> D2["高级模式"]
D --> D3["社区贡献"]
🎓 阶段 1:理解 MCP(1-2 小时)
步骤 1.1:什么是 MCP?(15 分钟)
目标:用非技术化语言理解基本概念。
把 MCP 想象成这样:
- 传统 AI:像把聪明人关在没有网络和工具的房间里
- 启用 MCP 的 AI:给 TA 一个能操控你数字生活的万能遥控器
现实类比:
🏠 Your House (Data & Tools)
├── 📁 Files and documents
├── 💾 Databases
├── 🌐 Web services
├── 📧 Email systems
└── 🔧 Various tools
🎮 MCP = Universal Remote
├── 🔌 Connects to everything
├── 🔒 Secure access control
├── 📋 Standardized interface
└── 🔄 Works with any AI✅ 自检:
- 能否用一句话向朋友解释 MCP?
- 是否理解 AI 为何需要外部连接?
步骤 1.2:为什么 MCP 很重要(20 分钟)
目标:看到全局与实际收益。
没有 MCP 之前(问题):
flowchart LR
AI1["AI App 1"] -.-> |custom code| DB[("Database")]
AI2["AI App 2"] -.-> |different code| DB
AI3["AI App 3"] -.-> |another way| DB
AI1 -.-> |custom API| WEB[("Web Service")]
AI2 -.-> |different API| WEB
AI3 -.-> |yet another way| WEB
问题:杂乱、不安全、难维护、厂商锁定
引入 MCP 之后(解决方案):
flowchart LR
AI1["AI App 1"] --> MCP["🎮 MCP Server"]
AI2["AI App 2"] --> MCP
AI3["AI App 3"] --> MCP
MCP --> DB[("Database")]
MCP --> WEB[("Web Service")]
MCP --> FILES[("Files")]
收益:清晰、安全、可复用、可演进
✅ 自检:
- 能否列出 MCP 解决的 3 个问题?
- 能否想到与你工作相关的用例?
步骤 1.3:关键概念(25 分钟)
目标:掌握核心术语。
MCP 家族:
🏠 MCP Host (Claude Desktop)
├── The "brain" that makes requests
├── Examples: Claude, IDEs, custom apps
└── Talks to servers through MCP protocol
🔧 MCP Server (The Helper)
├── Provides specific capabilities
├── Examples: file access, database queries, web search
└── Responds to host requests
📡 MCP Protocol (The Language)
├── How hosts and servers communicate
├── Standardized message format
└── Like HTTP for AI integrations核心能力:
- 🛠️ 工具(Tools):AI 可执行的动作(读文件、发邮件等)
- 📚 资源(Resources):AI 可访问的数据(文档、数据库记录等)
- 💭 提示(Prompts):面向任务的预置指令
- 🤖 采样(Sampling):允许服务器请求模型补全
✅ 自检:
- 能否区分 Host 与 Server?
- 是否理解 Tools 与 Resources?
🔧 阶段 2:使用 MCP(2-3 小时)
步骤 2.1:搭建首次体验(30 分钟)
目标:让 Claude Desktop 与 MCP 服务器协同工作。
准备清单:
- 电脑(Windows/Mac)
- 网络连接
- 15 分钟耐心
步骤详解:
下载 Claude Desktop
🌐 Visit: https://claude.ai/download 📥 Download for your OS ⚙️ Install following prompts验证安装
- 打开 Claude Desktop
- 进入设置菜单(⚙️)
- 找到 “Developer” 区域
添加第一个服务器
{ "mcpServers": { "filesystem": { "command": "npx", "args": [ "-y", "@modelcontextprotocol/server-filesystem", "/Users/yourname/Desktop" ] } } }验证运行
- 重启 Claude Desktop
- 在对话中查看锤子图标(🔨)
- 试问:“列出我桌面的文件?”
✅ 成功标志:
- 对话里出现锤子图标
- 能列出桌面文件
- 你开始对可能性兴奋!
步骤 2.2:探索不同服务器类型(45 分钟)
目标:尝试多种服务器,理解 MCP 的多样性。
服务器自助(任选 2-3 个):
🗂️ 文件管理:
"filesystem": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-filesystem", "/path/to/safe/folder"]
}试试:“创建购物清单文件”、“整理我的下载文件夹”
🔍 网络搜索:
"brave-search": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-brave-search"],
"env": {"BRAVE_API_KEY": "your-api-key"}
}试试:“搜索 MCP 教程”、“查找近期 AI 新闻”
🧠 记忆:
"memory": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-memory"]
}试试:“记住我偏好 Python”、“你记得我的哪些偏好?”
✅ 探索目标:
- 至少尝试 2 种类型
- 关注各自带来的能力差异
- 思考你想构建什么
步骤 2.3:深入服务器库(45 分钟)
目标:理解生态并找到适配需求的服务器。
官方服务器分类:
📊 数据与分析:
- PostgreSQL, SQLite:数据库访问
- Memory:持久化 AI 记忆
- 用例:“分析我的销售数据”、“记住客户偏好”
🔧 开发者工具:
- GitHub, Git:代码仓库访问
- Sentry:错误监控
- 用例:“查看最近提交”、“检查生产错误”
🌐 网络与通信:
- Slack:团队消息
- Fetch:网页抓取
- 用例:“发送团队更新”、“监控竞品网站”
🎨 创意与专业:
- EverArt:AI 图像生成
- Sequential Thinking:复杂推理
- 用例:“创建营销图片”、“解决多步问题”
✅ 发现练习:
- 浏览完整服务器列表
- 选择你感兴趣的 3 个
- 想象在工作中的用法
👨💻 阶段 3:自行构建(4-6 小时)
步骤 3.1:第一个自定义服务器(90 分钟)
目标:从零构建一个简单但可用的 MCP 服务器。
项目:个人任务管理服务器
功能清单:
- 添加任务到列表
- 标记任务完成
- 列出所有任务
- 清理已完成任务
环境准备:
# Create project folder
mkdir my-first-mcp-server
cd my-first-mcp-server
# Initialize Node.js project
npm init -y
# Install MCP SDK
npm install @modelcontextprotocol/sdk-typescript实现服务器(逐步):
- 创建基本结构:
// server.ts
import { Server } from '@modelcontextprotocol/sdk-typescript';
const server = new Server({
name: 'personal-tasks',
version: '1.0.0'
});
// We'll add functionality here
server.start();- 添加任务存储:
// Simple in-memory storage
let tasks: Array<{id: number, text: string, done: boolean}> = [];
let nextId = 1;- 添加第一个工具:
server.tool('add-task', 'Add a new task', {
text: { type: 'string', description: 'Task description' }
}, async (args) => {
const task = {
id: nextId++,
text: args.text,
done: false
};
tasks.push(task);
return `Added task: ${task.text}`;
});- 测试服务器:
npx tsx server.ts✅ 里程碑自检:
- 无错误启动
- 可通过 Claude 添加任务
- 产生成就感!
步骤 3.2:扩展功能(90 分钟)
目标:增强服务器的能力。
增加更多工具:
// List all tasks
server.tool('list-tasks', 'Show all tasks', {}, async () => {
if (tasks.length === 0) return 'No tasks yet!';
return tasks.map(t =>
`${t.id}. [${t.done ? '✅' : '⭐'}] ${t.text}`
).join('\n');
});
// Complete a task
server.tool('complete-task', 'Mark task as done', {
id: { type: 'number', description: 'Task ID' }
}, async (args) => {
const task = tasks.find(t => t.id === args.id);
if (!task) return 'Task not found!';
task.done = true;
return `Completed: ${task.text}`;
});
// Clear completed tasks
server.tool('clear-completed', 'Remove all completed tasks', {}, async () => {
const completedCount = tasks.filter(t => t.done).length;
tasks = tasks.filter(t => !t.done);
return `Cleared ${completedCount} completed tasks`;
});添加持久化存储:
import fs from 'fs';
const TASKS_FILE = 'tasks.json';
// Load tasks on startup
function loadTasks() {
try {
const data = fs.readFileSync(TASKS_FILE, 'utf8');
tasks = JSON.parse(data);
nextId = Math.max(...tasks.map(t => t.id), 0) + 1;
} catch {
tasks = [];
nextId = 1;
}
}
// Save tasks after changes
function saveTasks() {
fs.writeFileSync(TASKS_FILE, JSON.stringify(tasks, null, 2));
}✅ 增强目标:
- 所有 CRUD 操作正常
- 任务可持久化
- 错误处理优雅
步骤 3.3:接入真实场景(120 分钟)
目标:连接真实数据/服务。
三选一:
选项 A:基于文件的笔记
// Add note-taking capability
server.tool('save-note', 'Save a note to file', {
title: { type: 'string' },
content: { type: 'string' }
}, async (args) => {
const filename = `notes/${args.title.replace(/\s+/g, '-')}.md`;
fs.writeFileSync(filename, args.content);
return `Note saved: ${filename}`;
});选项 B:API 集成
// Weather integration example
server.tool('get-weather', 'Get current weather', {
city: { type: 'string' }
}, async (args) => {
const response = await fetch(
`https://api.openweathermap.org/data/2.5/weather?q=${args.city}&appid=${API_KEY}`
);
const data = await response.json();
return `Weather in ${args.city}: ${data.weather[0].description}`;
});选项 C:数据库连接
import sqlite3 from 'sqlite3';
// Simple database integration
server.tool('query-db', 'Query database', {
query: { type: 'string' }
}, async (args) => {
return new Promise((resolve, reject) => {
db.all(args.query, (err, rows) => {
if (err) reject(err);
else resolve(JSON.stringify(rows, null, 2));
});
});
});✅ 集成成功:
- 能连接外部数据/服务
- 具备网络错误处理
- 直观感受 MCP 价值!
🚀 阶段 4:持续进阶(长期)
可深入主题
🏗️ 生产部署:
- Docker 容器化
- 环境配置
- 监控与日志
- 安全最佳实践
🔧 高级模式:
- 资源流式传输
- 批量操作
- 自定义传输层
- 协议扩展
🌟 社区贡献:
- 开源你的服务器
- 参与 MCP 生态
- 帮助其他学习者
- 分享你的实践
持续学习资源
📚 深入文档:
🤝 社区参与:
🎯 学习路径完成
自评清单
阶段 1 - 理解 ✅
- 能用通俗语言解释 MCP
- 理解其价值点
- 掌握关键术语
阶段 2 - 使用 ✅
- 搭好 Claude Desktop + MCP
- 体验多种服务器
- 能发现并评估新服务器
阶段 3 - 构建 ✅
- 构建自定义服务器
- 添加多种工具与能力
- 接入真实数据/服务
阶段 4 - 精通 🚀
- 理解生产级考量
- 积极参与社区
- 帮助他人学习 MCP
接下来做什么?
继续成长:
- 多做项目:每个项目都是新模式
- 加入社区:分享收获,获取反馈
- 跟进更新:MCP 迭代很快
- 教会他人:最强的学习方式
职业方向:
- AI 集成工程师
- MCP 服务器开发
- 企业 AI 架构师
- 开发者关系(MCP 生态)
🎉
恭喜! 你已完成 MCP 学习路径,具备构建强大 AI 集成的能力,也能为 AI 与人的协作未来贡献力量。
📞 需要帮助?
遇到问题? 别担心,这很正常!