在Claude Code使用MCP功能

MCP 為什麼重要

現有的 LLM 模型像 GPT-4 或 Claude 雖然很強,但常見限制包括:

  • 無法即時查資料(知識截止)
  • 無法串接你用的工具(ERP、CI/CD)
  • 整合要自己 hardcode,沒標準

MCP 正是為了解決這些問題:

問題MCP 解法
AI 不能接 CRM 或 APIMCP 伺服器公開標準工具讓 AI 使用
每個模型都要客製整合MCP 是「AI 世界的 USB-C」
整合效率低用標準協議連接,不再重寫 glue code
缺乏即時專業資料MCP Server 可串接資料庫或第三方 API

MCP 架構核心概念

MCP 架構中有三個主要角色:

元件說明
Host(大腦)AI 模型平台(如 Claude、GitHub Copilot)
Server提供功能的 MCP Server(如 Firecrawl、Notion)
Client負責與 Server 溝通的代理程式

支援兩種通訊協定:

  • stdio:用於本地執行程式
  • http + SSE:用於網路 API、第三方系統

精選 MCP Server 實例

名稱功能備註
Firecrawl網站爬蟲支援 JSON、Markdown 回傳
Notion MCP讀寫 Notion database適合做知識庫整合
Perplexity Ask接入 Sonar API 問答、研究需要 API 金鑰
Time MCP查詢世界時間適合簡單 demo
Playwright MCP幫你操控瀏覽器、截圖、資料擷取自動化超強!

配置 MCP 伺服器

添加 MCP stdio 伺服器

# Basic syntax
claude mcp add <name> <command> [args...]

# Example: Adding a local server
claude mcp add my-server -e API_KEY=123 -- /path/to/server arg1 arg2
# This creates: command="/path/to/server", args=["arg1", "arg2"]

添加 MCP SSE 伺服器

# Basic syntax
claude mcp add --transport sse <name> <url>

# Example: Adding an SSE server
claude mcp add --transport sse sse-server https://example.com/sse-endpoint

# Example: Adding an SSE server with custom headers
claude mcp add --transport sse api-server https://api.example.com/mcp --header "X-API-Key: your-key"

添加 MCP HTTP 伺服器

# Basic syntax
claude mcp add --transport http <name> <url>

# Example: Adding a streamable HTTP server
claude mcp add --transport http http-server https://example.com/mcp

# Example: Adding an HTTP server with authentication header
claude mcp add --transport http secure-server https://api.example.com/mcp --header "Authorization: Bearer your-token"

管理您的 MCP 伺服器

# List all configured servers
claude mcp list

# Get details for a specific server
claude mcp get my-server

# Remove a server
claude mcp remove my-server

在Claude Code新增Firecrawl的功能

在本機 Windows(非 WSL)上,使用 npx 的本地 MCP 伺服器需要 cmd /c 包裝器來確保正確執行。

https://github.com/mendableai/firecrawl-mcp-server

安裝方式

1. 到https://www.firecrawl.dev/app/api-keys申請API KEY

2. 設定環境變數FIRECRAWL_API_KEY,值為剛剛申請的API KEY

3. 安裝firecrawl-mcp

    npm install -g firecrawl-mcp
    

    4. 設定MCP

    claude mcp add firecrawl-mcp -- cmd /c npx -y firecrawl-mcp
    

    5. 確認有連接上

    claude mcp list
    

    出現Connected代表成功連接

    接著就可以打開Claude Code使用firecrawl來抓取網頁了!