From cec36cfa5e08d7fba10fd09c0ff1a1b868c0c54a Mon Sep 17 00:00:00 2001 From: Ali Hashemi Date: Sat, 22 Feb 2025 12:08:09 -0400 Subject: [PATCH] feat: more type conversion utilities --- src/generated_schema/2024_11_05/mcp_schema.rs | 2 +- .../2024_11_05/schema_utils.rs | 488 ++++++++++++++++++ src/generated_schema/draft/mcp_schema.rs | 2 +- src/generated_schema/draft/schema_utils.rs | 466 +++++++++++++++++ 4 files changed, 956 insertions(+), 2 deletions(-) diff --git a/src/generated_schema/2024_11_05/mcp_schema.rs b/src/generated_schema/2024_11_05/mcp_schema.rs index 9cf9023..66f267c 100644 --- a/src/generated_schema/2024_11_05/mcp_schema.rs +++ b/src/generated_schema/2024_11_05/mcp_schema.rs @@ -6,7 +6,7 @@ /// /// Generated from : /// Hash : bb1446ff1810a0df57989d78366d626d2c01b9d7 -/// Generated at : 2025-02-22 11:26:40 +/// Generated at : 2025-02-22 12:06:03 /// ---------------------------------------------------------------------------- /// /// 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 06e3b60..f71a0e5 100644 --- a/src/generated_schema/2024_11_05/schema_utils.rs +++ b/src/generated_schema/2024_11_05/schema_utils.rs @@ -1187,6 +1187,30 @@ pub enum MessageFromServer { Error(JsonrpcErrorError), } +impl From for MessageFromServer { + fn from(value: RequestFromServer) -> Self { + Self::RequestFromServer(value) + } +} + +impl From for MessageFromServer { + fn from(value: ResultFromServer) -> Self { + Self::ResultFromServer(value) + } +} + +impl From for MessageFromServer { + fn from(value: NotificationFromServer) -> Self { + Self::NotificationFromServer(value) + } +} + +impl From for MessageFromServer { + fn from(value: JsonrpcErrorError) -> Self { + Self::Error(value) + } +} + impl MCPMessage for MessageFromServer { fn is_response(&self) -> bool { matches!(self, MessageFromServer::ResultFromServer(_)) @@ -1271,6 +1295,30 @@ pub enum MessageFromClient { Error(JsonrpcErrorError), } +impl From for MessageFromClient { + fn from(value: RequestFromClient) -> Self { + Self::RequestFromClient(value) + } +} + +impl From for MessageFromClient { + fn from(value: ResultFromClient) -> Self { + Self::ResultFromClient(value) + } +} + +impl From for MessageFromClient { + fn from(value: NotificationFromClient) -> Self { + Self::NotificationFromClient(value) + } +} + +impl From for MessageFromClient { + fn from(value: JsonrpcErrorError) -> Self { + Self::Error(value) + } +} + impl FromMessage for ClientMessage { fn from_message( message: MessageFromClient, @@ -3045,6 +3093,446 @@ impl ToMessage for LoggingMessageNotification { ServerMessage::from_message(self, request_id) } } +impl TryFrom for InitializeRequest { + type Error = JsonrpcErrorError; + fn try_from(value: RequestFromClient) -> std::result::Result { + let matched_type: ClientRequest = value.try_into()?; + if let ClientRequest::InitializeRequest(result) = matched_type { + Ok(result) + } else { + Err(JsonrpcErrorError::internal_error().with_message("Not a InitializeRequest".to_string())) + } + } +} +impl TryFrom for PingRequest { + type Error = JsonrpcErrorError; + fn try_from(value: RequestFromClient) -> std::result::Result { + let matched_type: ClientRequest = value.try_into()?; + if let ClientRequest::PingRequest(result) = matched_type { + Ok(result) + } else { + Err(JsonrpcErrorError::internal_error().with_message("Not a PingRequest".to_string())) + } + } +} +impl TryFrom for ListResourcesRequest { + type Error = JsonrpcErrorError; + fn try_from(value: RequestFromClient) -> std::result::Result { + let matched_type: ClientRequest = value.try_into()?; + if let ClientRequest::ListResourcesRequest(result) = matched_type { + Ok(result) + } else { + Err(JsonrpcErrorError::internal_error().with_message("Not a ListResourcesRequest".to_string())) + } + } +} +impl TryFrom for ListResourceTemplatesRequest { + type Error = JsonrpcErrorError; + fn try_from(value: RequestFromClient) -> std::result::Result { + let matched_type: ClientRequest = value.try_into()?; + if let ClientRequest::ListResourceTemplatesRequest(result) = matched_type { + Ok(result) + } else { + Err(JsonrpcErrorError::internal_error().with_message("Not a ListResourceTemplatesRequest".to_string())) + } + } +} +impl TryFrom for ReadResourceRequest { + type Error = JsonrpcErrorError; + fn try_from(value: RequestFromClient) -> std::result::Result { + let matched_type: ClientRequest = value.try_into()?; + if let ClientRequest::ReadResourceRequest(result) = matched_type { + Ok(result) + } else { + Err(JsonrpcErrorError::internal_error().with_message("Not a ReadResourceRequest".to_string())) + } + } +} +impl TryFrom for SubscribeRequest { + type Error = JsonrpcErrorError; + fn try_from(value: RequestFromClient) -> std::result::Result { + let matched_type: ClientRequest = value.try_into()?; + if let ClientRequest::SubscribeRequest(result) = matched_type { + Ok(result) + } else { + Err(JsonrpcErrorError::internal_error().with_message("Not a SubscribeRequest".to_string())) + } + } +} +impl TryFrom for UnsubscribeRequest { + type Error = JsonrpcErrorError; + fn try_from(value: RequestFromClient) -> std::result::Result { + let matched_type: ClientRequest = value.try_into()?; + if let ClientRequest::UnsubscribeRequest(result) = matched_type { + Ok(result) + } else { + Err(JsonrpcErrorError::internal_error().with_message("Not a UnsubscribeRequest".to_string())) + } + } +} +impl TryFrom for ListPromptsRequest { + type Error = JsonrpcErrorError; + fn try_from(value: RequestFromClient) -> std::result::Result { + let matched_type: ClientRequest = value.try_into()?; + if let ClientRequest::ListPromptsRequest(result) = matched_type { + Ok(result) + } else { + Err(JsonrpcErrorError::internal_error().with_message("Not a ListPromptsRequest".to_string())) + } + } +} +impl TryFrom for GetPromptRequest { + type Error = JsonrpcErrorError; + fn try_from(value: RequestFromClient) -> std::result::Result { + let matched_type: ClientRequest = value.try_into()?; + if let ClientRequest::GetPromptRequest(result) = matched_type { + Ok(result) + } else { + Err(JsonrpcErrorError::internal_error().with_message("Not a GetPromptRequest".to_string())) + } + } +} +impl TryFrom for ListToolsRequest { + type Error = JsonrpcErrorError; + fn try_from(value: RequestFromClient) -> std::result::Result { + let matched_type: ClientRequest = value.try_into()?; + if let ClientRequest::ListToolsRequest(result) = matched_type { + Ok(result) + } else { + Err(JsonrpcErrorError::internal_error().with_message("Not a ListToolsRequest".to_string())) + } + } +} +impl TryFrom for CallToolRequest { + type Error = JsonrpcErrorError; + fn try_from(value: RequestFromClient) -> std::result::Result { + let matched_type: ClientRequest = value.try_into()?; + if let ClientRequest::CallToolRequest(result) = matched_type { + Ok(result) + } else { + Err(JsonrpcErrorError::internal_error().with_message("Not a CallToolRequest".to_string())) + } + } +} +impl TryFrom for SetLevelRequest { + type Error = JsonrpcErrorError; + fn try_from(value: RequestFromClient) -> std::result::Result { + let matched_type: ClientRequest = value.try_into()?; + if let ClientRequest::SetLevelRequest(result) = matched_type { + Ok(result) + } else { + Err(JsonrpcErrorError::internal_error().with_message("Not a SetLevelRequest".to_string())) + } + } +} +impl TryFrom for CompleteRequest { + type Error = JsonrpcErrorError; + fn try_from(value: RequestFromClient) -> std::result::Result { + let matched_type: ClientRequest = value.try_into()?; + if let ClientRequest::CompleteRequest(result) = matched_type { + Ok(result) + } else { + Err(JsonrpcErrorError::internal_error().with_message("Not a CompleteRequest".to_string())) + } + } +} +impl TryFrom for Result { + type Error = JsonrpcErrorError; + fn try_from(value: ResultFromClient) -> std::result::Result { + let matched_type: ClientResult = value.try_into()?; + if let ClientResult::Result(result) = matched_type { + Ok(result) + } else { + Err(JsonrpcErrorError::internal_error().with_message("Not a Result".to_string())) + } + } +} +impl TryFrom for CreateMessageResult { + type Error = JsonrpcErrorError; + fn try_from(value: ResultFromClient) -> std::result::Result { + let matched_type: ClientResult = value.try_into()?; + if let ClientResult::CreateMessageResult(result) = matched_type { + Ok(result) + } else { + Err(JsonrpcErrorError::internal_error().with_message("Not a CreateMessageResult".to_string())) + } + } +} +impl TryFrom for ListRootsResult { + type Error = JsonrpcErrorError; + fn try_from(value: ResultFromClient) -> std::result::Result { + let matched_type: ClientResult = value.try_into()?; + if let ClientResult::ListRootsResult(result) = matched_type { + Ok(result) + } else { + Err(JsonrpcErrorError::internal_error().with_message("Not a ListRootsResult".to_string())) + } + } +} +impl TryFrom for CancelledNotification { + type Error = JsonrpcErrorError; + fn try_from(value: NotificationFromClient) -> std::result::Result { + let matched_type: ClientNotification = value.try_into()?; + if let ClientNotification::CancelledNotification(result) = matched_type { + Ok(result) + } else { + Err(JsonrpcErrorError::internal_error().with_message("Not a CancelledNotification".to_string())) + } + } +} +impl TryFrom for InitializedNotification { + type Error = JsonrpcErrorError; + fn try_from(value: NotificationFromClient) -> std::result::Result { + let matched_type: ClientNotification = value.try_into()?; + if let ClientNotification::InitializedNotification(result) = matched_type { + Ok(result) + } else { + Err(JsonrpcErrorError::internal_error().with_message("Not a InitializedNotification".to_string())) + } + } +} +impl TryFrom for ProgressNotification { + type Error = JsonrpcErrorError; + fn try_from(value: NotificationFromClient) -> std::result::Result { + let matched_type: ClientNotification = value.try_into()?; + if let ClientNotification::ProgressNotification(result) = matched_type { + Ok(result) + } else { + Err(JsonrpcErrorError::internal_error().with_message("Not a ProgressNotification".to_string())) + } + } +} +impl TryFrom for RootsListChangedNotification { + type Error = JsonrpcErrorError; + fn try_from(value: NotificationFromClient) -> std::result::Result { + let matched_type: ClientNotification = value.try_into()?; + if let ClientNotification::RootsListChangedNotification(result) = matched_type { + Ok(result) + } else { + Err(JsonrpcErrorError::internal_error().with_message("Not a RootsListChangedNotification".to_string())) + } + } +} +impl TryFrom for PingRequest { + type Error = JsonrpcErrorError; + fn try_from(value: RequestFromServer) -> std::result::Result { + let matched_type: ServerRequest = value.try_into()?; + if let ServerRequest::PingRequest(result) = matched_type { + Ok(result) + } else { + Err(JsonrpcErrorError::internal_error().with_message("Not a PingRequest".to_string())) + } + } +} +impl TryFrom for CreateMessageRequest { + type Error = JsonrpcErrorError; + fn try_from(value: RequestFromServer) -> std::result::Result { + let matched_type: ServerRequest = value.try_into()?; + if let ServerRequest::CreateMessageRequest(result) = matched_type { + Ok(result) + } else { + Err(JsonrpcErrorError::internal_error().with_message("Not a CreateMessageRequest".to_string())) + } + } +} +impl TryFrom for ListRootsRequest { + type Error = JsonrpcErrorError; + fn try_from(value: RequestFromServer) -> std::result::Result { + let matched_type: ServerRequest = value.try_into()?; + if let ServerRequest::ListRootsRequest(result) = matched_type { + Ok(result) + } else { + Err(JsonrpcErrorError::internal_error().with_message("Not a ListRootsRequest".to_string())) + } + } +} +impl TryFrom for Result { + type Error = JsonrpcErrorError; + fn try_from(value: ResultFromServer) -> std::result::Result { + let matched_type: ServerResult = value.try_into()?; + if let ServerResult::Result(result) = matched_type { + Ok(result) + } else { + Err(JsonrpcErrorError::internal_error().with_message("Not a Result".to_string())) + } + } +} +impl TryFrom for InitializeResult { + type Error = JsonrpcErrorError; + fn try_from(value: ResultFromServer) -> std::result::Result { + let matched_type: ServerResult = value.try_into()?; + if let ServerResult::InitializeResult(result) = matched_type { + Ok(result) + } else { + Err(JsonrpcErrorError::internal_error().with_message("Not a InitializeResult".to_string())) + } + } +} +impl TryFrom for ListResourcesResult { + type Error = JsonrpcErrorError; + fn try_from(value: ResultFromServer) -> std::result::Result { + let matched_type: ServerResult = value.try_into()?; + if let ServerResult::ListResourcesResult(result) = matched_type { + Ok(result) + } else { + Err(JsonrpcErrorError::internal_error().with_message("Not a ListResourcesResult".to_string())) + } + } +} +impl TryFrom for ListResourceTemplatesResult { + type Error = JsonrpcErrorError; + fn try_from(value: ResultFromServer) -> std::result::Result { + let matched_type: ServerResult = value.try_into()?; + if let ServerResult::ListResourceTemplatesResult(result) = matched_type { + Ok(result) + } else { + Err(JsonrpcErrorError::internal_error().with_message("Not a ListResourceTemplatesResult".to_string())) + } + } +} +impl TryFrom for ReadResourceResult { + type Error = JsonrpcErrorError; + fn try_from(value: ResultFromServer) -> std::result::Result { + let matched_type: ServerResult = value.try_into()?; + if let ServerResult::ReadResourceResult(result) = matched_type { + Ok(result) + } else { + Err(JsonrpcErrorError::internal_error().with_message("Not a ReadResourceResult".to_string())) + } + } +} +impl TryFrom for ListPromptsResult { + type Error = JsonrpcErrorError; + fn try_from(value: ResultFromServer) -> std::result::Result { + let matched_type: ServerResult = value.try_into()?; + if let ServerResult::ListPromptsResult(result) = matched_type { + Ok(result) + } else { + Err(JsonrpcErrorError::internal_error().with_message("Not a ListPromptsResult".to_string())) + } + } +} +impl TryFrom for GetPromptResult { + type Error = JsonrpcErrorError; + fn try_from(value: ResultFromServer) -> std::result::Result { + let matched_type: ServerResult = value.try_into()?; + if let ServerResult::GetPromptResult(result) = matched_type { + Ok(result) + } else { + Err(JsonrpcErrorError::internal_error().with_message("Not a GetPromptResult".to_string())) + } + } +} +impl TryFrom for ListToolsResult { + type Error = JsonrpcErrorError; + fn try_from(value: ResultFromServer) -> std::result::Result { + let matched_type: ServerResult = value.try_into()?; + if let ServerResult::ListToolsResult(result) = matched_type { + Ok(result) + } else { + Err(JsonrpcErrorError::internal_error().with_message("Not a ListToolsResult".to_string())) + } + } +} +impl TryFrom for CallToolResult { + type Error = JsonrpcErrorError; + fn try_from(value: ResultFromServer) -> std::result::Result { + let matched_type: ServerResult = value.try_into()?; + if let ServerResult::CallToolResult(result) = matched_type { + Ok(result) + } else { + Err(JsonrpcErrorError::internal_error().with_message("Not a CallToolResult".to_string())) + } + } +} +impl TryFrom for CompleteResult { + type Error = JsonrpcErrorError; + fn try_from(value: ResultFromServer) -> std::result::Result { + let matched_type: ServerResult = value.try_into()?; + if let ServerResult::CompleteResult(result) = matched_type { + Ok(result) + } else { + Err(JsonrpcErrorError::internal_error().with_message("Not a CompleteResult".to_string())) + } + } +} +impl TryFrom for CancelledNotification { + type Error = JsonrpcErrorError; + fn try_from(value: NotificationFromServer) -> std::result::Result { + let matched_type: ServerNotification = value.try_into()?; + if let ServerNotification::CancelledNotification(result) = matched_type { + Ok(result) + } else { + Err(JsonrpcErrorError::internal_error().with_message("Not a CancelledNotification".to_string())) + } + } +} +impl TryFrom for ProgressNotification { + type Error = JsonrpcErrorError; + fn try_from(value: NotificationFromServer) -> std::result::Result { + let matched_type: ServerNotification = value.try_into()?; + if let ServerNotification::ProgressNotification(result) = matched_type { + Ok(result) + } else { + Err(JsonrpcErrorError::internal_error().with_message("Not a ProgressNotification".to_string())) + } + } +} +impl TryFrom for ResourceListChangedNotification { + type Error = JsonrpcErrorError; + fn try_from(value: NotificationFromServer) -> std::result::Result { + let matched_type: ServerNotification = value.try_into()?; + if let ServerNotification::ResourceListChangedNotification(result) = matched_type { + Ok(result) + } else { + Err(JsonrpcErrorError::internal_error().with_message("Not a ResourceListChangedNotification".to_string())) + } + } +} +impl TryFrom for ResourceUpdatedNotification { + type Error = JsonrpcErrorError; + fn try_from(value: NotificationFromServer) -> std::result::Result { + let matched_type: ServerNotification = value.try_into()?; + if let ServerNotification::ResourceUpdatedNotification(result) = matched_type { + Ok(result) + } else { + Err(JsonrpcErrorError::internal_error().with_message("Not a ResourceUpdatedNotification".to_string())) + } + } +} +impl TryFrom for PromptListChangedNotification { + type Error = JsonrpcErrorError; + fn try_from(value: NotificationFromServer) -> std::result::Result { + let matched_type: ServerNotification = value.try_into()?; + if let ServerNotification::PromptListChangedNotification(result) = matched_type { + Ok(result) + } else { + Err(JsonrpcErrorError::internal_error().with_message("Not a PromptListChangedNotification".to_string())) + } + } +} +impl TryFrom for ToolListChangedNotification { + type Error = JsonrpcErrorError; + fn try_from(value: NotificationFromServer) -> std::result::Result { + let matched_type: ServerNotification = value.try_into()?; + if let ServerNotification::ToolListChangedNotification(result) = matched_type { + Ok(result) + } else { + Err(JsonrpcErrorError::internal_error().with_message("Not a ToolListChangedNotification".to_string())) + } + } +} +impl TryFrom for LoggingMessageNotification { + type Error = JsonrpcErrorError; + fn try_from(value: NotificationFromServer) -> std::result::Result { + let matched_type: ServerNotification = value.try_into()?; + if let ServerNotification::LoggingMessageNotification(result) = matched_type { + Ok(result) + } else { + Err(JsonrpcErrorError::internal_error().with_message("Not a LoggingMessageNotification".to_string())) + } + } +} /// END AUTO GENERATED #[cfg(test)] mod tests { diff --git a/src/generated_schema/draft/mcp_schema.rs b/src/generated_schema/draft/mcp_schema.rs index 9f9920b..91da355 100644 --- a/src/generated_schema/draft/mcp_schema.rs +++ b/src/generated_schema/draft/mcp_schema.rs @@ -6,7 +6,7 @@ /// /// Generated from : /// Hash : bb1446ff1810a0df57989d78366d626d2c01b9d7 -/// Generated at : 2025-02-22 11:26:41 +/// Generated at : 2025-02-22 12:06:03 /// ---------------------------------------------------------------------------- /// /// MCP Protocol Version diff --git a/src/generated_schema/draft/schema_utils.rs b/src/generated_schema/draft/schema_utils.rs index 07645d3..137b976 100644 --- a/src/generated_schema/draft/schema_utils.rs +++ b/src/generated_schema/draft/schema_utils.rs @@ -1187,6 +1187,30 @@ pub enum MessageFromServer { Error(JsonrpcErrorError), } +impl From for MessageFromServer { + fn from(value: RequestFromServer) -> Self { + Self::RequestFromServer(value) + } +} + +impl From for MessageFromServer { + fn from(value: ResultFromServer) -> Self { + Self::ResultFromServer(value) + } +} + +impl From for MessageFromServer { + fn from(value: NotificationFromServer) -> Self { + Self::NotificationFromServer(value) + } +} + +impl From for MessageFromServer { + fn from(value: JsonrpcErrorError) -> Self { + Self::Error(value) + } +} + impl MCPMessage for MessageFromServer { fn is_response(&self) -> bool { matches!(self, MessageFromServer::ResultFromServer(_)) @@ -1271,6 +1295,30 @@ pub enum MessageFromClient { Error(JsonrpcErrorError), } +impl From for MessageFromClient { + fn from(value: RequestFromClient) -> Self { + Self::RequestFromClient(value) + } +} + +impl From for MessageFromClient { + fn from(value: ResultFromClient) -> Self { + Self::ResultFromClient(value) + } +} + +impl From for MessageFromClient { + fn from(value: NotificationFromClient) -> Self { + Self::NotificationFromClient(value) + } +} + +impl From for MessageFromClient { + fn from(value: JsonrpcErrorError) -> Self { + Self::Error(value) + } +} + impl FromMessage for ClientMessage { fn from_message( message: MessageFromClient, @@ -2987,6 +3035,424 @@ impl ToMessage for LoggingMessageNotification { ServerMessage::from_message(self, request_id) } } +impl TryFrom for InitializeRequest { + type Error = JsonrpcErrorError; + fn try_from(value: RequestFromClient) -> std::result::Result { + let matched_type: ClientRequest = value.try_into()?; + if let ClientRequest::InitializeRequest(result) = matched_type { + Ok(result) + } else { + Err(JsonrpcErrorError::internal_error().with_message("Not a InitializeRequest".to_string())) + } + } +} +impl TryFrom for PingRequest { + type Error = JsonrpcErrorError; + fn try_from(value: RequestFromClient) -> std::result::Result { + let matched_type: ClientRequest = value.try_into()?; + if let ClientRequest::PingRequest(result) = matched_type { + Ok(result) + } else { + Err(JsonrpcErrorError::internal_error().with_message("Not a PingRequest".to_string())) + } + } +} +impl TryFrom for ListResourcesRequest { + type Error = JsonrpcErrorError; + fn try_from(value: RequestFromClient) -> std::result::Result { + let matched_type: ClientRequest = value.try_into()?; + if let ClientRequest::ListResourcesRequest(result) = matched_type { + Ok(result) + } else { + Err(JsonrpcErrorError::internal_error().with_message("Not a ListResourcesRequest".to_string())) + } + } +} +impl TryFrom for ReadResourceRequest { + type Error = JsonrpcErrorError; + fn try_from(value: RequestFromClient) -> std::result::Result { + let matched_type: ClientRequest = value.try_into()?; + if let ClientRequest::ReadResourceRequest(result) = matched_type { + Ok(result) + } else { + Err(JsonrpcErrorError::internal_error().with_message("Not a ReadResourceRequest".to_string())) + } + } +} +impl TryFrom for SubscribeRequest { + type Error = JsonrpcErrorError; + fn try_from(value: RequestFromClient) -> std::result::Result { + let matched_type: ClientRequest = value.try_into()?; + if let ClientRequest::SubscribeRequest(result) = matched_type { + Ok(result) + } else { + Err(JsonrpcErrorError::internal_error().with_message("Not a SubscribeRequest".to_string())) + } + } +} +impl TryFrom for UnsubscribeRequest { + type Error = JsonrpcErrorError; + fn try_from(value: RequestFromClient) -> std::result::Result { + let matched_type: ClientRequest = value.try_into()?; + if let ClientRequest::UnsubscribeRequest(result) = matched_type { + Ok(result) + } else { + Err(JsonrpcErrorError::internal_error().with_message("Not a UnsubscribeRequest".to_string())) + } + } +} +impl TryFrom for ListPromptsRequest { + type Error = JsonrpcErrorError; + fn try_from(value: RequestFromClient) -> std::result::Result { + let matched_type: ClientRequest = value.try_into()?; + if let ClientRequest::ListPromptsRequest(result) = matched_type { + Ok(result) + } else { + Err(JsonrpcErrorError::internal_error().with_message("Not a ListPromptsRequest".to_string())) + } + } +} +impl TryFrom for GetPromptRequest { + type Error = JsonrpcErrorError; + fn try_from(value: RequestFromClient) -> std::result::Result { + let matched_type: ClientRequest = value.try_into()?; + if let ClientRequest::GetPromptRequest(result) = matched_type { + Ok(result) + } else { + Err(JsonrpcErrorError::internal_error().with_message("Not a GetPromptRequest".to_string())) + } + } +} +impl TryFrom for ListToolsRequest { + type Error = JsonrpcErrorError; + fn try_from(value: RequestFromClient) -> std::result::Result { + let matched_type: ClientRequest = value.try_into()?; + if let ClientRequest::ListToolsRequest(result) = matched_type { + Ok(result) + } else { + Err(JsonrpcErrorError::internal_error().with_message("Not a ListToolsRequest".to_string())) + } + } +} +impl TryFrom for CallToolRequest { + type Error = JsonrpcErrorError; + fn try_from(value: RequestFromClient) -> std::result::Result { + let matched_type: ClientRequest = value.try_into()?; + if let ClientRequest::CallToolRequest(result) = matched_type { + Ok(result) + } else { + Err(JsonrpcErrorError::internal_error().with_message("Not a CallToolRequest".to_string())) + } + } +} +impl TryFrom for SetLevelRequest { + type Error = JsonrpcErrorError; + fn try_from(value: RequestFromClient) -> std::result::Result { + let matched_type: ClientRequest = value.try_into()?; + if let ClientRequest::SetLevelRequest(result) = matched_type { + Ok(result) + } else { + Err(JsonrpcErrorError::internal_error().with_message("Not a SetLevelRequest".to_string())) + } + } +} +impl TryFrom for CompleteRequest { + type Error = JsonrpcErrorError; + fn try_from(value: RequestFromClient) -> std::result::Result { + let matched_type: ClientRequest = value.try_into()?; + if let ClientRequest::CompleteRequest(result) = matched_type { + Ok(result) + } else { + Err(JsonrpcErrorError::internal_error().with_message("Not a CompleteRequest".to_string())) + } + } +} +impl TryFrom for Result { + type Error = JsonrpcErrorError; + fn try_from(value: ResultFromClient) -> std::result::Result { + let matched_type: ClientResult = value.try_into()?; + if let ClientResult::Result(result) = matched_type { + Ok(result) + } else { + Err(JsonrpcErrorError::internal_error().with_message("Not a Result".to_string())) + } + } +} +impl TryFrom for CreateMessageResult { + type Error = JsonrpcErrorError; + fn try_from(value: ResultFromClient) -> std::result::Result { + let matched_type: ClientResult = value.try_into()?; + if let ClientResult::CreateMessageResult(result) = matched_type { + Ok(result) + } else { + Err(JsonrpcErrorError::internal_error().with_message("Not a CreateMessageResult".to_string())) + } + } +} +impl TryFrom for ListRootsResult { + type Error = JsonrpcErrorError; + fn try_from(value: ResultFromClient) -> std::result::Result { + let matched_type: ClientResult = value.try_into()?; + if let ClientResult::ListRootsResult(result) = matched_type { + Ok(result) + } else { + Err(JsonrpcErrorError::internal_error().with_message("Not a ListRootsResult".to_string())) + } + } +} +impl TryFrom for CancelledNotification { + type Error = JsonrpcErrorError; + fn try_from(value: NotificationFromClient) -> std::result::Result { + let matched_type: ClientNotification = value.try_into()?; + if let ClientNotification::CancelledNotification(result) = matched_type { + Ok(result) + } else { + Err(JsonrpcErrorError::internal_error().with_message("Not a CancelledNotification".to_string())) + } + } +} +impl TryFrom for InitializedNotification { + type Error = JsonrpcErrorError; + fn try_from(value: NotificationFromClient) -> std::result::Result { + let matched_type: ClientNotification = value.try_into()?; + if let ClientNotification::InitializedNotification(result) = matched_type { + Ok(result) + } else { + Err(JsonrpcErrorError::internal_error().with_message("Not a InitializedNotification".to_string())) + } + } +} +impl TryFrom for ProgressNotification { + type Error = JsonrpcErrorError; + fn try_from(value: NotificationFromClient) -> std::result::Result { + let matched_type: ClientNotification = value.try_into()?; + if let ClientNotification::ProgressNotification(result) = matched_type { + Ok(result) + } else { + Err(JsonrpcErrorError::internal_error().with_message("Not a ProgressNotification".to_string())) + } + } +} +impl TryFrom for RootsListChangedNotification { + type Error = JsonrpcErrorError; + fn try_from(value: NotificationFromClient) -> std::result::Result { + let matched_type: ClientNotification = value.try_into()?; + if let ClientNotification::RootsListChangedNotification(result) = matched_type { + Ok(result) + } else { + Err(JsonrpcErrorError::internal_error().with_message("Not a RootsListChangedNotification".to_string())) + } + } +} +impl TryFrom for PingRequest { + type Error = JsonrpcErrorError; + fn try_from(value: RequestFromServer) -> std::result::Result { + let matched_type: ServerRequest = value.try_into()?; + if let ServerRequest::PingRequest(result) = matched_type { + Ok(result) + } else { + Err(JsonrpcErrorError::internal_error().with_message("Not a PingRequest".to_string())) + } + } +} +impl TryFrom for CreateMessageRequest { + type Error = JsonrpcErrorError; + fn try_from(value: RequestFromServer) -> std::result::Result { + let matched_type: ServerRequest = value.try_into()?; + if let ServerRequest::CreateMessageRequest(result) = matched_type { + Ok(result) + } else { + Err(JsonrpcErrorError::internal_error().with_message("Not a CreateMessageRequest".to_string())) + } + } +} +impl TryFrom for ListRootsRequest { + type Error = JsonrpcErrorError; + fn try_from(value: RequestFromServer) -> std::result::Result { + let matched_type: ServerRequest = value.try_into()?; + if let ServerRequest::ListRootsRequest(result) = matched_type { + Ok(result) + } else { + Err(JsonrpcErrorError::internal_error().with_message("Not a ListRootsRequest".to_string())) + } + } +} +impl TryFrom for Result { + type Error = JsonrpcErrorError; + fn try_from(value: ResultFromServer) -> std::result::Result { + let matched_type: ServerResult = value.try_into()?; + if let ServerResult::Result(result) = matched_type { + Ok(result) + } else { + Err(JsonrpcErrorError::internal_error().with_message("Not a Result".to_string())) + } + } +} +impl TryFrom for InitializeResult { + type Error = JsonrpcErrorError; + fn try_from(value: ResultFromServer) -> std::result::Result { + let matched_type: ServerResult = value.try_into()?; + if let ServerResult::InitializeResult(result) = matched_type { + Ok(result) + } else { + Err(JsonrpcErrorError::internal_error().with_message("Not a InitializeResult".to_string())) + } + } +} +impl TryFrom for ListResourcesResult { + type Error = JsonrpcErrorError; + fn try_from(value: ResultFromServer) -> std::result::Result { + let matched_type: ServerResult = value.try_into()?; + if let ServerResult::ListResourcesResult(result) = matched_type { + Ok(result) + } else { + Err(JsonrpcErrorError::internal_error().with_message("Not a ListResourcesResult".to_string())) + } + } +} +impl TryFrom for ReadResourceResult { + type Error = JsonrpcErrorError; + fn try_from(value: ResultFromServer) -> std::result::Result { + let matched_type: ServerResult = value.try_into()?; + if let ServerResult::ReadResourceResult(result) = matched_type { + Ok(result) + } else { + Err(JsonrpcErrorError::internal_error().with_message("Not a ReadResourceResult".to_string())) + } + } +} +impl TryFrom for ListPromptsResult { + type Error = JsonrpcErrorError; + fn try_from(value: ResultFromServer) -> std::result::Result { + let matched_type: ServerResult = value.try_into()?; + if let ServerResult::ListPromptsResult(result) = matched_type { + Ok(result) + } else { + Err(JsonrpcErrorError::internal_error().with_message("Not a ListPromptsResult".to_string())) + } + } +} +impl TryFrom for GetPromptResult { + type Error = JsonrpcErrorError; + fn try_from(value: ResultFromServer) -> std::result::Result { + let matched_type: ServerResult = value.try_into()?; + if let ServerResult::GetPromptResult(result) = matched_type { + Ok(result) + } else { + Err(JsonrpcErrorError::internal_error().with_message("Not a GetPromptResult".to_string())) + } + } +} +impl TryFrom for ListToolsResult { + type Error = JsonrpcErrorError; + fn try_from(value: ResultFromServer) -> std::result::Result { + let matched_type: ServerResult = value.try_into()?; + if let ServerResult::ListToolsResult(result) = matched_type { + Ok(result) + } else { + Err(JsonrpcErrorError::internal_error().with_message("Not a ListToolsResult".to_string())) + } + } +} +impl TryFrom for CallToolResult { + type Error = JsonrpcErrorError; + fn try_from(value: ResultFromServer) -> std::result::Result { + let matched_type: ServerResult = value.try_into()?; + if let ServerResult::CallToolResult(result) = matched_type { + Ok(result) + } else { + Err(JsonrpcErrorError::internal_error().with_message("Not a CallToolResult".to_string())) + } + } +} +impl TryFrom for CompleteResult { + type Error = JsonrpcErrorError; + fn try_from(value: ResultFromServer) -> std::result::Result { + let matched_type: ServerResult = value.try_into()?; + if let ServerResult::CompleteResult(result) = matched_type { + Ok(result) + } else { + Err(JsonrpcErrorError::internal_error().with_message("Not a CompleteResult".to_string())) + } + } +} +impl TryFrom for CancelledNotification { + type Error = JsonrpcErrorError; + fn try_from(value: NotificationFromServer) -> std::result::Result { + let matched_type: ServerNotification = value.try_into()?; + if let ServerNotification::CancelledNotification(result) = matched_type { + Ok(result) + } else { + Err(JsonrpcErrorError::internal_error().with_message("Not a CancelledNotification".to_string())) + } + } +} +impl TryFrom for ProgressNotification { + type Error = JsonrpcErrorError; + fn try_from(value: NotificationFromServer) -> std::result::Result { + let matched_type: ServerNotification = value.try_into()?; + if let ServerNotification::ProgressNotification(result) = matched_type { + Ok(result) + } else { + Err(JsonrpcErrorError::internal_error().with_message("Not a ProgressNotification".to_string())) + } + } +} +impl TryFrom for ResourceListChangedNotification { + type Error = JsonrpcErrorError; + fn try_from(value: NotificationFromServer) -> std::result::Result { + let matched_type: ServerNotification = value.try_into()?; + if let ServerNotification::ResourceListChangedNotification(result) = matched_type { + Ok(result) + } else { + Err(JsonrpcErrorError::internal_error().with_message("Not a ResourceListChangedNotification".to_string())) + } + } +} +impl TryFrom for ResourceUpdatedNotification { + type Error = JsonrpcErrorError; + fn try_from(value: NotificationFromServer) -> std::result::Result { + let matched_type: ServerNotification = value.try_into()?; + if let ServerNotification::ResourceUpdatedNotification(result) = matched_type { + Ok(result) + } else { + Err(JsonrpcErrorError::internal_error().with_message("Not a ResourceUpdatedNotification".to_string())) + } + } +} +impl TryFrom for PromptListChangedNotification { + type Error = JsonrpcErrorError; + fn try_from(value: NotificationFromServer) -> std::result::Result { + let matched_type: ServerNotification = value.try_into()?; + if let ServerNotification::PromptListChangedNotification(result) = matched_type { + Ok(result) + } else { + Err(JsonrpcErrorError::internal_error().with_message("Not a PromptListChangedNotification".to_string())) + } + } +} +impl TryFrom for ToolListChangedNotification { + type Error = JsonrpcErrorError; + fn try_from(value: NotificationFromServer) -> std::result::Result { + let matched_type: ServerNotification = value.try_into()?; + if let ServerNotification::ToolListChangedNotification(result) = matched_type { + Ok(result) + } else { + Err(JsonrpcErrorError::internal_error().with_message("Not a ToolListChangedNotification".to_string())) + } + } +} +impl TryFrom for LoggingMessageNotification { + type Error = JsonrpcErrorError; + fn try_from(value: NotificationFromServer) -> std::result::Result { + let matched_type: ServerNotification = value.try_into()?; + if let ServerNotification::LoggingMessageNotification(result) = matched_type { + Ok(result) + } else { + Err(JsonrpcErrorError::internal_error().with_message("Not a LoggingMessageNotification".to_string())) + } + } +} /// END AUTO GENERATED #[cfg(test)] mod tests {