From 28c54cd291c7a1ae2a3adf7edbe6f401a0f2b15d Mon Sep 17 00:00:00 2001 From: Ali Hashemi Date: Sun, 9 Feb 2025 16:57:29 -0400 Subject: [PATCH 1/2] chore: enhance schema_utils --- src/generated_schema/2024_11_05/mcp_schema.rs | 5 +- .../2024_11_05/schema_utils.rs | 59 +++++++++++++++++-- src/generated_schema/draft/mcp_schema.rs | 5 +- src/generated_schema/draft/schema_utils.rs | 55 +++++++++++++++++ 4 files changed, 116 insertions(+), 8 deletions(-) diff --git a/src/generated_schema/2024_11_05/mcp_schema.rs b/src/generated_schema/2024_11_05/mcp_schema.rs index 0a72118..60a8f3b 100644 --- a/src/generated_schema/2024_11_05/mcp_schema.rs +++ b/src/generated_schema/2024_11_05/mcp_schema.rs @@ -1,11 +1,12 @@ /// ---------------------------------------------------------------------------- -/// WARNING: This file is auto-generated by mcp-schema-gen v0.0.1. +/// This file is auto-generated by mcp-schema-gen v0.1.1. +/// 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 : 3d4877e69cbc9921e1b511a90cdf17d42483036b -/// Generated at : 2025-02-06 11:59:05 +/// Generated at : 2025-02-09 16:55:01 /// ---------------------------------------------------------------------------- /// /// 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 97d374b..8a3a7f3 100644 --- a/src/generated_schema/2024_11_05/schema_utils.rs +++ b/src/generated_schema/2024_11_05/schema_utils.rs @@ -1004,6 +1004,26 @@ impl From for NotificationFromClient { Self::ClientNotification(value.into()) } } +impl From for ClientJsonrpcNotification { + fn from(value: CancelledNotification) -> Self { + Self::new(value.into()) + } +} +impl From for ClientJsonrpcNotification { + fn from(value: InitializedNotification) -> Self { + Self::new(value.into()) + } +} +impl From for ClientJsonrpcNotification { + fn from(value: ProgressNotification) -> Self { + Self::new(value.into()) + } +} +impl From for ClientJsonrpcNotification { + fn from(value: RootsListChangedNotification) -> Self { + Self::new(value.into()) + } +} impl From for ResultFromClient { fn from(value: Result) -> Self { Self::ClientResult(value.into()) @@ -1093,6 +1113,41 @@ impl From for NotificationFromServer { Self::ServerNotification(value.into()) } } +impl From for ServerJsonrpcNotification { + fn from(value: CancelledNotification) -> Self { + Self::new(value.into()) + } +} +impl From for ServerJsonrpcNotification { + fn from(value: ProgressNotification) -> Self { + Self::new(value.into()) + } +} +impl From for ServerJsonrpcNotification { + fn from(value: ResourceListChangedNotification) -> Self { + Self::new(value.into()) + } +} +impl From for ServerJsonrpcNotification { + fn from(value: ResourceUpdatedNotification) -> Self { + Self::new(value.into()) + } +} +impl From for ServerJsonrpcNotification { + fn from(value: PromptListChangedNotification) -> Self { + Self::new(value.into()) + } +} +impl From for ServerJsonrpcNotification { + fn from(value: ToolListChangedNotification) -> Self { + Self::new(value.into()) + } +} +impl From for ServerJsonrpcNotification { + fn from(value: LoggingMessageNotification) -> Self { + Self::new(value.into()) + } +} impl From for RequestFromServer { fn from(value: PingRequest) -> Self { Self::ServerRequest(value.into()) @@ -1223,9 +1278,5 @@ mod tests { ); let result = detect_message_type(&json!(message)); assert!(matches!(result, MessageTypes::Error)); - - // default - let result = detect_message_type(&json!({})); - assert!(matches!(result, MessageTypes::Request)); } } diff --git a/src/generated_schema/draft/mcp_schema.rs b/src/generated_schema/draft/mcp_schema.rs index e91f374..5dfc208 100644 --- a/src/generated_schema/draft/mcp_schema.rs +++ b/src/generated_schema/draft/mcp_schema.rs @@ -1,11 +1,12 @@ /// ---------------------------------------------------------------------------- -/// WARNING: This file is auto-generated by mcp-schema-gen v0.0.1. +/// This file is auto-generated by mcp-schema-gen v0.1.1. +/// 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 : 3d4877e69cbc9921e1b511a90cdf17d42483036b -/// Generated at : 2025-02-06 11:59:05 +/// Generated at : 2025-02-09 16:55:01 /// ---------------------------------------------------------------------------- /// /// MCP Protocol Version diff --git a/src/generated_schema/draft/schema_utils.rs b/src/generated_schema/draft/schema_utils.rs index 31b182c..5d73020 100644 --- a/src/generated_schema/draft/schema_utils.rs +++ b/src/generated_schema/draft/schema_utils.rs @@ -998,6 +998,26 @@ impl From for NotificationFromClient { Self::ClientNotification(value.into()) } } +impl From for ClientJsonrpcNotification { + fn from(value: CancelledNotification) -> Self { + Self::new(value.into()) + } +} +impl From for ClientJsonrpcNotification { + fn from(value: InitializedNotification) -> Self { + Self::new(value.into()) + } +} +impl From for ClientJsonrpcNotification { + fn from(value: ProgressNotification) -> Self { + Self::new(value.into()) + } +} +impl From for ClientJsonrpcNotification { + fn from(value: RootsListChangedNotification) -> Self { + Self::new(value.into()) + } +} impl From for ResultFromClient { fn from(value: Result) -> Self { Self::ClientResult(value.into()) @@ -1087,6 +1107,41 @@ impl From for NotificationFromServer { Self::ServerNotification(value.into()) } } +impl From for ServerJsonrpcNotification { + fn from(value: CancelledNotification) -> Self { + Self::new(value.into()) + } +} +impl From for ServerJsonrpcNotification { + fn from(value: ProgressNotification) -> Self { + Self::new(value.into()) + } +} +impl From for ServerJsonrpcNotification { + fn from(value: ResourceListChangedNotification) -> Self { + Self::new(value.into()) + } +} +impl From for ServerJsonrpcNotification { + fn from(value: ResourceUpdatedNotification) -> Self { + Self::new(value.into()) + } +} +impl From for ServerJsonrpcNotification { + fn from(value: PromptListChangedNotification) -> Self { + Self::new(value.into()) + } +} +impl From for ServerJsonrpcNotification { + fn from(value: ToolListChangedNotification) -> Self { + Self::new(value.into()) + } +} +impl From for ServerJsonrpcNotification { + fn from(value: LoggingMessageNotification) -> Self { + Self::new(value.into()) + } +} impl From for RequestFromServer { fn from(value: PingRequest) -> Self { Self::ServerRequest(value.into()) From df436604987abdfb941305a96c3b3534e6684cd3 Mon Sep 17 00:00:00 2001 From: Ali Hashemi Date: Sun, 9 Feb 2025 16:57:43 -0400 Subject: [PATCH 2/2] test: improve tests --- tests/test_serialize.rs | 40 ++++++++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/tests/test_serialize.rs b/tests/test_serialize.rs index bb97db9..005f511 100644 --- a/tests/test_serialize.rs +++ b/tests/test_serialize.rs @@ -376,11 +376,13 @@ mod test_serialize { #[test] fn test_client_initialized_notification() { - let message: ClientMessage = ClientMessage::Notification(ClientJsonrpcNotification::new( - NotificationFromClient::ClientNotification(ClientNotification::InitializedNotification( - InitializedNotification::new(Some(InitializedNotificationParams { meta: None, extra: None })), - )), - )); + let init_notification = + InitializedNotification::new(Some(InitializedNotificationParams { meta: None, extra: None })); + + let message: ClientMessage = + ClientMessage::Notification(ClientJsonrpcNotification::new(NotificationFromClient::ClientNotification( + ClientNotification::InitializedNotification(init_notification.clone()), + ))); let message: ClientMessage = re_serialize(message); @@ -388,6 +390,23 @@ mod test_serialize { if matches!(&client_message.notification,NotificationFromClient::ClientNotification(client_notification) if matches!( client_notification, ClientNotification::InitializedNotification(_))) )); + + // test From for NotificationFromClient + let message: ClientMessage = + ClientMessage::Notification(ClientJsonrpcNotification::new(init_notification.clone().into())); + + assert!(matches!(message, ClientMessage::Notification(client_message) + if matches!(&client_message.notification,NotificationFromClient::ClientNotification(client_notification) + if matches!( client_notification, ClientNotification::InitializedNotification(_))) + )); + + // test From for ClientJsonrpcNotification + let message: ClientMessage = ClientMessage::Notification(init_notification.into()); + + assert!(matches!(message, ClientMessage::Notification(client_message) + if matches!(&client_message.notification,NotificationFromClient::ClientNotification(client_notification) + if matches!( client_notification, ClientNotification::InitializedNotification(_))) + )); } #[test] @@ -460,7 +479,16 @@ mod test_serialize { )); // test From for NotificationFromServer - let message: ServerMessage = ServerMessage::Notification(ServerJsonrpcNotification::new(cancel_notification.into())); + let message: ServerMessage = + ServerMessage::Notification(ServerJsonrpcNotification::new(cancel_notification.clone().into())); + + assert!(matches!(message, ServerMessage::Notification(client_message) + if matches!(&client_message.notification,NotificationFromServer::ServerNotification(client_notification) + if matches!( client_notification, ServerNotification::CancelledNotification(_))) + )); + + // test From for ServerNotification + let message: ServerMessage = ServerMessage::Notification(cancel_notification.into()); assert!(matches!(message, ServerMessage::Notification(client_message) if matches!(&client_message.notification,NotificationFromServer::ServerNotification(client_notification)