Skip to content

Commit 034ee8f

Browse files
authored
feat: add SdkError codes and types (#37)
1 parent 9a0abb9 commit 034ee8f

File tree

4 files changed

+132
-2
lines changed

4 files changed

+132
-2
lines changed

src/generated_schema/2024_11_05/mcp_schema.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
///
77
/// Generated from : <https://github.com/modelcontextprotocol/specification.git>
88
/// Hash : bb1446ff1810a0df57989d78366d626d2c01b9d7
9-
/// Generated at : 2025-02-22 12:06:03
9+
/// Generated at : 2025-02-22 12:34:28
1010
/// ----------------------------------------------------------------------------
1111
///
1212
/// MCP Protocol Version

src/generated_schema/2024_11_05/schema_utils.rs

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2032,6 +2032,71 @@ impl From<ListRootsResult> for MessageFromClient {
20322032
MessageFromClient::ResultFromClient(value.into())
20332033
}
20342034
}
2035+
/// Enum representing SDK error codes.
2036+
#[allow(non_camel_case_types)]
2037+
pub enum SdkErrorCodes {
2038+
CONNECTION_CLOSED = -32000,
2039+
REQUEST_TIMEOUT = -32001,
2040+
}
2041+
impl core::fmt::Display for SdkErrorCodes {
2042+
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
2043+
match self {
2044+
SdkErrorCodes::CONNECTION_CLOSED => write!(f, "Connection closed"),
2045+
SdkErrorCodes::REQUEST_TIMEOUT => write!(f, "Request timeout"),
2046+
}
2047+
}
2048+
}
2049+
impl From<SdkErrorCodes> for i64 {
2050+
fn from(code: SdkErrorCodes) -> Self {
2051+
code as i64
2052+
}
2053+
}
2054+
#[derive(Debug)]
2055+
pub struct SdkError {
2056+
///The error type that occurred.
2057+
pub code: i64,
2058+
///Additional information about the error.
2059+
pub data: ::std::option::Option<::serde_json::Value>,
2060+
///A short description of the error.
2061+
pub message: ::std::string::String,
2062+
}
2063+
impl core::fmt::Display for SdkError {
2064+
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
2065+
write!(f, "MCP error {}: {}", self.code, self.message)
2066+
}
2067+
}
2068+
impl std::error::Error for SdkError {
2069+
fn description(&self) -> &str {
2070+
&self.message
2071+
}
2072+
}
2073+
impl SdkError {
2074+
pub fn new(
2075+
error_code: SdkErrorCodes,
2076+
message: ::std::string::String,
2077+
data: ::std::option::Option<::serde_json::Value>,
2078+
) -> Self {
2079+
Self {
2080+
code: error_code.into(),
2081+
data,
2082+
message,
2083+
}
2084+
}
2085+
pub fn connection_closed() -> Self {
2086+
Self {
2087+
code: SdkErrorCodes::CONNECTION_CLOSED.into(),
2088+
data: None,
2089+
message: SdkErrorCodes::CONNECTION_CLOSED.to_string(),
2090+
}
2091+
}
2092+
pub fn request_timeout(timeout: u128) -> Self {
2093+
Self {
2094+
code: SdkErrorCodes::REQUEST_TIMEOUT.into(),
2095+
data: Some(json!({ "timeout" : timeout })),
2096+
message: SdkErrorCodes::REQUEST_TIMEOUT.to_string(),
2097+
}
2098+
}
2099+
}
20352100
/// Enum representing standard JSON-RPC error codes.
20362101
#[allow(non_camel_case_types)]
20372102
pub enum RpcErrorCodes {

src/generated_schema/draft/mcp_schema.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
///
77
/// Generated from : <https://github.com/modelcontextprotocol/specification.git>
88
/// Hash : bb1446ff1810a0df57989d78366d626d2c01b9d7
9-
/// Generated at : 2025-02-22 12:06:03
9+
/// Generated at : 2025-02-22 12:34:29
1010
/// ----------------------------------------------------------------------------
1111
///
1212
/// MCP Protocol Version

src/generated_schema/draft/schema_utils.rs

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2017,6 +2017,71 @@ impl From<ListRootsResult> for MessageFromClient {
20172017
MessageFromClient::ResultFromClient(value.into())
20182018
}
20192019
}
2020+
/// Enum representing SDK error codes.
2021+
#[allow(non_camel_case_types)]
2022+
pub enum SdkErrorCodes {
2023+
CONNECTION_CLOSED = -32000,
2024+
REQUEST_TIMEOUT = -32001,
2025+
}
2026+
impl core::fmt::Display for SdkErrorCodes {
2027+
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
2028+
match self {
2029+
SdkErrorCodes::CONNECTION_CLOSED => write!(f, "Connection closed"),
2030+
SdkErrorCodes::REQUEST_TIMEOUT => write!(f, "Request timeout"),
2031+
}
2032+
}
2033+
}
2034+
impl From<SdkErrorCodes> for i64 {
2035+
fn from(code: SdkErrorCodes) -> Self {
2036+
code as i64
2037+
}
2038+
}
2039+
#[derive(Debug)]
2040+
pub struct SdkError {
2041+
///The error type that occurred.
2042+
pub code: i64,
2043+
///Additional information about the error.
2044+
pub data: ::std::option::Option<::serde_json::Value>,
2045+
///A short description of the error.
2046+
pub message: ::std::string::String,
2047+
}
2048+
impl core::fmt::Display for SdkError {
2049+
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
2050+
write!(f, "MCP error {}: {}", self.code, self.message)
2051+
}
2052+
}
2053+
impl std::error::Error for SdkError {
2054+
fn description(&self) -> &str {
2055+
&self.message
2056+
}
2057+
}
2058+
impl SdkError {
2059+
pub fn new(
2060+
error_code: SdkErrorCodes,
2061+
message: ::std::string::String,
2062+
data: ::std::option::Option<::serde_json::Value>,
2063+
) -> Self {
2064+
Self {
2065+
code: error_code.into(),
2066+
data,
2067+
message,
2068+
}
2069+
}
2070+
pub fn connection_closed() -> Self {
2071+
Self {
2072+
code: SdkErrorCodes::CONNECTION_CLOSED.into(),
2073+
data: None,
2074+
message: SdkErrorCodes::CONNECTION_CLOSED.to_string(),
2075+
}
2076+
}
2077+
pub fn request_timeout(timeout: u128) -> Self {
2078+
Self {
2079+
code: SdkErrorCodes::REQUEST_TIMEOUT.into(),
2080+
data: Some(json!({ "timeout" : timeout })),
2081+
message: SdkErrorCodes::REQUEST_TIMEOUT.to_string(),
2082+
}
2083+
}
2084+
}
20202085
/// Enum representing standard JSON-RPC error codes.
20212086
#[allow(non_camel_case_types)]
20222087
pub enum RpcErrorCodes {

0 commit comments

Comments
 (0)