From 7ea8065485a012ddbdbbf5508a918434b63d2b34 Mon Sep 17 00:00:00 2001 From: Ali Hashemi Date: Sat, 22 Feb 2025 14:29:19 -0400 Subject: [PATCH 1/4] add is_initialized_notification utility function --- src/generated_schema/2024_11_05/mcp_schema.rs | 4 +- .../2024_11_05/schema_utils.rs | 73 +++++++++++++++++++ src/generated_schema/draft/mcp_schema.rs | 4 +- src/generated_schema/draft/schema_utils.rs | 73 +++++++++++++++++++ 4 files changed, 150 insertions(+), 4 deletions(-) diff --git a/src/generated_schema/2024_11_05/mcp_schema.rs b/src/generated_schema/2024_11_05/mcp_schema.rs index 66f267c..f0d7778 100644 --- a/src/generated_schema/2024_11_05/mcp_schema.rs +++ b/src/generated_schema/2024_11_05/mcp_schema.rs @@ -1,12 +1,12 @@ /// ---------------------------------------------------------------------------- -/// This file is auto-generated by mcp-schema-gen v0.1.6. +/// This file is auto-generated by mcp-schema-gen v0.1.7. /// WARNING: /// It is not recommended to modify this file directly. You are free to /// modify or extend the implementations as needed, but please do so at your own risk. /// /// Generated from : /// Hash : bb1446ff1810a0df57989d78366d626d2c01b9d7 -/// Generated at : 2025-02-22 12:06:03 +/// Generated at : 2025-02-22 14:26:53 /// ---------------------------------------------------------------------------- /// /// MCP Protocol Version diff --git a/src/generated_schema/2024_11_05/schema_utils.rs b/src/generated_schema/2024_11_05/schema_utils.rs index f71a0e5..a80c2a1 100644 --- a/src/generated_schema/2024_11_05/schema_utils.rs +++ b/src/generated_schema/2024_11_05/schema_utils.rs @@ -493,6 +493,14 @@ impl TryFrom for ClientNotification { } impl NotificationFromClient { + /// Checks if the current notification is an `InitializedNotification` from the client, indicating that the client has been initialized. + pub fn is_initialized_notification(&self) -> bool { + matches!( + self, + NotificationFromClient::ClientNotification(ClientNotification::InitializedNotification(_)) + ) + } + #[deprecated(since = "0.1.4", note = "Use `method()` instead.")] pub fn get_method(&self) -> &str { match self { @@ -2032,6 +2040,71 @@ impl From for MessageFromClient { MessageFromClient::ResultFromClient(value.into()) } } +/// Enum representing SDK error codes. +#[allow(non_camel_case_types)] +pub enum SdkErrorCodes { + CONNECTION_CLOSED = -32000, + REQUEST_TIMEOUT = -32001, +} +impl core::fmt::Display for SdkErrorCodes { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + match self { + SdkErrorCodes::CONNECTION_CLOSED => write!(f, "Connection closed"), + SdkErrorCodes::REQUEST_TIMEOUT => write!(f, "Request timeout"), + } + } +} +impl From for i64 { + fn from(code: SdkErrorCodes) -> Self { + code as i64 + } +} +#[derive(Debug)] +pub struct SdkError { + ///The error type that occurred. + pub code: i64, + ///Additional information about the error. + pub data: ::std::option::Option<::serde_json::Value>, + ///A short description of the error. + pub message: ::std::string::String, +} +impl core::fmt::Display for SdkError { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + write!(f, "MCP error {}: {}", self.code, self.message) + } +} +impl std::error::Error for SdkError { + fn description(&self) -> &str { + &self.message + } +} +impl SdkError { + pub fn new( + error_code: SdkErrorCodes, + message: ::std::string::String, + data: ::std::option::Option<::serde_json::Value>, + ) -> Self { + Self { + code: error_code.into(), + data, + message, + } + } + pub fn connection_closed() -> Self { + Self { + code: SdkErrorCodes::CONNECTION_CLOSED.into(), + data: None, + message: SdkErrorCodes::CONNECTION_CLOSED.to_string(), + } + } + pub fn request_timeout(timeout: u128) -> Self { + Self { + code: SdkErrorCodes::REQUEST_TIMEOUT.into(), + data: Some(json!({ "timeout" : timeout })), + message: SdkErrorCodes::REQUEST_TIMEOUT.to_string(), + } + } +} /// Enum representing standard JSON-RPC error codes. #[allow(non_camel_case_types)] pub enum RpcErrorCodes { diff --git a/src/generated_schema/draft/mcp_schema.rs b/src/generated_schema/draft/mcp_schema.rs index 91da355..56d371c 100644 --- a/src/generated_schema/draft/mcp_schema.rs +++ b/src/generated_schema/draft/mcp_schema.rs @@ -1,12 +1,12 @@ /// ---------------------------------------------------------------------------- -/// This file is auto-generated by mcp-schema-gen v0.1.6. +/// This file is auto-generated by mcp-schema-gen v0.1.7. /// WARNING: /// It is not recommended to modify this file directly. You are free to /// modify or extend the implementations as needed, but please do so at your own risk. /// /// Generated from : /// Hash : bb1446ff1810a0df57989d78366d626d2c01b9d7 -/// Generated at : 2025-02-22 12:06:03 +/// Generated at : 2025-02-22 14:26:53 /// ---------------------------------------------------------------------------- /// /// MCP Protocol Version diff --git a/src/generated_schema/draft/schema_utils.rs b/src/generated_schema/draft/schema_utils.rs index 137b976..d4c50b4 100644 --- a/src/generated_schema/draft/schema_utils.rs +++ b/src/generated_schema/draft/schema_utils.rs @@ -493,6 +493,14 @@ impl TryFrom for ClientNotification { } impl NotificationFromClient { + /// Checks if the current notification is an `InitializedNotification` from the client, indicating that the client has been initialized. + pub fn is_initialized_notification(&self) -> bool { + matches!( + self, + NotificationFromClient::ClientNotification(ClientNotification::InitializedNotification(_)) + ) + } + #[deprecated(since = "0.1.4", note = "Use `method()` instead.")] pub fn get_method(&self) -> &str { match self { @@ -2017,6 +2025,71 @@ impl From for MessageFromClient { MessageFromClient::ResultFromClient(value.into()) } } +/// Enum representing SDK error codes. +#[allow(non_camel_case_types)] +pub enum SdkErrorCodes { + CONNECTION_CLOSED = -32000, + REQUEST_TIMEOUT = -32001, +} +impl core::fmt::Display for SdkErrorCodes { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + match self { + SdkErrorCodes::CONNECTION_CLOSED => write!(f, "Connection closed"), + SdkErrorCodes::REQUEST_TIMEOUT => write!(f, "Request timeout"), + } + } +} +impl From for i64 { + fn from(code: SdkErrorCodes) -> Self { + code as i64 + } +} +#[derive(Debug)] +pub struct SdkError { + ///The error type that occurred. + pub code: i64, + ///Additional information about the error. + pub data: ::std::option::Option<::serde_json::Value>, + ///A short description of the error. + pub message: ::std::string::String, +} +impl core::fmt::Display for SdkError { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + write!(f, "MCP error {}: {}", self.code, self.message) + } +} +impl std::error::Error for SdkError { + fn description(&self) -> &str { + &self.message + } +} +impl SdkError { + pub fn new( + error_code: SdkErrorCodes, + message: ::std::string::String, + data: ::std::option::Option<::serde_json::Value>, + ) -> Self { + Self { + code: error_code.into(), + data, + message, + } + } + pub fn connection_closed() -> Self { + Self { + code: SdkErrorCodes::CONNECTION_CLOSED.into(), + data: None, + message: SdkErrorCodes::CONNECTION_CLOSED.to_string(), + } + } + pub fn request_timeout(timeout: u128) -> Self { + Self { + code: SdkErrorCodes::REQUEST_TIMEOUT.into(), + data: Some(json!({ "timeout" : timeout })), + message: SdkErrorCodes::REQUEST_TIMEOUT.to_string(), + } + } +} /// Enum representing standard JSON-RPC error codes. #[allow(non_camel_case_types)] pub enum RpcErrorCodes { From 1b0e3c69ab1d0575f0c80bb60f3f6d56bf8ff49f Mon Sep 17 00:00:00 2001 From: Ali Hashemi <14126952+hashemix@users.noreply.github.com> Date: Sat, 22 Feb 2025 14:35:44 -0400 Subject: [PATCH 2/4] Update schema_utils.rs --- .../2024_11_05/schema_utils.rs | 66 +------------------ 1 file changed, 1 insertion(+), 65 deletions(-) diff --git a/src/generated_schema/2024_11_05/schema_utils.rs b/src/generated_schema/2024_11_05/schema_utils.rs index a80c2a1..b5a9a05 100644 --- a/src/generated_schema/2024_11_05/schema_utils.rs +++ b/src/generated_schema/2024_11_05/schema_utils.rs @@ -2040,71 +2040,7 @@ impl From for MessageFromClient { MessageFromClient::ResultFromClient(value.into()) } } -/// Enum representing SDK error codes. -#[allow(non_camel_case_types)] -pub enum SdkErrorCodes { - CONNECTION_CLOSED = -32000, - REQUEST_TIMEOUT = -32001, -} -impl core::fmt::Display for SdkErrorCodes { - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - match self { - SdkErrorCodes::CONNECTION_CLOSED => write!(f, "Connection closed"), - SdkErrorCodes::REQUEST_TIMEOUT => write!(f, "Request timeout"), - } - } -} -impl From for i64 { - fn from(code: SdkErrorCodes) -> Self { - code as i64 - } -} -#[derive(Debug)] -pub struct SdkError { - ///The error type that occurred. - pub code: i64, - ///Additional information about the error. - pub data: ::std::option::Option<::serde_json::Value>, - ///A short description of the error. - pub message: ::std::string::String, -} -impl core::fmt::Display for SdkError { - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - write!(f, "MCP error {}: {}", self.code, self.message) - } -} -impl std::error::Error for SdkError { - fn description(&self) -> &str { - &self.message - } -} -impl SdkError { - pub fn new( - error_code: SdkErrorCodes, - message: ::std::string::String, - data: ::std::option::Option<::serde_json::Value>, - ) -> Self { - Self { - code: error_code.into(), - data, - message, - } - } - pub fn connection_closed() -> Self { - Self { - code: SdkErrorCodes::CONNECTION_CLOSED.into(), - data: None, - message: SdkErrorCodes::CONNECTION_CLOSED.to_string(), - } - } - pub fn request_timeout(timeout: u128) -> Self { - Self { - code: SdkErrorCodes::REQUEST_TIMEOUT.into(), - data: Some(json!({ "timeout" : timeout })), - message: SdkErrorCodes::REQUEST_TIMEOUT.to_string(), - } - } -} + /// Enum representing standard JSON-RPC error codes. #[allow(non_camel_case_types)] pub enum RpcErrorCodes { From 2f903173c0893342813acf922465a6e0b30bb693 Mon Sep 17 00:00:00 2001 From: Ali Hashemi <14126952+hashemix@users.noreply.github.com> Date: Sat, 22 Feb 2025 14:36:14 -0400 Subject: [PATCH 3/4] Update schema_utils.rs --- src/generated_schema/draft/schema_utils.rs | 65 ---------------------- 1 file changed, 65 deletions(-) diff --git a/src/generated_schema/draft/schema_utils.rs b/src/generated_schema/draft/schema_utils.rs index d4c50b4..769f6ac 100644 --- a/src/generated_schema/draft/schema_utils.rs +++ b/src/generated_schema/draft/schema_utils.rs @@ -2025,71 +2025,6 @@ impl From for MessageFromClient { MessageFromClient::ResultFromClient(value.into()) } } -/// Enum representing SDK error codes. -#[allow(non_camel_case_types)] -pub enum SdkErrorCodes { - CONNECTION_CLOSED = -32000, - REQUEST_TIMEOUT = -32001, -} -impl core::fmt::Display for SdkErrorCodes { - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - match self { - SdkErrorCodes::CONNECTION_CLOSED => write!(f, "Connection closed"), - SdkErrorCodes::REQUEST_TIMEOUT => write!(f, "Request timeout"), - } - } -} -impl From for i64 { - fn from(code: SdkErrorCodes) -> Self { - code as i64 - } -} -#[derive(Debug)] -pub struct SdkError { - ///The error type that occurred. - pub code: i64, - ///Additional information about the error. - pub data: ::std::option::Option<::serde_json::Value>, - ///A short description of the error. - pub message: ::std::string::String, -} -impl core::fmt::Display for SdkError { - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - write!(f, "MCP error {}: {}", self.code, self.message) - } -} -impl std::error::Error for SdkError { - fn description(&self) -> &str { - &self.message - } -} -impl SdkError { - pub fn new( - error_code: SdkErrorCodes, - message: ::std::string::String, - data: ::std::option::Option<::serde_json::Value>, - ) -> Self { - Self { - code: error_code.into(), - data, - message, - } - } - pub fn connection_closed() -> Self { - Self { - code: SdkErrorCodes::CONNECTION_CLOSED.into(), - data: None, - message: SdkErrorCodes::CONNECTION_CLOSED.to_string(), - } - } - pub fn request_timeout(timeout: u128) -> Self { - Self { - code: SdkErrorCodes::REQUEST_TIMEOUT.into(), - data: Some(json!({ "timeout" : timeout })), - message: SdkErrorCodes::REQUEST_TIMEOUT.to_string(), - } - } -} /// Enum representing standard JSON-RPC error codes. #[allow(non_camel_case_types)] pub enum RpcErrorCodes { From 38bc1855d7051be8fb75747d1aef4db6c7e3c999 Mon Sep 17 00:00:00 2001 From: Ali Hashemi <14126952+hashemix@users.noreply.github.com> Date: Sat, 22 Feb 2025 14:36:55 -0400 Subject: [PATCH 4/4] Update schema_utils.rs --- src/generated_schema/2024_11_05/schema_utils.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/generated_schema/2024_11_05/schema_utils.rs b/src/generated_schema/2024_11_05/schema_utils.rs index b5a9a05..b8142a6 100644 --- a/src/generated_schema/2024_11_05/schema_utils.rs +++ b/src/generated_schema/2024_11_05/schema_utils.rs @@ -2040,7 +2040,6 @@ impl From for MessageFromClient { MessageFromClient::ResultFromClient(value.into()) } } - /// Enum representing standard JSON-RPC error codes. #[allow(non_camel_case_types)] pub enum RpcErrorCodes {