> ## 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" />

本页定义核心协议的消息模式：客户端和服务器如何将 JSON-RPC
[请求、响应和通知](/specification/draft/basic/index#messages)
组合成交互。每种[传输](/specification/draft/basic/transports)都会承载所有这些模式；
传输之间的差异只在于消息如何成帧和交付。

每次交互都由客户端开始：

* **客户端**发送 JSON-RPC *请求* 和 *通知*。
* **服务器**用 JSON-RPC *响应*（结果或错误）回答每个请求；在响应之前可以选择发送作用域限定到该请求的 *通知*。

服务器 **MUST NOT** 发起 JSON-RPC 请求，客户端也不发送 JSON-RPC 响应。

## Request and Response

客户端发送请求；服务器以结果或错误回答该请求。请求进行期间，服务器 **MAY** 发送作用域限定到该请求的通知，例如
[`notifications/progress`](/specification/draft/basic/patterns/progress)
和 [`notifications/message`](/specification/draft/server/utilities/logging)。

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

    Client->>Server: request
    Server-->>Client: notifications/progress (optional)
    Server-->>Client: response
```

## Multi Round-Trip Requests

当服务器需要客户端输入（采样、引出或根目录）才能完成请求时，它会以
[`InputRequiredResult`](/specification/draft/basic/patterns/mrtr#inputrequiredresult)
回答，客户端随后带上匹配的 `inputResponses` 重试该请求。见[多轮往返请求](/specification/draft/basic/patterns/mrtr)。

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

    Client->>Server: request (id: 1)
    Server-->>Client: InputRequiredResult (inputRequests)
    Client->>Server: request (id: 2, original params + inputResponses)
    Server-->>Client: response
```

## Subscribe and Notify

为了接收变更通知（列表变更、资源更新），客户端发送
[`subscriptions/listen`](/specification/draft/basic/patterns/subscriptions)
请求；回复是一个长生命周期流，包含所请求的通知类型。流状态的作用域限定在请求内：
如果底层通道丢失，客户端会重新发出该请求。

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

    Client->>Server: subscriptions/listen
    Server-->>Client: notifications/subscriptions/acknowledged
    note over Client,Server: Stream stays open
    Server-->>Client: notifications/* (tagged with subscriptionId)
```

## 添加模式

所有核心协议特性都由这些模式构建而成。添加模式的协议版本会在本页定义该模式。
传输无需变更即可承载新模式，因为模式完全以请求、响应和通知来表达。
