AI 翻译。由人工以英文核验。 阅读原文
教学套件
来自版次 2026.11.19,即本书当前版次。本书变更时,此版次随之变更。可自由使用和改编,但须注明出处。
教学大纲
阅读时长仅针对本章正文。学生还可在实验环境或自己的机器上运行其中的示例。
每周一章:12周
| 周 | 各章 | 阅读 | 示例 |
|---|---|---|---|
| 1 | 1. MCP 端到端 | 67 分钟 | 5 |
| 2 | 2. MCP 为 API 增添了什么 | 62 分钟 | 6 |
| 3 | 3. 设计模型可以使用的工具 | 85 分钟 | 8 |
| 4 | 4. 将数据作为资源和提示提供 | 76 分钟 | 5 |
| 5 | 5. 在调用中途询问用户 | 84 分钟 | 6 |
| 6 | 6. 通过 Streamable HTTP 提供服务 | 102 分钟 | 6 |
| 7 | 7. 将长时间工作作为任务运行 | 89 分钟 | 4 |
| 8 | 8. 使用 OAuth 授权客户端 | 122 分钟 | 7 |
| 9 | 9. 保护工具免遭滥用 | 78 分钟 | 6 |
| 10 | 10. 构建一个处理工单的宿主 | 85 分钟 | 6 |
| 11 | 11. 测试服务器并观察其运行 | 103 分钟 | 6 |
| 12 | 12. 迁移 2025 年代的服务器 | 82 分钟 | 6 |
5 周后
| 周 | 各章 | 阅读 | 示例 |
|---|---|---|---|
| 1 | 1. MCP 端到端 2. MCP 为 API 增添了什么 3. 设计模型可以使用的工具 | 214 分钟 | 19 |
| 2 | 4. 将数据作为资源和提示提供 5. 在调用中途询问用户 6. 通过 Streamable HTTP 提供服务 | 262 分钟 | 17 |
| 3 | 7. 将长时间工作作为任务运行 8. 使用 OAuth 授权客户端 | 211 分钟 | 11 |
| 4 | 9. 保护工具免遭滥用 10. 构建一个处理工单的宿主 | 163 分钟 | 12 |
| 5 | 11. 测试服务器并观察其运行 12. 迁移 2025 年代的服务器 | 185 分钟 | 12 |
学习目标与大纲
每章的学习目标即其第一句。每份大纲依循该章的节,列出该章定义的术语、运行示例前要求做出的预测,以及每节结尾的规则。 其关键术语和待提问的预测内容采用英文版次,与测验题库的设置一致。
1. MCP 端到端
阅读约 67 分钟,5个示例。
读完本章,你将能够把一个现有的 HTTP API 放到基于 stdio 的 Model Context Protocol 服务器之后,从客户端调用它的工具,读懂二者交换的每一条消息,并通过一个小型主机让模型自行选择工具。
讲义大纲:7节
-
认识商店及其 API
- 工作准则 封装你已经在运行的 API,并让它继续作为记录系统。MCP 服务器应当是一个轻量的适配器,用自己的凭据调用 API 并转换其回答,这样 API 的校验、授权和日志对每一种客户端都继续有效,而不只是对模型有效。只有在没有 API 可封装时,才直接基于数据库构建;即便如此,也要把业务规则放在一处,供两类客户端共用。
-
将一个端点封装为工具
- 工作准则 先为一个端点提供一个只读工具,并面向模型编写其文档字符串:它做什么、输入是什么样子、返回什么。抛出
ToolError时,消息要告诉模型应当改用什么做法;意外的异常则保持通用,使内部细节不会离开服务器。端点超过少数几个之后,应围绕模型要完成的任务来设计工具,而不是每个端点一个工具(围绕任务而非端点设计工具)。
- 工作准则 先为一个端点提供一个只读工具,并面向模型编写其文档字符串:它做什么、输入是什么样子、返回什么。抛出
-
Call the tool from a client
- 工作准则 Connect with
mcp.Client, launch stdio servers withsys.executableand an explicitenv=, and give the client a name. Pass each variable the server needs and nothing else from your environment, so no server sees secrets meant for another program. When a tool fails with only the SDK's generic message, read the server's standard error before you change the client.
- 工作准则 Connect with
-
Read the messages on the wire
- 关键术语
server/discover - 工作准则 When a call behaves unexpectedly, trace the wire before you read the SDK's code: a relay that copies and logs lines works with any client and any server. Never write to standard output from a stdio server, not even a debugging
print(), because the client reads every line there as a message. Uselogging, which the SDK sends to standard error, or write to standard error yourself.
- 关键术语
-
让模型选择工具
- 工作准则 把宿主的提示词和对模型回复的解析保留在你自己的代码中,并用录制的回复而不是实时模型来测试循环。记录模型的原始文本,而不是 SDK 对象,这样 SDK 发布新版本时不会使录制失效,并让回放在输入变化时失败。只有在为决定发布哪些描述、哪个模型而进行的衡量运行中,才切换到实时模型。
-
What goes wrong in production
- 工作准则 On the machine that launches a stdio server in production, check three things: nothing but JSON-RPC reaches standard output, every variable the server needs is passed explicitly, and the server answers
server/discoverwithin 10 seconds of starting. Keep the server's standard error in your logs, because that is where its real errors go.
- 工作准则 On the machine that launches a stdio server in production, check three things: nothing but JSON-RPC reaches standard output, every variable the server needs is passed explicitly, and the server answers
- 本章做出的决定
2. MCP 为 API 增添了什么
阅读约 62 分钟,6个示例。
读完本章,你应当能够说明宿主、客户端和服务器各自承担什么职责,把商店的每项能力放入正确的 Model Context Protocol 原语,读懂每个请求都携带的版本和能力信息,并判断商店在什么情况下应当保留普通的 HTTP API。
讲义大纲:11节
-
区分宿主、客户端和服务器
- 关键术语 host, client, capability
- 工作准则 在宿主中为每台服务器配备各自的客户端,并把对话以及任何跨服务器的操作放在宿主的代码中,而不是服务器里。每个客户端启动时都先读取服务器提供的内容,而不是想当然地假定,这样服务器更改工具时就不会破坏宿主。编写服务器时,应假定它只能看到发给它的请求,因为规范只允许它看到这些。
- 把每项能力放进合适的原语
-
工具是由模型选择的动作
- 关键术语 tool
- 工作准则 当模型应当根据对话来决定是否使用某项能力时,就把它做成工具。这包括取决于顾客所写内容的查询,也包括所有会改变某些状态的操作,例如退款;对于这类操作,宿主会在调用之前征求同意。
-
资源是由应用程序选择的数据
- 关键术语 resource
- 工作准则 当宿主自身的代码能够判断何时需要某项数据时,就把它做成资源,例如适用于某类已知工单的政策,或用户已打开的记录。只有模型通过阅读对话才能判断是否需要时,才把它保留为工具。
-
提示词是用户选择的模板
- 关键术语 prompt
- 工作准则 当某个工作流应由人来启动、且每次运行都应遵循相同步骤时,就把它做成提示词,并把提示词的文本保存在服务器上,这样一次修改即可同时作用于所有宿主。如果没有人来选择它何时运行,它就不是提示词:应把这些步骤做成工具,或写入宿主自身的指令中。
-
Carry the version and capabilities on every request
- 工作准则 Read the version and the client's capabilities from each request, never from an earlier one, and answer
-32021when a call needs a capability the request didn't declare. Put the shop's own request metadata under its own reverse-DNS prefix, never underio.modelcontextprotocol/ormcp. LogclientInfoandserverInfofor debugging, and decide nothing on them.
- 工作准则 Read the version and the client's capabilities from each request, never from an earlier one, and answer
-
处理服务器不支持的版本
- 工作准则 当服务器返回
-32022时,从你的列表和它的supported列表共有的版本中选出最新的,重试一次;若两者没有交集,则向用户显示一个写明两份列表的错误。不要循环重试,也不要猜测服务器未列出的版本。在你自己的服务器上,要保持 supported 列表准确,因为客户端会从中进行选择。
- 工作准则 当服务器返回
-
缓存列表结果
- 工作准则 对每个调用方都相同的列表,例如商店的工具列表,设置 TTL 和
"public"范围,并且所选 TTL 不要超过你在部署后愿意容忍列表过时的时长:以分钟计,而不是以小时计。对取决于请求者身份的任何内容,保持 SDK 的默认值"private",并且绝不要让cacheScope代替授权检查。在客户端,保留默认缓存,它会在client.listen(tools_list_changed=True)流上收到变更通知时丢弃对应条目(mcp/client/client.py),在资源变化时通知客户端打开的正是这类流。没有这个流,客户端就收不到任何通知,所以要打开一个;当你有其他理由怀疑某个条目时,使用cache_mode="refresh",而不是按 TTL 轮询。
- 工作准则 对每个调用方都相同的列表,例如商店的工具列表,设置 TTL 和
-
在 MCP 没有增益之处保留 HTTP API
- 工作准则 对于代码知道该调用哪个端点的调用方,例如其他服务、固定工作流和批处理作业,保留普通的 HTTP API;对于由模型或用户在运行时做出选择的宿主,则在同一个 API 之前放置 MCP 服务器。在把大批量流量路由到 MCP 之前,请在你自己的传输方式上测量开销;并在你能控制的客户端中固定协议版本,使它们跳过发现探测。对于可能遇到你无法控制的服务器的客户端,请保留自动模式,因为这些服务器可能只支持 2025 版协议。
-
生产环境中会出什么问题
- 工作准则 在发布任何服务器之前,检查四件事:每项能力的原语与决定其何时运行的一方相符;客户端与服务器之间没有任何环节编辑 MCP 请求体;没有任何决定依据
clientInfo作出;每一个"public"缓存提示所涵盖的数据,对所有调用方都相同。请记录每个失败请求的协议版本和错误码,因为版本错误和信封错误,是客户端或网关发生变化的最早迹象。
- 工作准则 在发布任何服务器之前,检查四件事:每项能力的原语与决定其何时运行的一方相符;客户端与服务器之间没有任何环节编辑 MCP 请求体;没有任何决定依据
- 本章做出的决定
3. 设计模型可以使用的工具
阅读约 85 分钟,8个示例。
读完本章,你将能够把商店的 API 转换为 Model Context Protocol 工具,使其名称、描述、输入模式、结果和错误都能让模型据以行动,并能衡量修改某个描述会如何改变模型选用的工具。
讲义大纲:10节
-
Shape tools around tasks, not endpoints
- 关键术语 Consent
- 工作准则 Start from the tasks in your tickets or logs, not from your routes, and give each task one tool. Move every decision the model shouldn't make into the server, such as an amount or a sequence of calls. Use a handle when one task needs the result of another, state its lifetime in the description of the tool that creates it, make it unguessable, and check on every call that it belongs to the caller. Expose an endpoint as it stands only when the task and the endpoint are the same, as
check_stockandGET /stock/{sku}are.
-
编写供模型阅读的描述
- 先行询问 Before you run it, predict how many first calls the vague set and the draft each get right.
- 工作准则 每条描述写两到四句话:工具做什么,什么时候应使用它而不是最容易与它混淆的工具,它的输入是什么样子,以及它返回什么。以
description=的形式传入,而不要依赖多行文档字符串,这样模型读到的就恰好是你写下的文字。然后录制你要发布的模型在真实工单上选择工具的过程,阅读其中的错误选择,并修改这些选择所指向的描述。需要知道哪项改动起了作用时,每次录制只改一处,并在没有用于编写这项改动的工单上检查结果。
-
用 JSON Schema 为输入定型
- 工作准则 在 API 允许的范围内,尽可能严格地为每个参数定型:ID 用 pattern,固定取值用 enum,数量用边界,日期用 format。让 SDK 在你的代码运行之前拒绝错误调用,并一次返回所有失败。不要指望模式承载含义,因为有效的日期仍可能是错误的日期。在工具内部检查模式无法表达的内容,并在描述中说明如何填写工单中常常不完整的值。
-
通过输出模式返回结构化内容
- 工作准则 为每个工具指定一个 pydantic 模型作为返回类型,这样 SDK 会发布输出模式,返回不带包装器的结构化内容,并为你添加文本块。宿主代码要做的每项决定,例如
within_limit,都应在模型中设一个字段,而不是留在一句话里。只有结果不被任何代码读取的工具,才返回裸字符串。
- 工作准则 为每个工具指定一个 pydantic 模型作为返回类型,这样 SDK 会发布输出模式,返回不带包装器的结构化内容,并为你添加文本块。宿主代码要做的每项决定,例如
-
将失败作为工具结果报告
- 关键术语 protocol error, tool execution error
- 工作准则 对模型能够纠正的每一种失败,都抛出
ToolError,消息中要指明错在哪里以及应改为发送什么;有效值较少时,要一并列出。只对没有模型能修复的失败,例如配置问题,才抛出MCPError,并让意外异常保持泛化,使内部细节留在服务器上。切勿把错误作为普通字符串返回。
- Mark what a tool changes with annotations
-
将注解视为提示,而非保证
- 工作准则 为每个工具添加注解,因为省略提示会让谨慎的宿主按最坏情况假设。只有在服务器强制保证幂等时,才将工具标记为幂等,并且让退款、支付以及其他必须只发生一次的操作处于服务器端检查之后。作为宿主,应使用来自可信服务器的注解来决定向用户展示什么,绝不能把它当作跳过用户同意的许可(在产生副作用前征求同意),并将其他所有服务器的注解视为未经验证的声明。
-
保持工具列表精简
- 工作准则 为每个服务器只设定一类受众,只提供该受众的任务所需的少数工具,并测量列表在你的宿主提示词中的成本。把词元花在模式上,以及用来区分模型容易混淆的两个工具的那句话上,删去重复模式内容的描述文字。当宿主需要的工具超出其模型能够很好地从中选择的数量时,应把它们拆分到多个服务器上,只连接某次对话所需的服务器,而不是让某个服务器的列表随连接而变。
-
生产环境中会出什么问题
- 工作准则 商店的工具上线之前,请记录你将要发布的模型在一批已标注的真实工单样本上选择工具的情况,检查模型能够自行修正的每一种失败都以带有有用信息的
ToolError返回,并为每个输出模式加上契约测试。发布之后,请监控工具选择的次数、参数中的示例值,以及宿主中的RuntimeError。
- 工作准则 商店的工具上线之前,请记录你将要发布的模型在一批已标注的真实工单样本上选择工具的情况,检查模型能够自行修正的每一种失败都以带有有用信息的
- 本章做出的决定
4. 将数据作为资源和提示提供
阅读约 76 分钟,5个示例。
读完本章,你将能够把商店的政策和记录发布为 Model Context Protocol 资源,用一个资源模板寻址多条记录,在用户输入参数时补全该参数,在资源变化时通知客户端,并把退款审核打包成用户可以选择的提示。
讲义大纲:8节
-
将政策作为资源公开
- 关键术语 annotations
- 工作准则 将宿主应当能够放到模型面前的文档作为静态资源发布,使用能体现你的系统名称的 scheme,并提供宿主可以显示的 MIME 类型和描述。仅对客户端无需经过你的服务器即可获取的资源使用
https://。只有当每个调用方得到的结果都相同时,才将结果标记为public,并且只给每个回答都依赖的一两份文档设置高优先级,而不是给所有文档。
-
用资源模板定位记录
- 工作准则 对形状相同、带有 ID 的记录使用资源模板。返回 API 自己的 JSON,未命中时抛出
ResourceNotFoundError,这会让客户端得到 -32602 和 URI。凡属于某个用户的内容,都保持作用域为private。保持 SDK 的ResourceSecurity开启,并自行验证变量的格式。只有当变量必须携带路径时,才可将其排除在检查之外,此时要自行检查该路径。
- 工作准则 对形状相同、带有 ID 的记录使用资源模板。返回 API 自己的 JSON,未命中时抛出
-
为用户补全参数
- 工作准则 只根据调用者有权读取的内容补全参数,并由服务器所代表的对象来决定,而不是由请求中的任何内容来决定。自行按输入的前缀过滤,并把列表控制在 100 个值以内,因为 SDK 不会这样做。只要你过滤的数据源本身被截断,就设置
has_more;只有在统计了每一个匹配项时,才报告total。对无权访问的记录,应给出与不存在的记录相同的“未找到”答复,读取和补全都是如此。
- 工作准则 只根据调用者有权读取的内容补全参数,并由服务器所代表的对象来决定,而不是由请求中的任何内容来决定。自行按输入的前缀过滤,并把列表控制在 100 个值以内,因为 SDK 不会这样做。只要你过滤的数据源本身被截断,就设置
-
在资源变化时通知客户端
- 工作准则 只监视宿主已呈现给模型或用户的资源,并把每个事件当作再次读取的提示,而不是新的值。每次打开流时,无论是第一次还是每次中断之后,都要重新读取你所依赖的全部内容,因为任何内容都不会重放。从造成变更的代码路径中,为客户端所读取的确切 URI 发布更新。
-
Package a workflow as a prompt
- 工作准则 Offer a prompt for a procedure a person starts by name, and keep its arguments to values with a format you can check. Embed the resources the procedure depends on, so the host needn't fetch them. Validate every argument before you use it, and raise
MCPErrorwithINVALID_PARAMSfor a bad one, because the SDK's own checks answer with an internal error.
- 工作准则 Offer a prompt for a procedure a person starts by name, and keep its arguments to values with a format you can check. Embed the resources the procedure depends on, so the host needn't fetch them. Validate every argument before you use it, and raise
-
在资源与工具之间做选择
- 工作准则 当宿主会附上某条记录、模型又会查询该记录时,应将它同时作为资源和工具提供,并通过同一条代码路径为两者提供服务,使它们不会不一致。当工具找到宿主可能保留的记录时,应返回指向这些记录的资源链接,而不是记录的内容。
-
What goes wrong in production
- 工作准则 Test resources and prompts with two callers before they reach production. Neither may see, complete or watch the other's records, and neither should see a list change without a list-changed notification. Check that every
resources/readof a user's data carries theprivatescope, and that a host recovers from a dropped stream by re-listening and re-reading.
- 工作准则 Test resources and prompts with two callers before they reach production. Neither may see, complete or watch the other's records, and neither should see a list change without a list-changed notification. Check that every
- Decisions this chapter made
5. 在调用中途询问用户
阅读约 84 分钟,6个示例。
读完本章,你将能够让商店的退款工具在调用中途暂停,请主机端的人确认一笔退款,并带着答案继续执行。
讲义大纲:9节
-
了解无状态服务器为何无法等待答复
- 工作准则 不要在工具调用内部等待只有客户端才能提供的内容。在固定修订版的连接上,把每一次对
ctx.elicit()或ctx.elicit_url()的调用都视为缺陷,并改为返回输入请求,如下一节所做的那样。只有在必须同时应答 2025 年代客户端的服务器上才保留旧的调用,并且只能放在对ctx.protocol_version的检查之后(通过窗口同时服务新旧客户端)。
- 工作准则 不要在工具调用内部等待只有客户端才能提供的内容。在固定修订版的连接上,把每一次对
-
Return an input request instead of a result
- 工作准则 When a tool can't finish without the user, return an
InputRequiredResultwith one input request per question and arequestStatethat says what the retry must finish. Check the client's declared capabilities before you ask. Put in the state only what the tool needs to carry on, and let the SDK seal it. Make every side effect before the question either idempotent or harmless when no one answers, because the client may never call again.
- 工作准则 When a tool can't finish without the user, return an
-
Resume the call with the answer
- 工作准则 Use
Client.call_toolwith an elicitation callback in a host, and let the SDK run the rounds. Drive the loop yourself withclient.session.call_tool(..., allow_input_required=True)only when the host must keep the state across a restart or show each round, and then repeat the arguments exactly. On the server, read the answer and the state together. When your server always sends a state, treat an answer that arrives without it, or with a state for another record, as a question never asked.
- 工作准则 Use
-
通过征询获取结构化输入
- 工作准则 只有主机端的人才能给出的答案,使用表单模式,并让每个表单只包含工具要据以行动的少数字段,凡答案属于已知集合的,就使用枚举。用解析器和 pydantic 模型来声明表单,当拒绝和取消应导向不同的处理时,采用
ElicitationResult。只有在需要自行控制状态时,才手工构造输入请求。
- 工作准则 只有主机端的人才能给出的答案,使用表单模式,并让每个表单只包含工具要据以行动的少数字段,凡答案属于已知集合的,就使用枚举。用解析器和 pydantic 模型来声明表单,当拒绝和取消应导向不同的处理时,采用
-
将敏感步骤交给 URL
- 工作准则 任何机密内容,以及任何让人登录到另一项服务的步骤,都通过 URL 模式发送,绝不通过表单。把流程自身的 ID 放入
requestState,把accept视为“用户已前往该页面”,并在每次重试时根据服务器自己的记录判断流程是否已完成。检查完成流程的人是否就是发起流程的人。
- 工作准则 任何机密内容,以及任何让人登录到另一项服务的步骤,都通过 URL 模式发送,绝不通过表单。把流程自身的 ID 放入
-
确保往返状态不可篡改
- 工作准则 让 SDK 封装每一个
requestState,对于涉及资金、访问权限或数据的状态,绝不要关闭封装。保持状态小而不透明:用 ID,而不是整条记录。对于任何必须只发生一次的步骤,在服务器上自行保存已回答状态的记录,并在产生副作用之前检查,而不是之后。
- 工作准则 让 SDK 封装每一个
-
Choose elicitation or a tool argument
- 工作准则 Make a value a tool argument when the model can know it, and validate it in the tool. Elicit it when only the person can give it, or when the policy says a person must decide, and never accept that kind of value as an argument. Use URL mode for every secret. When you aren't sure, ask who would be at fault if the value were wrong.
-
生产环境中会出什么问题
- 工作准则 在带有提问功能的服务器上线生产之前,为它的各个副本配置同一个可轮换的共享密钥,把状态的有效期设为人们实际所需的时间,并把报价存储和所有仅一次的记录移入共享存储。凡传输层有调用方的地方,都要把每个问题绑定到调用方。然后按记录的原因观察 -32602,按宿主观察 -32021,并观察每次调用的轮数。
- 本章做出的决定
6. 通过 Streamable HTTP 提供服务
阅读约 102 分钟,6个示例。
读完本章,你将能够:通过 Streamable HTTP 提供商店的 Model Context Protocol 服务器;读懂每个请求和响应所携带的内容;从长时间运行的调用中以流的方式返回进度,并取消该调用;将服务器作为多个副本运行在同一个地址之后,且不使用粘性会话;拒绝浏览器被诱骗发出的请求。
讲义大纲:9节
-
Move the server from stdio to HTTP
- 工作准则 Serve over Streamable HTTP with
MCPServer.run(transport="streamable-http")and its loopback default while you develop, and give clients the endpoint's URL. Leavestateless_httpalone unless you also serve clients on a 2025 revision, where it decides whether they get sessions. Keep stdio for servers that a host launches for one user, as Choose stdio or Streamable HTTP explains.
- 工作准则 Serve over Streamable HTTP with
-
Read one HTTP exchange
- 工作准则 When an HTTP call fails, read the exchange first: the three routing headers,
_metain the body, the status and the content type. Route in a gateway onMcp-MethodandMcp-Nameif you need to, and never rewrite a body without rewriting its headers to match, because the server will refuse the pair with -32020. On a server that supports only the pinned revision, a 405 means an older client is opening a GET stream; the SDK's app serves those clients instead.
- 工作准则 When an HTTP call fails, read the exchange first: the three routing headers,
-
Stream progress on a long call
- 关键术语 Progress
- 工作准则 Report progress from any tool that can run longer than a few seconds, with a
totalwhen you know it and a message a person can read. Keep the SDK's default response mode. Usejson_response=Trueonly for a server whose every tool is quick, and know that it drops every progress report and every cancellation without telling anyone.
-
取消客户端不再需要的调用
- 工作准则 通过 Streamable HTTP 取消调用时,应取消正在等待该调用的任务,或使用超时,并让 SDK 关闭流。把长时间运行的工具写成
async def,重新抛出取消异常,并把任何需要等待的清理工作放在受屏蔽的作用域之下。使每个长时间运行的工具都能安全重试,因为断开的流会丢失调用,而客户端会再次发送它。
- 工作准则 通过 Streamable HTTP 取消调用时,应取消正在等待该调用的任务,或使用超时,并让 SDK 关闭流。把长时间运行的工具写成
-
Run replicas without sticky sessions
- 工作准则 Run replicas with no sticky sessions, and give every replica the same server name and the same
requestStatekeys, injected from your secret store. Before you add a second replica, list every piece of state your tools keep in memory, such as handles, once-only records and subscriptions, and move each into storage that every replica reaches. Until one is moved, route the tools that depend on it to a single replica byMcp-Name.
- 工作准则 Run replicas with no sticky sessions, and give every replica the same server name and the same
-
Reject requests from other origins
- 工作准则 Keep the SDK's loopback default on a developer's machine. When you deploy on any other address, pass
transport_security=TransportSecuritySettings(allowed_hosts=[...], allowed_origins=[...])with the names your server answers to, such asmcp.fernhill.example, and never rely on the default. Treat Origin validation as protection against browsers only, and put authorization in front of every server that anything but its own host can reach.
- 工作准则 Keep the SDK's loopback default on a developer's machine. When you deploy on any other address, pass
-
选择 stdio 还是 Streamable HTTP
- 工作准则 当服务器为单个用户在该用户的机器上工作时,通过 stdio 交付。当它服务多个宿主、守护宿主无法访问的系统或必须扩展时,通过 Streamable HTTP 交付,并在其第一个外部用户出现之前为它配置来源检查和授权。同一份服务器代码可以同时支持两者,因此应按部署而非按服务器来选择。
-
生产环境中会出什么问题
- 工作准则 在商店的服务器于某个地址上接收流量之前,请通过真实的代理路径测试四件事:外来的
Origin得到 403;调用运行期间进度能够到达;超过代理空闲时限的调用能够存活;关闭调用的流会使工具停止。然后按客户端观察 421、403 和 -32020,并按时长观察取消。
- 工作准则 在商店的服务器于某个地址上接收流量之前,请通过真实的代理路径测试四件事:外来的
- Decisions this chapter made
7. 将长时间工作作为任务运行
阅读约 89 分钟,4个示例。
读完本章,你将能够协商一项模型上下文协议(Model Context Protocol)扩展,把缓慢的补货报告作为由客户端轮询的任务来运行,让任务过期并取消任务,并说明 MCP Apps 为工具增加了什么。
讲义大纲:8节
-
Negotiate an extension
- 工作准则 Turn an extension on only on a side that implements it, through the SDK's extension classes, never by writing the identifier into capabilities by hand. Decide, for each tool on the server, what a client without the extension gets: an ordinary result when the work can finish within a normal call, and error -32021 when it can't. Check the client's declaration on every request, because at the pinned revision each request declares its own.
-
Start a task instead of waiting
- 工作准则 Answer with a task when the work can outlive the connection, and decide per call, not per tool, when some calls are short. Store the task before you return the handle, and generate its ID from a cryptographic random source, with at least 128 bits. Run the same code a plain call runs, so a task's result never differs from a plain result. Never return a task to a request that didn't declare the extension.
-
Poll a task and fetch its result
- 工作准则 Poll at the server's
pollIntervalMs, re-read it on every reply, and stop at the first terminal status. Treatcompletedas the original call's result,isErrorand all, andfailedas a protocol error. Hide the polling in a client extension so the rest of the host sees plain calls. When a host must survive a restart, store each task ID before the first poll, and resume from it.
- 工作准则 Poll at the server's
-
Expire and cancel tasks
- 工作准则 Give every task a TTL that covers the longest wait you expect between the work finishing and the client fetching it, and purge after it; for the shop's restock report, that is an hour. Make long work check for cancellation at each natural step, such as each product, and clean up there. In the client, treat a cancel's acknowledgement as "asked", not "stopped", and treat -32602 from
tasks/getas a task that is gone for good.
- 工作准则 Give every task a TTL that covers the longest wait you expect between the work finishing and the client fetching it, and purge after it; for the shop's restock report, that is an hour. Make long work check for cancellation at each natural step, such as each product, and clean up there. In the client, treat a cancel's acknowledgement as "asked", not "stopped", and treat -32602 from
-
了解 MCP Apps 增加了什么
- 工作准则 当结果需要的不只是文本才能据以操作,例如需要排序的表格或每行一个选择,并且用户所用的宿主支持该扩展时,再使用 MCP Apps。让每个启用界面的工具的文本结果保持完整,这样不支持 Apps 的宿主只会失去视图。当模型不应调用应用专用工具时,把它们的可见性设为
["app"],并记住强制执行这一限制的是宿主,而不是你的服务器。
- 工作准则 当结果需要的不只是文本才能据以操作,例如需要排序的表格或每行一个选择,并且用户所用的宿主支持该扩展时,再使用 MCP Apps。让每个启用界面的工具的文本结果保持完整,这样不支持 Apps 的宿主只会失去视图。当模型不应调用应用专用工具时,把它们的可见性设为
-
在任务、进度通知与普通调用之间做选择
- 工作准则 当结果能远在宿主与服务器之间所有超时限制之内返回时,使用普通调用。当工作耗时较长,调用方在一条你信得过会保持打开的连接上等待,并且希望得到可展示的数值时,使用进度通知。当工作可能比连接存续得更久,或调用方希望离开后再回来时,使用任务。要接受任务只报告一条状态消息这一点,并为没有该扩展的客户端保留普通调用的后备方案,或明确返回 -32021。
-
生产环境中会出什么问题
- 工作准则 在任务投入生产之前,把任务的存储迁移到所有副本都能读取的地方;记录每个任务的所有者,并在每个任务请求上检查;设置 TTL,并配以按计划运行的清理。然后按副本监控
tasks/get返回的 -32602、tasks/get与tools/call的比值、已存储任务的数量,以及取消之后工作还会运行多久。
- 工作准则 在任务投入生产之前,把任务的存储迁移到所有副本都能读取的地方;记录每个任务的所有者,并在每个任务请求上检查;设置 TTL,并配以按计划运行的清理。然后按副本监控
- 本章做出的决定
8. 使用 OAuth 授权客户端
阅读约 122 分钟,7个示例。
读完本章,你将能够用 OAuth 保护商店的 Model Context Protocol 服务器。
讲义大纲:9节
-
Find the authorization server from the resource
- 工作准则 Give every protected server an
AuthSettingswith its endpoint's URL asresource_server_url, exactly as clients will type it, and the smallestrequired_scopesthat every request needs. Check the chain with one request that carries no token: a 401, aresource_metadataURL, metadata whoseresourceis the endpoint, and authorization server metadata whoseissueris the URL you fetched it from. When a value differs by a trailing slash or a port, fix the configuration rather than relaxing the client.
- 工作准则 Give every protected server an
-
Identify the client with a metadata document
- 工作准则 Give every host one Client ID Metadata Document at a stable
https://URL, with only the redirect URIs it uses and no secret, and pass that URL to the SDK asclient_metadata_url. Use pre-registered credentials where an authorization server has issued them, since they rank first, and keep Dynamic Client Registration only for authorization servers that support nothing else. In tests on loopback, keep the client ID anhttps://URL and associate it with a local copy of the document in the test authorization server, rather than giving the client anhttp://ID that no production server accepts.
- 工作准则 Give every host one Client ID Metadata Document at a stable
-
用 PKCE 获取令牌
- 工作准则 让 SDK 的
OAuthClientProvider运行授权码流程,并从授权服务器一侧检查一次它发送的内容:S256、state,以及在两个请求中都等于服务器 URL 的resource。补上 SDK 跳过的那项检查,拒绝元数据中未列出S256的授权服务器。在你自己运行的授权服务器上,只接受S256,使授权码一次性且短时有效,并把每个授权码绑定到它的客户端、重定向 URI 和资源。
- 工作准则 让 SDK 的
-
Bind each token to one server
- 工作准则 Set
validate_token_resource=Trueon every protected server, and make the token verifier fillAccessToken.resourcefrom the token'saud. Treat anMCPDeprecationWarningfromAuthSettingsas a failed deployment, not as noise. Test the check with a token for another resource from the same authorization server, which must get 401. A server that calls another service on a client's behalf gets its own token for that service and never passes the client's token on (Never pass a client's token through).
- 工作准则 Set
-
Validate the issuer of each response
- 工作准则 Send
issfrom every authorization server you run, and advertise it withauthorization_response_iss_parameter_supported: true, so that clients reject an answer without it. In a host, keep the SDK's check, add no normalisation around it, and treat a mismatch as an attack: show the user none of that response's error text. When a host must use an authorization server that doesn't sendiss, keep the host to an allow-list of authorization servers, and refuse or warn the user about any server not on it. Don't count on a separate redirect URI per server when the host is identified by a metadata document.
- 工作准则 Send
-
按令牌允许的范围限定工具
- 工作准则 为每个工具映射其权限范围,并且严格使用 SDK 所认证的凭据来授权已解析的请求,绝不只依据某个标头。拒绝带有两个
Authorization标头的请求,以及映射表未覆盖的任何方法。将Mcp-Name视为一个提示,解码后它必须与请求体一致,并拒绝任何无法按服务器相同方式精确解析的请求体。对缺失的权限范围,返回 403insufficient_scope质询,并写明该工具的全部权限范围,同时让required_scopes只包含每个请求都需要的范围。
- 工作准则 为每个工具映射其权限范围,并且严格使用 SDK 所认证的凭据来授权已解析的请求,绝不只依据某个标头。拒绝带有两个
-
调用需要时再申请更多范围
- 工作准则 让 SDK 负责升级授权,并保留它对范围取并集的做法。列出调用方可能通过升级授权获得的每一个工具,因为被隐藏的工具永远不会收到触发升级的那个 403。在宿主中,将令牌响应所授予的范围与质询所要求的范围加以比较。两者不一致时,应将其视为一项决定,而不是故障:告诉用户该调用需要哪个范围,并把工单转交给持有该范围的人。绝不能让授权服务器通过升级授权授予用户角色所不允许的权限。客户端只负责申请,决定权在授权服务器。
-
What goes wrong in production
- 工作准则 Run three probes against the deployment before the shop's server takes traffic. A request without a token gets 401 with a
resource_metadataURL. A token for another resource gets 401. A refund with a read-only token gets 403 withscope="refunds:write", and the same refund with a secondAuthorizationheader gets 400. Then check the metadata of every authorization server your hosts use forS256,isssupport and metadata document support, and watch the 401s, 403s and authorization requests per host.
- 工作准则 Run three probes against the deployment before the shop's server takes traffic. A request without a token gets 401 with a
- Decisions this chapter made
9. 保护工具免遭滥用
阅读约 78 分钟,6个示例。
读完本章,你将能够划定 Model Context Protocol 服务器及其宿主周围的信任边界,拒绝令牌透传,防止服务器充当混淆代理人(confused deputy),固定工具定义以便发现被改动的定义,把工单文本当作数据处理,并在任何有副作用的工具调用之前询问用户。
讲义大纲:9节
-
划定信任边界
- 工作准则 在发布 MCP 服务器或宿主之前,先写出它的边界表:每一对交换数据或权限的双方各占一行,写明跨越边界的内容和检查者。检查者是"模型"或"另一方"的行,就是一个缺口。用你能控制的检查来补上它;如果不可能存在任何检查,比如对于模型所读的文本,就限制其背后的工具能做的事。
-
Never pass a client's token through
- 工作准则 Accept only tokens whose audience is your server, and turn the check on explicitly, since the SDK doesn't by default. Call every upstream service with a credential of the server's own: an API key, a client-credentials token, or a token for the user from the upstream's own authorization server. Never forward the bearer token you received, even to a service that would accept it, and log the caller's identity yourself, because the upstream's logs will show only your server.
-
防止服务器充当混淆代理
- 工作准则 绝不从工具参数中获取执行操作的用户。应从已验证令牌的主体中获取;若接受多个签发者,则同时取签发者。在客户登录的场景中,主体就是客户。在员工登录的场景中,主体是该员工,而客户来自服务器按 ID 查找的记录,并对照该员工可处理的范围进行检查。要用它核对一次调用涉及的每条记录。把服务器签发的每个句柄绑定到它所签发给的用户,并对其他用户的记录和句柄一律答复为未找到。如果你的服务器代理第三方 OAuth API,还要遵循安全指南中关于混淆代理的一节,并在转发任何内容之前,为每个客户端显示你自己的同意页面。
-
Catch poisoned tool descriptions
- 先行询问 Before you run the example, predict how many of the three poisoned runs call
track_parcel. - 工作准则 Treat every definition from a server you don't operate as untrusted input to the model. When a user first enables a server, show the full definitions, not only titles, and look for free-text parameters the tool doesn't need, which are a poisoned description's channel. Don't count on the model or a scanner. Limit what each server can receive and each tool can do, and gate the calls.
- 先行询问 Before you run the example, predict how many of the three poisoned runs call
-
Pin tool definitions and flag changes
- 工作准则 Pin every tool definition the user approves, by a hash over its name, title, description, schemas and annotations, per server. On a list-changed notification or a cache refresh, compare, keep any changed or new tool from the model, and show the user the difference before enabling it again. Accept that harmless rewordings ask again too: a definition the model reads is part of what the user agreed to.
-
将工单文本视为不可信数据
- 工作准则 假定客户写下的任何文本迟早会作为指令到达模型,并据此设计工具,使服从这些文本造成的危害有界。金额、所有者和限额取自服务器自己的记录,绝不取自模型根据文本填写的参数;副作用则要置于服务器端的检查和宿主端的同意之后。记录工具所忽略的参数,因为在一个不接受该参数的调用上出现
amount,就是文本被注入的迹象。
- 工作准则 假定客户写下的任何文本迟早会作为指令到达模型,并据此设计工具,使服从这些文本造成的危害有界。金额、所有者和限额取自服务器自己的记录,绝不取自模型根据文本填写的参数;副作用则要置于服务器端的检查和宿主端的同意之后。记录工具所忽略的参数,因为在一个不接受该参数的调用上出现
-
在产生副作用之前征求同意
- 工作准则 对于不在宿主自己的无副作用调用列表中的每一次工具调用,都要先询问用户;该列表应按服务器,依据你所掌握的情况来建立,绝不依据注解。展示确切的参数,用户展开时展示完整内容,并将每项决定与调用一并记录。即使服务器自己会请求确认,也要把同意保留在宿主中,因为一个你不信任的服务器不会去询问。
-
生产环境中会出什么问题
- 工作准则 安全控制在上线之前,应通过 HTTP 并使用至少两位用户的真实令牌进行测试。把句柄所有者存放在每个副本都能读取的位置,令牌从读取范围起步,并验证服务器交给宿主的命令和 URL。然后观察已签发的令牌与已使用的权限范围之比、各副本上的“无此报价”错误、每个服务器提出的确认问题数量,以及用户的回答速度。
- 本章做出的决定
10. 构建一个处理工单的宿主
阅读约 85 分钟,6个示例。
读完本章,你将能够:把一个宿主连接到多个 Model Context Protocol 服务器,为它们的工具命名并避免冲突,运行一个简短的循环,让模型调用工具并读取结果,代表用户回应服务器的输入请求,把资源放入模型的上下文,并用以上全部能力处理一队工单。
讲义大纲:8节
-
Connect one client per server
- 工作准则 Give each server its own
Client, in auto mode, under a key from the host's configuration. Cache each server's era for as long as its process or origin lasts, reuse it across restarts of the same configuration if you like, and probe again when a request fails with a version error. Don't useClientSessionGroupatmcp2.3.0: itsconnect_to_serverspeaks only the 2025 handshake, and givenClientsessions it adds merged lists but not the retry rounds or the host's own names. Check again at each SDK release, because a group that probes would remove the need for your own map.
- 工作准则 Give each server its own
-
Name tools across servers
- 工作准则 Prefix every tool name with a key from the host's configuration, joined by
.or_, and route each call back through your own map, never byserverInfo.name. Prefix all names, not only the ones that collide, so names stay stable when a server changes. Send an unknown or unprefixed name back to the model as an error instead of guessing.
- 工作准则 Prefix every tool name with a key from the host's configuration, joined by
-
运行宿主循环
- 工作准则 把循环保留在宿主中,保持简短且有界:让每个调用都经过你自己的映射来路由,经过同意关卡,设置超时,并把每种结果,包括错误,都以你自己的代码所写的格式发回给模型。限制每张工单的模型调用次数。任何超过几轮的处理,例如跨工单的规划或记忆,都属于智能体框架,而不属于宿主的协议代码。
-
Answer input requests for the user
- 工作准则 Give each client its own elicitation callback that knows which server it belongs to, and show the user that server's name with its message, the fields and a way to decline. Return a decline to the model as the server's error, not as silence, so the model can say what happened. Keep consent in the host as well, because the server's question covers only what the server chooses to ask.
-
Put resources in the model's context
- 工作准则 Decide in the host which resources reach the model, by rules you can state: a fixed list, or annotations from servers you trust, with a cap on their size. Read them through the client's cache. Let the user add a resource for one ticket when the rule misses it, and never let the model or a ticket's text choose on its own.
-
处理整个工单队列
- 工作准则 把模型的最终回复视为草稿,把主机的调用日志视为实际发生的事。回复送达客户之前,将其中的承诺与已运行的调用相比较,二者不一致时,例如退款工单并未退款,就把工单交给人处理。在回复发出之前,删去其中的任何句柄,例如
quote_id。按结果而不只是按第一个工具给运行评分,并且每次更改提示词、描述或模型时,都对整个队列录制一次运行。
- 工作准则 把模型的最终回复视为草稿,把主机的调用日志视为实际发生的事。回复送达客户之前,将其中的承诺与已运行的调用相比较,二者不一致时,例如退款工单并未退款,就把工单交给人处理。在回复发出之前,删去其中的任何句柄,例如
-
生产环境中会出什么问题
- 工作准则 在投入生产之前,让主机按工单分别记录所提供的工具、每次调用及其结果、每个同意询问和输入请求,以及模型的最后一条回复,以便把一个糟糕的回答追溯到引起它的那一轮。关注每次模型调用的工具列表大小,在调用丢失时重新连接并重试,并让每个服务器的工具列表和固定值始终处于主机的控制之下。
- 本章做出的决定
11. 测试服务器并观察其运行
阅读约 103 分钟,6个示例。
读完本章,你将能够:在内存中和通过 HTTP 测试 Model Context Protocol 服务器的工具;在发布前发现会破坏客户端的模式变更;把记录下来的宿主运行重放为回归测试;用 OpenTelemetry 追踪工具调用;衡量模型选对工具的频率;以及在不破坏现有客户端的前提下停用一个工具。
讲义大纲:8节
-
Test tools in memory
- 工作准则 Test each tool in memory with
Client(server, raise_exceptions=True), and assert onstructured_contentfields andis_error, not on whole results. Keep at least one test per transport you ship that goes over it on loopback, for the header, origin and streaming checks an in-memory test can't reach, and put the tests of trace propagation and list changes there too.
- 工作准则 Test each tool in memory with
-
Check schemas as a contract
- 工作准则 Keep the last release's
tools/listin the repository, and in CI validate every structured result your tests produce against it as well as against the new schema, each by the dialect it declares and by 2020-12 when it declares none. Treat a removed, renamed or retyped output field and a new required input as a breaking change: add the new field beside the old one, or add a new tool, and retire the old shape through a window (Change tools without breaking clients). Don't rely on a short TTL to protect clients that are already connected.
- 工作准则 Keep the last release's
-
Replay recorded host runs
- 工作准则 Replay a recorded run of the whole queue in CI, assert on each ticket's tool sequence, and run a check that compares each reply's promises with the calls that returned a result. Keep generated IDs and clocks fixed in the servers a replay runs against, or it stops for reasons that aren't changes. Then treat
RecordingMismatchas a signal, not as a flaky test: when you change a description, a prompt or a tool's output, record again with the recording script and compare the new run's scores with the old run's before you ship.
- 工作准则 Replay a recorded run of the whole queue in CI, assert on each ticket's tool sequence, and run a check that compares each reply's promises with the calls that returned a result. Keep generated IDs and clocks fixed in the servers a replay runs against, or it stops for reasons that aren't changes. Then treat
-
Trace calls with OpenTelemetry
- 工作准则 Install an OpenTelemetry SDK and exporter in every server and host you run, and let the SDK's middleware make the server spans. Build dashboards on the attributes the SDK emits,
mcp.method.name,gen_ai.tool.nameanderror.type, and label them as following a Development-status convention at a named version, because the names may change. Don't validate method names against the pinned conventions package. Test propagation over a real transport, and wrap in-memory calls in a span of your own when a test needs a parent.
- 工作准则 Install an OpenTelemetry SDK and exporter in every server and host you run, and let the SDK's middleware make the server spans. Build dashboards on the attributes the SDK emits,
-
衡量正确选择工具的频率
- 工作准则 对每次已记录的运行,按标签给第一个工具打分,而不只看总体;参数则单独打分,既对照工单给模型的内容,也对照事实。先处理最大混淆背后的描述,重新记录,并比较两次记录之间各标签的得分。在每个得分旁标明模型、提示词和工单集,并且不要在不同设置之间比较得分。
-
Change tools without breaking clients
- 工作准则 Retire a tool in three releases: add the replacement and mark the old tool deprecated in its description, keep both working through a window you announce, then answer the old name with an execution error that names the replacement. Shorten
ttlMsontools/listwhile the change is under way, publish a list change at each release, and open asubscriptions/listenstream in every host you control. Say in your changelog that the window is your policy, since the protocol defines none.
- 工作准则 Retire a tool in three releases: add the replacement and mark the old tool deprecated in its description, keep both working through a window you announce, then answer the old name with an execution error that names the replacement. Shorten
-
生产环境中会出什么问题
- 工作准则 在依赖某条追踪或某个分数之前,先检查它涵盖了什么:哪种传输方式、哪个模型,以及每个模式的哪个版本。让 span 名称保持有界,默认不把参数放入 span,把仪表盘所用的属性名称固定到某个具名的约定版本,并在每个版本到达副本之前,对它运行契约测试和回放。
- 本章所做的决定
12. 迁移 2025 年代的服务器
阅读约 82 分钟,6个示例。
读完本章,你将能够把为 2025 年各修订版编写、基于 Python SDK 1.x 系列的 Model Context Protocol 服务器,迁移到修订版 2026-07-28 的规范以及 mcp 2.3.0 上。
讲义大纲:9节
-
Inventory what the old server depends on
- 工作准则 Inventory before you change anything, and sort the list by status. Fix every removed dependency before you let a client at the pinned revision connect, because there is no window for it, and count every request the server pushes mid-call as removed, even when the feature it asks for is only deprecated. Give each deprecated one a date of your own, earlier than the registry's earliest removal, and don't wait for warnings: run a scan like this one in CI, because the SDK is silent about some deprecated features.
-
移除 initialize 与会话 ID
- 工作准则 在旧服务器中搜索对会话、会话 ID 以及任何按连接存储的内容的每一处使用,把每一份状态都改为由一个工具返回、由下一个工具作为参数接收的句柄。让句柄保持不透明,并设置过期时间,由创建句柄的工具在其描述中说明;每次调用时检查调用方是否有权使用它,并把它存放在每个副本都能读取的位置。不要把后续调用所需的任何内容放在以会话为键的字典中,即使对仍有会话的 2025 年代客户端也是如此。
-
从 HTTP+SSE 迁移到 Streamable HTTP
- 工作准则 除非日志显示仍有宿主在使用 HTTP+SSE 传输,否则应从服务器中删除该传输,而不是移植它。如果有,就在 Streamable HTTP 端点旁提供旧端点,按客户端记录对它们的每一次连接,并设定移除日期,告知每个宿主的所有者。应把该传输视为已经具备移除条件,因为它的窗口期是三个月,而不是十二个月。
-
替换 sampling、roots 和 logging
- 工作准则 把每一个推送式 elicitation 都迁入解析器,它能同时服务两个时代的客户端。删除 sampling 而不是迁移它:让宿主的模型去做模型的工作,或者由服务器用自己的凭据去调用提供方。把 roots 改成参数,并对照服务器配置中的允许列表进行检查;把日志行发往 stderr,把追踪数据发往你的追踪系统,绝不发给客户端。
-
Replace dynamic client registration
- 工作准则 Publish a Client ID Metadata Document for every host and pass its URL as
client_metadata_url. Make every authorization server you run advertise support for it, keep its registration endpoint only until the hosts that need it have moved, and log which kind of client ID each token was issued to, so that you can see when registration traffic has stopped.
- 工作准则 Publish a Client ID Metadata Document for every host and pass its URL as
-
将代码从 SDK 1.x 移植到 2.x
- 工作准则 在移植后的代码通过测试之前,让 2025 年代的服务器一直固定在
mcp<2,然后一次性完成移植:先处理错误信息指出的导入和更名,再处理迁移指南中的每一项无声变更,并用针对客户端所见内容的测试加以检查。移植完成后,应精确固定 2.x 版本,并把每个 2.x 版本都当作需要测试的变更,因为 SDK 的警告和默认值会在版本之间变化。
- 工作准则 在移植后的代码通过测试之前,让 2025 年代的服务器一直固定在
-
Serve old and new clients through the window
- 工作准则 Serve both eras from one
streamable_http_app()through the window, write every question a tool asks as a resolver, and route requests that carryMcp-Session-Idto the replica that minted it. Count requests by era. When the 2025 count has stayed at zero for as long as your slowest host takes to upgrade, serve the pinned revision only, and answerinitializewith an error that names the versions you support, as the specification asks.
- 工作准则 Serve both eras from one
-
生产环境中会出什么问题
- 工作准则 在迁移后的服务接收流量之前,先通过真实的代理路径验证它,并做四项测试:2025 客户端完成一次确认,2026 客户端完成同样的确认,2025 会话在一次部署后仍然存在,版本标头能够到达服务器。然后按时代观察请求、按客户端观察 404,并观察每一条弃用警告,直到 2025 的计数降为零。
- 本章的决定
测验题库
为通过认证的教育者提供每章的习题及参考答案。每个答案均对应其所在的节。 如何获取
正在加载题库…