Phase 13: Tools & Protocols

标题:无国籍工具生态系统

生产代理系统是一个界限集,而不是一个功能堆. 这块结石分开了可读的过程模拟,从协议客户端,授权服务器,沙箱和远程仪表出口者,一个实际部署仍然需要.

Type: Build

Languages: Python (stdlib, in-process simulation)

Prerequisites: Phase 13 · 01 through 22, using MCP revision 2026-07-28

Time: ~120 minutes

学习目标

  • 编写工具调用,任务形状的结果,委托工作,UI资源,授权政策,并将记录记录记录集成到一个流程中.
  • 在每个MCP请求中运行协议版本,客户端身份和功能,而不是依赖连接会话.
  • 在使用前发现服务器,并通过官方任务扩展程序进行长时间工作.
  • 区分一个协议形状的模拟与MCP,A2A,OAuth或OpenTelemetry实现.
  • 绘制每个模拟的边界,将其取代的生产元件绘制出来.
  • 保持AGENTS.md机器,机器,安全政策,
  • 解释哪些索赔可以从本地输出中验证,哪些需要实时集成测试.

问题

设计一个研究和报告系统.用户要求关于代理协议的论文.系统搜索了纸质目录,委托了总结,生成了报告,返回了一个UI资源,并记录了系统的路径.

这句话隐藏了几个独立的合同:

  • 模型面向的工具方案;
  • 无国籍请求包和服务器发现合同;
  • 关口决定参与者,范围和工具身份;
  • 长期运营合同;
  • 委托议定书;
  • 接待者与应用程序之间的桥梁;
  • 痕迹传播和出口;
  • 可重复使用的操作程序.

code/main.py它不会打开传输,联系 arXiv,执行 OAuth,调用A2A服务器,染MCP应用程序或导出远程测量.这使得控制流程很容易检查,而不需要呈现模拟为符合服务.

概念

目标架构

flowchart LR
  U[User] --> C[Agent client]
  C --> G[Authorization gateway]
  G --> M[Research MCP server]
  M --> T[Search and report tools]
  M --> R[Resources and prompts]
  M --> Q[Task store]
  M --> A[A2A client]
  A --> W[Writer agent]
  M --> UI[MCP App resource]
  C --> O[Telemetry exporter]
  G --> O
  M --> O
  A --> O

建筑是公共协议模式的概念组成. 它不是关于任何产品的私人内部的声明.

目标追踪

flowchart TD
  I[agent.invoke_agent] --> SD[server/discover]
  I --> L1[llm.chat]
  I --> S[tools/call: arxiv_search]
  I --> D[A2A SendMessage]
  D --> X[Opaque writer-agent execution]
  I --> G[tools/call: generate_report]
  G --> K[tasks/get polling]
  K --> V[completed Task with final result]
  V --> UI[ui:// report resource]
  I --> L2[llm.chat final synthesis]

在实际实现中,每个跳跃都传播了痕迹背景. 跨度名称和属性必须遵循由选定的仪器版本支持的OpenTelemetry语义公约.单独的共享痕迹识别符不能证明正确的亲属,出口或后端摄入.

现行协议表面

使用当前协议所定义的方法名称,而不是从旧草案中记忆的名称:

BoundaryCurrent surfaceWhat the capstone simulates
MCP discoveryMandatory server/discoverA direct function returning versions, capabilities, and server identity
MCP request contextVersion, capabilities, and client identity in every params._metaFresh request metadata passed to every simulated call
MCP tool calltools/callDirect Python function dispatch
MCP task pollingio.modelcontextprotocol/tasks with tasks/getA working handle followed by a completed task carrying its final result
A2A delegationSendMessage in gRPC and JSON-RPC; POST /message:send in HTTP+JSONOne nested span with no remote call or artificial delay
MCP App calling a server toolapp.callServerTool({ name, arguments })An HTML string with no live bridge
OAuth authorizationAuthorization server, protected-resource metadata, audience and scope validationStatic token lookup and scope membership
OpenTelemetrySDK, propagator, exporter, and collector or backendIn-memory span dictionaries

协议名称仅仅是第一层. 生产测试必须在实线上进行序列化,身份验证故障,取消,时间切断,重试和版本兼容性.

无国籍的MCP改变了集成边界

修订2026-07-28删除协议会议和initialize现在,notifications/initialized握手,也可以消除Mcp-Session-Id每个请求都包含这些名字空间_meta字段:

json{
  "io.modelcontextprotocol/protocolVersion": "2026-07-28",
  "io.modelcontextprotocol/clientCapabilities": {
    "extensions": {
      "io.modelcontextprotocol/tasks": {}
    }
  },
  "io.modelcontextprotocol/clientInfo": {
    "name": "capstone-client",
    "version": "1.0.0"
  }
}

服务器必须实现server/discover常见结果使用resultType: "complete"任务处理器使用resultType: "task"每个结果都应该在 _meta.io.modelcontextprotocol/serverInfo现在,我们要去.

任务延长已tasks/get现在tasks/update其他tasks/cancel一个工具可能首先返回resultType: "task"其他tasks/get它们本身回来了.resultType: "complete"完成的Task总体而言,tasks/result其他tasks/list客户必须宣传 io.modelcontextprotocol/tasks如果没有,服务器会返回 -32021随着requiredCapabilities形状为缺失客户能力对象,包括extensions.io.modelcontextprotocol/tasks现在,我们要去.

安全姿势

预期部署使用深度防御:

  • 客户端类型要求的PKCE的OAuth授权;
  • 发行访问令牌的资源和观众绑定;
  • 通过RBAC检查所需工具和范围的门口;
  • 存储在模型可见的背景之外的上游凭证;
  • 置或审查的工具描述说明书;
  • 对于不值得信赖的输入,敏感数据和后续行动的第二规则审查;
  • 执行沙箱,其文件系统,进程,网络,凭证和资源限制在技能之外被执行.

演示程序只实现静态代币,范围检查和描述哈希. 它是用于政策流动,而不是安全验证.

技能是程序,而不是交通

经理技能可以告诉运行时间如何执行研究工作流程,哪些工具合约预期,什么证据保存,何时停止.它不能使一个MCP服务器存在,建立A2A兼容性,授予范围,或创建沙箱.

flowchart TD
  RI[Repository instructions] --> H[Host runtime]
  SK[Agent Skill procedure] --> H
  H --> P[Invocation and permission policy]
  P --> MCP[MCP client adapter]
  P --> A2A[A2A client adapter]
  P --> EX[Sandboxed executor]

程序引用伴侣文件时,请发送完整的技能目录.这块旧的顶石中的平面文物是课程蓝图,而不是主机保存可移植的捆绑的证据.24-27课程构建和测试完整的捆绑生命周期.

课程文物元数据是本地适配器

课程目录和安装器识别名为平板文件skill-*.md它们的最小前面材料解析器只读取顶级键.因此,这个课程保持了可移植的身份字段和课程目录字段在相同的水平:

yaml---
name: ecosystem-blueprint
description: Produce a full Phase 13 ecosystem architecture for a product need.
version: "1.0.0"
phase: "13"
lesson: "23"
tags: [mcp, capstone, ecosystem, architecture, a2a, otel]
---

name其他description它们是可移植的身份字段.version现在phase现在lesson其他tags课程分析器需要tags作为一个直线列表--tag capstone能匹配它.

可移植目录技能可能会使用可选的metadata字符串值扩展数据的地图.metadata如果这个平板文件子version或tags下面metadata产品主机应该使用安全的YAML解析器并验证自己的记录式方案.

模拟与生产

Layercode/main.pyProduction replacementRequired evidence
Discoveryserver_discover() plus static TOOLSserver/discover followed by cache-aware tools/listWire transcript, deterministic order, and schema validation
AuthenticationToken-keyed dictionaryOAuth authorization and resource server validationIssuer, audience, scope, expiry, and failure tests
AuthorizationScope membershipGateway policy bound to actor, tool, target, and tenantAllow and deny audit cases
SearchStatic paper fixturesSearch API or MCP serverSource provenance, ranking, and error tests
TasksLocal handle plus immediate tasks/getDurable io.modelcontextprotocol/tasks store with tasks/get, tasks/update, tasks/cancel, and TTLState-transition, input, cancellation, and recovery tests
DelegationSleep plus nested spanA2A client and remote Agent CardContract, timeout, retry, and opacity tests
AppHTML string and URIMCP Apps resource and App bridgeCSP, permissions, tool-call, and browser tests
TelemetryIn-memory listOTel SDK and exporterCollector receipt and trace-parent assertions
SandboxNoneHost-enforced isolated executorEscape, egress, secret, and resource-limit tests

绿色局部运行仅验证了模拟.

阶段13地图

LessonsContribution
01-05Tool interfaces, calls, schemas, structured results, and deterministic validation
06-14Stateless MCP request envelopes, discovery, transports, resources, prompts, extensions, and Apps
15-18Poisoning defenses, OAuth, gateways, registries, and production authentication
19A2A message and task delegation
20OpenTelemetry GenAI trace design
21Model-provider routing
22Portable skill contract and runtime boundary

建立它

运行过程中的带:

bashcd phases/13-tools-and-protocols/23-capstone-tool-ecosystem
python3 code/main.py

检查五件事:

  1. server/discover宣传修订2026-07-28并且扩展任务.
  2. 爱丽丝可以读取和生成报告,而勃的写作电话被拒绝.
  3. 每个在一个管弦乐队运行的本地跨度都共享一个痕迹识别符,并记录了父母跨度识别符.
  4. 报告开始作为一个任务处理.tasks/get返回完成任务,最终结果包含文本和一个ui://参考
  5. 委托的作者仍然不透明,因为乐团主持人只记录了边界跨度.
  6. 没有输出索赔网络连接,OAuth交换,集装器出口,浏览器染或沙箱执行发生.

编程运行两次,所以产生两个根痕迹.审计输入是过程本地,然后在下一次运行上重置.

用它

推广一个层次:

  1. 取代server_discover()和现实的静态工具列表server/discover其他tools/list发送版本,身份和功能在每个请求中.
  2. 通过授权服务器和保护资源验证来取代静态代币.
  3. 执行io.modelcontextprotocol/tasks延长和测试tasks/get现在tasks/update现在tasks/cancel没有添加tasks/result或tasks/list现在,我们要去.
  4. 替换代理文件,用A2A客户端来解决代理卡并发送消息.
  5. 使用官方SDK构建应用程序,并通过 调用服务器工具app.callServerTool现在,我们要去.
  6. 输出到检测器,并在接收器确认亲属.
  7. 运行工具和脚本执行从课26的沙盒合同中.
  8. 包装程序作为一个完整的目录捆绑,然后通过27课的释放门.

每次促销都需要一个跨越新界限的集成测试.

运送它

这一课产生了outputs/skill-ecosystem-blueprint.md要求一个页面的架构,涵盖原始,安全,委托,远程测量,包装和最难的运营风险.其顶级目录领域由库的真实目录和安装器进行.

由于它不是目录捆绑,它不能携带参考,脚本,资产或评估设置.在本课外发布可重复使用技能时,使用从课程22和24到27的包格式.

运动

  1. 跑步code/main.py产量证明的单独事实与生产索赔,仍然需要集成证据.
  2. 添加第二个静态后端,并定义两个同名工具的碰撞规则.然后将两个列表替换为真tools/list电话.
  3. 取代写作器的片用A2A测试服务器记录代理卡,消息请求,时间过关路径,返回的文物.
  4. 添加一个存储任务, 保存进程重启. 证明客户端可以恢复tasks/get尊重pollIntervalMs阅读完成任务的最终结果tasks/result现在,我们要去.
  5. 建立一个最小的MCP应用程序,并验证app.callServerTool在具有限制性CSP和明确许可的浏览器中.
  6. 通过OTel SDK将模拟的跨度输出到本地收藏器. 声明收件,追踪标识符,亲属和错误状态.
  7. 写下AGENTS.md对于整个库的维护规则和可重复使用的研究程序的单独技能包.解释为什么没有文件都授予工具权.

关键词

TermWhat people sayWhat it actually means
Capstone"Everything wired together"A staged integration whose simulated and live boundaries remain explicit
Protocol-shaped simulation"It is basically MCP"Local data and calls that resemble a protocol without implementing its wire contract
Tasks extension"Long tool call"An optional io.modelcontextprotocol/tasks lifecycle with durable identity, polling, client input, final result, and cancellation semantics
Opacity boundary"The other agent handles it"The caller sees the declared interface and artifacts, not private reasoning or internal state
Runtime adapter"Skill integration"Host code that maps portable procedure to discovery, invocation, tools, policy, and context
Integration evidence"It passed"A transcript, artifact, or receiver-side observation proving the real boundary was crossed

进一步阅读

This free lesson is part of the AI Engineering from Scratch curriculum. Read the full explanation, run the lesson code, and verify the result in the interactive reader or from the repository source.

Browse the complete course catalog or open this lesson on GitHub.