> ## Documentation Index
> Fetch the complete documentation index at: https://mcp.transdocs.org/llms.txt
> Use this file to discover all available pages before exploring further.

# 进度跟踪

<Info>**协议修订日期**：2024-11-05</Info>

模型上下文协议（MCP）通过通知消息支持对长时间运行的操作进行可选的进度跟踪。通信的任意一方都可以发送进度通知，以提供操作状态的更新。

## 进度流程

当一方希望为某个请求接收进度更新时，应在请求的元数据中包含一个 `progressToken`。

* 进度令牌 **必须** 是字符串或整数类型
* 发送方可以使用任意方式选择进度令牌，但 **必须** 确保其在所有活跃请求中是唯一的

```json theme={null}
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "some_method",
  "params": {
    "_meta": {
      "progressToken": "abc123"
    }
  }
}
```

接收方随后可以发送包含以下内容的进度通知：

* 原始的进度令牌
* 当前的进度值
* 可选的“总进度”值

```json theme={null}
{
  "jsonrpc": "2.0",
  "method": "notifications/progress",
  "params": {
    "progressToken": "abc123",
    "progress": 50,
    "total": 100
  }
}
```

* 每次通知中的 `progress` 值 **必须** 递增，即使总值未知也是如此。
* `progress` 和 `total` 值 **可以** 是浮点数。

## 行为要求

1. 进度通知 **只能** 引用以下令牌：
   * 在活跃请求中提供的令牌
   * 与正在进行的操作关联的令牌

2. 接收进度请求的一方 **可以**：
   * 选择不发送任何进度通知
   * 按照认为合适的频率发送通知
   * 如果总值未知，可以省略 `total` 字段

```mermaid theme={null}
sequenceDiagram
    participant Sender
    participant Receiver

    Note over Sender,Receiver: 包含进度令牌的请求
    Sender->>Receiver: 包含 progressToken 的方法请求

    Note over Sender,Receiver: 进度更新
    loop 进度更新
        Receiver-->>Sender: 进度通知 (0.2/1.0)
        Receiver-->>Sender: 进度通知 (0.6/1.0)
        Receiver-->>Sender: 进度通知 (1.0/1.0)
    end

    Note over Sender,Receiver: 操作完成
    Receiver->>Sender: 方法响应
```

## 实现说明

* 发送方和接收方 **应该** 跟踪活跃的进度令牌
* 双方 **应该** 实现速率限制以防止消息洪泛
* 完成后 **必须** 停止发送进度通知
