Claude Code 101 系列教程 · 第 8 课
2026-05-20
Claude Code 101 系列教程 · 第 8 课 · 来自 Claude 官方频道
MCP(Model Context Protocol) 是一个开源标准,让 Claude Code 能够连接外部工具和数据源。
没有 MCP,你需要手动把其他工具的数据复制粘贴到聊天中。有了 MCP,Claude Code 可以直接读取和操作这些系统:
核心思路: 如果你发现自己总是在某个工具和 Claude Code 之间复制粘贴,那就是该加一个 MCP Server 的时候了。
适合云端服务,最广泛支持的传输方式:
claude mcp add --transport http notion https://mcp.notion.com/mcp旧版远程协议,逐步被 HTTP 取代:
claude mcp add --transport sse asana https://mcp.asana.com/sse适合需要直接系统访问或自定义脚本的场景:
claude mcp add --transport stdio db \
-- npx -y @bytebase/dbhub \
--dsn "postgresql://readonly:pass@localhost:5432/mydb"| 作用域 | 加载范围 | 团队共享 | 存储位置 |
|---|---|---|---|
| Local(默认) | 仅当前项目 | 否 | ~/.claude.json |
| Project | 仅当前项目 | 是(通过版本控制) | 项目根目录 .mcp.json |
| User | 你的所有项目 | 否 | ~/.claude.json |
# 项目级(提交到版本控制,团队共享)
claude mcp add --transport http github --scope project \
https://api.githubcopilot.com/mcp/
# 用户级(跨项目可用,个人私有)
claude mcp add --transport http hubspot --scope user \
https://mcp.hubspot.com/anthropicLocal > Project > User > Plugin > Claude.ai Connectors
claude mcp list # 列出所有已配置的 server
claude mcp get github # 查看某个 server 的详情
claude mcp remove github # 移除 server在 Claude Code 内部运行 /mcp
可以查看所有 server 的连接状态和工具数量。
claude mcp add --transport http github \
https://api.githubcopilot.com/mcp/ \
--header "Authorization: Bearer YOUR_GITHUB_PAT"连接后你可以直接说:
Review PR #456 and suggest improvements
Create a new issue for the bug we just found
claude mcp add --transport http sentry https://mcp.sentry.dev/mcp然后:
What are the most common errors in the last 24 hours?
Show me the stack trace for error ID abc123
claude mcp add --transport stdio db \
-- npx -y @bytebase/dbhub \
--dsn "postgresql://user:pass@host:5432/analytics"然后:
What's our total revenue this month?
Show me the schema for the orders table
MCP Server 默认采用 Tool Search(工具搜索) 机制:
这意味着你可以添加很多 MCP Server,而不必担心上下文窗口被占满。
如果你已经在 Claude Desktop 中配置了 MCP Server,可以一键导入:
claude mcp add-from-claude-desktop/mcp 命令查看连接状态本教程基于 Claude 官方视频 MCP in Claude Code 整理,属于 Claude Code 101 系列第 8 课。