> ## 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 中的所有消息 **必须** 遵循
[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。
