AI 工程从零到一(中文)
为面向协议 revision 2026-07-28 的 MCP operation 设计一个 user-input step。
产出:
- Scope 契约。将 workspace、directory 或 resource URI 放入可见 tool arguments 或 server configuration。说明哪些 authenticated principals 可以使用它。
- Boundary checks。定义 URI normalization、path-component containment、symbolic-link policy 和 operating-system sandbox。
- Trigger condition。说明需要用户 input 的精确 ambiguity、confirmation 或 external interaction。
- Discovery 与 capability gate。从
server/discover返回精确的supportedVersions、capabilities、ttlMs和cacheScope。如果声明 tools,包含必需的确定性tools/listdescriptors,且有有效 objectinputSchema、server identity metadata 和 cache hints。将elicitation: \{\}和显式elicitation.form视为 form support。以-32021和data.requiredCapabilities.elicitation.form拒绝缺失或仅 URL support;对于不支持 version,以精确supported与requesteddata 使用-32022。 - MRTR result。返回带稳定
inputRequestskey 和elicitation/createrequest 的resultType: "input_required"。 - Interaction design。对 form mode 提供纯文本 message 和受限 flat schema;对 URL mode 展示 HTTPS destination 与 out-of-band completion rule。
- Retry 契约。要求新的 JSON-RPC id、原始 method 与 arguments、当前
inputResponses、逐请求_meta和精确requestStateecho。无 id notification 绝不接收 JSON-RPC result 或 error;已接受 Streamable HTTP notification 返回无 body 的202。 - Branch handling。将
accept、decline和cancel映射到不同安全 outcomes。 - State protection。将 HMAC 或 authenticated encryption 绑定到 authenticated principal、原始 argument digest、candidate set、operation phase、expiry 与 one-time nonce。在由所有 handler instances 共享的有界、TTL-pruned replay store 中原子消费 nonce。
- Final revalidation。在 mutation 前立即重新检查 authorization、live record state 与 containment。
硬拒绝:
- 将已弃用 Roots 视为 authorization、containment 或 sandboxing。
- 在新的 2026-07-28 design 中使用
roots/list或notifications/roots/list_changed。 - 发送反向
elicitation/createrequest,而非通过 MRTR 返回它。 - 在 form mode 中收集 passwords、API keys、access tokens 或 payment credentials。
- 发送当前逐请求 capabilities 中缺少的 elicitation mode。
- 将
clientInfo视为 authenticated user identity。 - 在 validated acceptance 与最终 authorization checks 前执行破坏性 action。
- 使用携带 candidates 或 permission-relevant data 的未签名
requestState。
拒绝规则:
- 在明确 decline 后拒绝重复 prompts。
- 对 server 可以不借助用户就能派生或校验的 value,拒绝 elicitation。
- 拒绝包含 credentials、user secrets 或 pre-authenticated bearer value 的 URL。
- 拒绝使用隐藏协议-session state、
initialize或Mcp-Session-Id的 request。
输出一页设计,包含 scope、authorization、containment、interaction mode、schema 或 URL、MRTR wire shape、state fields、response branches、replay policy 与最终 revalidation checklist。