Documentation Index
Fetch the complete documentation index at: https://mcp.zhcndoc.com/llms.txt
Use this file to discover all available pages before exploring further.
subscriptions/listen 会从服务器到客户端打开一个长期存在的通知流。与一次性请求不同,该流会保持打开状态并持续发送通知,直到客户端取消它。它取代了原先的 resources/subscribe RPC 和 HTTP GET 端点。
打开流
客户端发送一个带有notifications 过滤器的 subscriptions/listen 请求,用于指定希望接收哪些事件类型。服务器 不得 发送客户端未明确请求的通知类型。
通知过滤器
| 字段 | 类型 | 描述 |
|---|---|---|
toolsListChanged | boolean | 当工具发生变化时接收 notifications/tools/list_changed |
promptsListChanged | boolean | 当提示词发生变化时接收 notifications/prompts/list_changed |
resourcesListChanged | boolean | 当列表发生变化时接收 notifications/resources/list_changed |
resourceSubscriptions | string[] | 为这些资源 URI 接收 notifications/resources/updated |
确认
服务器 必须 作为流上的第一条消息发送notifications/subscriptions/acknowledged。确认中的 notifications 字段反映了服务器同意支持的子集——服务器不支持的通知类型会被省略。
接收通知
流上发送的所有通知都会在_meta 中携带 io.modelcontextprotocol/subscriptionId,该值与打开流的 subscriptions/listen 请求 ID 相匹配。对于 stdio,由于所有消息共享单一通道,客户端 必须 使用此字段将通知与其来源订阅关联起来。
多个并发订阅
客户端 可以 同时拥有多个活动订阅——例如,一个监听工具列表变更,另一个监听资源更新。每个订阅都由其subscriptions/listen 请求的 JSON-RPC 请求 ID 标识,而流上的每条通知都会在 io.modelcontextprotocol/subscriptionId 中携带该 ID,以便客户端进行分流。
取消
订阅在以下情况下结束:- 客户端 取消它——关闭 SSE 流(HTTP)或发送引用监听请求 ID 的
notifications/cancelled(stdio)。 - 服务器 将其拆除(例如,在关闭期间)——它会关闭底层传输连接。
- 底层传输关闭(HTTP 超时、TCP 断开连接、stdio 进程退出)。
subscriptions/listen 以重建其订阅——服务器不会在重连之间保留任何订阅状态。
完整规则请参见 取消。