> ## 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.

# 进度跟踪

<div id="enable-section-numbers" />

<Info>**协议修订版本**: 2025-06-18</Info>

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

## 进度流程

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

* 进度令牌 **必须**为字符串或整数
* 进度令牌可以由发送方以任意方式选择，但**必须**在所有活动请求中唯一

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

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

* 原始的进度令牌
* 到目前为止的当前进度值
* 可选的 "total"（总进度）值
* 可选的 "message"（消息）值

```json theme={null}
{
  "jsonrpc": "2.0",
  "method": "notifications/progress",
  "params": {
    "progressToken": "abc123",
    "progress": 50,
    "total": 100,
    "message": "正在校准曲线..."
  }
}
```

* 每次通知中的 `progress`（进度）值**必须**递增，即使总进度未知也是如此。
* `progress` 和 `total` 值**可以**是浮点数。
* `message` 字段**应该**提供相关的、人类可读的进度信息。

## 行为要求

1. 进度通知**必须**仅引用以下令牌：
   * 在活动请求中提供的令牌
   * 与正在进行的操作相关联的令牌

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

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

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

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

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

## 实现注意事项

* 发送方和接收方**应该**跟踪当前活动的进度令牌
* 双方**应该**实现速率限制以防止通知泛滥
* 操作完成后，进度通知**必须**停止
