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

# Ping

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

<Info>**协议版本**：草案</Info>

模型上下文协议包含一个可选的 Ping 机制，允许通信双方验证对方是否仍然响应正常且连接处于活动状态。

## 概述

Ping 功能通过一个简单的请求/响应模式实现。客户端或服务器均可通过发送 `ping` 请求来发起 Ping 操作。

## 消息格式

Ping 请求是一个不包含参数的标准 JSON-RPC 请求：

```json theme={null}
{
  "jsonrpc": "2.0",
  "id": "123",
  "method": "ping"
}
```

## 行为要求

1. 接收方 **必须** 立即响应一个空响应：

```json theme={null}
{
  "jsonrpc": "2.0",
  "id": "123",
  "result": {}
}
```

2. 如果在合理的超时时间内未收到响应，发送方 **可以**：
   * 认为连接已失效
   * 终止连接
   * 尝试重新连接流程

## 使用模式

```mermaid theme={null}
sequenceDiagram
    participant 发送方
    participant 接收方

    发送方->>接收方: ping 请求
    接收方->>发送方: 空响应
```

## 实现考虑

* 实现 **应该** 周期性地发送 Ping 请求以检测连接状态
* Ping 请求的频率 **应该** 可配置
* 超时时间 **应该** 根据网络环境合理设置
* 应 **避免** 过度的 Ping 请求以减少网络开销

## 错误处理

* 超时 **应该** 被视为连接失败
* 多次 Ping 失败 **可以** 触发连接重置
* 实现 **应该** 记录 Ping 失败信息以供诊断
