透過 MCP 將 Claude Code 連接到工具
學習如何使用 Model Context Protocol 將 Claude Code 連接到您的工具。
Claude Code 可以透過 Model Context Protocol (MCP) 連接到數百個外部工具和資料來源,這是一個用於 AI 工具整合的開源標準。MCP 伺服器讓 Claude Code 能夠存取您的工具、資料庫和 API。
您可以使用 MCP 做什麼
連接 MCP 伺服器後,您可以要求 Claude Code:
- 從問題追蹤器實作功能:“新增 JIRA 問題 ENG-4521 中描述的功能,並在 GitHub 上建立 PR。”
- 分析監控資料:“檢查 Sentry 和 Statsig 來查看 ENG-4521 中描述功能的使用情況。”
- 查詢資料庫:“根據我們的 Postgres 資料庫,找出 10 個使用過 ENG-4521 功能的隨機使用者的電子郵件。”
- 整合設計:“根據在 Slack 中發布的新 Figma 設計更新我們的標準電子郵件範本”
- 自動化工作流程:“建立 Gmail 草稿,邀請這 10 位使用者參加關於新功能的回饋會議。“
熱門 MCP 伺服器
以下是一些您可以連接到 Claude Code 的常用 MCP 伺服器:
使用第三方 MCP 伺服器需自行承擔風險 - Anthropic 未驗證 所有這些伺服器的正確性或安全性。 請確保您信任正在安裝的 MCP 伺服器。 使用可能獲取不受信任內容的 MCP 伺服器時要特別小心, 因為這些可能會讓您面臨提示注入風險。
Development & Testing Tools
Monitor errors, debug production issues
Command
claude mcp add --transport http sentry https://mcp.sentry.dev/mcp
Security analysis for dependencies
Command
claude mcp add --transport http socket https://mcp.socket.dev/
Provides access to Hugging Face Hub information and Gradio AI Applications
Command
claude mcp add --transport http hugging-face https://huggingface.co/mcp
Debug faster with AI agents that can access Jam recordings like video, console logs, network requests, and errors
Command
claude mcp add --transport http jam https://mcp.jam.dev/mcp
Project Management & Documentation
Interact with your Asana workspace to keep projects on track
Command
claude mcp add --transport sse asana https://mcp.asana.com/sse
Manage your Jira tickets and Confluence docs
Command
claude mcp add --transport sse atlassian https://mcp.atlassian.com/v1/sse
Task management, project tracking
Command
claude mcp add clickup --env CLICKUP_API_KEY=YOUR_KEY --env CLICKUP_TEAM_ID=YOUR_ID -- npx -y @hauptsache.net/clickup-mcp
Access real-time customer conversations, tickets, and user data
Command
claude mcp add --transport http intercom https://mcp.intercom.com/mcp
Integrate with Linear's issue tracking and project management
Command
claude mcp add --transport sse linear https://mcp.linear.app/sse
Read docs, update pages, manage tasks
Command
claude mcp add --transport http notion https://mcp.notion.com/mcp
Ask questions about your enterprise content, get insights from unstructured data, automate content workflows
Command
claude mcp add --transport http box https://mcp.box.com/
Extract valuable insights from meeting transcripts and summaries
Command
claude mcp add --transport http fireflies https://api.fireflies.ai/mcp
Manage monday.com boards by creating items, updating columns, assigning owners, setting timelines, adding CRM activities, and writing summaries
Command
claude mcp add --transport sse monday https://mcp.monday.com/sse
Databases & Data Management
Read/write records, manage bases and tables
Command
claude mcp add airtable --env AIRTABLE_API_KEY=YOUR_KEY -- npx -y airtable-mcp-server
Supplies high quality fundamental financial data sourced from SEC Filings, investor presentations
Command
claude mcp add --transport http daloopa https://mcp.daloopa.com/server/mcp
Access and manage HubSpot CRM data by fetching contacts, companies, and deals, and creating and updating records
Command
claude mcp add --transport http hubspot https://mcp.hubspot.com/anthropic
Payments & Commerce
Integrate PayPal commerce capabilities, payment processing, transaction management
Command
claude mcp add --transport http paypal https://mcp.paypal.com/mcp
Analyze, troubleshoot, and optimize Plaid integrations. Banking data, financial account linking
Command
claude mcp add --transport sse plaid https://api.dashboard.plaid.com/mcp/sse
Use an agent to build on Square APIs. Payments, inventory, orders, and more
Command
claude mcp add --transport sse square https://mcp.squareup.com/sse
Payment processing, subscription management, and financial transactions
Command
claude mcp add --transport http stripe https://mcp.stripe.com
Design & Media
Access designs, export assetsRequires latest Figma Desktop with Dev Mode MCP Server. If you have an existing server at http://127.0.0.1:3845/sse, delete it first before adding the new one.
Command
claude mcp add --transport http figma-dev-mode-mcp-server http://127.0.0.1:3845/mcp
Upload, manage, transform, and analyze your media assets
Command
claude mcp add --transport http cloudinary https://mcp.cloudinary.com/mcp
Build video creation capabilities into your applications
Command
claude mcp add --transport sse invideo https://mcp.invideo.io/sse
Browse, summarize, autofill, and even generate new Canva designs directly from Claude
Command
claude mcp add --transport http canva https://mcp.canva.com/mcp
Infrastructure & DevOps
Build applications, analyze traffic, monitor performance, and manage security settings through CloudflareMultiple services available. See documentation for specific server URLs. Claude Code can use the Cloudflare CLI if installed.
Create, deploy, and manage websites on Netlify. Control all aspects of your site from creating secrets to enforcing access controls to aggregating form submissions
Command
claude mcp add --transport http netlify https://netlify-mcp.netlify.app/mcp
Configure and manage Stytch authentication services, redirect URLs, email templates, and workspace settings
Command
claude mcp add --transport http stytch http://mcp.stytch.dev/mcp
Vercel's official MCP server, allowing you to search and navigate documentation, manage projects and deployments, and analyze deployment logs—all in one place
Command
claude mcp add --transport http vercel https://mcp.vercel.com/
Automation & Integration
需要特定整合? 在 GitHub 上找到數百個更多的 MCP 伺服器,或使用 MCP SDK 建立您自己的。
安裝 MCP 伺服器
根據您的需求,MCP 伺服器可以透過三種不同的方式進行配置:
選項 1:新增本地 stdio 伺服器
Stdio 伺服器作為您機器上的本地程序運行。它們非常適合需要直接系統存取或自訂腳本的工具。
理解 ”—” 參數:
--
(雙破折號)將 Claude 自己的 CLI 標誌與傳遞給 MCP 伺服器的命令和參數分開。--
之前的所有內容都是 Claude 的選項(如 --env
、--scope
),--
之後的所有內容都是運行 MCP 伺服器的實際命令。
例如:
claude mcp add myserver -- npx server
→ 運行npx server
claude mcp add myserver --env KEY=value -- python server.py --port 8080
→ 在環境中使用KEY=value
運行python server.py --port 8080
這可以防止 Claude 的標誌與伺服器標誌之間的衝突。
選項 2:新增遠端 SSE 伺服器
SSE(Server-Sent Events)伺服器提供即時串流連接。許多雲端服務使用此方式進行即時更新。
選項 3:新增遠端 HTTP 伺服器
HTTP 伺服器使用標準的請求/回應模式。大多數 REST API 和網路服務使用此傳輸方式。
管理您的伺服器
配置完成後,您可以使用這些命令管理您的 MCP 伺服器:
提示:
- 使用
--scope
標誌指定配置儲存位置:local
(預設):僅在目前專案中對您可用(在舊版本中稱為project
)project
:透過.mcp.json
檔案與專案中的每個人共享user
:在所有專案中對您可用(在舊版本中稱為global
)
- 使用
--env
標誌設定環境變數(例如,--env KEY=value
) - 使用 MCP_TIMEOUT 環境變數配置 MCP 伺服器啟動逾時(例如,
MCP_TIMEOUT=10000 claude
設定 10 秒逾時) - 使用
/mcp
與需要 OAuth 2.0 身份驗證的遠端伺服器進行身份驗證
Windows 使用者:在原生 Windows(非 WSL)上,使用 npx
的本地 MCP 伺服器需要 cmd /c
包裝器以確保正確執行。
沒有 cmd /c
包裝器,您會遇到「連接已關閉」錯誤,因為 Windows 無法直接執行 npx
。(請參閱上面關於 --
參數的說明。)
MCP 安裝範圍
MCP 伺服器可以在三個不同的範圍層級進行配置,每個層級都有不同的目的來管理伺服器可存取性和共享。了解這些範圍有助於您確定為特定需求配置伺服器的最佳方式。
本地範圍
本地範圍的伺服器代表預設配置層級,儲存在您的專案特定使用者設定中。這些伺服器對您保持私有,只有在目前專案目錄中工作時才能存取。此範圍非常適合個人開發伺服器、實驗性配置或包含不應共享的敏感憑證的伺服器。
專案範圍
專案範圍的伺服器透過在專案根目錄中儲存配置到 .mcp.json
檔案來實現團隊協作。此檔案設計為檢入版本控制,確保所有團隊成員都能存取相同的 MCP 工具和服務。當您新增專案範圍的伺服器時,Claude Code 會自動建立或更新此檔案,使用適當的配置結構。
產生的 .mcp.json
檔案遵循標準化格式:
基於安全原因,Claude Code 在使用來自 .mcp.json
檔案的專案範圍伺服器之前會提示批准。如果您需要重設這些批准選擇,請使用 claude mcp reset-project-choices
命令。
使用者範圍
使用者範圍的伺服器提供跨專案可存取性,使它們在您機器上的所有專案中都可用,同時對您的使用者帳戶保持私有。此範圍適用於個人實用程式伺服器、開發工具或您在不同專案中經常使用的服務。
選擇正確的範圍
根據以下條件選擇您的範圍:
- 本地範圍:個人伺服器、實驗性配置或特定於一個專案的敏感憑證
- 專案範圍:團隊共享伺服器、專案特定工具或協作所需的服務
- 使用者範圍:跨多個專案需要的個人實用程式、開發工具或經常使用的服務
範圍階層和優先順序
MCP 伺服器配置遵循清晰的優先順序階層。當相同名稱的伺服器存在於多個範圍時,系統透過首先優先考慮本地範圍伺服器,然後是專案範圍伺服器,最後是使用者範圍伺服器來解決衝突。這種設計確保個人配置可以在需要時覆蓋共享配置。
.mcp.json
中的環境變數展開
Claude Code 支援在 .mcp.json
檔案中進行環境變數展開,允許團隊共享配置,同時為機器特定路徑和 API 金鑰等敏感值保持靈活性。
支援的語法:
${VAR}
- 展開為環境變數VAR
的值${VAR:-default}
- 如果設定了VAR
則展開為VAR
,否則使用default
展開位置: 環境變數可以在以下位置展開:
command
- 伺服器可執行檔路徑args
- 命令列參數env
- 傳遞給伺服器的環境變數url
- 用於 SSE/HTTP 伺服器類型headers
- 用於 SSE/HTTP 伺服器身份驗證
帶有變數展開的範例:
如果未設定必需的環境變數且沒有預設值,Claude Code 將無法解析配置。
實際範例
範例:使用 Sentry 監控錯誤
與遠端 MCP 伺服器進行身份驗證
許多基於雲端的 MCP 伺服器需要身份驗證。Claude Code 支援 OAuth 2.0 以進行安全連接。
新增需要身份驗證的伺服器
例如:
在 Claude Code 內使用 /mcp 命令
在 Claude code 中,使用命令:
然後按照瀏覽器中的步驟進行登入。
提示:
- 身份驗證權杖會安全儲存並自動刷新
- 在
/mcp
選單中使用「清除身份驗證」來撤銷存取權限 - 如果您的瀏覽器沒有自動開啟,請複製提供的 URL
- OAuth 身份驗證適用於 SSE 和 HTTP 傳輸
從 JSON 配置新增 MCP 伺服器
如果您有 MCP 伺服器的 JSON 配置,您可以直接新增它:
從 JSON 新增 MCP 伺服器
驗證伺服器已新增
提示:
- 確保 JSON 在您的 shell 中正確轉義
- JSON 必須符合 MCP 伺服器配置架構
- 您可以使用
--scope user
將伺服器新增到您的使用者配置而不是專案特定配置
從 Claude Desktop 匯入 MCP 伺服器
如果您已經在 Claude Desktop 中配置了 MCP 伺服器,您可以匯入它們:
從 Claude Desktop 匯入伺服器
選擇要匯入的伺服器
運行命令後,您會看到一個互動式對話框,允許您選擇要匯入的伺服器。
驗證伺服器已匯入
提示:
- 此功能僅在 macOS 和 Windows Subsystem for Linux (WSL) 上運作
- 它從這些平台上的標準位置讀取 Claude Desktop 配置檔案
- 使用
--scope user
標誌將伺服器新增到您的使用者配置 - 匯入的伺服器將具有與 Claude Desktop 中相同的名稱
- 如果已存在相同名稱的伺服器,它們將獲得數字後綴(例如,
server_1
)
將 Claude Code 用作 MCP 伺服器
您可以將 Claude Code 本身用作其他應用程式可以連接的 MCP 伺服器:
您可以透過將此配置新增到 claude_desktop_config.json 在 Claude Desktop 中使用此功能:
提示:
- 伺服器提供對 Claude 工具的存取,如 View、Edit、LS 等。
- 在 Claude Desktop 中,嘗試要求 Claude 讀取目錄中的檔案、進行編輯等。
- 請注意,此 MCP 伺服器只是將 Claude Code 的工具暴露給您的 MCP 客戶端,因此您自己的客戶端負責為個別工具呼叫實作使用者確認。
使用 MCP 資源
MCP 伺服器可以暴露您可以使用 @ 提及引用的資源,類似於您引用檔案的方式。
引用 MCP 資源
列出可用資源
在您的提示中輸入 @
以查看來自所有連接的 MCP 伺服器的可用資源。資源與檔案一起出現在自動完成選單中。
引用特定資源
使用格式 @server:protocol://resource/path
來引用資源:
多個資源引用
您可以在單個提示中引用多個資源:
提示:
- 引用時資源會自動獲取並作為附件包含
- 資源路徑在 @ 提及自動完成中可進行模糊搜尋
- 當伺服器支援時,Claude Code 會自動提供工具來列出和讀取 MCP 資源
- 資源可以包含 MCP 伺服器提供的任何類型內容(文字、JSON、結構化資料等)
將 MCP 提示用作斜線命令
MCP 伺服器可以暴露提示,這些提示在 Claude Code 中成為可用的斜線命令。
執行 MCP 提示
發現可用提示
輸入 /
以查看所有可用命令,包括來自 MCP 伺服器的命令。MCP 提示以格式 /mcp__servername__promptname
出現。
執行不帶參數的提示
執行帶參數的提示
許多提示接受參數。在命令後以空格分隔傳遞它們:
提示:
- MCP 提示從連接的伺服器動態發現
- 參數根據提示定義的參數進行解析
- 提示結果直接注入到對話中
- 伺服器和提示名稱會正規化(空格變成底線)