pub struct ErrorPayload {
pub code: i64,
pub message: String,
pub details: Option<Value>,
pub server_version: Option<String>,
pub client_version: Option<String>,
pub min_supported: Option<String>,
pub max_supported: Option<String>,
pub mcp_server_name: Option<String>,
pub capability: Option<String>,
pub extra: Map<String, Value>,
}Expand description
A2C-SMCP flat 错误负载 / A2C-SMCP flat error payload
协议 0.2.2 统一错误形态:顶层 code/message,诊断信息置于可选的 details 容器。
禁止嵌套 {"error": {...}} envelope —— 所有 client:* ack 路由的协议级错误 MUST 为本结构。
线格式 / Wire shape: { "code": <int>, "message": <str>, "details"?: <object> }。
details 是诊断容器,Agent MUST NOT 原样透传给最终用户(防信息泄露)。
details is a diagnostic container; the Agent MUST NOT propagate it verbatim to end users.
协议依据 / Protocol: a2c-smcp-protocol error-handling.md(flat ErrorPayload,禁止二次 unwrap)。
Python 参考 / Python reference: a2c_smcp/smcp.py 的 ErrorPayload。
协议 0.2.x 对特定码在顶层平铺分流字段(对齐 Python smcp.py:484 ErrorPayload
total=False TypedDict):
- 4008(协议版本不兼容)→
server_version/client_version/min_supported/max_supported(HS-01 #21 / HS-02 #22;构造见ErrorPayload::version_mismatch)。 - 4014(MCP Server 未命中)→
mcp_server_name;4015(能力不支持)→mcp_server_name/capability(SRV-01 #47 / AUTH-01 #23;构造见ErrorPayload::with_mcp_server_name/ErrorPayload::with_capability)。 - 4016 / 4017 / 4018 的 code-specific 字段下沉到
details子对象(无顶层平铺新字段)。
未知顶层字段由 ErrorPayload::extra(#[serde(flatten)])捕获并保留,跨-SDK 往返
不静默丢字段——镜像 Python total=False TypedDict(运行时即 dict)的开放语义,避免旧
Rust SDK 在协议非破坏性新增顶层字段后把它们悄悄抹掉。
Fields§
§code: i64错误码(协议 ErrorCode 取值;线格式为裸整数)/ Error code (a protocol ErrorCode value; bare int on the wire)
message: String人类可读的错误描述 / Human-readable error message
details: Option<Value>诊断容器(可选;为空时不序列化)/ Diagnostic container (optional; skipped when absent)
server_version: Option<String>4008 顶层分流:服务端协议版本 / top-level for 4008: server protocol version。
client_version: Option<String>4008 顶层分流:客户端协议版本 / top-level for 4008: client protocol version。
min_supported: Option<String>4008 顶层分流:服务端支持的最小版本 / top-level for 4008: min supported。
max_supported: Option<String>4008 顶层分流:服务端支持的最大版本 / top-level for 4008: max supported。
mcp_server_name: Option<String>4014 / 4015 顶层分流:未命中 / 缺能力的 MCP Server 名 / top-level for 4014&4015: MCP server name。
capability: Option<String>4015 顶层分流:缺失的 capability 名(如 "resources")/ top-level for 4015: missing capability。
extra: Map<String, Value>未知顶层字段兜底容器:捕获本结构未显式建模的顶层键,跨-SDK 往返不丢字段(见结构体文档)。 为空时不产出任何额外键(空 map flatten 后无输出),故不影响既有 byte 兼容契约。 Catch-all for unmodeled top-level keys so cross-SDK round-trips never silently drop fields.
Implementations§
Source§impl ErrorPayload
impl ErrorPayload
Sourcepub fn new(code: i64, message: impl Into<String>) -> ErrorPayload
pub fn new(code: i64, message: impl Into<String>) -> ErrorPayload
创建 flat 错误负载 / Create a flat error payload
Sourcepub fn from_error_code(
code: ErrorCode,
message: impl Into<String>,
) -> ErrorPayload
pub fn from_error_code( code: ErrorCode, message: impl Into<String>, ) -> ErrorPayload
由协议 ErrorCode 构造 flat 错误负载,消除调用点手工 i64::from(ErrorCode::X.code()) 样板。
产出的 code 必属 is_protocol_error_payload 识别的协议级闭集(编译期由 ErrorCode 保证),
杜绝误用传输/管理层整数字面量(400 / 401 / 500 / 4101…)落入 client:* ack 致 Agent 端
is_protocol_error_payload 误判为「非协议错误」。
Build a flat payload from a protocol ErrorCode, removing manual
i64::from(ErrorCode::X.code()) boilerplate and guaranteeing the wire code is always a
protocol-level value recognized by is_protocol_error_payload.
Sourcepub fn with_details(self, details: Value) -> ErrorPayload
pub fn with_details(self, details: Value) -> ErrorPayload
设置整个 details 诊断容器 / Set the whole details diagnostic container
Sourcepub fn with_detail(
self,
key: impl Into<String>,
value: impl Into<Value>,
) -> ErrorPayload
pub fn with_detail( self, key: impl Into<String>, value: impl Into<Value>, ) -> ErrorPayload
向 details 对象插入单个字段(若 details 非对象则重置为对象)
Insert a single field into the details object (reset to an object if it is not one)
Sourcepub fn with_mcp_server_name(self, name: impl Into<String>) -> ErrorPayload
pub fn with_mcp_server_name(self, name: impl Into<String>) -> ErrorPayload
顶层平铺 mcp_server_name(4014 / 4015 分流字段)/ Set top-level mcp_server_name (4014/4015).
Sourcepub fn with_capability(self, capability: impl Into<String>) -> ErrorPayload
pub fn with_capability(self, capability: impl Into<String>) -> ErrorPayload
顶层平铺 capability(4015 缺失能力名,如 "resources")/ Set top-level capability (4015).
Sourcepub fn version_mismatch(
client: &ProtocolVersion,
server: &ProtocolVersion,
) -> ErrorPayload
pub fn version_mismatch( client: &ProtocolVersion, server: &ProtocolVersion, ) -> ErrorPayload
构造 4008(协议版本不兼容)flat ErrorPayload,顶层平铺 4 个版本分流字段。
min_supported / max_supported 由 server 版本派生:同 MAJOR.MINOR 的整个 PATCH 段
({maj}.{min}.0 ~ {maj}.{min}.999)。message 固定为 "Protocol version mismatch"。
与 Python middleware _mismatch_body 逐字段对齐。供 HS-01 (#21) 服务端握手中间件复用。
Trait Implementations§
Source§impl Clone for ErrorPayload
impl Clone for ErrorPayload
Source§fn clone(&self) -> ErrorPayload
fn clone(&self) -> ErrorPayload
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ErrorPayload
impl Debug for ErrorPayload
Source§impl<'de> Deserialize<'de> for ErrorPayload
impl<'de> Deserialize<'de> for ErrorPayload
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<ErrorPayload, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<ErrorPayload, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl PartialEq for ErrorPayload
impl PartialEq for ErrorPayload
Source§fn eq(&self, other: &ErrorPayload) -> bool
fn eq(&self, other: &ErrorPayload) -> bool
self and other values to be equal, and is used by ==.