Skip to main content

ErrorPayload

Struct ErrorPayload 

Source
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.pyErrorPayload

协议 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

Source

pub fn new(code: i64, message: impl Into<String>) -> ErrorPayload

创建 flat 错误负载 / Create a flat error payload

Source

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.

Source

pub fn with_details(self, details: Value) -> ErrorPayload

设置整个 details 诊断容器 / Set the whole details diagnostic container

Source

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)

Source

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).

Source

pub fn with_capability(self, capability: impl Into<String>) -> ErrorPayload

顶层平铺 capability(4015 缺失能力名,如 "resources")/ Set top-level capability (4015).

Source

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

Source§

fn clone(&self) -> ErrorPayload

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ErrorPayload

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for ErrorPayload

Source§

fn deserialize<__D>( __deserializer: __D, ) -> Result<ErrorPayload, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for ErrorPayload

Source§

fn eq(&self, other: &ErrorPayload) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for ErrorPayload

Source§

fn serialize<__S>( &self, __serializer: __S, ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for ErrorPayload

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more