Schema 参考

Schema 参考

社区译文;来源: MCP 80041ab0

JSON-RPC

JSONRPCErrorResponse

interface JSONRPCErrorResponse {
  jsonrpc: "2.0";
  id?: RequestId;
  error: Error;
}

表示请求发生错误的响应。

JSONRPCMessage

表示可从传输线路解码或编码后发送的任意有效 JSON-RPC 对象。

JSONRPCNotification

interface JSONRPCNotification {
  method: string;
  params?: { [key: string]: any };
  jsonrpc: "2.0";
}

不期望响应的通知。

JSONRPCRequest

interface JSONRPCRequest {
  method: string;
  params?: { [key: string]: any };
  jsonrpc: "2.0";
  id: RequestId;
}

期望响应的请求。

JSONRPCResponse

请求的响应,其中包含结果或错误。

JSONRPCResultResponse

interface JSONRPCResultResponse {
  jsonrpc: "2.0";
  id: RequestId;
  result: Result;
}

请求的成功(无错误)响应。

Common Types

Annotations

interface Annotations {
  audience?: Role[];
  priority?: number;
  lastModified?: string;
}

提供给客户端的可选注解。客户端可以使用注解决定对象的使用或显示方式。

描述此对象或数据的预期受众。

可包含多个条目,以表示内容对多个受众有用(例如 ["user", "assistant"]).

描述此数据对服务器运行的重要程度。

值 1 表示 " 最重要," 表示数据是有效必需的,而 0 表示 " 最不重要," 表示数据完全是可选的。

资源的最后修改时间,采用 ISO 8601 格式的字符串。

应为 ISO 8601 格式的字符串(例如 "2025-01-12T15:00:58Z")。

示例:打开文件中的最后一个活动时间戳、附加资源时的时间戳等。

Cursor

Cursor: string

用于表示分页游标的不透明令牌。

EmptyResult

EmptyResult: Result

表示成功但不携带数据的结果。

Icon

interface Icon {
  src: string;
  mimeType?: string;
  sizes?: string[];
  theme?: "light" | "dark";
}

可在用户界面中显示、可选指定尺寸的图标。

指向图标资源的标准 URI。可以是 HTTP/HTTPS URL,也可以是 data: URI,其中包含 Base64 编码的图像数据。

消费者 SHOULD 采取措施确保 URLs 服务图标来自与 client/server 相同的域或受信任的域。

使用方处理 SVG 时 SHOULD 采取适当的防范措施,因为其中可能包含 可执行 JavaScript。

当源 MIME 类型缺失或过于宽泛时,可选择覆盖 MIME 类型。 例如: "image/png", "image/jpeg",或 "image/svg+xml".

可选字符串数组,用于指定图标可使用的尺寸。 每个字符串应采用 WxH 格式(例如 "48x48", "96x96")或 "any" ;对于 SVG 等可缩放格式则使用

如未提供,客户端应假定图标可用于任意尺寸。

可选字段,用于指定此图标所适配的主题。 "light" 表示该图标设计为与浅色背景一起使用,并且 "dark" 表示该图标设计为与深色背景一起使用。

如未提供,客户端应假定图标可用于任意主题。

InputResponseRequestParams

interface InputResponseRequestParams {
  _meta: RequestMetaObject;
  inputResponses?: InputResponses;
  requestState?: string;
}

所有请求的通用参数。

JSONArray

JSONArray: JSONValue[]

JSONObject

JSONObject: { [key: string]: JSONValue }
类型声明

JSONValue

JSONValue: string | number | boolean | null | JSONObject | JSONArray

LoggingLevel

LoggingLevel:
  | "debug"
  | "info"
  | "notice"
  | "warning"
  | "error"
  | "critical"
  | "alert"
  | "emergency"

日志消息的严重性级别。

这些级别对应 RFC 5424 中规定的 syslog 消息严重性: https://datatracker.ietf.org/doc/html/rfc5424#section-6.2.1

自协议版本 2026-07-28 (SEP-2577) 起已弃用。仍保留在规范中至少十二个月;请参阅已弃用的功能注册表。

MetaObject

MetaObject: Record<string, unknown>

表示 _meta 字段的内容,客户端和服务器使用该字段为交互附加额外元数据。

MCP 为协议级元数据保留了某些键名;实现 MUST NOT 对这些键的值做出假设。此外,特定模式定义可以为特定目的元数据保留特定名称,如这些定义中所声明的。

有效键包含两个部分:

前缀:

  • 可选;如指定,MUST 是一系列 标签 ,各标签以点号(.)分隔,末尾跟一个斜杠(/).
  • 标签 MUST 以字母开头,并以字母或数字结尾。中间字符可以是字母、数字或连字符(-).
  • 实现 SHOULD 使用反向 DNS 表示法(例如 com.example/ ,而不是 example.com/).
  • 第二个标签为 modelcontextprotocol 或 mcp 是 保留 供 MCP 使用。例如: io.modelcontextprotocol/, dev.mcp/, org.modelcontextprotocol.api/和 com.mcp.tools/ 都被保留了。然而, com.example.mcp/ 是 NOT 保留的,因为第二个标签是 example.

名称:

  • 除非为空,否则 MUST 以字母数字字符([a-z0-9A-Z])开头并结尾。
  • 中间字符可以是字母数字字符、连字符(-)、下划线(_)或点号(.)。

通用字段: _meta ,了解更多详情。

NotificationMetaObject

interface NotificationMetaObject {
  "io.modelcontextprotocol/subscriptionId"?: RequestId;
  [key: string]: unknown;
}

扩展 MetaObject,增加通知专用字段。MetaObject 的所有键命名规则仍然适用。

标识通知所经由的订阅流。服务器 MUST 在通过 subscriptions/listen 流传递的每条通知中包含此键,以便客户端将通知与原始订阅关联。未通过订阅流传递的通知(例如正在进行的请求的进度通知)不包含此键,因此该键在这里是可选的。

其值为打开此流的 subscriptions/listen 请求的 JSON-RPC ID。

NotificationParams

interface NotificationParams {
  _meta?: NotificationMetaObject;
}

所有通知的通用参数。

PaginatedRequestParams

interface PaginatedRequestParams {
  _meta: RequestMetaObject;
  cursor?: string;
}

分页请求的通用参数。

示例: 带游标的列表请求
{
"_meta": {
"io.modelcontextprotocol/protocolVersion": "2026-07-28",
"io.modelcontextprotocol/clientInfo": {
"name": "ExampleClient",
"version": "1.0.0"
},
"io.modelcontextprotocol/clientCapabilities": {}
},
"cursor": "eyJwYWdlIjogMn0="
}

表示当前分页位置的不透明标记。如果提供,服务器应从该光标之后开始返回结果。

ProgressToken

ProgressToken: string | number

用于将进度通知与原始请求关联的进度令牌。

RequestId

RequestId: string | number

JSON-RPC 中唯一标识请求的 ID。

RequestMetaObject

扩展 MetaObject,增加请求专用字段。MetaObject 的所有键命名规则仍然适用。

如果指定,则调用者正在请求此请求的带外进度通知(如 notifications/progress)。此参数的值是一个不透明令牌,将附加到任何后续通知。接收者没有义务提供这些通知。

此请求使用的 MCP 协议版本。必需。

对于 HTTP 传输,此值 MUST 与 MCP-Protocol-Version 标头匹配;否则服务器 MUST 返回 400 Bad Request。如果服务器不支持请求的版本,则 MUST 返回 UnsupportedProtocolVersionError。

标识发出请求的客户端软件。客户端 SHOULD 在每个请求中都包含此字段,除非专门配置为不这样做。

Implementation 模式要求提供 name 和 version;其他字段可选。

该值由客户端自行报告,未经协议验证。它用于显示、记录和调试。服务器 SHOULD NOT 使用它来更改其行为,并且 SHOULD NOT 依赖它做出安全决策。

客户端针对此请求的能力。必需。

能力按每个请求声明,而非仅在初始化时声明一次;空对象表示客户端不支持任何可选能力。服务器 MUST NOT 根据先前请求推断能力。

此请求所需的日志级别。可选。

如果未提供,服务器 MUST NOT 为此请求发送任何 notifications/message 通知。客户端通过显式设置级别来选择接收日志消息。此字段替代了原来的 logging/setLevel RPC。

自协议版本 2026-07-28 (SEP-2577) 起已弃用。仍保留在规范中至少十二个月;请参阅已弃用的功能注册表。

RequestParams

interface RequestParams {
  _meta: RequestMetaObject;
}

所有请求的通用参数。

Result

interface Result {
  _meta?: ResultMetaObject;
  resultType: string;
  [key: string]: unknown;
}

通用结果字段。

指示结果的类型,允许客户端决定如何解析结果对象。

实现此协议版本的服务器 MUST 包含此字段。为向后兼容,当客户端收到实现较早协议版本(不包含 resultType)的服务器返回的结果时,客户端 MUST 将缺失字段视为 "complete"。

ResultMetaObject

interface ResultMetaObject {
  "io.modelcontextprotocol/serverInfo"?: Implementation;
  [key: string]: unknown;
}

扩展 MetaObject,增加结果专用字段。MetaObject 的所有键命名规则仍然适用。

标识产生响应的服务器软件。服务器 SHOULD 在每个响应中都包含此字段,除非专门配置为不这样做。

Implementation 模式要求提供 name 和 version;其他字段可选。

该值由服务器自行报告,未经协议验证。它用于显示、记录和调试。客户端 SHOULD NOT 使用它来更改其行为,并且 SHOULD NOT 依赖它做出安全决策。

ResultType

ResultType: "complete" | "input_required" | string

指示 Result 对象,允许客户端确定如何解析响应。

Complete - 请求成功完成,结果包含最终内容。 input_required - 请求需要额外的输入,结果包含 InputRequiredResult 对象,其中包含客户端在重试原始请求前提供额外输入的说明。

Role

Role: "user" | "assistant"

对话中消息和数据的发送方或接收方。

Errors

Error

interface Error {
  code: number;
  message: string;
  data?: unknown;
}

发生的错误类型。

错误的简短说明。消息 SHOULD 限制为简洁的单个句子。

有关错误的附加信息。此成员的值由发送方定义(例如详细错误信息、嵌套错误等)。

HEADER_MISMATCH

HEADER_MISMATCH: -32020

当请求的 HTTP 标头与请求正文中的相应值不匹配,或者所需标头丢失或格式错误时,返回错误代码。

HeaderMismatchError

interface HeaderMismatchError {
  jsonrpc: "2.0";
  id?: RequestId;
  error: Error & { code: -32020 };
}

当服务器拒绝请求时返回,因为 HTTP 标头中的值与请求正文中的相应值不匹配,或者因为所需的标头丢失或格式错误。对于 HTTP,响应状态码 MUST 为

400 Bad Request.

示例: 请求头不匹配
{
"jsonrpc": "2.0",
"id": 1,
"error": {
"code": -32020,
"message": "Header mismatch: Mcp-Name header value 'foo' does not match body value 'bar'"
}
}

InternalError

interface InternalError {
  message: string;
  data?: unknown;
  code: -32603;
}

表示接收方发生内部错误的 JSON-RPC 错误。当接收方遇到意外情况而无法完成请求时返回。

示例: 意外错误
{
"code": -32603,
"message": "Internal error"
}

错误的简短说明。消息 SHOULD 限制为简洁的单个句子。

有关错误的附加信息。此成员的值由发送方定义(例如详细错误信息、嵌套错误等)。

发生的错误类型。

InvalidParamsError

interface InvalidParamsError {
  message: string;
  data?: unknown;
  code: -32602;
}

JSON-RPC 错误,指示方法参数无效或格式错误。

在MCP中,当请求参数验证失败时,在各种上下文中都会返回此错误:

  • 工具: 未知工具 name或invalid tool arguments
  • 提示: 未知提示 name或missing required arguments
  • 分页: Invalid或expired cursor values
  • 记录:日志级别无效
  • 启发:服务器请求了客户端能力中未声明的征询模式
  • 取样:工具结果缺失或工具结果与其他内容混合
示例: 未知工具
{
"code": -32602,
"message": "Unknown tool: invalid_tool_name"
}
示例: 工具参数无效
{
"code": -32602,
"message": "Invalid arguments for tool calculate: Missing required property 'expression'"
}
示例: 未知提示
{
"code": -32602,
"message": "Unknown prompt: invalid_prompt_name"
}
示例: 无效游标
{
"code": -32602,
"message": "Invalid cursor"
}

错误的简短说明。消息 SHOULD 限制为简洁的单个句子。

有关错误的附加信息。此成员的值由发送方定义(例如详细错误信息、嵌套错误等)。

发生的错误类型。

InvalidRequestError

interface InvalidRequestError {
  message: string;
  data?: unknown;
  code: -32600;
}

JSON-RPC 错误,指示请求不是有效的请求对象。当消息结构不符合请求的 JSON-RPC 2.0 规范要求(例如缺少必填字段,如 jsonrpc 或 method,或对这些字段使用无效类型)。

错误的简短说明。消息 SHOULD 限制为简洁的单个句子。

有关错误的附加信息。此成员的值由发送方定义(例如详细错误信息、嵌套错误等)。

发生的错误类型。

MethodNotFoundError

interface MethodNotFoundError {
  message: string;
  data?: unknown;
  code: -32601;
}

JSON-RPC 错误,指示请求的方法不存在或不可用。

在 MCP 中,当客户端调用服务器未实现的方法时,服务器会返回此错误 - 要么是真正未知的方法,要么是服务器未公布的服务器功能后面的方法(例如调用 prompts/list ,但 prompts 能力未声明)。

需要客户端未声明的客户端功能的请求由以下方式发出信号 MissingRequiredClientCapabilityError (-32021).

示例: 不支持提示
{
"code": -32601,
"message": "Prompts not supported",
"data": {
"reason": "Server does not support the prompts capability"
}
}

错误的简短说明。消息 SHOULD 限制为简洁的单个句子。

有关错误的附加信息。此成员的值由发送方定义(例如详细错误信息、嵌套错误等)。

发生的错误类型。

MISSING_REQUIRED_CLIENT_CAPABILITY

MISSING_REQUIRED_CLIENT_CAPABILITY: -32021

当服务器需要未在请求中声明的客户端功能时返回的错误代码 clientCapabilities.

MissingRequiredClientCapabilityError

interface MissingRequiredClientCapabilityError {
  jsonrpc: "2.0";
  id?: RequestId;
  error: Error & {
    code: -32021;
    data: { requiredCapabilities: ClientCapabilities };
  };
}

当处理请求需要客户端未声明的功能时返回 clientCapabilities. 对于 HTTP,响应状态码 MUST 为 400 Bad Request.

示例: 缺少征询能力
{
"jsonrpc": "2.0",
"id": 1,
"error": {
"code": -32021,
"message": "Server requires the elicitation capability for this request",
"data": {
"requiredCapabilities": {
"elicitation": {}
}
}
}
}

ParseError

interface ParseError {
  message: string;
  data?: unknown;
  code: -32700;
}

表示服务器收到无效 JSON 的 JSON-RPC 错误。当服务器无法解析消息的 JSON 文本时返回。

示例: 无效 JSON
{
"code": -32700,
"message": "Parse error: Invalid JSON"
}

错误的简短说明。消息 SHOULD 限制为简洁的单个句子。

有关错误的附加信息。此成员的值由发送方定义(例如详细错误信息、嵌套错误等)。

发生的错误类型。

UNSUPPORTED_PROTOCOL_VERSION

UNSUPPORTED_PROTOCOL_VERSION: -32022

服务器不支持请求的协议版本时返回的错误码。

UnsupportedProtocolVersionError

interface UnsupportedProtocolVersionError {
  jsonrpc: "2.0";
  id?: RequestId;
  error: Error & {
    code: -32022;
    data: { supported: string[]; requested: string };
  };
}

当服务器未知或不支持请求的协议版本时返回(例如服务器选择不实现的已知实验或草稿版本)。对于 HTTP,响应状态码 MUST 为

400 Bad Request.

示例: 不支持的协议版本
{
"jsonrpc": "2.0",
"id": 1,
"error": {
"code": -32022,
"message": "Unsupported protocol version",
"data": {
"supported": [
"2026-07-28",
"2025-11-25"
],
"requested": "1900-01-01"
}
}
}

Content

AudioContent

interface AudioContent {
  type: "audio";
  data: string;
  mimeType: string;
  annotations?: Annotations;
  _meta?: MetaObject;
}

提供给 LLM 或由 LLM 返回的音频。

示例: `audio/wav` content
{
"type": "audio",
"data": "UklGRiQAAABXQVZFZm10IBAAAAABAAEARKwAAIhYAQACABAAZGF0YQAAAAA=",
"mimeType": "audio/wav"
}

Base64 编码的音频数据。

音频的 MIME 类型。不同提供商可能支持不同的音频类型。

提供给客户端的可选注解。

BlobResourceContents

interface BlobResourceContents {
  uri: string;
  mimeType?: string;
  _meta?: MetaObject;
  blob: string;
}
示例: 图像文件内容
{
"uri": "file:///example.png",
"mimeType": "image/png",
"blob": "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg=="
}

此资源的 URI。

此资源的 MIME 类型(如已知)。

表示该项二进制数据的 Base64 编码字符串。

ContentBlock

ContentBlock:
  | TextContent
  | ImageContent
  | AudioContent
  | ResourceLink
  | EmbeddedResource

EmbeddedResource

interface EmbeddedResource {
  type: "resource";
  resource: TextResourceContents | BlobResourceContents;
  annotations?: Annotations;
  _meta?: MetaObject;
}

嵌入提示或工具调用结果中的资源内容。

为了 LLM 和/或用户的利益,如何最好地呈现嵌入资源取决于客户端。

示例: 带注解的嵌入文件资源
{
"type": "resource",
"resource": {
"uri": "file:///project/src/main.rs",
"mimeType": "text/x-rust",
"text": "fn main() {\n println!(\"Hello world!\");\n}"
},
"annotations": {
"audience": ["user", "assistant"],
"priority": 0.7,
"lastModified": "2025-05-03T14:30:00Z"
}
}

提供给客户端的可选注解。

ImageContent

interface ImageContent {
  type: "image";
  data: string;
  mimeType: string;
  annotations?: Annotations;
  _meta?: MetaObject;
}

提供给 LLM 或由 LLM 返回的图像。

示例: `image/png` 带注解的内容
{
"type": "image",
"data": "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==",
"mimeType": "image/png",
"annotations": {
"audience": ["user"],
"priority": 0.9
}
}

Base64 编码的图像数据。

图像的 MIME 类型。不同提供商可能支持不同的图像类型。

提供给客户端的可选注解。

ResourceLink

interface ResourceLink {
  icons?: Icon[];
  name: string;
  title?: string;
  uri: string;
  description?: string;
  mimeType?: string;
  annotations?: Annotations;
  size?: number;
  _meta?: MetaObject;
  type: "resource_link";
}

服务器能够读取的资源,包含在提示或工具调用结果中。

注意:工具返回的资源链接不保证出现在 resources/list 请求。

示例: 文件资源链接

客户端可在用户界面中显示的一组可选尺寸图标。

支持渲染图标的客户端 MUST 至少支持以下 MIME 类型:

  • image/png - PNG 图像(安全、通用兼容)
  • image/jpeg (和 image/jpg) - JPEG 图像(安全、通用兼容)

支持渲染图标的客户端 SHOULD 还支持:

  • image/svg+xml - SVG 图像(可缩放,但需要安全防范)
  • image/webp - WebP 图像(现代、高效格式)

用于编程或逻辑用途,但在旧版规范中曾用作显示名称,或作为回退值 (如果不存在 title)。

用于 UI 和最终用户场景 — 针对人类可读性和易理解性进行了优化, 即使不熟悉领域术语的人也能理解。

如未提供,应使用 name 进行显示(但 Tool, 其中 annotations.title 应优先于 name,如果存在)。

此资源的 URI。

此资源所表示内容的说明。

客户端可使用此字段增进 LLM 对可用资源的理解。可将其视为提供给模型的“提示”。

此资源的 MIME 类型(如已知)。

提供给客户端的可选注解。

原始资源内容的大小(以字节为单位,即 Base64 编码或任何分词之前的大小,如已知)。

主机可用此字段显示文件大小并估算上下文窗口用量。

TextContent

interface TextContent {
  type: "text";
  text: string;
  annotations?: Annotations;
  _meta?: MetaObject;
}

提供给 LLM 或由 LLM 返回的文本。

示例:文本内容
{
"type": "text",
"text": "Tool result text"
}

消息的文本内容。

提供给客户端的可选注解。

TextResourceContents

interface TextResourceContents {
  uri: string;
  mimeType?: string;
  _meta?: MetaObject;
  text: string;
}
示例:文本文件内容
{
"uri": "file:///example.txt",
"mimeType": "text/plain",
"text": "Resource content"
}

此资源的 URI。

此资源的 MIME 类型(如已知)。

该项的文本。仅当该项确实可表示为文本(而非二进制数据)时才能设置。

completion/complete

CompleteRequest

interface CompleteRequest {
  jsonrpc: "2.0";
  id: RequestId;
  method: "completion/complete";
  params: CompleteRequestParams;
}

客户端向服务器发出的请求,用于请求completion options。

示例: 补全请求
{
"jsonrpc": "2.0",
"id": "completion-example",
"method": "completion/complete",
"params": {
"_meta": {
"io.modelcontextprotocol/protocolVersion": "2026-07-28",
"io.modelcontextprotocol/clientInfo": {
"name": "ExampleClient",
"version": "1.0.0"
},
"io.modelcontextprotocol/clientCapabilities": {}
},
"ref": {
"type": "ref/prompt",
"name": "code_review"
},
"argument": {
"name": "language",
"value": "py"
}
}
}

CompleteRequestParams

interface CompleteRequestParams {
  _meta: RequestMetaObject;
  ref: PromptReference | ResourceTemplateReference;
  argument: { name: string; value: string };
  context?: { arguments?: { [key: string]: string } };
}

以下请求的参数: completion/complete 请求。

示例: 提示参数补全
{
"_meta": {
"io.modelcontextprotocol/protocolVersion": "2026-07-28",
"io.modelcontextprotocol/clientInfo": {
"name": "ExampleClient",
"version": "1.0.0"
},
"io.modelcontextprotocol/clientCapabilities": {}
},
"ref": {
"type": "ref/prompt",
"name": "code_review"
},
"argument": {
"name": "language",
"value": "py"
}
}
示例: 带上下文的提示参数补全
{
"_meta": {
"io.modelcontextprotocol/protocolVersion": "2026-07-28",
"io.modelcontextprotocol/clientInfo": {
"name": "ExampleClient",
"version": "1.0.0"
},
"io.modelcontextprotocol/clientCapabilities": {}
},
"ref": {
"type": "ref/prompt",
"name": "code_review"
},
"argument": {
"name": "framework",
"value": "fla"
},
"context": {
"arguments": {
"language": "python"
}
}
}

参数信息。

类型声明
  • name: string

    参数名称。

  • value: string

    用于自动补全匹配的参数值。

自动补全的附加可选上下文。

类型声明
  • 可选arguments?: { [key: string]: string }

    URI 模板或提示中此前已解析的变量。

CompleteResultResponse

interface CompleteResultResponse {
  jsonrpc: "2.0";
  id: RequestId;
  result: CompleteResult;
}

服务器对 completion/complete 请求。

示例: 补全结果响应
{
"jsonrpc": "2.0",
"id": "completion-example",
"result": {
"resultType": "complete",
"completion": {
"values": ["flask"],
"total": 1,
"hasMore": false
}
}
}

CompleteResult

interface CompleteResult {
  _meta?: ResultMetaObject;
  resultType: string;
  completion: { values: string[]; total?: number; hasMore?: boolean };
  [key: string]: unknown;
}

服务器针对 completion/complete 请求。

示例: 单个补全值
{
"resultType": "complete",
"completion": {
"values": ["flask"],
"total": 1,
"hasMore": false
}
}
示例: 多个补全值且仍有更多结果
{
"resultType": "complete",
"completion": {
"values": ["python", "pytorch", "pyside"],
"total": 10,
"hasMore": true
}
}

指示结果的类型,允许客户端决定如何解析结果对象。

实现此协议版本的服务器 MUST 包含此字段。为向后兼容,当客户端收到实现较早协议版本(不包含 resultType)的服务器返回的结果时,客户端 MUST 将缺失字段视为 "complete"。

类型声明
  • values: string[]

    自动补全值数组。不得超过 100 项。

  • 可选total?: number

    可用自动补全选项的总数。该数值可以大于响应中实际发送的值数量。

  • 可选hasMore?: boolean

    指示除当前响应提供的选项外是否还有其他自动补全选项,即使确切总数未知。

PromptReference

interface PromptReference {
  name: string;
  title?: string;
  type: "ref/prompt";
}

标识一个提示。

用于编程或逻辑用途,但在旧版规范中曾用作显示名称,或作为回退值 (如果不存在 title)。

用于 UI 和最终用户场景 — 针对人类可读性和易理解性进行了优化, 即使不熟悉领域术语的人也能理解。

如未提供,应使用 name 进行显示(但 Tool, 其中 annotations.title 应优先于 name,如果存在)。

ResourceTemplateReference

interface ResourceTemplateReference {
  type: "ref/resource";
  uri: string;
}

对资源或资源模板定义的引用。

资源的 URI 或 URI 模板。

elicitation/create

ElicitRequest

interface ElicitRequest {
  method: "elicitation/create";
  params: ElicitRequestParams;
}

服务器通过客户端向用户征询附加信息的请求。

示例: 征询请求
{
"method": "elicitation/create",
"params": {
"mode": "form",
"message": "Please provide your GitHub username",
"requestedSchema": {
"type": "object",
"properties": {
"name": {
"type": "string",
"title": "GitHub Username",
"description": "Your GitHub username"
}
},
"required": ["name"]
}
}
}

ElicitRequestParams

服务器通过客户端向用户征询附加信息的请求参数。

ElicitResult

interface ElicitResult {
  action: "accept" | "decline" | "cancel";
  content?: { [key: string]: string | number | boolean | string[] };
}

客户端针对 elicitation/create 请求。

示例: 输入单个字段
{
"action": "accept",
"content": {
"name": "octocat"
}
}
示例: 输入多个字段
{
"action": "accept",
"content": {
"name": "Monalisa Octocat",
"email": "[email protected]",
"age": 30
}
}
示例: 接受 URL 模式(无内容)
{
"action": "accept"
}

用户对信息征询的响应操作。

  • "accept":用户提交了表单/确认了操作
  • "decline":用户明确拒绝了操作
  • "cancel":用户关闭了界面,未作明确选择

提交的表单数据,仅在action执行时出现 "accept" 且模式为 "form"。包含与请求的架构匹配的值。对于带外模式响应省略。

BooleanSchema

interface BooleanSchema {
  type: "boolean";
  title?: string;
  description?: string;
  default?: boolean;
}
示例: 布尔输入 schema
{
"type": "boolean",
"title": "Display Name",
"description": "Description text",
"default": false
}

ElicitRequestFormParams

interface ElicitRequestFormParams {
  mode?: "form";
  message: string;
  requestedSchema: {
    $schema?: string;
    type: "object";
    properties: { [key: string]: PrimitiveSchemaDefinition };
    required?: string[];
  };
}

通过客户端表单向用户征询非敏感信息的请求参数。

示例: 征询单个字段
{
"mode": "form",
"message": "Please provide your GitHub username",
"requestedSchema": {
"type": "object",
"properties": {
"name": {
"type": "string"
}
},
"required": ["name"]
}
}
示例: 征询多个字段
{
"mode": "form",
"message": "Please provide your contact information",
"requestedSchema": {
"type": "object",
"properties": {
"name": {
"type": "string",
"description": "Your full name"
},
"email": {
"type": "string",
"format": "email",
"description": "Your email address"
},
"age": {
"type": "number",
"minimum": 18,
"description": "Your age"
}
},
"required": ["name", "email"]
}
}

信息征询模式。

向用户显示、说明所请求信息的消息。

JSON 模式的受限子集。仅允许顶级属性,不允许嵌套。

ElicitRequestURLParams

interface ElicitRequestURLParams {
  mode: "url";
  message: string;
  url: string;
}

通过客户端中的 URL 向用户征询信息的请求参数。

示例: 征询敏感数据
{
"mode": "url",
"url": "https://mcp.example.com/ui/set_api_key",
"message": "Please provide your API key to continue."
}

信息征询模式。

向用户显示、说明为何需要此次交互的消息。

用户应访问的 URL。

LegacyTitledEnumSchema

interface LegacyTitledEnumSchema {
  type: "string";
  title?: string;
  description?: string;
  enum: string[];
  enumNames?: string[];
  default?: string;
}

使用 TitledSingleSelectEnumSchema 相反。该接口将在未来版本中删除。

(旧版)枚举值的显示名称。根据 JSON Schema 2020-12 非标准。

MultiSelectEnumSchema

NumberSchema

interface NumberSchema {
  type: "number" | "integer";
  title?: string;
  description?: string;
  minimum?: number;
  maximum?: number;
  default?: number;
}
示例: 数字输入 schema
{
"type": "number",
"title": "Display Name",
"description": "Description text",
"minimum": 0,
"maximum": 100,
"default": 50
}

PrimitiveSchemaDefinition

PrimitiveSchemaDefinition:
  | StringSchema
  | NumberSchema
  | BooleanSchema
  | EnumSchema

受限制的架构定义,仅允许没有嵌套对象或数组的原始类型。

SingleSelectEnumSchema

StringSchema

interface StringSchema {
  type: "string";
  title?: string;
  description?: string;
  minLength?: number;
  maxLength?: number;
  format?: "uri" | "email" | "date" | "date-time";
  default?: string;
}
示例: 电子邮件输入 schema
{
"type": "string",
"title": "Display Name",
"description": "Description text",
"minLength": 3,
"maxLength": 50,
"format": "email",
"default": "[email protected]"
}

TitledMultiSelectEnumSchema

interface TitledMultiSelectEnumSchema {
  type: "array";
  title?: string;
  description?: string;
  minItems?: number;
  maxItems?: number;
  items: { anyOf: { const: string; title: string }[] };
  default?: string[];
}

每个选项带显示标题的多选枚举 schema。

示例: 带标题的颜色多选 schema
{
"type": "array",
"title": "Color Selection",
"description": "Choose your favorite colors",
"minItems": 1,
"maxItems": 2,
"items": {
"anyOf": [
{ "const": "#FF0000", "title": "Red" },
{ "const": "#00FF00", "title": "Green" },
{ "const": "#0000FF", "title": "Blue" }
]
},
"default": ["#FF0000", "#00FF00"]
}

枚举字段的可选标题。

枚举字段的可选说明。

最少选择项数。

最多选择项数。

包含枚举选项和显示标签的数组项 schema。

类型声明
  • anyOf: { const: string; title: string }[]

    包含值和显示标签的枚举选项数组。

可选默认值。

TitledSingleSelectEnumSchema

interface TitledSingleSelectEnumSchema {
  type: "string";
  title?: string;
  description?: string;
  oneOf: { const: string; title: string }[];
  default?: string;
}

每个选项带显示标题的单选枚举 schema。

示例: 带标题的颜色单选 schema
{
"type": "string",
"title": "Color Selection",
"description": "Choose your favorite color",
"oneOf": [
{ "const": "#FF0000", "title": "Red" },
{ "const": "#00FF00", "title": "Green" },
{ "const": "#0000FF", "title": "Blue" }
],
"default": "#FF0000"
}

枚举字段的可选标题。

枚举字段的可选说明。

包含值和显示标签的枚举选项数组。

类型声明
  • const: string

    枚举值。

  • title: string

    此选项的显示标签。

可选默认值。

UntitledMultiSelectEnumSchema

interface UntitledMultiSelectEnumSchema {
  type: "array";
  title?: string;
  description?: string;
  minItems?: number;
  maxItems?: number;
  items: { type: "string"; enum: string[] };
  default?: string[];
}

选项不带显示标题的多选枚举 schema。

示例: 颜色多选 schema
{
"type": "array",
"title": "Color Selection",
"description": "Choose your favorite colors",
"minItems": 1,
"maxItems": 2,
"items": {
"type": "string",
"enum": ["Red", "Green", "Blue"]
},
"default": ["Red", "Green"]
}

枚举字段的可选标题。

枚举字段的可选说明。

最少选择项数。

最多选择项数。

数组项的 schema。

类型声明
  • type: "string"
  • enum: string[]

    可供选择的枚举值数组。

可选默认值。

UntitledSingleSelectEnumSchema

interface UntitledSingleSelectEnumSchema {
  type: "string";
  title?: string;
  description?: string;
  enum: string[];
  default?: string;
}

选项不带显示标题的单选枚举 schema。

示例: 颜色单选 schema
{
"type": "string",
"title": "Color Selection",
"description": "Choose your favorite color",
"enum": ["Red", "Green", "Blue"],
"default": "Red"
}

枚举字段的可选标题。

枚举字段的可选说明。

可供选择的枚举值数组。

可选默认值。

notifications/cancelled

CancelledNotification

interface CancelledNotification {
  jsonrpc: "2.0";
  method: "notifications/cancelled";
  params: CancelledNotificationParams;
}

该通知由客户端发送,表明它正在取消之前发出的请求。

在 stdio 上,服务器也会发送此通知,但仅用于终止 subscriptions/listen 流:它引用打开该流的 subscriptions/listen 打开流的请求。服务器 MUST NOT 使用此通知来取消任何其他请求。

请求 SHOULD 仍在进行中,但由于通信延迟,该通知 MAY 始终可能在请求完成后到达。

此通知表示结果将不会使用,因此相关处理 SHOULD 停止。

示例: 用户请求取消
{
"jsonrpc": "2.0",
"method": "notifications/cancelled",
"params": {
"requestId": "123",
"reason": "User requested cancellation"
}
}

CancelledNotificationParams

interface CancelledNotificationParams {
  _meta?: NotificationMetaObject;
  requestId: RequestId;
  reason?: string;
}

以下请求的参数: notifications/cancelled 通知。

示例: 用户请求取消
{
"requestId": "123",
"reason": "User requested cancellation"
}

要取消的请求 ID。

此值 MUST 对应客户端此前发出请求的 ID。

描述取消原因的可选字符串。该 MAY 被记录或呈现给用户。

notifications/message

LoggingMessageNotification

interface LoggingMessageNotification {
  jsonrpc: "2.0";
  method: "notifications/message";
  params: LoggingMessageNotificationParams;
}

服务器传递给客户端的日志消息 JSONRPCNotification。客户端通过设置 "io.modelcontextprotocol/logLevel" 来选择接收。该字段位于请求的 _meta.

自协议版本 2026-07-28 (SEP-2577) 起已弃用。仍保留在规范中至少十二个月;请参阅已弃用的功能注册表。

示例: 记录数据库连接失败
{
"jsonrpc": "2.0",
"method": "notifications/message",
"params": {
"level": "error",
"logger": "database",
"data": {
"error": "Connection failed",
"details": {
"host": "localhost",
"port": 5432
}
}
}
}

LoggingMessageNotificationParams

interface LoggingMessageNotificationParams {
  _meta?: NotificationMetaObject;
  level: LoggingLevel;
  logger?: string;
  data: unknown;
}

以下请求的参数: notifications/message 通知。

自协议版本 2026-07-28 (SEP-2577) 起已弃用。仍保留在规范中至少十二个月;请参阅已弃用的功能注册表。

示例: 记录数据库连接失败
{
"level": "error",
"logger": "database",
"data": {
"error": "Connection failed",
"details": {
"host": "localhost",
"port": 5432
}
}
}

此日志消息的严重性级别。

发出此消息的日志记录器的可选名称。

要记录的数据,例如字符串消息或对象。此处允许任何 JSON 可序列化类型。

notifications/progress

ProgressNotification

interface ProgressNotification {
  jsonrpc: "2.0";
  method: "notifications/progress";
  params: ProgressNotificationParams;
}

用于通知接收方长时间运行请求进度更新的带外通知。

示例: 进度消息
{
"jsonrpc": "2.0",
"method": "notifications/progress",
"params": {
"progressToken": "oivaizmir",
"progress": 50,
"total": 100,
"message": "Reticulating splines..."
}
}

ProgressNotificationParams

interface ProgressNotificationParams {
  _meta?: NotificationMetaObject;
  progressToken: ProgressToken;
  progress: number;
  total?: number;
  message?: string;
}

以下请求的参数: notifications/progress 通知。

示例: 进度消息
{
"progressToken": "oivaizmir",
"progress": 50,
"total": 100,
"message": "Reticulating splines..."
}

初始请求中给出的进度令牌,用于将此通知与正在进行的请求关联起来。

到目前为止的进展。每次取得进展时,即使总数未知,该值也会增加。

要处理的总项数(或所需总进度,如已知)。

描述当前进度的可选消息。

notifications/prompts/list_changed

PromptListChangedNotification

interface PromptListChangedNotification {
  jsonrpc: "2.0";
  method: "notifications/prompts/list_changed";
  params?: NotificationParams;
}

服务器发给客户端的可选通知,告知可用提示列表已更改。此通知仅经由 subscriptions/listen 流传递,且只在客户端通过 promptsListChanged 过滤字段请求接收后才会传递。

示例: 提示列表已更改
{
"jsonrpc": "2.0",
"method": "notifications/prompts/list_changed",
"params": {
"_meta": {
"io.modelcontextprotocol/subscriptionId": "listen-1"
}
}
}

notifications/resources/list_changed

ResourceListChangedNotification

interface ResourceListChangedNotification {
  jsonrpc: "2.0";
  method: "notifications/resources/list_changed";
  params?: NotificationParams;
}

服务器发给客户端的可选通知,告知可用资源列表已更改。此通知仅经由 subscriptions/listen 流传递,且只在客户端通过 resourcesListChanged 过滤字段请求接收后才会传递。

示例: 资源列表已更改
{
"jsonrpc": "2.0",
"method": "notifications/resources/list_changed",
"params": {
"_meta": {
"io.modelcontextprotocol/subscriptionId": "listen-1"
}
}
}

notifications/resources/updated

ResourceUpdatedNotification

interface ResourceUpdatedNotification {
  jsonrpc: "2.0";
  method: "notifications/resources/updated";
  params: ResourceUpdatedNotificationParams;
}

服务器发给客户端的通知,告知资源已更改,可能需要重新读取。仅当客户端通过 resourceSubscriptions 字段在 subscriptions/listen 请求中选择订阅某个资源后,才会为该资源发送此通知。

示例: 文件资源更新通知
{
"jsonrpc": "2.0",
"method": "notifications/resources/updated",
"params": {
"_meta": {
"io.modelcontextprotocol/subscriptionId": "listen-1"
},
"uri": "file:///project/src/main.rs"
}
}

ResourceUpdatedNotificationParams

interface ResourceUpdatedNotificationParams {
  _meta?: NotificationMetaObject;
  uri: string;
}

以下请求的参数: notifications/resources/updated 通知。

示例: 文件资源已更新
{
"uri": "file:///project/src/main.rs"
}

已更新资源的 URI。它可能是客户端实际订阅资源的子资源。

notifications/subscriptions/acknowledged

SubscriptionsAcknowledgedNotification

interface SubscriptionsAcknowledgedNotification {
  jsonrpc: "2.0";
  method: "notifications/subscriptions/acknowledged";
  params: SubscriptionsAcknowledgedNotificationParams;
}

服务器发送此通知,以确认 subscriptions/listen 订阅已建立并报告其同意接受的通知类型。

此通知 MUST 是服务器发送的第一条消息,其中携带订阅的 ID io.modelcontextprotocol/subscriptionId。服务器 MUST NOT 在确认之前发送有关订阅的任何通知。在 stdio 上,每个订阅共享一个通道,此排序是针对每个订阅 ID 而不是每个通道定义的:属于其他订阅 MAY 的消息将在其之前交错。

示例: 监听已确认
{
"jsonrpc": "2.0",
"method": "notifications/subscriptions/acknowledged",
"params": {
"_meta": {
"io.modelcontextprotocol/subscriptionId": "listen-1"
},
"notifications": {
"toolsListChanged": true,
"resourceSubscriptions": ["file:///project/config.json"]
}
}
}

SubscriptionsAcknowledgedNotificationParams

interface SubscriptionsAcknowledgedNotificationParams {
  _meta?: NotificationMetaObject;
  notifications: SubscriptionFilter;
}

以下请求的参数: notifications/subscriptions/acknowledged 通知。

服务器同意接受的请求通知类型的子集。只包含服务器实际支持的通知类型;如果客户端请求不支持的类型(例如

promptsListChanged 当服务器没有提示时),则从该集合中省略。

notifications/tools/list_changed

ToolListChangedNotification

interface ToolListChangedNotification {
  jsonrpc: "2.0";
  method: "notifications/tools/list_changed";
  params?: NotificationParams;
}

服务器发给客户端的可选通知,告知可用工具列表已更改。此通知仅经由 subscriptions/listen 流传递,且只在客户端通过 toolsListChanged 过滤字段请求接收后才会传递。

示例: 工具列表已更改
{
"jsonrpc": "2.0",
"method": "notifications/tools/list_changed",
"params": {
"_meta": {
"io.modelcontextprotocol/subscriptionId": "listen-1"
}
}
}

Multi Round-Trip

InputRequests

InputRequests: any

客户端必须满足的服务器发起请求的映射。键是服务器分配的标识符;值是请求对象。

示例: 征询与采样输入请求
{
"github_login": {
"method": "elicitation/create",
"params": {
"mode": "form",
"message": "Please provide your GitHub username",
"requestedSchema": {
"type": "object",
"properties": {
"name": {
"type": "string"
}
},
"required": ["name"]
}
}
},
"capital_of_france": {
"method": "sampling/createMessage",
"params": {
"messages": [
{
"role": "user",
"content": {
"type": "text",
"text": "What is the capital of France?"
}
}
],
"maxTokens": 100
}
}
}

InputRequiredResult

interface InputRequiredResult {
  _meta?: ResultMetaObject;
  resultType: string;
  inputRequests?: InputRequests;
  requestState?: string;
  [key: string]: unknown;
}

服务器发送的 InputRequiredResult 指示在完成请求之前需要额外的输入。

inputRequests 或 requestState MUST 至少提供一项。

示例:带有启发和采样输入请求和请求状态的 InputRequiredResult
{
"resultType": "input_required",
"inputRequests": {
"github_login": {
"method": "elicitation/create",
"params": {
"message": "Please provide your GitHub username",
"requestedSchema": {
"type": "object",
"properties": {
"name": {
"type": "string"
}
},
"required": ["name"]
}
}
},
"capital_of_france": {
"method": "sampling/createMessage",
"params": {
"messages": [
{
"role": "user",
"content": {
"type": "text",
"text": "What is the capital of France?"
}
}
],
"maxTokens": 100
}
}
},
"requestState": "eyJsb2NhdGlvbiI6Ik5ldyBZb3JrIn0"
}
示例:InputRequiredResult 仅具有请求状态(减载)
{
"resultType": "input_required",
"requestState": "eyJwcm9ncmVzcyI6IjUwJSIsInN0YXRlIjoicHJvY2Vzc2luZyJ9"
}

指示结果的类型,允许客户端决定如何解析结果对象。

实现此协议版本的服务器 MUST 包含此字段。为向后兼容,当客户端收到实现较早协议版本(不包含 resultType)的服务器返回的结果时,客户端 MUST 将缺失字段视为 "complete"。

InputResponses

InputResponses: any

客户端对服务器发起的请求的响应的映射。键对应于中的键 InputRequests 地图;值是客户端每个请求的结果。

示例:征询与采样输入响应
{
"github_login": {
"action": "accept",
"content": {
"name": "octocat"
}
},
"capital_of_france": {
"role": "assistant",
"content": {
"type": "text",
"text": "The capital of France is Paris."
},
"model": "claude-3-sonnet-20240307",
"stopReason": "endTurn"
}
}

prompts/get

GetPromptRequest

interface GetPromptRequest {
  jsonrpc: "2.0";
  id: RequestId;
  method: "prompts/get";
  params: GetPromptRequestParams;
}

客户端使用它来获取服务器提供的提示。

示例:获取提示请求
{
"jsonrpc": "2.0",
"id": "get-prompt-example",
"method": "prompts/get",
"params": {
"_meta": {
"io.modelcontextprotocol/protocolVersion": "2026-07-28",
"io.modelcontextprotocol/clientInfo": {
"name": "ExampleClient",
"version": "1.0.0"
},
"io.modelcontextprotocol/clientCapabilities": {}
},
"name": "code_review",
"arguments": {
"code": "def hello():\n print('world')"
}
}
}

GetPromptRequestParams

interface GetPromptRequestParams {
  _meta: RequestMetaObject;
  inputResponses?: InputResponses;
  requestState?: string;
  name: string;
  arguments?: { [key: string]: string };
}

以下请求的参数: prompts/get 请求。

示例:获取代码审查提示
{
"_meta": {
"io.modelcontextprotocol/protocolVersion": "2026-07-28",
"io.modelcontextprotocol/clientInfo": {
"name": "ExampleClient",
"version": "1.0.0"
},
"io.modelcontextprotocol/clientCapabilities": {}
},
"name": "code_review",
"arguments": {
"code": "def hello():\n print('world')"
}
}

提示或提示模板的名称。

用于模板化提示的参数。

GetPromptResultResponse

interface GetPromptResultResponse {
  jsonrpc: "2.0";
  id: RequestId;
  result: InputRequiredResult | GetPromptResult;
}

服务器对 prompts/get 请求。

示例:获取即时结果响应
{
"jsonrpc": "2.0",
"id": "get-prompt-example",
"result": {
"resultType": "complete",
"description": "Code review prompt",
"messages": [
{
"role": "user",
"content": {
"type": "text",
"text": "Please review this Python code:\ndef hello():\n print('world')"
}
}
]
}
}

GetPromptResult

interface GetPromptResult {
  _meta?: ResultMetaObject;
  resultType: string;
  description?: string;
  messages: PromptMessage[];
  [key: string]: unknown;
}

服务器针对 prompts/get 请求。

示例:代码审查提示
{
"resultType": "complete",
"description": "Code review prompt",
"messages": [
{
"role": "user",
"content": {
"type": "text",
"text": "Please review this Python code:\ndef hello():\n print('world')"
}
}
]
}

指示结果的类型,允许客户端决定如何解析结果对象。

实现此协议版本的服务器 MUST 包含此字段。为向后兼容,当客户端收到实现较早协议版本(不包含 resultType)的服务器返回的结果时,客户端 MUST 将缺失字段视为 "complete"。

提示的可选说明。

PromptMessage

interface PromptMessage {
  role: Role;
  content: ContentBlock;
}

描述作为提示的一部分返回的消息。

这类似于 SamplingMessage,还支持嵌入来自 MCP 服务器的资源。

prompts/list

ListPromptsRequest

interface ListPromptsRequest {
  jsonrpc: "2.0";
  id: RequestId;
  params: PaginatedRequestParams;
  method: "prompts/list";
}

从客户端发送,请求服务器具有的提示列表和提示模板。

示例:列出提示请求
{
"jsonrpc": "2.0",
"id": "list-prompts-example",
"method": "prompts/list",
"params": {
"_meta": {
"io.modelcontextprotocol/protocolVersion": "2026-07-28",
"io.modelcontextprotocol/clientInfo": {
"name": "ExampleClient",
"version": "1.0.0"
},
"io.modelcontextprotocol/clientCapabilities": {}
}
}
}

ListPromptsResultResponse

interface ListPromptsResultResponse {
  jsonrpc: "2.0";
  id: RequestId;
  result: ListPromptsResult;
}

服务器对 prompts/list 请求。

示例:列表提示结果响应
{
"jsonrpc": "2.0",
"id": "list-prompts-example",
"result": {
"resultType": "complete",
"prompts": [
{
"name": "code_review",
"title": "Request Code Review",
"description": "Asks the LLM to analyze code quality and suggest improvements",
"arguments": [
{
"name": "code",
"description": "The code to review",
"required": true
}
],
"icons": [
{
"src": "https://example.com/review-icon.svg",
"mimeType": "image/svg+xml",
"sizes": ["any"]
}
]
}
],
"nextCursor": "next-page-cursor",
"ttlMs": 600000,
"cacheScope": "public"
}
}

ListPromptsResult

interface ListPromptsResult {
  _meta?: ResultMetaObject;
  resultType: string;
  nextCursor?: string;
  ttlMs: number;
  cacheScope: "public" | "private";
  prompts: Prompt[];
  [key: string]: unknown;
}

服务器针对 prompts/list 请求。

示例:带有光标和 TTL 的提示列表
{
"resultType": "complete",
"prompts": [
{
"name": "code_review",
"title": "Request Code Review",
"description": "Asks the LLM to analyze code quality and suggest improvements",
"arguments": [
{
"name": "code",
"description": "The code to review",
"required": true
}
],
"icons": [
{
"src": "https://example.com/review-icon.svg",
"mimeType": "image/svg+xml",
"sizes": ["any"]
}
]
}
],
"nextCursor": "next-page-cursor",
"ttlMs": 600000,
"cacheScope": "public"
}

指示结果的类型,允许客户端决定如何解析结果对象。

实现此协议版本的服务器 MUST 包含此字段。为向后兼容,当客户端收到实现较早协议版本(不包含 resultType)的服务器返回的结果时,客户端 MUST 将缺失字段视为 "complete"。

表示最后一个返回结果之后分页位置的不透明令牌。 如存在,则可能还有更多可用结果。

来自服务器的提示,指示客户端 MAY 在重新获取之前缓存此响应的时间(以毫秒为单位)。语义类似于 HTTP Cache-Control max-age。

  • 如果为0,则响应 SHOULD 被立即视为过时,客户端 MAY 在每次需要结果时重新获取。
  • 如果为正数,则客户端 SHOULD 认为在收到响应后这么多毫秒内结果是新鲜的。

指示缓存响应的预期作用域,类似于 HTTP Cache-Control: public 与 Cache-Control: private.

  • "public":响应不包含用户特定数据。任何客户端或中介(例如共享网关、缓存代理)MAY 缓存响应并跨授权上下文提供服务。
  • "private":响应 MAY 只能在同一授权上下文中缓存和重用。缓存 MUST NOT 在授权上下文之间共享(例如不同的访问令牌需要不同的缓存)。

Prompt

interface Prompt {
  icons?: Icon[];
  name: string;
  title?: string;
  description?: string;
  arguments?: PromptArgument[];
  _meta?: MetaObject;
}

服务器提供的提示或提示模板。

客户端可在用户界面中显示的一组可选尺寸图标。

支持渲染图标的客户端 MUST 至少支持以下 MIME 类型:

  • image/png - PNG 图像(安全、通用兼容)
  • image/jpeg (和 image/jpg) - JPEG 图像(安全、通用兼容)

支持渲染图标的客户端 SHOULD 还支持:

  • image/svg+xml - SVG 图像(可缩放,但需要安全防范)
  • image/webp - WebP 图像(现代、高效格式)

用于编程或逻辑用途,但在旧版规范中曾用作显示名称,或作为回退值 (如果不存在 title)。

用于 UI 和最终用户场景 — 针对人类可读性和易理解性进行了优化, 即使不熟悉领域术语的人也能理解。

如未提供,应使用 name 进行显示(但 Tool, 其中 annotations.title 应优先于 name,如果存在)。

此提示所提供内容的可选说明。

用于模板化提示的参数列表。

PromptArgument

interface PromptArgument {
  name: string;
  title?: string;
  description?: string;
  required?: boolean;
}

描述提示可接受的参数。

用于编程或逻辑用途,但在旧版规范中曾用作显示名称,或作为回退值 (如果不存在 title)。

用于 UI 和最终用户场景 — 针对人类可读性和易理解性进行了优化, 即使不熟悉领域术语的人也能理解。

如未提供,应使用 name 进行显示(但 Tool, 其中 annotations.title 应优先于 name,如果存在)。

参数的可读说明。

是否必须提供此参数。

resources/list

ListResourcesRequest

interface ListResourcesRequest {
  jsonrpc: "2.0";
  id: RequestId;
  params: PaginatedRequestParams;
  method: "resources/list";
}

从客户端发送,请求服务器拥有的资源列表。

示例:列出资源请求
{
"jsonrpc": "2.0",
"id": "list-resources-example",
"method": "resources/list",
"params": {
"_meta": {
"io.modelcontextprotocol/protocolVersion": "2026-07-28",
"io.modelcontextprotocol/clientInfo": {
"name": "ExampleClient",
"version": "1.0.0"
},
"io.modelcontextprotocol/clientCapabilities": {}
}
}
}

ListResourcesResultResponse

interface ListResourcesResultResponse {
  jsonrpc: "2.0";
  id: RequestId;
  result: ListResourcesResult;
}

服务器对 resources/list 请求。

示例:列出资源结果响应
{
"jsonrpc": "2.0",
"id": "list-resources-example",
"result": {
"resultType": "complete",
"resources": [
{
"uri": "file:///project/src/main.rs",
"name": "main.rs",
"title": "Rust Software Application Main File",
"description": "Primary application entry point",
"mimeType": "text/x-rust",
"icons": [
{
"src": "https://example.com/rust-file-icon.png",
"mimeType": "image/png",
"sizes": ["48x48"]
}
]
}
],
"nextCursor": "eyJwYWdlIjogM30=",
"ttlMs": 600000,
"cacheScope": "private"
}
}

ListResourcesResult

interface ListResourcesResult {
  _meta?: ResultMetaObject;
  resultType: string;
  nextCursor?: string;
  ttlMs: number;
  cacheScope: "public" | "private";
  resources: Resource[];
  [key: string]: unknown;
}

服务器针对 resources/list 请求。

示例:带有光标和 TTL 的资源列表
{
"resultType": "complete",
"resources": [
{
"uri": "file:///project/src/main.rs",
"name": "main.rs",
"title": "Rust Software Application Main File",
"description": "Primary application entry point",
"mimeType": "text/x-rust",
"icons": [
{
"src": "https://example.com/rust-file-icon.png",
"mimeType": "image/png",
"sizes": ["48x48"]
}
]
}
],
"nextCursor": "eyJwYWdlIjogM30=",
"ttlMs": 600000,
"cacheScope": "private"
}

指示结果的类型,允许客户端决定如何解析结果对象。

实现此协议版本的服务器 MUST 包含此字段。为向后兼容,当客户端收到实现较早协议版本(不包含 resultType)的服务器返回的结果时,客户端 MUST 将缺失字段视为 "complete"。

表示最后一个返回结果之后分页位置的不透明令牌。 如存在,则可能还有更多可用结果。

来自服务器的提示,指示客户端 MAY 在重新获取之前缓存此响应的时间(以毫秒为单位)。语义类似于 HTTP Cache-Control max-age。

  • 如果为0,则响应 SHOULD 被立即视为过时,客户端 MAY 在每次需要结果时重新获取。
  • 如果为正数,则客户端 SHOULD 认为在收到响应后这么多毫秒内结果是新鲜的。

指示缓存响应的预期作用域,类似于 HTTP Cache-Control: public 与 Cache-Control: private.

  • "public":响应不包含用户特定数据。任何客户端或中介(例如共享网关、缓存代理)MAY 缓存响应并跨授权上下文提供服务。
  • "private":响应 MAY 只能在同一授权上下文中缓存和重用。缓存 MUST NOT 在授权上下文之间共享(例如不同的访问令牌需要不同的缓存)。

Resource

interface Resource {
  icons?: Icon[];
  name: string;
  title?: string;
  uri: string;
  description?: string;
  mimeType?: string;
  annotations?: Annotations;
  size?: number;
  _meta?: MetaObject;
}

服务器能够读取的已知资源。

示例:带注解的文件资源
{
"uri": "file:///project/README.md",
"name": "README.md",
"title": "Project Documentation",
"mimeType": "text/markdown",
"annotations": {
"audience": ["user"],
"priority": 0.8,
"lastModified": "2025-01-12T15:00:58Z"
}
}

客户端可在用户界面中显示的一组可选尺寸图标。

支持渲染图标的客户端 MUST 至少支持以下 MIME 类型:

  • image/png - PNG 图像(安全、通用兼容)
  • image/jpeg (和 image/jpg) - JPEG 图像(安全、通用兼容)

支持渲染图标的客户端 SHOULD 还支持:

  • image/svg+xml - SVG 图像(可缩放,但需要安全防范)
  • image/webp - WebP 图像(现代、高效格式)

用于编程或逻辑用途,但在旧版规范中曾用作显示名称,或作为回退值 (如果不存在 title)。

用于 UI 和最终用户场景 — 针对人类可读性和易理解性进行了优化, 即使不熟悉领域术语的人也能理解。

如未提供,应使用 name 进行显示(但 Tool, 其中 annotations.title 应优先于 name,如果存在)。

此资源的 URI。

此资源所表示内容的说明。

客户端可使用此字段增进 LLM 对可用资源的理解。可将其视为提供给模型的“提示”。

此资源的 MIME 类型(如已知)。

提供给客户端的可选注解。

原始资源内容的大小(以字节为单位,即 Base64 编码或任何分词之前的大小,如已知)。

主机可用此字段显示文件大小并估算上下文窗口用量。

resources/read

ReadResourceRequest

interface ReadResourceRequest {
  jsonrpc: "2.0";
  id: RequestId;
  method: "resources/read";
  params: ReadResourceRequestParams;
}

从客户端发送到服务器,读取特定资源URI。

示例:读取资源请求
{
"jsonrpc": "2.0",
"id": "read-resource-example",
"method": "resources/read",
"params": {
"_meta": {
"io.modelcontextprotocol/protocolVersion": "2026-07-28",
"io.modelcontextprotocol/clientInfo": {
"name": "ExampleClient",
"version": "1.0.0"
},
"io.modelcontextprotocol/clientCapabilities": {}
},
"uri": "file:///project/src/main.rs"
}
}

ReadResourceRequestParams

interface ReadResourceRequestParams {
  _meta: RequestMetaObject;
  inputResponses?: InputResponses;
  requestState?: string;
  uri: string;
}

以下请求的参数: resources/read 请求。

资源的 URI。URI 可以使用任意协议,其解释方式由服务器决定。

ReadResourceResultResponse

interface ReadResourceResultResponse {
  jsonrpc: "2.0";
  id: RequestId;
  result: InputRequiredResult | ReadResourceResult;
}

服务器对 resources/read 请求。

示例:读取资源结果响应
{
"jsonrpc": "2.0",
"id": "read-resource-example",
"result": {
"resultType": "complete",
"contents": [
{
"uri": "file:///project/src/main.rs",
"mimeType": "text/x-rust",
"text": "fn main() {\n println!(\"Hello world!\");\n}"
}
]
}
}
示例:使用 TTL 读取资源结果响应
{
"jsonrpc": "2.0",
"id": "read-resource-with-ttl-example",
"result": {
"resultType": "complete",
"contents": [
{
"uri": "file:///project/src/main.rs",
"mimeType": "text/x-rust",
"text": "fn main() {\n println!(\"Hello world!\");\n}"
}
],
"ttlMs": 60000,
"cacheScope": "private"
}
}

ReadResourceResult

interface ReadResourceResult {
  _meta?: ResultMetaObject;
  resultType: string;
  ttlMs: number;
  cacheScope: "public" | "private";
  contents: (TextResourceContents | BlobResourceContents)[];
  [key: string]: unknown;
}

服务器针对 resources/read 请求。

示例:文件资源内容
{
"resultType": "complete",
"contents": [
{
"uri": "file:///project/src/main.rs",
"mimeType": "text/x-rust",
"text": "fn main() {\n println!(\"Hello world!\");\n}"
}
],
"ttlMs": 60000,
"cacheScope": "private"
}

指示结果的类型,允许客户端决定如何解析结果对象。

实现此协议版本的服务器 MUST 包含此字段。为向后兼容,当客户端收到实现较早协议版本(不包含 resultType)的服务器返回的结果时,客户端 MUST 将缺失字段视为 "complete"。

来自服务器的提示,指示客户端 MAY 在重新获取之前缓存此响应的时间(以毫秒为单位)。语义类似于 HTTP Cache-Control max-age。

  • 如果为0,则响应 SHOULD 被立即视为过时,客户端 MAY 在每次需要结果时重新获取。
  • 如果为正数,则客户端 SHOULD 认为在收到响应后这么多毫秒内结果是新鲜的。

指示缓存响应的预期作用域,类似于 HTTP Cache-Control: public 与 Cache-Control: private.

  • "public":响应不包含用户特定数据。任何客户端或中介(例如共享网关、缓存代理)MAY 缓存响应并跨授权上下文提供服务。
  • "private":响应 MAY 只能在同一授权上下文中缓存和重用。缓存 MUST NOT 在授权上下文之间共享(例如不同的访问令牌需要不同的缓存)。

resources/templates/list

ListResourceTemplatesRequest

interface ListResourceTemplatesRequest {
  jsonrpc: "2.0";
  id: RequestId;
  params: PaginatedRequestParams;
  method: "resources/templates/list";
}

从客户端发送,请求服务器拥有的资源模板列表。

示例:列出资源模板请求
{
"jsonrpc": "2.0",
"id": "list-resource-templates-example",
"method": "resources/templates/list",
"params": {
"_meta": {
"io.modelcontextprotocol/protocolVersion": "2026-07-28",
"io.modelcontextprotocol/clientInfo": {
"name": "ExampleClient",
"version": "1.0.0"
},
"io.modelcontextprotocol/clientCapabilities": {}
}
}
}

ListResourceTemplatesResultResponse

interface ListResourceTemplatesResultResponse {
  jsonrpc: "2.0";
  id: RequestId;
  result: ListResourceTemplatesResult;
}

服务器对 resources/templates/list 请求。

示例:列出资源模板结果响应
{
"jsonrpc": "2.0",
"id": "list-resource-templates-example",
"result": {
"resultType": "complete",
"resourceTemplates": [
{
"uriTemplate": "file:///{path}",
"name": "Project Files",
"title": "Project Files",
"description": "Access files in the project directory",
"mimeType": "application/octet-stream",
"icons": [
{
"src": "https://example.com/folder-icon.png",
"mimeType": "image/png",
"sizes": ["48x48"]
}
]
}
],
"ttlMs": 3600000,
"cacheScope": "public"
}
}

ListResourceTemplatesResult

interface ListResourceTemplatesResult {
  _meta?: ResultMetaObject;
  resultType: string;
  nextCursor?: string;
  ttlMs: number;
  cacheScope: "public" | "private";
  resourceTemplates: ResourceTemplate[];
  [key: string]: unknown;
}

服务器针对 resources/templates/list 请求。

示例:带有光标和 TTL 的资源模板列表
{
"resultType": "complete",
"resourceTemplates": [
{
"uriTemplate": "file:///{path}",
"name": "Project Files",
"title": "📁 Project Files",
"description": "Access files in the project directory",
"mimeType": "application/octet-stream",
"icons": [
{
"src": "https://example.com/folder-icon.png",
"mimeType": "image/png",
"sizes": ["48x48"]
}
]
}
],
"nextCursor": "next-page-cursor",
"ttlMs": 3600000,
"cacheScope": "public"
}

指示结果的类型,允许客户端决定如何解析结果对象。

实现此协议版本的服务器 MUST 包含此字段。为向后兼容,当客户端收到实现较早协议版本(不包含 resultType)的服务器返回的结果时,客户端 MUST 将缺失字段视为 "complete"。

表示最后一个返回结果之后分页位置的不透明令牌。 如存在,则可能还有更多可用结果。

来自服务器的提示,指示客户端 MAY 在重新获取之前缓存此响应的时间(以毫秒为单位)。语义类似于 HTTP Cache-Control max-age。

  • 如果为0,则响应 SHOULD 被立即视为过时,客户端 MAY 在每次需要结果时重新获取。
  • 如果为正数,则客户端 SHOULD 认为在收到响应后这么多毫秒内结果是新鲜的。

指示缓存响应的预期作用域,类似于 HTTP Cache-Control: public 与 Cache-Control: private.

  • "public":响应不包含用户特定数据。任何客户端或中介(例如共享网关、缓存代理)MAY 缓存响应并跨授权上下文提供服务。
  • "private":响应 MAY 只能在同一授权上下文中缓存和重用。缓存 MUST NOT 在授权上下文之间共享(例如不同的访问令牌需要不同的缓存)。

ResourceTemplate

interface ResourceTemplate {
  icons?: Icon[];
  name: string;
  title?: string;
  uriTemplate: string;
  description?: string;
  mimeType?: string;
  annotations?: Annotations;
  _meta?: MetaObject;
}

服务器上可用资源的模板说明。

客户端可在用户界面中显示的一组可选尺寸图标。

支持渲染图标的客户端 MUST 至少支持以下 MIME 类型:

  • image/png - PNG 图像(安全、通用兼容)
  • image/jpeg (和 image/jpg) - JPEG 图像(安全、通用兼容)

支持渲染图标的客户端 SHOULD 还支持:

  • image/svg+xml - SVG 图像(可缩放,但需要安全防范)
  • image/webp - WebP 图像(现代、高效格式)

用于编程或逻辑用途,但在旧版规范中曾用作显示名称,或作为回退值 (如果不存在 title)。

用于 UI 和最终用户场景 — 针对人类可读性和易理解性进行了优化, 即使不熟悉领域术语的人也能理解。

如未提供,应使用 name 进行显示(但 Tool, 其中 annotations.title 应优先于 name,如果存在)。

可用于构造资源 URI 的 URI 模板(符合 RFC 6570)。

此模板用途的说明。

客户端可使用此字段增进 LLM 对可用资源的理解。可将其视为提供给模型的“提示”。

与此模板匹配的所有资源的 MIME 类型。仅当与此模板匹配的所有资源都具有相同类型时才应包含此内容。

提供给客户端的可选注解。

roots/list

ListRootsRequest

interface ListRootsRequest {
  method: "roots/list";
  params?: { _meta?: MetaObject };
}

从服务器发送,向客户端请求根 URIs 的列表。根允许服务器请求要操作的特定目录或文件。根的一个常见示例是提供服务器应操作的一组存储库或目录。

当服务器需要了解文件系统结构或访问客户端有权读取的特定位置时,通常使用此请求。

示例:列出根目录请求
{
"id": "list-roots-example",
"method": "roots/list"
}

自协议版本 2026-07-28 (SEP-2577) 起已弃用。仍保留在规范中至少十二个月;请参阅已弃用的功能注册表。

ListRootsResult

interface ListRootsResult {
  roots: Root[];
}

客户端返回的结果 roots/list 请求。该结果包含一个数组 Root 对象,每个对象代表服务器可以操作的根目录或文件。

示例:单个根目录
{
"roots": [
{
"uri": "file:///home/user/projects/myproject",
"name": "My Project"
}
]
}
示例:多个根目录
{
"roots": [
{
"uri": "file:///home/user/repos/frontend",
"name": "Frontend Repository"
},
{
"uri": "file:///home/user/repos/backend",
"name": "Backend Repository"
}
]
}

自协议版本 2026-07-28 (SEP-2577) 起已弃用。仍保留在规范中至少十二个月;请参阅已弃用的功能注册表。

Root

interface Root {
  uri: string;
  name?: string;
  _meta?: MetaObject;
}

表示服务器可以操作的根目录或文件。

示例:项目目录根
{
"uri": "file:///home/user/projects/myproject",
"name": "My Project"
}

自协议版本 2026-07-28 (SEP-2577) 起已弃用。仍保留在规范中至少十二个月;请参阅已弃用的功能注册表。

URI 标识根。这个 必须 开始于 file:// 现在。在协议的未来版本中可能会放宽此限制,以允许其他 URI 方案。

根的可选名称。这可用于为根提供人类可读的标识符,这对于显示目的或在应用程序的其他部分引用根可能很有用。

sampling/createMessage

CreateMessageRequest

interface CreateMessageRequest {
  method: "sampling/createMessage";
  params: CreateMessageRequestParams;
}

来自服务器的请求,通过客户端对 LLM 进行采样。客户可以完全自行决定选择哪种模型。客户端还应该在开始采样之前通知用户,以便他们检查请求(循环中的人)并决定是否批准它。

示例:采样请求
{
"method": "sampling/createMessage",
"params": {
"messages": [
{
"role": "user",
"content": {
"type": "text",
"text": "What is the capital of France?"
}
}
],
"modelPreferences": {
"hints": [
{
"name": "claude-3-sonnet"
}
],
"intelligencePriority": 0.8,
"speedPriority": 0.5
},
"systemPrompt": "You are a helpful assistant.",
"maxTokens": 100
}
}

自协议版本 2026-07-28 (SEP-2577) 起已弃用。仍保留在规范中至少十二个月;请参阅已弃用的功能注册表。

CreateMessageRequestParams

interface CreateMessageRequestParams {
  messages: SamplingMessage[];
  modelPreferences?: ModelPreferences;
  systemPrompt?: string;
  includeContext?: "none" | "thisServer" | "allServers";
  temperature?: number;
  maxTokens: number;
  stopSequences?: string[];
  metadata?: JSONObject;
  tools?: Tool[];
  toolChoice?: ToolChoice;
}

以下请求的参数: sampling/createMessage 请求。

示例:基本请求
{
"messages": [
{
"role": "user",
"content": {
"type": "text",
"text": "What is the capital of France?"
}
}
],
"modelPreferences": {
"hints": [
{
"name": "claude-3-sonnet"
}
],
"intelligencePriority": 0.8,
"speedPriority": 0.5
},
"systemPrompt": "You are a helpful assistant.",
"maxTokens": 100
}
示例:使用工具请求
{
"messages": [
{
"role": "user",
"content": {
"type": "text",
"text": "What's the weather like in Paris and London?"
}
}
],
"tools": [
{
"name": "get_weather",
"description": "Get current weather for a city",
"inputSchema": {
"type": "object",
"properties": {
"city": {
"type": "string",
"description": "City name"
}
},
"required": ["city"]
}
}
],
"toolChoice": {
"mode": "auto"
},
"maxTokens": 1000
}
示例:带有工具结果的后续请求
{
"messages": [
{
"role": "user",
"content": {
"type": "text",
"text": "What's the weather like in Paris and London?"
}
},
{
"role": "assistant",
"content": [
{
"type": "tool_use",
"id": "call_abc123",
"name": "get_weather",
"input": { "city": "Paris" }
},
{
"type": "tool_use",
"id": "call_def456",
"name": "get_weather",
"input": { "city": "London" }
}
]
},
{
"role": "user",
"content": [
{
"type": "tool_result",
"toolUseId": "call_abc123",
"content": [
{
"type": "text",
"text": "Weather in Paris: 18°C, partly cloudy"
}
]
},
{
"type": "tool_result",
"toolUseId": "call_def456",
"content": [
{
"type": "text",
"text": "Weather in London: 15°C, rainy"
}
]
}
]
}
],
"tools": [
{
"name": "get_weather",
"description": "Get current weather for a city",
"inputSchema": {
"type": "object",
"properties": {
"city": { "type": "string" }
},
"required": ["city"]
}
}
],
"maxTokens": 1000
}

自协议版本 2026-07-28 (SEP-2577) 起已弃用。仍保留在规范中至少十二个月;请参阅已弃用的功能注册表。

服务器选择模型的偏好。客户端 MAY 忽略这些首选项。

服务器想要用于采样的可选系统提示。客户端 MAY 修改或省略该提示。

请求包含来自一台或多台 MCP 服务器(包括调用者)的上下文,并将其附加到提示中。客户端 MAY 忽略该请求。

默认为 "none"。价值观 "thisServer" 和 "allServers" 已弃用 (SEP-2596):服务器 SHOULD 省略此字段或使用 "none",并且 SHOULD 仅在客户端声明时才使用已弃用的值 ClientCapabilities.sampling.context.

的 "thisServer" 和 "allServers" 自协议版本 2025-11-25 (SEP-2596) 起,这些值已弃用,并且将在采样功能本身 (SEP-2577) 之前删除。省略该字段或使用 "none".

请求采样的最大 token 数 (to prevent runaway completions).

客户端 MAY 选择采样少于请求的最大值的令牌。

用于传递到 LLM 提供程序的可选元数据。该元数据的格式是特定于提供商的。

模型在生成过程中可能使用的工具。如果提供了此字段,则客户端 MUST 返回错误,但 ClientCapabilities.sampling.tools 没有声明。

控制模型如何使用工具。如果提供了此字段,则客户端 MUST 返回错误,但 ClientCapabilities.sampling.tools 没有声明。默认为 { mode: "auto" }.

CreateMessageResult

interface CreateMessageResult {
  model: string;
  stopReason?: string;
  role: Role;
  content: SamplingMessageContentBlock | SamplingMessageContentBlock[];
  _meta?: MetaObject;
}

客户端返回的结果 sampling/createMessage 请求。客户端应在返回采样消息之前通知用户,以允许他们检查响应(循环中的人)并决定是否允许服务器查看它。

示例:文本响应
{
"role": "assistant",
"content": {
"type": "text",
"text": "The capital of France is Paris."
},
"model": "claude-3-sonnet-20240307",
"stopReason": "endTurn"
}
示例:工具使用响应
{
"role": "assistant",
"content": [
{
"type": "tool_use",
"id": "call_abc123",
"name": "get_weather",
"input": {
"city": "Paris"
}
},
{
"type": "tool_use",
"id": "call_def456",
"name": "get_weather",
"input": {
"city": "London"
}
}
],
"model": "claude-3-sonnet-20240307",
"stopReason": "toolUse"
}
示例:使用工具后的最终响应
{
"role": "assistant",
"content": {
"type": "text",
"text": "Based on the current weather data:\n\n- **Paris**: 18°C and partly cloudy - quite pleasant!\n- **London**: 15°C and rainy - you'll want an umbrella.\n\nParis has slightly warmer and drier conditions today."
},
"model": "claude-3-sonnet-20240307",
"stopReason": "endTurn"
}

自协议版本 2026-07-28 (SEP-2577) 起已弃用。仍保留在规范中至少十二个月;请参阅已弃用的功能注册表。

生成该消息的模型名称。

采样停止的原因(如已知)。

标准值:

  • "endTurn":助手轮自然结束
  • "stopSequence":遇到停止序列
  • "maxTokens":已达到最大代币限制
  • "toolUse":模型想要使用一种或多种工具

此字段为开放字符串,以允许提供商特定的停止原因。

ModelHint

interface ModelHint {
  name?: string;
}

用于模型选择的提示。

此处未声明的键当前未由规范指定,并由客户端解释。

自协议版本 2026-07-28 (SEP-2577) 起已弃用。仍保留在规范中至少十二个月;请参阅已弃用的功能注册表。

模型名称提示。

客户端 SHOULD 将其视为模型名称的子字符串;例如:

  • claude-3-5-sonnet 应该匹配 claude-3-5-sonnet-20241022
  • sonnet 应该匹配 claude-3-5-sonnet-20241022, claude-3-sonnet-20240229等
  • claude 应该匹配任何Claude 模型

客户端 MAY 还会将该字符串映射到不同提供商的模型名称或不同的模型系列,只要它填补了类似的空白;例如:

  • gemini-1.5-flash 可以匹配 claude-3-haiku-20240307

ModelPreferences

interface ModelPreferences {
  hints?: ModelHint[];
  costPriority?: number;
  speedPriority?: number;
  intelligencePriority?: number;
}

服务器在采样期间向客户端提出的模型选择偏好。

由于 LLMs 可以沿多个维度变化,因此选择 "best" 模型绝非易事。不同的模型在不同的领域表现出色——有些速度更快但能力较差,另一些模型能力更强但更昂贵,等等。该接口允许服务器跨多个维度表达其优先级,以帮助客户端为其用例做出适当的选择。

这些偏好始终是建议性的。客户端 MAY 忽略它们。客户还可以决定如何解释这些偏好以及如何平衡它们与其他考虑因素。

示例:带有提示和优先级
{
"hints": [
{ "name": "claude-3-sonnet" },
{ "name": "claude" }
],
"costPriority": 0.3,
"speedPriority": 0.8,
"intelligencePriority": 0.5
}

自协议版本 2026-07-28 (SEP-2577) 起已弃用。仍保留在规范中至少十二个月;请参阅已弃用的功能注册表。

用于模型选择的可选提示。

如果指定了多个提示,则客户端 MUST 按顺序评估它们(以便采用第一个匹配项)。

客户端 SHOULD 优先考虑这些提示而不是数字优先级,但 MAY 仍然使用优先级从不明确的匹配中进行选择。

选择模型时优先考虑成本多少。值为 0 表示成本不重要,而值为 1 表示成本是最重要的因素。

选择模型时优先考虑采样速度(延迟)的程度。值为 0 表示速度不重要,而值为 1 表示速度是最重要的因素。

选择模型时,应优先考虑智能和功能。值为 0 表示智力不重要,而值为 1 表示智力是最重要的因素。

SamplingMessage

描述发送给 LLM API 或从其接收的消息。

示例:单个内容块
{
"role": "user",
"content": {
"type": "text",
"text": "What is the capital of France?"
}
}
示例:多个内容块
{
"role": "user",
"content": [
{
"type": "tool_result",
"toolUseId": "call_123",
"content": [{ "type": "text", "text": "Result 1" }]
},
{
"type": "tool_result",
"toolUseId": "call_456",
"content": [{ "type": "text", "text": "Result 2" }]
}
]
}

自协议版本 2026-07-28 (SEP-2577) 起已弃用。仍保留在规范中至少十二个月;请参阅已弃用的功能注册表。

SamplingMessageContentBlock

SamplingMessageContentBlock:
  | TextContent
  | ImageContent
  | AudioContent
  | ToolUseContent
  | ToolResultContent

自协议版本 2026-07-28 (SEP-2577) 起已弃用。仍保留在规范中至少十二个月;请参阅已弃用的功能注册表。

ToolChoice

interface ToolChoice {
  mode?: "none" | "required" | "auto";
}

控制采样请求的工具选择行为。

自协议版本 2026-07-28 (SEP-2577) 起已弃用。仍保留在规范中至少十二个月;请参阅已弃用的功能注册表。

控制模型使用工具的能力:

  • "auto":模型决定是否使用工具(默认)
  • "required":模型 MUST 在完成之前至少使用一种工具
  • "none":模型 MUST NOT 使用任何工具

ToolResultContent

interface ToolResultContent {
  type: "tool_result";
  toolUseId: string;
  content: ContentBlock[];
  structuredContent?: unknown;
  isError?: boolean;
  _meta?: MetaObject;
}

工具使用的结果,由用户提供给助手。

示例: `get_weather` tool result
{
"type": "tool_result",
"toolUseId": "call_abc123",
"content": [
{
"type": "text",
"text": "Weather in Paris: 18°C, partly cloudy"
}
]
}

自协议版本 2026-07-28 (SEP-2577) 起已弃用。仍保留在规范中至少十二个月;请参阅已弃用的功能注册表。

此结果所对应的工具使用 ID。

此 MUST 与之前的 ID 匹配 ToolUseContent.

工具使用的非结构化结果内容。

这与以下格式相同 CallToolResult.content 并且可以包括文本、图像、音频、资源链接和嵌入资源。

可选的结构化结果值。

这可以是任何 JSON 值(对象、数组、字符串、数字、布尔值或 null)。如果该工具定义了 Tool.outputSchema,此 SHOULD 符合该模式。

工具使用是否导致错误。

如果为 true,则内容通常描述发生的错误。默认值:假

有关工具结果的可选元数据。当客户端 SHOULD 将工具结果包含在后续采样请求中以启用缓存优化时,会保留此字段。

ToolUseContent

interface ToolUseContent {
  type: "tool_use";
  id: string;
  name: string;
  input: { [key: string]: unknown };
  _meta?: MetaObject;
}

助手调用工具的请求。

示例: `get_weather` tool use
{
"type": "tool_use",
"id": "call_abc123",
"name": "get_weather",
"input": {
"city": "Paris"
}
}

自协议版本 2026-07-28 (SEP-2577) 起已弃用。仍保留在规范中至少十二个月;请参阅已弃用的功能注册表。

此次工具使用的唯一标识符。

此 ID 用于将工具结果与对应的工具使用匹配。

要调用的工具名称。

传递给工具的参数,须符合工具的输入 schema。

有关工具使用的可选元数据。当在后续采样请求中包含工具使用以启用缓存优化时,客户端 SHOULD 会保留此字段。

server/discover

DiscoverRequest

interface DiscoverRequest {
  jsonrpc: "2.0";
  id: RequestId;
  method: "server/discover";
  params: RequestParams;
}

来自客户端的请求,要求服务器公布其支持的协议版本、功能和其他元数据。服务器 MUST 实施 server/discover。客户 MAY 调用它,但不需要这样做——版本协商也可以通过每个请求内联进行 _meta.

示例:发现请求
{
"jsonrpc": "2.0",
"id": "discover-1",
"method": "server/discover",
"params": {
"_meta": {
"io.modelcontextprotocol/protocolVersion": "2026-07-28",
"io.modelcontextprotocol/clientInfo": {
"name": "ExampleClient",
"version": "1.0.0"
},
"io.modelcontextprotocol/clientCapabilities": {}
}
}
}

DiscoverResultResponse

interface DiscoverResultResponse {
  jsonrpc: "2.0";
  id: RequestId;
  result: DiscoverResult;
}

服务器对 server/discover 请求。

示例:发现结果响应
{
"jsonrpc": "2.0",
"id": "discover-1",
"result": {
"resultType": "complete",
"supportedVersions": ["2026-07-28"],
"capabilities": {
"tools": {},
"resources": {}
},
"_meta": {
"io.modelcontextprotocol/serverInfo": {
"name": "ExampleServer",
"version": "1.0.0"
}
},
"ttlMs": 3600000,
"cacheScope": "public"
}
}

DiscoverResult

interface DiscoverResult {
  _meta?: ResultMetaObject;
  resultType: string;
  supportedVersions: string[];
  capabilities: ServerCapabilities;
  instructions?: string;
  ttlMs: number;
  cacheScope: "public" | "private";
  [key: string]: unknown;
}

服务器针对 server/discover 请求。

示例:服务器能力发现
{
"resultType": "complete",
"supportedVersions": ["2026-07-28"],
"capabilities": {
"tools": {},
"resources": {}
},
"_meta": {
"io.modelcontextprotocol/serverInfo": {
"name": "ExampleServer",
"version": "1.0.0"
}
},
"instructions": "This server provides weather and resource utilities. Prefer `get_weather` for forecast lookups.",
"ttlMs": 3600000,
"cacheScope": "public"
}

指示结果的类型,允许客户端决定如何解析结果对象。

实现此协议版本的服务器 MUST 包含此字段。为向后兼容,当客户端收到实现较早协议版本(不包含 resultType)的服务器返回的结果时,客户端 MUST 将缺失字段视为 "complete"。

MCP 该服务器支持的协议版本。客户端应从此列表中选择一个版本以在后续请求中使用。

服务器的能力。

描述服务器及其功能的自然语言指南。

客户可以使用它来提高 LLM 对可用工具的理解(例如通过将其包含在系统提示中)。它应该侧重于帮助模型有效使用服务器的信息,并且不应重复工具描述中已有的信息。

来自服务器的提示,指示客户端 MAY 在重新获取之前缓存此响应的时间(以毫秒为单位)。语义类似于 HTTP Cache-Control max-age。

  • 如果为0,则响应 SHOULD 被立即视为过时,客户端 MAY 在每次需要结果时重新获取。
  • 如果为正数,则客户端 SHOULD 认为在收到响应后这么多毫秒内结果是新鲜的。

指示缓存响应的预期作用域,类似于 HTTP Cache-Control: public 与 Cache-Control: private.

  • "public":响应不包含用户特定数据。任何客户端或中介(例如共享网关、缓存代理)MAY 缓存响应并跨授权上下文提供服务。
  • "private":响应 MAY 只能在同一授权上下文中缓存和重用。缓存 MUST NOT 在授权上下文之间共享(例如不同的访问令牌需要不同的缓存)。

ClientCapabilities

interface ClientCapabilities {
  experimental?: { [key: string]: JSONObject };
  roots?: {};
  sampling?: { context?: JSONObject; tools?: JSONObject };
  elicitation?: { form?: JSONObject; url?: JSONObject };
  extensions?: { [key: string]: JSONObject };
}

客户端可能支持的能力。 已知能力在此 schema 中定义,但这不是封闭集合: 任何客户端都可以定义自己的附加能力。

客户端支持的实验性非标准能力。

客户端支持列出根目录时存在。

自协议版本 2026-07-28 (SEP-2577) 起已弃用。仍保留在规范中至少十二个月;请参阅已弃用的功能注册表。

示例:根目录 — 最低基线支持
{
"roots": {}
}

客户端支持从 LLM 采样时存在。

类型声明
  • 可选context?: JSONObject

    客户端是否支持 context inclusion via includeContext 参数。如果未声明,服务器 SHOULD 仅使用 includeContext: "none" (或省略它)。

  • 可选tools?: JSONObject

    客户端是否支持 tool use via tools 和 toolChoice 参数。

自协议版本 2026-07-28 (SEP-2577) 起已弃用。仍保留在规范中至少十二个月;请参阅已弃用的功能注册表。

示例:采样 — 最低基线支持
{
"sampling": {}
}
示例:采样 — 工具使用支持
{
"sampling": {
"tools": {}
}
}
示例:采样 — 上下文包含支持(已弃用)
{
"sampling": {
"context": {}
}
}

客户端支持服务器发起的信息征询时存在。

示例:征询 — 表单和 URL 模式支持
{
"elicitation": {
"form": {},
"url": {}
}
}
示例:征询 — 仅表单模式(隐式)
{
"elicitation": {}
}

客户端支持的可选 MCP 扩展。键是扩展标识符(例如"io.modelcontextprotocol/oauth-client-credentials"),值是每个扩展设置对象。空对象表示支持但没有设置。

键 MUST 遵循 _meta 关键命名规则,带有强制前缀。

示例:扩展 — 支持 MIME 类型的 MCP Apps(UI)扩展
{
"extensions": {
"io.modelcontextprotocol/ui": {
"mimeTypes": ["text/html;profile=mcp-app"]
}
}
}

Implementation

interface Implementation {
  icons?: Icon[];
  name: string;
  title?: string;
  version: string;
  description?: string;
  websiteUrl?: string;
}

描述 MCP 实现。

客户端可在用户界面中显示的一组可选尺寸图标。

支持渲染图标的客户端 MUST 至少支持以下 MIME 类型:

  • image/png - PNG 图像(安全、通用兼容)
  • image/jpeg (和 image/jpg) - JPEG 图像(安全、通用兼容)

支持渲染图标的客户端 SHOULD 还支持:

  • image/svg+xml - SVG 图像(可缩放,但需要安全防范)
  • image/webp - WebP 图像(现代、高效格式)

用于编程或逻辑用途,但在旧版规范中曾用作显示名称,或作为回退值 (如果不存在 title)。

用于 UI 和最终用户场景 — 针对人类可读性和易理解性进行了优化, 即使不熟悉领域术语的人也能理解。

如未提供,应使用 name 进行显示(但 Tool, 其中 annotations.title 应优先于 name,如果存在)。

此实现的版本。

对此实现功能的可选可读说明。

客户端或服务器可以使用它来提供有关其目的和功能的上下文。例如,服务器可能描述其提供的资源或工具的类型,而客户端可能描述其预期用例。

此实现网站的可选 URL。

ServerCapabilities

interface ServerCapabilities {
  experimental?: { [key: string]: JSONObject };
  logging?: JSONObject;
  completions?: JSONObject;
  prompts?: { listChanged?: boolean };
  resources?: { subscribe?: boolean; listChanged?: boolean };
  tools?: { listChanged?: boolean };
  extensions?: { [key: string]: JSONObject };
}

服务器可能支持的能力。 已知能力在此 schema 中定义,但这不是封闭集合: 任何服务器都可以定义自己的附加能力。

服务器支持的实验性非标准能力。

服务器支持向客户端发送日志消息时存在。

自协议版本 2026-07-28 (SEP-2577) 起已弃用。仍保留在规范中至少十二个月;请参阅已弃用的功能注册表。

示例:日志 — 最低基线支持
{
"logging": {}
}

服务器支持参数自动补全建议时存在。

示例:补全 — 最低基线支持
{
"completions": {}
}

服务器提供提示模板时存在。

类型声明
  • 可选listChanged?: boolean

    此服务器是否支持提示列表变更通知。

示例:提示 — 最低基线支持
{
"prompts": {}
}
示例:提示 — 列表变更通知
{
"prompts": {
"listChanged": true
}
}

服务器提供可读资源时存在。

类型声明
  • 可选subscribe?: boolean

    此服务器是否支持订阅资源更新。

  • 可选listChanged?: boolean

    此服务器是否支持资源列表变更通知。

示例:资源 — 最低基线支持
{
"resources": {}
}
示例:资源 — 订阅单个资源更新(仅)
{
"resources": {
"subscribe": true
}
}
示例:资源 — 仅列表变更通知
{
"resources": {
"listChanged": true
}
}
示例:资源 — 所有通知
{
"resources": {
"subscribe": true,
"listChanged": true
}
}

服务器提供可调用工具时存在。

类型声明
  • 可选listChanged?: boolean

    此服务器是否支持工具列表变更通知。

示例:工具 — 最低基线支持
{
"tools": {}
}
示例:工具 — 列表变更通知
{
"tools": {
"listChanged": true
}
}

服务器支持的可选 MCP 扩展。键是扩展标识符(例如"io.modelcontextprotocol/tasks"),值是每个扩展设置对象。空对象表示支持但没有设置。

键 MUST 遵循 _meta 关键命名规则,带有强制前缀。

示例:扩展 — Tasks 扩展支持
{
"extensions": {
"io.modelcontextprotocol/tasks": {}
}
}

subscriptions/listen

SubscriptionsListenRequest

interface SubscriptionsListenRequest {
  jsonrpc: "2.0";
  id: RequestId;
  method: "subscriptions/listen";
  params: SubscriptionsListenRequestParams;
}

从客户端发送以打开长期通道以接收特定请求上下文之外的通知。替换以前的 HTTP GET 端点,并确保 HTTP 和 STDIO 之间的行为一致。

示例:监听工具和资源列表更改
{
"jsonrpc": "2.0",
"id": "listen-1",
"method": "subscriptions/listen",
"params": {
"_meta": {
"io.modelcontextprotocol/protocolVersion": "2026-07-28",
"io.modelcontextprotocol/clientInfo": {
"name": "ExampleClient",
"version": "1.0.0"
},
"io.modelcontextprotocol/clientCapabilities": {}
},
"notifications": {
"toolsListChanged": true,
"resourceSubscriptions": ["file:///project/config.json"]
}
}
}

SubscriptionsListenRequestParams

interface SubscriptionsListenRequestParams {
  _meta: RequestMetaObject;
  notifications: SubscriptionFilter;
}

以下请求的参数: subscriptions/listen 请求。

客户端在此流上选择接收的通知。服务器 MUST NOT 发送客户端未明确请求的通知类型。

SubscriptionsListenResultResponse

interface SubscriptionsListenResultResponse {
  jsonrpc: "2.0";
  id: RequestId;
  result: SubscriptionsListenResult;
}

服务器对 subscriptions/listen 请求,当服务器优雅地终止订阅时发送。

示例:优雅关闭订阅响应
{
"jsonrpc": "2.0",
"id": "listen-1",
"result": {
"resultType": "complete",
"_meta": {
"io.modelcontextprotocol/subscriptionId": "listen-1"
}
}
}

SubscriptionsListenResult

interface SubscriptionsListenResult {
  resultType: string;
  _meta: SubscriptionsListenResultMetaObject;
  [key: string]: unknown;
}

对一个的回应 subscriptions/listen 请求,表明订阅已正常结束(例如,在服务器关闭期间)。因为监听流是长期存在的,所以只有当服务器取消订阅时才会发送此结果;突然的传输关闭不会有任何响应。否则结果正文为空。

示例:优雅关闭订阅
{
"resultType": "complete",
"_meta": {
"io.modelcontextprotocol/subscriptionId": "listen-1"
}
}

指示结果的类型,允许客户端决定如何解析结果对象。

实现此协议版本的服务器 MUST 包含此字段。为向后兼容,当客户端收到实现较早协议版本(不包含 resultType)的服务器返回的结果时,客户端 MUST 将缺失字段视为 "complete"。

SubscriptionFilter

interface SubscriptionFilter {
  toolsListChanged?: boolean;
  promptsListChanged?: boolean;
  resourcesListChanged?: boolean;
  resourceSubscriptions?: string[];
}

客户端可以在以下请求中选择接收的通知类型集合: subscriptions/listen 请求。

每个通知类型是 选择加入;服务器 MUST NOT 发送客户端未在此处明确请求的通知类型。

如果为 true,则接收 notifications/tools/list_changed.

如果为 true,则接收 notifications/prompts/list_changed.

如果为 true,则接收 notifications/resources/list_changed.

订阅 notifications/resources/updated 对于这些资源 URIs。取代前者 resources/subscribe RPC.

SubscriptionsListenResultMetaObject

interface SubscriptionsListenResultMetaObject {
  "io.modelcontextprotocol/serverInfo"?: Implementation;
  "io.modelcontextprotocol/subscriptionId": RequestId;
  [key: string]: unknown;
}

扩展 ResultMetaObject,增加 SubscriptionsListenResult 携带的订阅流标识符。MetaObject 的所有键命名规则仍然适用。

MetaObject 用于键命名规则和保留前缀。

标识产生响应的服务器软件。服务器 SHOULD 在每个响应中都包含此字段,除非专门配置为不这样做。

Implementation 模式要求提供 name 和 version;其他字段可选。

该值由服务器自行报告,未经协议验证。它用于显示、记录和调试。客户端 SHOULD NOT 使用它来更改其行为,并且 SHOULD NOT 依赖它做出安全决策。

标识此响应关闭的订阅流,以便客户端将其与原始订阅关联;流上的通知也使用同一个键。其值为打开此流的 subscriptions/listen 请求的 JSON-RPC ID(与此响应的 id 相同)。

tools/call

CallToolRequest

interface CallToolRequest {
  jsonrpc: "2.0";
  id: RequestId;
  method: "tools/call";
  params: CallToolRequestParams;
}

客户端用来调用服务器提供的工具。

示例:调用工具请求
{
"jsonrpc": "2.0",
"id": "call-tool-example",
"method": "tools/call",
"params": {
"_meta": {
"io.modelcontextprotocol/protocolVersion": "2026-07-28",
"io.modelcontextprotocol/clientInfo": {
"name": "ExampleClient",
"version": "1.0.0"
},
"io.modelcontextprotocol/clientCapabilities": {}
},
"name": "get_weather",
"arguments": {
"location": "New York"
}
}
}

CallToolRequestParams

interface CallToolRequestParams {
  _meta: RequestMetaObject;
  inputResponses?: InputResponses;
  requestState?: string;
  name: string;
  arguments?: { [key: string]: unknown };
}

以下请求的参数: tools/call 请求。

示例: `get_weather` tool call params
{
"_meta": {
"io.modelcontextprotocol/protocolVersion": "2026-07-28",
"io.modelcontextprotocol/clientInfo": {
"name": "ExampleClient",
"version": "1.0.0"
},
"io.modelcontextprotocol/clientCapabilities": {}
},
"name": "get_weather",
"arguments": {
"location": "New York"
}
}
示例:带进度 token 的工具调用参数
{
"_meta": {
"io.modelcontextprotocol/protocolVersion": "2026-07-28",
"io.modelcontextprotocol/clientInfo": {
"name": "ExampleClient",
"version": "1.0.0"
},
"io.modelcontextprotocol/clientCapabilities": {},
"progressToken": "oivaizmir"
},
"name": "build_simulation",
"arguments": {
"city": "Micropolis"
}
}

工具名称。

工具调用使用的参数。

CallToolResultResponse

interface CallToolResultResponse {
  jsonrpc: "2.0";
  id: RequestId;
  result: InputRequiredResult | CallToolResult;
}

服务器对 tools/call 请求。

示例:调用工具结果响应
{
"jsonrpc": "2.0",
"id": "call-tool-example",
"result": {
"resultType": "complete",
"content": [
{
"type": "text",
"text": "Current weather in New York:\nTemperature: 72°F\nConditions: Partly cloudy"
}
],
"isError": false
}
}

CallToolResult

interface CallToolResult {
  _meta?: ResultMetaObject;
  resultType: string;
  content: ContentBlock[];
  structuredContent?: unknown;
  isError?: boolean;
  [key: string]: unknown;
}

服务器针对 tools/call 请求。

示例:非结构化文本的结果
{
"resultType": "complete",
"content": [
{
"type": "text",
"text": "Current weather in New York:\nTemperature: 72°F\nConditions: Partly cloudy"
}
],
"isError": false
}
示例:包含结构化内容的结果
{
"resultType": "complete",
"content": [
{
"type": "text",
"text": "{\"temperature\": 22.5, \"conditions\": \"Partly cloudy\", \"humidity\": 65}"
}
],
"structuredContent": {
"temperature": 22.5,
"conditions": "Partly cloudy",
"humidity": 65
}
}
示例:无效工具输入错误
{
"resultType": "complete",
"content": [
{
"type": "text",
"text": "Invalid departure date: must be in the future. Current date is 08/08/2025."
}
],
"isError": true
}

指示结果的类型,允许客户端决定如何解析结果对象。

实现此协议版本的服务器 MUST 包含此字段。为向后兼容,当客户端收到实现较早协议版本(不包含 resultType)的服务器返回的结果时,客户端 MUST 将缺失字段视为 "complete"。

表示工具调用非结构化结果的内容对象列表。

表示工具调用结构化结果的可选 JSON 值。

这可以是符合工具的 outputSchema(如果已定义)的任何 JSON 值(对象、数组、字符串、数字、布尔值或 null)。

工具调用是否以错误结束。

如未设置,则假定为 false(调用成功)。

源自工具 SHOULD 的任何错误都会在结果对象内报告,其中 isError 设置为真, 不 作为 MCP 协议级错误响应。否则,LLM 将无法发现错误发生并进行自我纠正。

然而,任何错误 发现 工具、指示服务器不支持工具调用的错误或任何其他异常情况应报告为 MCP 错误响应。

tools/list

ListToolsRequest

interface ListToolsRequest {
  jsonrpc: "2.0";
  id: RequestId;
  params: PaginatedRequestParams;
  method: "tools/list";
}

从客户端发送以请求服务器拥有的工具列表。

示例:列出工具请求
{
"jsonrpc": "2.0",
"id": "list-tools-example",
"method": "tools/list",
"params": {
"_meta": {
"io.modelcontextprotocol/protocolVersion": "2026-07-28",
"io.modelcontextprotocol/clientInfo": {
"name": "ExampleClient",
"version": "1.0.0"
},
"io.modelcontextprotocol/clientCapabilities": {}
}
}
}

ListToolsResultResponse

interface ListToolsResultResponse {
  jsonrpc: "2.0";
  id: RequestId;
  result: ListToolsResult;
}

服务器对 tools/list 请求。

示例:列出工具结果响应
{
"jsonrpc": "2.0",
"id": "list-tools-example",
"result": {
"resultType": "complete",
"tools": [
{
"name": "get_weather",
"title": "Weather Information Provider",
"description": "Get current weather information for a location",
"inputSchema": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "City name or zip code"
}
},
"required": ["location"]
},
"icons": [
{
"src": "https://example.com/weather-icon.png",
"mimeType": "image/png",
"sizes": ["48x48"]
}
]
}
],
"nextCursor": "next-page-cursor",
"ttlMs": 3600000,
"cacheScope": "public"
}
}

ListToolsResult

interface ListToolsResult {
  _meta?: ResultMetaObject;
  resultType: string;
  nextCursor?: string;
  ttlMs: number;
  cacheScope: "public" | "private";
  tools: Tool[];
  [key: string]: unknown;
}

服务器针对 tools/list 请求。

示例:带有光标和 TTL 的工具列表
{
"resultType": "complete",
"tools": [
{
"name": "get_weather",
"title": "Weather Information Provider",
"description": "Get current weather information for a location",
"inputSchema": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "City name or zip code"
}
},
"required": ["location"]
},
"icons": [
{
"src": "https://example.com/weather-icon.png",
"mimeType": "image/png",
"sizes": ["48x48"]
}
]
}
],
"nextCursor": "next-page-cursor",
"ttlMs": 300000,
"cacheScope": "public"
}

指示结果的类型,允许客户端决定如何解析结果对象。

实现此协议版本的服务器 MUST 包含此字段。为向后兼容,当客户端收到实现较早协议版本(不包含 resultType)的服务器返回的结果时,客户端 MUST 将缺失字段视为 "complete"。

表示最后一个返回结果之后分页位置的不透明令牌。 如存在,则可能还有更多可用结果。

来自服务器的提示,指示客户端 MAY 在重新获取之前缓存此响应的时间(以毫秒为单位)。语义类似于 HTTP Cache-Control max-age。

  • 如果为0,则响应 SHOULD 被立即视为过时,客户端 MAY 在每次需要结果时重新获取。
  • 如果为正数,则客户端 SHOULD 认为在收到响应后这么多毫秒内结果是新鲜的。

指示缓存响应的预期作用域,类似于 HTTP Cache-Control: public 与 Cache-Control: private.

  • "public":响应不包含用户特定数据。任何客户端或中介(例如共享网关、缓存代理)MAY 缓存响应并跨授权上下文提供服务。
  • "private":响应 MAY 只能在同一授权上下文中缓存和重用。缓存 MUST NOT 在授权上下文之间共享(例如不同的访问令牌需要不同的缓存)。

Tool

interface Tool {
  icons?: Icon[];
  name: string;
  title?: string;
  description?: string;
  inputSchema: { $schema?: string; type: "object"; [key: string]: unknown };
  outputSchema?: { $schema?: string; [key: string]: unknown };
  annotations?: ToolAnnotations;
  _meta?: MetaObject;
}

客户端可调用工具的定义。

示例:使用默认 2020-12 输入 schema
{
"name": "calculate_sum",
"description": "Add two numbers",
"inputSchema": {
"type": "object",
"properties": {
"a": { "type": "number" },
"b": { "type": "number" }
},
"required": ["a", "b"]
}
}
示例:使用显式 draft-07 输入 schema
{
"name": "calculate_sum",
"description": "Add two numbers",
"inputSchema": {
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"a": { "type": "number" },
"b": { "type": "number" }
},
"required": ["a", "b"]
}
}
示例:无参数
{
"name": "get_current_time",
"description": "Returns the current server time",
"inputSchema": {
"type": "object",
"additionalProperties": false
}
}
示例:使用结构化内容的输出架构
{
"name": "get_weather_data",
"title": "Weather Data Retriever",
"description": "Get current weather data for a location",
"inputSchema": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "City name or zip code"
}
},
"required": ["location"]
},
"outputSchema": {
"type": "object",
"properties": {
"temperature": {
"type": "number",
"description": "Temperature in celsius"
},
"conditions": {
"type": "string",
"description": "Weather conditions description"
},
"humidity": {
"type": "number",
"description": "Humidity percentage"
}
},
"required": ["temperature", "conditions", "humidity"]
}
}

客户端可在用户界面中显示的一组可选尺寸图标。

支持渲染图标的客户端 MUST 至少支持以下 MIME 类型:

  • image/png - PNG 图像(安全、通用兼容)
  • image/jpeg (和 image/jpg) - JPEG 图像(安全、通用兼容)

支持渲染图标的客户端 SHOULD 还支持:

  • image/svg+xml - SVG 图像(可缩放,但需要安全防范)
  • image/webp - WebP 图像(现代、高效格式)

用于编程或逻辑用途,但在旧版规范中曾用作显示名称,或作为回退值 (如果不存在 title)。

用于 UI 和最终用户场景 — 针对人类可读性和易理解性进行了优化, 即使不熟悉领域术语的人也能理解。

如未提供,应使用 name 进行显示(但 Tool, 其中 annotations.title 应优先于 name,如果存在)。

工具的可读说明。

客户端可使用此字段增进 LLM 对可用工具的理解。可将其视为提供给模型的“提示”。

定义工具预期参数的 JSON Schema 对象。

工具参数始终是 JSON 对象,因此根节点必须包含 type: "object"。除此之外,任意 JSON Schema 2020-12 关键字都可以与 type 并列,包括组合关键字(oneOf、anyOf、allOf、not)、条件关键字(if/then/else)、引用关键字($ref、$defs、$anchor)以及其他标准校验或注解关键字。

属性模式可以携带 x-mcp-header 注解,将参数值映射到 Streamable HTTP 传输的 HTTP 标头中。有效性和提取规则见 Streamable HTTP 传输规范。

未显式提供 $schema 时,默认使用 JSON Schema 2020-12。

可选的 JSON Schema 对象,定义 CallToolResult 的 structuredContent 字段返回的工具输出结构。它可以是任意有效的 JSON Schema 2020-12。

未显式提供 $schema 时,默认使用 JSON Schema 2020-12。

可选的附加工具信息。

显示名称的优先顺序为:title、annotations.title、name。

ToolAnnotations

interface ToolAnnotations {
  title?: string;
  readOnlyHint?: boolean;
  destructiveHint?: boolean;
  idempotentHint?: boolean;
  openWorldHint?: boolean;
}

向客户端描述 Tool 的附加属性。

注意:ToolAnnotations 中所有属性都是提示,不保证准确描述工具行为(包括 title 之类的描述性属性)。

客户端绝不应根据从不可信服务器收到的 ToolAnnotations 决定如何使用工具。

工具的可读标题。

如果为 true,工具不会修改其环境。

默认值:false。

如果为 true,该工具可能会对其环境执行破坏性更新。如果为 false,则该工具仅执行附加更新。

(仅当 readOnlyHint == false 时,此属性才有意义。)

默认值:true。

如果为 true,则使用相同参数重复调用该工具不会对其环境产生额外影响。

(仅当 readOnlyHint == false 时,此属性才有意义。)

默认值:false。

如果为 true,此工具可能与外部实体构成的“开放世界”交互;如果为 false,工具的交互范围是封闭的。例如,网页搜索工具的交互范围是开放的,而记忆工具的交互范围则不是。

默认值:true。