From 0a9f87134a44609e05ba05da9ee30e4a4983d509 Mon Sep 17 00:00:00 2001 From: Ali Hashemi Date: Tue, 11 Feb 2025 20:18:37 -0400 Subject: [PATCH 1/3] feat: implement default trait for Result --- src/generated_schema/2024_11_05/mcp_schema.rs | 12 ++++++++++-- src/generated_schema/draft/mcp_schema.rs | 12 ++++++++++-- 2 files changed, 20 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 c1e7015..f051723 100644 --- a/src/generated_schema/2024_11_05/mcp_schema.rs +++ b/src/generated_schema/2024_11_05/mcp_schema.rs @@ -5,8 +5,8 @@ /// modify or extend the implementations as needed, but please do so at your own risk. /// /// Generated from : -/// Hash : 3d4877e69cbc9921e1b511a90cdf17d42483036b -/// Generated at : 2025-02-09 20:40:09 +/// Hash : 55c983fd85fafa458d31f729e433c60e95932178 +/// Generated at : 2025-02-11 20:13:30 /// ---------------------------------------------------------------------------- /// /// MCP Protocol Version @@ -4542,6 +4542,14 @@ pub struct Result { #[serde(flatten, default, skip_serializing_if = "::std::option::Option::is_none")] pub extra: ::std::option::Option<::serde_json::Map<::std::string::String, ::serde_json::Value>>, } +impl ::std::default::Default for Result { + fn default() -> Self { + Self { + meta: Default::default(), + extra: Default::default(), + } + } +} ///The sender or recipient of messages and data in a conversation. /// ///
JSON schema diff --git a/src/generated_schema/draft/mcp_schema.rs b/src/generated_schema/draft/mcp_schema.rs index 46a83f5..a083bbb 100644 --- a/src/generated_schema/draft/mcp_schema.rs +++ b/src/generated_schema/draft/mcp_schema.rs @@ -5,8 +5,8 @@ /// modify or extend the implementations as needed, but please do so at your own risk. /// /// Generated from : -/// Hash : 3d4877e69cbc9921e1b511a90cdf17d42483036b -/// Generated at : 2025-02-09 20:40:10 +/// Hash : 55c983fd85fafa458d31f729e433c60e95932178 +/// Generated at : 2025-02-11 20:13:30 /// ---------------------------------------------------------------------------- /// /// MCP Protocol Version @@ -4673,6 +4673,14 @@ pub struct Result { #[serde(flatten, default, skip_serializing_if = "::std::option::Option::is_none")] pub extra: ::std::option::Option<::serde_json::Map<::std::string::String, ::serde_json::Value>>, } +impl ::std::default::Default for Result { + fn default() -> Self { + Self { + meta: Default::default(), + extra: Default::default(), + } + } +} ///The sender or recipient of messages and data in a conversation. /// ///
JSON schema From 47274b082182a39b0e985ba65cde516aca563217 Mon Sep 17 00:00:00 2001 From: Ali Hashemi Date: Tue, 11 Feb 2025 20:19:14 -0400 Subject: [PATCH 2/3] implement Display trait for ClientMessage and ServerMessage variants --- .../2024_11_05/schema_utils.rs | 79 +++++++++++++++++++ src/generated_schema/draft/schema_utils.rs | 79 +++++++++++++++++++ 2 files changed, 158 insertions(+) diff --git a/src/generated_schema/2024_11_05/schema_utils.rs b/src/generated_schema/2024_11_05/schema_utils.rs index c076896..13d3ffe 100644 --- a/src/generated_schema/2024_11_05/schema_utils.rs +++ b/src/generated_schema/2024_11_05/schema_utils.rs @@ -77,6 +77,17 @@ impl ClientJsonrpcRequest { } } +/// Formats the ClientJsonrpcRequest as a JSON string. +impl Display for ClientJsonrpcRequest { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!( + f, + "{}", + serde_json::to_string(self).unwrap_or_else(|err| format!("Serialization error: {}", err)) + ) + } +} + //*************************// //** Request From Client **// //*************************// @@ -150,6 +161,17 @@ impl ClientJsonrpcNotification { } } +/// Formats the ClientJsonrpcNotification as a JSON string. +impl Display for ClientJsonrpcNotification { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!( + f, + "{}", + serde_json::to_string(self).unwrap_or_else(|err| format!("Serialization error: {}", err)) + ) + } +} + //*******************************// //** NotificationFromClient **// //*******************************// @@ -210,6 +232,17 @@ impl ClientJsonrpcResponse { } } +/// Formats the ClientJsonrpcResponse as a JSON string. +impl Display for ClientJsonrpcResponse { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!( + f, + "{}", + serde_json::to_string(self).unwrap_or_else(|err| format!("Serialization error: {}", err)) + ) + } +} + //*******************************// //** ResultFromClient **// //*******************************// @@ -331,6 +364,16 @@ impl ServerJsonrpcRequest { } } +/// Formats the ServerJsonrpcRequest as a JSON string. +impl Display for ServerJsonrpcRequest { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!( + f, + "{}", + serde_json::to_string(self).unwrap_or_else(|err| format!("Serialization error: {}", err)) + ) + } +} //*************************// //** Request From Server **// //*************************// @@ -404,6 +447,16 @@ impl ServerJsonrpcNotification { } } +/// Formats the ServerJsonrpcNotification as a JSON string. +impl Display for ServerJsonrpcNotification { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!( + f, + "{}", + serde_json::to_string(self).unwrap_or_else(|err| format!("Serialization error: {}", err)) + ) + } +} //*******************************// //** NotificationFromServer **// //*******************************// @@ -464,6 +517,17 @@ impl ServerJsonrpcResponse { } } +/// Formats the ServerJsonrpcResponse as a JSON string. +impl Display for ServerJsonrpcResponse { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!( + f, + "{}", + serde_json::to_string(self).unwrap_or_else(|err| format!("Serialization error: {}", err)) + ) + } +} + //*******************************// //** ResultFromServer **// //*******************************// @@ -511,6 +575,21 @@ impl<'de> serde::Deserialize<'de> for ResultFromServer { } } +//***************************// +//** impl for JsonrpcError **// +//***************************// + +/// Formats the ServerJsonrpcResponse as a JSON string. +impl Display for JsonrpcError { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!( + f, + "{}", + serde_json::to_string(self).unwrap_or_else(|err| format!("Serialization error: {}", err)) + ) + } +} + /// BEGIN AUTO GENERATED impl ::serde::Serialize for ClientJsonrpcRequest { fn serialize(&self, serializer: S) -> std::result::Result diff --git a/src/generated_schema/draft/schema_utils.rs b/src/generated_schema/draft/schema_utils.rs index 3dd2e49..09a0986 100644 --- a/src/generated_schema/draft/schema_utils.rs +++ b/src/generated_schema/draft/schema_utils.rs @@ -77,6 +77,17 @@ impl ClientJsonrpcRequest { } } +/// Formats the ClientJsonrpcRequest as a JSON string. +impl Display for ClientJsonrpcRequest { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!( + f, + "{}", + serde_json::to_string(self).unwrap_or_else(|err| format!("Serialization error: {}", err)) + ) + } +} + //*************************// //** Request From Client **// //*************************// @@ -150,6 +161,17 @@ impl ClientJsonrpcNotification { } } +/// Formats the ClientJsonrpcNotification as a JSON string. +impl Display for ClientJsonrpcNotification { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!( + f, + "{}", + serde_json::to_string(self).unwrap_or_else(|err| format!("Serialization error: {}", err)) + ) + } +} + //*******************************// //** NotificationFromClient **// //*******************************// @@ -210,6 +232,17 @@ impl ClientJsonrpcResponse { } } +/// Formats the ClientJsonrpcResponse as a JSON string. +impl Display for ClientJsonrpcResponse { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!( + f, + "{}", + serde_json::to_string(self).unwrap_or_else(|err| format!("Serialization error: {}", err)) + ) + } +} + //*******************************// //** ResultFromClient **// //*******************************// @@ -331,6 +364,16 @@ impl ServerJsonrpcRequest { } } +/// Formats the ServerJsonrpcRequest as a JSON string. +impl Display for ServerJsonrpcRequest { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!( + f, + "{}", + serde_json::to_string(self).unwrap_or_else(|err| format!("Serialization error: {}", err)) + ) + } +} //*************************// //** Request From Server **// //*************************// @@ -404,6 +447,16 @@ impl ServerJsonrpcNotification { } } +/// Formats the ServerJsonrpcNotification as a JSON string. +impl Display for ServerJsonrpcNotification { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!( + f, + "{}", + serde_json::to_string(self).unwrap_or_else(|err| format!("Serialization error: {}", err)) + ) + } +} //*******************************// //** NotificationFromServer **// //*******************************// @@ -464,6 +517,17 @@ impl ServerJsonrpcResponse { } } +/// Formats the ServerJsonrpcResponse as a JSON string. +impl Display for ServerJsonrpcResponse { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!( + f, + "{}", + serde_json::to_string(self).unwrap_or_else(|err| format!("Serialization error: {}", err)) + ) + } +} + //*******************************// //** ResultFromServer **// //*******************************// @@ -511,6 +575,21 @@ impl<'de> serde::Deserialize<'de> for ResultFromServer { } } +//***************************// +//** impl for JsonrpcError **// +//***************************// + +/// Formats the ServerJsonrpcResponse as a JSON string. +impl Display for JsonrpcError { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!( + f, + "{}", + serde_json::to_string(self).unwrap_or_else(|err| format!("Serialization error: {}", err)) + ) + } +} + /// BEGIN AUTO GENERATED impl ::serde::Serialize for ClientJsonrpcRequest { fn serialize(&self, serializer: S) -> std::result::Result From 57a0eed1a4c54b657da2c721069d6dab737d5db9 Mon Sep 17 00:00:00 2001 From: Ali Hashemi Date: Tue, 11 Feb 2025 20:19:53 -0400 Subject: [PATCH 3/3] fix: typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 22ed803..1f74dd9 100644 --- a/README.md +++ b/README.md @@ -288,7 +288,7 @@ fn handle_message(message_payload: &str) -> std::result::Result<(), AppError> { // Check it's a Request type of message if let JsonrpcMessage::Request(client_message) = message { - // Check method to detect it it a "initialize" request + // Check method to detect is a "initialize" request if client_message.method == "initialize" { // Now that we can handle the message, we simply print out the details.