📘 第 9 课:MCP(模型上下文协议)
官方课程名:MCP(Curriculum 第二段「Teaching your Agent」末课;下一课进入 Context management) 官方地址:
https://anthropic.skilljar.com/claude-platform-101归档路径:Claudeexams/20-课程/课程003 the AI Platform 101/针对认证:CCAR-P(架构师 Professional) 归档日期:2026-10-14 ⚠️ 语料来源:官方 Skilljar 课程正文(用户提供,需登录)。CC BY-NC-SA 4.0,仅供个人学习。⭐⭐ 本课权重提示:领域 3(19%)的选型正名课。CCAR-P 考纲明写要在 MCP / API-CLI / agent-to-agent 之间做集成选型——本课就是那个 MCP 在平台侧的落地讲。核心判据一句话:谁维护集成代码(who maintains the integration code)。同时命中领域 5(14%)(工具过滤=最小特权、read-only 模式)与领域 2(13%)(工具定义占上下文,所以要 scope down)。 🔗 三课合成完整集成图谱:第 7 课工具三分法管 what(custom/server/client)→ 第 8 课 Skills 管 how(规程)→ 本课 MCP 管 whose(谁的集成谁维护)。
🎯 本课学习目标
⚠️ 本课官方未提供
What you'll learn区块。以下按文稿结构反推:
- ⭐⭐ 能回答「已有 tools / skills / connectors,为什么还要 MCP」——判据是集成代码由谁维护。
- ⭐⭐ 能背出三分法判别句:tools for your stuff, skills for your processes, MCP for everyone else's stuff。
- ⭐⭐ 能写出 / 读懂 MCP 连接两件套:
mcp_servers(声明连接)+mcp_toolset(授予工具集)。 - ⭐ 能讲清introspect 机制:不写一个 schema,AI 自己探测服务器拿工具清单。
- ⭐⭐ 能用
default_config+configs做工具过滤(全关→按需开,read-only 模式)。 - 能记住 MCP connector 目前是 beta(
mcp-client-2025-11-20)。
📖 一、为什么有 MCP:维护问题(The maintenance problem)
官方原句: We have tools, skills, and connectors. So why does MCP exist? At first glance it looks like a second API stacked on top of the API. Fair question — and the answer comes down to who maintains the integration code.
精译:我们已经有 tools、skills 和 connectors 了。那 MCP 为什么存在?乍一看它像是叠在 API 之上的第二层 API。问得有理 —— 答案归结为一句:集成代码由谁来维护。
官方原句: Say your agent needs to pull tasks from Asana, check a Google Calendar, and search Slack — all in one go. With custom tools, you have to write three integrations. That part is doable. The painful part comes after: you also have to maintain those integrations every time one of those services changes its API, which happens often. Congratulations, you're now maintaining a pile of third-party API wrappers.
精译:假设你的 agent 要一次拉取 Asana 任务、查 Google 日历、搜 Slack。用 custom tools,你得写三套集成。这还能忍。痛的在后面:这些服务每次改 API(改得很勤),你都得跟着维护这三套集成。恭喜,你成了一堆第三方 API 包装器的维护工。
⭐⭐ 维护责任的转移(本课第一论断)
官方原句: MCP shifts that maintenance to the service provider.* Asana publishes an MCP server. Slack publishes one. Google publishes one. Each server exposes its own tools — with descriptions, schemas, and authentication — through a standard protocol. When their API changes, they update their server. You change nothing.***
精译:MCP 把这份维护转移给服务提供商。Asana 发布一个 MCP server,Slack 发布一个,Google 发布一个。每个 server 经标准协议暴露自家工具 —— 带描述、schema 和鉴权。它们的 API 变了,它们更新自己的 server。你一行不改。
| Custom tools(第 4–5 课) | MCP(本课) | |
|---|---|---|
| 集成代码谁写 | 你 | 服务商(Asana 写 Asana 的) |
| API 变更谁扛 | 你改 wrapper | 服务商更新 server,你零改动 |
| schema 谁维护 | 你写死在 tools 数组 | server 暴露,AI 自取 |
| 适合 | 内部系统、专有 API | 第三方 SaaS 服务 |
📖 二、Tools vs. Skills vs. MCP(本课第一判别句)
官方原句: Tools* connect the AI to your internal systems — your database, your project tracker, your proprietary APIs. You own the code, so you also own the maintenance. Skills teach the AI a procedure — your report template, your review checklist. Skills are instructions, not necessarily integrations. MCP connects the AI to third-party services, where the service provider maintains the integration. You don't write the Asana wrapper — Asana did*.
精译:Tools 把 AI 接到你的内部系统 —— 你的数据库、项目跟踪工具、专有 API。代码你拥有,维护也你扛。 Skills 教 AI 一套规程 —— 报告模板、审查清单。Skills 是指令,不一定是集成。 MCP 把 AI 接到第三方服务,集成由服务提供商维护。Asana 的 wrapper 不用你写 —— Asana 已经写好了。
⭐⭐ 判别句(必背)
Tools are for your stuff, skills are for your processes, and MCP is for everyone else's stuff. 「工具管你的东西,Skills 管你的流程,MCP 管别人的东西。」
| 特性 | 连接对象 | 集成维护方 | 一句话 |
|---|---|---|---|
| Tools | 内部系统(自有数据/动作) | 你 | your stuff |
| Skills | ——(规程,非集成) | ——(是指令) | your processes |
| MCP | 第三方服务 | 服务商 | everyone else's stuff |
⭐ 与第 8 课判别句连成一组:tools=what, skills=how, MCP=whose。三句连背,选型题直接秒。
📖 三、连接 MCP server(Connecting to an MCP server)
官方原句: The cleanest way to get a feel for MCP is to point the AI at any MCP server and let it discover what's there. For this example, we'll use the Linear MCP server, with the connection details and auth token stored in a
.envfile.
精译:体会 MCP 最干净的方式:把 AI 指向任意一个 MCP server,让它自己发现那里有什么。本例用 Linear 的 MCP server,连接信息与鉴权令牌存进 .env 文件(呼应第 2 课的密钥纪律)。
⭐⭐ 请求里的两个部件
官方原句: The
mcp_serverskey declares the connection* — a type, a URL, a name to refer to it by, and optionally an auth token. Then a tool with the typemcp_toolsetconfigures which tools* the AI can use from that server. The default is all of them, but if you want to scope it down, this is where you do it.
精译:请求里两个部件配合。mcp_servers 键声明连接 —— 类型、URL、引用名,可选鉴权令牌。然后 mcp_toolset 类型的工具配置 AI 能用该 server 的哪些工具。默认全开,要收窄就在这里收。
import os
import anthropic
client = anthropic.the AI provider()
response = client.beta.messages.create(
model="current-model",
max_tokens=1000,
messages=[
{"role": "user", "content": "What tools do you have available?"}
],
mcp_servers=[
{
"type": "url",
"url": "https://mcp.linear.app/mcp",
"name": "linear",
"authorization_token": os.environ["LINEAR_MCP_TOKEN"],
}
],
tools=[
{
"type": "mcp_toolset",
"mcp_server_name": "linear",
}
],
betas=["mcp-client-2025-11-20"],
)
print(response)
| 部件 | 字段 | 作用 | 考点 |
|---|---|---|---|
| ① 声明连接 | mcp_servers |
type: "url" + url + name(引用名)+ authorization_token(可选) |
name 是两个部件之间的引用键 |
| ② 授予工具 | tools 里的 mcp_toolset |
mcp_server_name: "linear" 指回声明;默认全部工具 |
不写 schema,只写引用 |
| beta 通道 | betas |
mcp-client-2025-11-20 |
MCP connector 目前 beta(第 8 课三件套在此复现) |
官方原句: Notice that we never wrote a single tool schema. the AI introspects the server, gets the list of tools and their schemas back, and picks the right one for the prompt. As of this lesson, the MCP connector is in beta — note the beta header in the request.
精译:注意我们没写过一个工具 schema。AI 自省该 server,拿回工具清单与各自的 schema,并为当前 prompt 挑对工具。截至本课,MCP connector 还在 beta —— 注意请求里的 beta 头。
官方原句: The same works for basically any compliant server. We didn't define a single tool. We didn't write a Linear client. Linear is maintaining that.**
精译:换任何合规的 server 都一样。我们没定义一个工具,没写 Linear 客户端。那是 Linear 在维护。
📖 四、工具过滤:最小特权(Filtering which tools the AI can use)
官方原句: MCP servers often expose many, many tools — and you don't always want the AI using all of them. Maybe you don't want it to have write permissions, or you just don't want all those tool definitions taking up context.
精译:MCP server 经常暴露一大堆工具,而你未必想让 AI 全都能用。也许你不想给它写权限,或者只是不想让那么多工具定义占着上下文。
⭐⭐ 过滤模式:默认全关,按需单开
官方原句: The fix: disable everything by default, then enable only the specific tools you want. Here's that pattern with a Slack MCP server.
精译:解法:默认全部禁用,只启用你想要的特定工具。Slack MCP server 示例:
tools=[
{
"type": "mcp_toolset",
"mcp_server_name": "slack",
"default_config": {
"enabled": False,
},
"configs": {
"search_messages": {"enabled": True},
"list_channels": {"enabled": True},
},
}
]
官方原句: Now the AI can search Slack and list channels, but it can't post or delete. This is useful when you trust a service for reads but don't want the AI writing on your behalf by accident.
精译:现在 AI 能搜 Slack、列频道,但不能发帖、不能删。当你只信任某服务的读操作、又怕 AI 手滑替你写时,这招正好。
| 层 | 字段 | 本例取值 | 效果 |
|---|---|---|---|
| 第一层(默认) | default_config.enabled |
False |
全关 |
| 第二层(例外) | configs.<tool>.enabled |
search_messages / list_channels 为 True |
只开两个读工具 |
| 结果 | —— | read-only server | 领域 5 最小特权的标准实现 |
⭐⭐ 领域 5 落点:这一段就是考纲「输入/输出筛查、工具调用授权」里授权收敛的直接答案——默认拒绝(deny by default)+ 显式白名单,与课程 001 的
allowed-tools白名单同构。
📌 五、Recap(官方六条要点)
| # | 官方原句 | 一句话 |
|---|---|---|
| 1 | MCP exists so you don't have to maintain integrations someone else has already built. | 别人建好的集成,你别维护 |
| 2 | Pick the right feature for the job: tools for your data, skills for your process, MCP for third-party services. | 三分法选型 |
| 3 | Declare the connection in mcp_servers … and grant access with an mcp_toolset entry in tools. the AI introspects the server and discovers the tools on its own — no schemas to write. |
两件套 + introspect 免 schema |
| 4 | Scope down access by setting default_config: {"enabled": False} and enabling specific tools in configs. |
默认拒绝+白名单 |
| 5 | The MCP connector is currently in beta, so include the beta header on your requests. | beta 头别忘 |
| 6 | Visit modelcontextprotocol.io for the list of available servers and to learn more about the protocol. | 官方站点:服务器目录+协议文档 |
🧠 本课 → CCAR-P 考点映射
| 本课内容 | 对应领域 | 权重 |
|---|---|---|
| MCP 作为集成选型(考纲原词:MCP / API-CLI / agent-to-agent);维护责任转移 | 领域 3 Integration | 19% |
| 工具过滤:默认拒绝+白名单、read-only、write permissions | 领域 5 Governance, Safety & Risk | 14% |
| 工具定义占上下文 → scope down | 领域 2 Models, Prompting & Context Engineering | 13% |
| 第三方服务信任边界 | 领域 5 + 领域 6(干系人信任) | 14% |
⭐ 战略结论:本课是领域 3 的核心弹药——选型题(MCP vs custom tools)、机制题(mcp_servers+mcp_toolset 两件套)、安全题(过滤收敛)三种题型都能出。与第 7 课三分法、第 8 课 Skills 判别句连成一个完整的「what / how / whose」答题框架。
🔤 本课新生词(已回灌 30-单词表/03,2026-10-14)
| 词汇 | 音标 | 释义 | 备注 |
|---|---|---|---|
⭐⭐ MCP / Model Context Protocol |
读作 em-cee-pee | 模型上下文协议 | 本课主题;开放标准协议 → 精讲 035 |
⭐⭐ maintain / maintenance |
/meɪnˈteɪn/;/ˈmeɪntənəns/ |
维护 | 全课痛点词:谁维护集成 → 精讲 036 |
⭐⭐ integration / integrate |
/ˌɪntɪˈɡreɪʃn/ |
集成 | 领域 3 名称原词 → 精讲 037 |
⭐⭐ third-party |
/ˌθɜːrd ˈpɑːrti/ |
第三方的 | 判别句关键词 → 精讲 038 |
⭐⭐ introspect / introspection |
/ˌɪntrəˈspekt/ |
自省(探测 server) | 免写 schema 的机制 → 精讲 039 |
⭐⭐ expose |
/ɪkˈspoʊz/ |
暴露、对外提供 | server 暴露自家工具 → 精讲 040 |
⭐ connector |
/kəˈnektər/ |
连接器 | 开场三件套:tools, skills, and connectors |
⭐ wrapper |
/ˈræpər/ |
包装器 | a pile of third-party API wrappers(自研胶水的贬称) |
⭐ proprietary |
/prəˈpraɪəteri/ |
专有的 | your proprietary APIs |
⭐ publish |
/ˈpʌblɪʃ/ |
发布 | Asana publishes an MCP server |
⭐ shift(v.) |
/ʃɪft/ |
转移 | MCP shifts that maintenance to the service provider |
⭐ scope down |
— | 收窄范围 | if you want to scope it down |
⭐ grant |
/ɡrænt/ |
授予 | grant access with an mcp_toolset entry |
⭐ discover |
/dɪˈskʌvər/ |
发现 | discovers the tools on its own |
⭐ read-only |
— | 只读 | keeping a server read-only(领域 5 最小特权) |
⭐ write permissions |
— | 写权限 | don't want it to have write permissions |
⭐ up to date |
— | 保持最新 | keeps it up to date |
⭐ authentication |
/əˌθentɪˈkeɪʃn/ |
鉴权 | descriptions, schemas, and authentication |
⭐ Tools vs. Skills vs. MCP |
— | 三分法判别句 | tools are for your stuff, skills are for your processes, MCP is for everyone else's stuff(必背) |
protocol |
/ˈproʊtəkɔːl/ |
协议 | through a standard protocol |
standard |
/ˈstændərd/ |
标准 | 同上 |
mcp_servers |
— | MCP 服务器声明键 | type / url / name / authorization_token |
mcp_toolset |
— | MCP 工具集类型 | tools 数组条目;mcp_server_name 指回声明 |
authorization_token |
— | 鉴权令牌 | optionally an auth token;进 .env(呼应第 2 课) |
default_config |
— | 默认配置层 | enabled: False 全关 |
configs |
— | 逐工具配置层 | search_messages / list_channels 单开 |
enabled |
— | 启用开关 | 两层过滤的开关字段 |
schema |
/ˈskiːmə/ |
模式(工具定义) | no schemas to write(若已收 → 复现) |
internal |
/ɪnˈtɜːrnl/ |
内部的 | your internal systems;表 01-063 已收 |
database |
/ˈdeɪtəbeɪs/ |
数据库 | tools 侧示例 |
project tracker |
— | 项目跟踪工具 | tools 侧示例 |
service provider |
— | 服务提供商 | 维护责任的接收方 |
Linear |
— | Linear(项目管理服务) | 本课示例 MCP server |
Asana |
— | Asana(任务管理服务) | 维护问题三例之一 |
Slack |
— | Slack(IM 服务) | 过滾示例;search / list 只读 |
Google Calendar |
— | 谷歌日历 | 三例之三 |
modelcontextprotocol.io |
— | MCP 官方站点 | 服务器目录+协议文档 |
at first glance |
— | 乍一看 | At first glance it looks like a second API |
comes down to |
— | 归结为 | the answer comes down to who maintains… |
stacked on top of |
— | 叠在……之上 | a second API stacked on top of the API |
doable |
/ˈduːəbl/ |
可做的 | That part is doable(对比 painful part) |
take up |
— | 占用 | tool definitions taking up context(领域 2 钩子) |
handy |
/ˈhændi/ |
好用的 | handy for keeping a server read-only |
by accident |
— | 无意中 | writing on your behalf by accident |
compliant |
/kəmˈplaɪənt/ |
合规的、遵从的 | any compliant server;表 01-043 compliance 同族 |
template |
— | 模板 | 第 8 课已收,此处复现(report template) |
review checklist |
— | 审查清单 | 第 8 课已收,此处复现 |
beta |
— | beta | 第 8 课已收,此处复现(mcp-client-2025-11-20) |
endpoint |
— | 端点 | 第 1、8 课已收,此处复现(Linear MCP endpoint) |
Skill |
— | 技能 | 第 8 课已收,此处复现(判别句三方之一) |
✅ 本课进度
- [x] 全文精译与架构师级拆解(2026-10-14)
- [x] ⭐⭐ 记录维护责任转移论断与三分法判别句(what / how / whose)
- [x] 记录 mcp_servers + mcp_toolset 两件套与过滤两层(default_config / configs)
- [x] 生词回灌
30-单词表/03-考试核心生词与术语表.md(2026-10-14:新增速查 44 条 → 全表 384 条(与表内重复 6 词标注「第 9 课复现」);新升级精讲 6 条 035–040) - [x] 保存本课英文原文(
24-English-09-MCP.md) - [ ] 跑通本课 runnable demo(需 Console 账号 + API key + 预付费额度 + LINEAR_MCP_TOKEN)
- [ ] 官方未提供
What you'll learn与练习区块 —— 若后续页面补全,需回填
🔗 关联
- 本课英文原文:
24-English-09-MCP.md✅ 已存(2026-10-14) - 上一课对照:第 8 课 Skills(how → 本课 whose)
- 三分法链条:第 7 课 Built-in tools(what)→ 第 8 课(how)→ 本课(whose)
- 跨课同构:课程 001 导读(
allowed-tools白名单 ↔ 本课 configs 白名单) - 课程大纲:01-课程导读与大纲全景
- 考纲:00-CCAR-P备考蓝图
- 生词表:
30-单词表/03-
⚠️ 语料说明:英文原文中的
anthropic.the AI provider()与model="current-model"为抓取/去品牌化残留;其余英文引句均为官方原句,未作改动。