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

# 分页

模型上下文协议 (MCP) 支持对可能返回大型结果集的列表操作进行分页。分页允许服务器以小批量而不是一次性地产生结果。

当通过互联网连接外部服务时，分页尤为重要，但对于本地集成也很有用，以避免大型数据集的性能问题。

## 分页模型

MCP 中的分页使用基于不透明游标的方法，而不是编号页。

* **游标**是一个不透明的字符串令牌，代表结果集中的一个位置
* **页面大小**由服务器决定，客户端 **不得** 假设固定的页面大小

## 响应格式

当服务器发送包含以下内容的 **响应** 时，分页开始：

* 当前页的结果
* 如果存在更多结果，则包含可选的 `nextCursor` 字段

```json theme={null}
{
  "jsonrpc": "2.0",
  "id": "123",
  "result": {
    "resources": [...],
    "nextCursor": "eyJwYWdlIjogM30="
  }
}
```

## 请求格式

收到游标后，客户端可以通过发出包含该游标的请求来 *继续* 分页：

```json theme={null}
{
  "jsonrpc": "2.0",
  "method": "resources/list",
  "params": {
    "cursor": "eyJwYWdlIjogMn0="
  }
}
```

## 分页流程

```mermaid theme={null}
sequenceDiagram
    participant Client
    participant Server

    Client->>Server: List Request (no cursor)
    loop Pagination Loop
      Server-->>Client: Page of results + nextCursor
      Client->>Server: List Request (with cursor)
    end
```

## 支持分页的操作

以下 MCP 操作支持分页：

* `resources/list` - 列出可用资源
* `resources/templates/list` - 列出资源模板
* `prompts/list` - 列出可用提示
* `tools/list` - 列出可用工具

## 实现指南

1. 服务器 **应该**：
   * 提供稳定的游标
   * 优雅地处理无效游标

2. 客户端 **应该**：
   * 将缺失的 `nextCursor` 视为结果结束
   * 支持分页和非分页流程

3. 客户端 **必须** 将游标视为不透明令牌：
   * 不要对游标格式做出假设
   * 不要尝试解析或修改游标
   * 不要跨会话持久化游标

## 错误处理

无效游标 **应该** 导致代码为 -32602（无效参数）的错误。
