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

# 消息

<Info>**协议修订**: 2024-11-05</Info>

MCP中的所有消息**必须**遵循[JSON-RPC 2.0](https://www.jsonrpc.org/specification)规范。该协议定义了三种类型的消息：

## 请求

请求从客户端发送到服务器或从服务器发送到客户端。

```typescript theme={null}
{
  jsonrpc: "2.0";
  id: string | number;
  method: string;
  params?: {
    [key: string]: unknown;
  };
}
```

* 请求**必须**包含字符串或整数ID。
* 与基础JSON-RPC不同，ID**不能**为 `null`。
* 请求ID**不能**在同一会话中被请求者之前使用过。

## 响应

响应发送以回复请求。

```typescript theme={null}
{
  jsonrpc: "2.0";
  id: string | number;
  result?: {
    [key: string]: unknown;
  }
  error?: {
    code: number;
    message: string;
    data?: unknown;
  }
}
```

* 响应**必须**包含与它们对应的请求相同的ID。
* **必须**设置 `result` 或 `error` 中的一个。响应**不能**同时设置两者。
* 错误代码**必须**是整数。

## 通知

通知从客户端发送到服务器或从服务器发送到客户端。它们不期望响应。

```typescript theme={null}
{
  jsonrpc: "2.0";
  method: string;
  params?: {
    [key: string]: unknown;
  };
}
```

* 通知**不能**包含ID。
