server/discover 允许客户端在发送任何其他请求之前,查询服务器支持的协议版本、
能力和标识。服务器 必须 实现它。
除标准 _meta 外,请求不携带任何主体参数:
服务器会返回其支持的协议版本、能力和
标识。此操作支持 缓存。
何时调用
对于客户端来说,调用 server/discover 是可选的——客户端可以内联发起任何
RPC,并在服务器不支持请求的版本时处理
UnsupportedProtocolVersionError。
不过,server/discover
在以下两种场景中很有用:
- 展示服务器信息。 虽然客户端不需要调用
server/discover 就能使用服务器,但它是一次性获取
服务器标识、能力和支持版本的便捷方式。例如,客户端可以根据
单个 server/discover 响应展示服务器支持的能力,而不必分别通过
tools/list、prompts/list 和 resources/list 请求进行探测。
- stdio 向后兼容探测。 在 stdio 中,没有按请求划分的
HTTP 状态码可用于驱动回退。支持现代(按请求
_meta)和旧版(initialize 握手)服务器的客户端 SHOULD
先发送 server/discover;有关回退规则,请参见
stdio: 向后兼容。
有关完整的版本选择流程,请参见 协议版本协商。
有关为未知方法返回的 HTTP 特定状态码,请参见传输中的
协议版本标头
部分。
数据类型
DiscoverResult
发现结果包括:
supportedVersions: Protocol versions the server supports. The client should
choose one of these for subsequent requests.
capabilities: Capabilities the server supports (tools, resources, prompts,
etc.)
_meta['io.modelcontextprotocol/serverInfo']: Name and version of the server
software. Servers SHOULD include this field.
instructions: Optional natural-language guidance for LLMs on how to use
this server effectively
serverInfo is self-reported by the server and is not verified by the
protocol. It is intended for display, logging, and debugging. Clients SHOULD
NOT use it to change their behavior, and SHOULD NOT rely on it for
security decisions.