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

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

Access any application, workflows or data via Workato, made accessible for AIMCP servers are programmatically generated

Connect to nearly 8,000 apps through Zapier's automation platformGenerate a user-specific URL at mcp.zapier.com

需要特定集成? 在 GitHub 上找到数百个更多的 MCP 服务器,或使用 MCP SDK 构建您自己的。

安装 MCP 服务器

根据您的需求,MCP 服务器可以通过三种不同的方式配置:

选项 1:添加本地 stdio 服务器

Stdio 服务器作为本地进程在您的机器上运行。它们非常适合需要直接系统访问或自定义脚本的工具。

# 基本语法
claude mcp add <name> <command> [args...]

# 实际示例:添加 Airtable 服务器
claude mcp add airtable --env AIRTABLE_API_KEY=YOUR_KEY \
  -- npx -y airtable-mcp-server

理解 ”—” 参数: --(双破折号)将 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(服务器发送事件)服务器提供实时流连接。许多云服务使用此功能进行实时更新。

# 基本语法
claude mcp add --transport sse <name> <url>

# 实际示例:连接到 Linear
claude mcp add --transport sse linear https://mcp.linear.app/sse

# 带身份验证标头的示例
claude mcp add --transport sse private-api https://api.company.com/mcp \
  --header "X-API-Key: your-key-here"

选项 3:添加远程 HTTP 服务器

HTTP 服务器使用标准的请求/响应模式。大多数 REST API 和 Web 服务使用此传输方式。

# 基本语法
claude mcp add --transport http <name> <url>

# 实际示例:连接到 Notion
claude mcp add --transport http notion https://mcp.notion.com/mcp

# 带 Bearer 令牌的示例
claude mcp add --transport http secure-api https://api.example.com/mcp \
  --header "Authorization: Bearer your-token"

管理您的服务器

配置完成后,您可以使用以下命令管理您的 MCP 服务器:

# 列出所有配置的服务器
claude mcp list

# 获取特定服务器的详细信息
claude mcp get github

# 删除服务器
claude mcp remove github

# (在 Claude Code 中)检查服务器状态
/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 包装器以确保正确执行。

# 这创建了 Windows 可以执行的 command="cmd"
claude mcp add my-server -- cmd /c npx -y @some/package

没有 cmd /c 包装器,您会遇到”连接关闭”错误,因为 Windows 无法直接执行 npx。(有关 -- 参数的解释,请参见上面的注释。)

MCP 安装范围

MCP 服务器可以在三个不同的范围级别配置,每个级别都有不同的目的来管理服务器可访问性和共享。了解这些范围有助于您确定为特定需求配置服务器的最佳方式。

本地范围

本地范围的服务器代表默认配置级别,存储在您的项目特定用户设置中。这些服务器对您保持私有,只有在当前项目目录中工作时才可访问。此范围非常适合个人开发服务器、实验性配置或包含不应共享的敏感凭据的服务器。

# 添加本地范围的服务器(默认)
claude mcp add my-private-server /path/to/server

# 明确指定本地范围
claude mcp add my-private-server --scope local /path/to/server

项目范围

项目范围的服务器通过将配置存储在项目根目录的 .mcp.json 文件中来实现团队协作。此文件设计为检入版本控制,确保所有团队成员都可以访问相同的 MCP 工具和服务。当您添加项目范围的服务器时,Claude Code 会自动创建或更新此文件,使用适当的配置结构。

# 添加项目范围的服务器
claude mcp add shared-server --scope project /path/to/server

生成的 .mcp.json 文件遵循标准化格式:

{
  "mcpServers": {
    "shared-server": {
      "command": "/path/to/server",
      "args": [],
      "env": {}
    }
  }
}

出于安全原因,Claude Code 在使用来自 .mcp.json 文件的项目范围服务器之前会提示批准。如果您需要重置这些批准选择,请使用 claude mcp reset-project-choices 命令。

用户范围

用户范围的服务器提供跨项目可访问性,使它们在您机器上的所有项目中都可用,同时对您的用户帐户保持私有。此范围适用于个人实用程序服务器、开发工具或您在不同项目中经常使用的服务。

# 添加用户服务器
claude mcp add my-user-server --scope user /path/to/server

选择正确的范围

根据以下条件选择您的范围:

  • 本地范围:个人服务器、实验性配置或特定于一个项目的敏感凭据
  • 项目范围:团队共享服务器、项目特定工具或协作所需的服务
  • 用户范围:多个项目需要的个人实用程序、开发工具或经常使用的服务

范围层次结构和优先级

MCP 服务器配置遵循清晰的优先级层次结构。当多个范围中存在同名服务器时,系统通过首先优先考虑本地范围的服务器,然后是项目范围的服务器,最后是用户范围的服务器来解决冲突。这种设计确保个人配置可以在需要时覆盖共享配置。

.mcp.json 中的环境变量扩展

Claude Code 支持在 .mcp.json 文件中进行环境变量扩展,允许团队共享配置,同时保持机器特定路径和 API 密钥等敏感值的灵活性。

支持的语法:

  • ${VAR} - 扩展为环境变量 VAR 的值
  • ${VAR:-default} - 如果设置了 VAR 则扩展为 VAR,否则使用 default

扩展位置: 环境变量可以在以下位置扩展:

  • command - 服务器可执行文件路径
  • args - 命令行参数
  • env - 传递给服务器的环境变量
  • url - 用于 SSE/HTTP 服务器类型
  • headers - 用于 SSE/HTTP 服务器身份验证

带变量扩展的示例:

{
  "mcpServers": {
    "api-server": {
      "type": "sse",
      "url": "${API_BASE_URL:-https://api.example.com}/mcp",
      "headers": {
        "Authorization": "Bearer ${API_KEY}"
      }
    }
  }
}

如果未设置所需的环境变量且没有默认值,Claude Code 将无法解析配置。

实际示例

示例:使用 Sentry 监控错误

# 1. 添加 Sentry MCP 服务器
claude mcp add --transport http sentry https://mcp.sentry.dev/mcp

# 2. 使用 /mcp 与您的 Sentry 帐户进行身份验证
> /mcp

# 3. 调试生产问题
> "过去 24 小时内最常见的错误是什么?"
> "显示错误 ID abc123 的堆栈跟踪"
> "哪个部署引入了这些新错误?"

与远程 MCP 服务器进行身份验证

许多基于云的 MCP 服务器需要身份验证。Claude Code 支持 OAuth 2.0 进行安全连接。

1

添加需要身份验证的服务器

例如:

claude mcp add --transport http sentry https://mcp.sentry.dev/mcp
2

在 Claude Code 中使用 /mcp 命令

在 Claude Code 中,使用命令:

> /mcp

然后按照浏览器中的步骤登录。

提示:

  • 身份验证令牌安全存储并自动刷新
  • /mcp 菜单中使用”清除身份验证”来撤销访问
  • 如果您的浏览器没有自动打开,请复制提供的 URL
  • OAuth 身份验证适用于 SSE 和 HTTP 传输

从 JSON 配置添加 MCP 服务器

如果您有 MCP 服务器的 JSON 配置,可以直接添加:

1

从 JSON 添加 MCP 服务器

# 基本语法
claude mcp add-json <name> '<json>'

# 示例:使用 JSON 配置添加 stdio 服务器
claude mcp add-json weather-api '{"type":"stdio","command":"/path/to/weather-cli","args":["--api-key","abc123"],"env":{"CACHE_DIR":"/tmp"}}'
2

验证服务器已添加

claude mcp get weather-api

提示:

  • 确保 JSON 在您的 shell 中正确转义
  • JSON 必须符合 MCP 服务器配置架构
  • 您可以使用 --scope user 将服务器添加到您的用户配置而不是项目特定配置

从 Claude Desktop 导入 MCP 服务器

如果您已经在 Claude Desktop 中配置了 MCP 服务器,可以导入它们:

1

从 Claude Desktop 导入服务器

# 基本语法 
claude mcp add-from-claude-desktop 
2

选择要导入的服务器

运行命令后,您将看到一个交互式对话框,允许您选择要导入的服务器。

3

验证服务器已导入

claude mcp list 

提示:

  • 此功能仅在 macOS 和 Windows Subsystem for Linux (WSL) 上有效
  • 它从这些平台上的标准位置读取 Claude Desktop 配置文件
  • 使用 --scope user 标志将服务器添加到您的用户配置
  • 导入的服务器将具有与 Claude Desktop 中相同的名称
  • 如果已存在同名服务器,它们将获得数字后缀(例如,server_1

将 Claude Code 用作 MCP 服务器

您可以将 Claude Code 本身用作其他应用程序可以连接的 MCP 服务器:

# 将 Claude 启动为 stdio MCP 服务器
claude mcp serve

您可以通过将此配置添加到 claude_desktop_config.json 在 Claude Desktop 中使用此功能:

{
  "mcpServers": {
    "claude-code": {
      "command": "claude",
      "args": ["mcp", "serve"],
      "env": {}
    }
  }
}

提示:

  • 服务器提供对 Claude 工具的访问,如 View、Edit、LS 等。
  • 在 Claude Desktop 中,尝试要求 Claude 读取目录中的文件、进行编辑等。
  • 请注意,此 MCP 服务器只是将 Claude Code 的工具暴露给您的 MCP 客户端,因此您自己的客户端负责为各个工具调用实现用户确认。

使用 MCP 资源

MCP 服务器可以公开资源,您可以使用 @ 提及来引用这些资源,类似于引用文件的方式。

引用 MCP 资源

1

列出可用资源

在您的提示中键入 @ 以查看所有连接的 MCP 服务器的可用资源。资源与文件一起出现在自动完成菜单中。

2

引用特定资源

使用格式 @server:protocol://resource/path 引用资源:

> 您能分析 @github:issue://123 并建议修复吗?
> 请查看 @docs:file://api/authentication 的 API 文档
3

多个资源引用

您可以在单个提示中引用多个资源:

> 比较 @postgres:schema://users 与 @docs:file://database/user-model

提示:

  • 引用时资源会自动获取并作为附件包含
  • 资源路径在 @ 提及自动完成中可进行模糊搜索
  • 当服务器支持时,Claude Code 会自动提供列出和读取 MCP 资源的工具
  • 资源可以包含 MCP 服务器提供的任何类型的内容(文本、JSON、结构化数据等)

将 MCP 提示用作斜杠命令

MCP 服务器可以公开提示,这些提示在 Claude Code 中作为斜杠命令可用。

执行 MCP 提示

1

发现可用提示

键入 / 查看所有可用命令,包括来自 MCP 服务器的命令。MCP 提示以格式 /mcp__servername__promptname 出现。

2

执行不带参数的提示

> /mcp__github__list_prs
3

执行带参数的提示

许多提示接受参数。在命令后用空格分隔传递它们:

> /mcp__github__pr_review 456
> /mcp__jira__create_issue "登录流程中的错误" high

提示:

  • MCP 提示从连接的服务器动态发现
  • 参数根据提示定义的参数进行解析
  • 提示结果直接注入到对话中
  • 服务器和提示名称已标准化(空格变为下划线)