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

# 进度

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

Model Context Protocol (MCP) 支持通过通知消息为长时间运行的操作提供可选进度跟踪。任一方都可以发送进度通知，以提供操作状态更新。

## 进度流程

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

* 进度 token **MUST** 是字符串或整数值
* 进度 token 可由发送方以任意方式选择，但 **MUST** 在所有活动请求中唯一。

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

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

* 原始进度 token
* 到目前为止的当前进度值
* 可选的 "total" 值
* 可选的 "message" 值

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

* `progress` 值 **MUST** 随每次通知递增，即使 total 未知。
* `progress` 和 `total` 值 **MAY** 为浮点数。
* `message` 字段 **SHOULD** 提供相关的人类可读进度信息。

## 行为要求

1. 进度通知 **MUST** 仅引用符合以下条件的 token：
   * 在活动请求中提供
   * 与正在进行的操作相关联

2. 进度请求的接收方 **MAY**：
   * 选择不发送任何进度通知
   * 以其认为适当的任意频率发送通知
   * 在 total 值未知时省略该值

3. 对于[任务增强请求](./tasks)，原始请求中提供的 `progressToken` **MUST** 在任务整个生命周期内继续用于进度通知，即使 `CreateTaskResult` 已经返回。进度 token 会保持有效并与任务关联，直到任务达到终止状态。
   * 任务的进度通知 **MUST** 使用初始任务增强请求中提供的同一个 `progressToken`
   * 任务达到终止状态（`completed`、`failed` 或 `cancelled`）后，任务的进度通知 **MUST** 停止

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

    Note over Sender,Receiver: Request with progress token
    Sender->>Receiver: Method request with progressToken

    Note over Sender,Receiver: Progress updates
    Receiver-->>Sender: Progress notification (0.2/1.0)
    Receiver-->>Sender: Progress notification (0.6/1.0)
    Receiver-->>Sender: Progress notification (1.0/1.0)

    Note over Sender,Receiver: Operation complete
    Receiver->>Sender: Method response
```

## 实现说明

* 发送方和接收方 **SHOULD** 跟踪活动进度 token
* 双方 **SHOULD** 实现速率限制以防止泛洪
* 完成后，进度通知 **MUST** 停止
