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 分鐘耐心

步驟詳解

  1. 下載 Claude Desktop

    🌐 Visit: https://claude.ai/download
    📥 Download for your OS
    ⚙️ Install following prompts
  2. 驗證安裝

    • 打開 Claude Desktop
    • 進入設定選單(⚙️)
    • 找到 “Developer” 區域
  3. 添加第一個伺服器

    {
      "mcpServers": {
        "filesystem": {
          "command": "npx",
          "args": [
            "-y",
            "@modelcontextprotocol/server-filesystem",
            "/Users/yourname/Desktop"
          ]
        }
      }
    }
  4. 驗證運行

    • 重啟 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:自行構建(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

實現伺服器(逐步):

  1. 建立基本結構
// 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();
  1. 添加任務儲存
// Simple in-memory storage
let tasks: Array<{id: number, text: string, done: boolean}> = [];
let nextId = 1;
  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}`;
});
  1. 測試伺服器
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

接下來做什麼?

繼續成長

  1. 多做專案:每個專案都是新模式
  2. 加入社群:分享收穫,獲取回饋
  3. 跟進更新:MCP 迭代很快
  4. 教會他人:最強的學習方式

職業方向

  • AI 整合工程師
  • MCP 伺服器開發
  • 企業 AI 架構師
  • 開發者關係(MCP 生態)
🎉
恭喜! 你已完成 MCP 學習路徑,具備構建強大 AI 整合的能力,也能為 AI 與人的協作未來貢獻力量。

📞 需要幫助?

遇到問題? 別擔心,這很正常!