Skip to content

Commit de51f57

Browse files
authored
feat: improve schema utils (#8)
* chore: enhance schema_utils * test: improve tests
1 parent f85e7e6 commit de51f57

File tree

5 files changed

+150
-14
lines changed

5 files changed

+150
-14
lines changed

src/generated_schema/2024_11_05/mcp_schema.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
/// ----------------------------------------------------------------------------
2-
/// WARNING: This file is auto-generated by mcp-schema-gen v0.0.1.
2+
/// This file is auto-generated by mcp-schema-gen v0.1.1.
3+
/// WARNING:
34
/// It is not recommended to modify this file directly. You are free to
45
/// modify or extend the implementations as needed, but please do so at your own risk.
56
///
67
/// Generated from : <https://github.com/modelcontextprotocol/specification.git>
78
/// Hash : 3d4877e69cbc9921e1b511a90cdf17d42483036b
8-
/// Generated at : 2025-02-06 11:59:05
9+
/// Generated at : 2025-02-09 16:55:01
910
/// ----------------------------------------------------------------------------
1011
///
1112
/// MCP Protocol Version

src/generated_schema/2024_11_05/schema_utils.rs

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,6 +1004,26 @@ impl From<RootsListChangedNotification> for NotificationFromClient {
10041004
Self::ClientNotification(value.into())
10051005
}
10061006
}
1007+
impl From<CancelledNotification> for ClientJsonrpcNotification {
1008+
fn from(value: CancelledNotification) -> Self {
1009+
Self::new(value.into())
1010+
}
1011+
}
1012+
impl From<InitializedNotification> for ClientJsonrpcNotification {
1013+
fn from(value: InitializedNotification) -> Self {
1014+
Self::new(value.into())
1015+
}
1016+
}
1017+
impl From<ProgressNotification> for ClientJsonrpcNotification {
1018+
fn from(value: ProgressNotification) -> Self {
1019+
Self::new(value.into())
1020+
}
1021+
}
1022+
impl From<RootsListChangedNotification> for ClientJsonrpcNotification {
1023+
fn from(value: RootsListChangedNotification) -> Self {
1024+
Self::new(value.into())
1025+
}
1026+
}
10071027
impl From<Result> for ResultFromClient {
10081028
fn from(value: Result) -> Self {
10091029
Self::ClientResult(value.into())
@@ -1093,6 +1113,41 @@ impl From<LoggingMessageNotification> for NotificationFromServer {
10931113
Self::ServerNotification(value.into())
10941114
}
10951115
}
1116+
impl From<CancelledNotification> for ServerJsonrpcNotification {
1117+
fn from(value: CancelledNotification) -> Self {
1118+
Self::new(value.into())
1119+
}
1120+
}
1121+
impl From<ProgressNotification> for ServerJsonrpcNotification {
1122+
fn from(value: ProgressNotification) -> Self {
1123+
Self::new(value.into())
1124+
}
1125+
}
1126+
impl From<ResourceListChangedNotification> for ServerJsonrpcNotification {
1127+
fn from(value: ResourceListChangedNotification) -> Self {
1128+
Self::new(value.into())
1129+
}
1130+
}
1131+
impl From<ResourceUpdatedNotification> for ServerJsonrpcNotification {
1132+
fn from(value: ResourceUpdatedNotification) -> Self {
1133+
Self::new(value.into())
1134+
}
1135+
}
1136+
impl From<PromptListChangedNotification> for ServerJsonrpcNotification {
1137+
fn from(value: PromptListChangedNotification) -> Self {
1138+
Self::new(value.into())
1139+
}
1140+
}
1141+
impl From<ToolListChangedNotification> for ServerJsonrpcNotification {
1142+
fn from(value: ToolListChangedNotification) -> Self {
1143+
Self::new(value.into())
1144+
}
1145+
}
1146+
impl From<LoggingMessageNotification> for ServerJsonrpcNotification {
1147+
fn from(value: LoggingMessageNotification) -> Self {
1148+
Self::new(value.into())
1149+
}
1150+
}
10961151
impl From<PingRequest> for RequestFromServer {
10971152
fn from(value: PingRequest) -> Self {
10981153
Self::ServerRequest(value.into())
@@ -1223,9 +1278,5 @@ mod tests {
12231278
);
12241279
let result = detect_message_type(&json!(message));
12251280
assert!(matches!(result, MessageTypes::Error));
1226-
1227-
// default
1228-
let result = detect_message_type(&json!({}));
1229-
assert!(matches!(result, MessageTypes::Request));
12301281
}
12311282
}

src/generated_schema/draft/mcp_schema.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
/// ----------------------------------------------------------------------------
2-
/// WARNING: This file is auto-generated by mcp-schema-gen v0.0.1.
2+
/// This file is auto-generated by mcp-schema-gen v0.1.1.
3+
/// WARNING:
34
/// It is not recommended to modify this file directly. You are free to
45
/// modify or extend the implementations as needed, but please do so at your own risk.
56
///
67
/// Generated from : <https://github.com/modelcontextprotocol/specification.git>
78
/// Hash : 3d4877e69cbc9921e1b511a90cdf17d42483036b
8-
/// Generated at : 2025-02-06 11:59:05
9+
/// Generated at : 2025-02-09 16:55:01
910
/// ----------------------------------------------------------------------------
1011
///
1112
/// MCP Protocol Version

src/generated_schema/draft/schema_utils.rs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -998,6 +998,26 @@ impl From<RootsListChangedNotification> for NotificationFromClient {
998998
Self::ClientNotification(value.into())
999999
}
10001000
}
1001+
impl From<CancelledNotification> for ClientJsonrpcNotification {
1002+
fn from(value: CancelledNotification) -> Self {
1003+
Self::new(value.into())
1004+
}
1005+
}
1006+
impl From<InitializedNotification> for ClientJsonrpcNotification {
1007+
fn from(value: InitializedNotification) -> Self {
1008+
Self::new(value.into())
1009+
}
1010+
}
1011+
impl From<ProgressNotification> for ClientJsonrpcNotification {
1012+
fn from(value: ProgressNotification) -> Self {
1013+
Self::new(value.into())
1014+
}
1015+
}
1016+
impl From<RootsListChangedNotification> for ClientJsonrpcNotification {
1017+
fn from(value: RootsListChangedNotification) -> Self {
1018+
Self::new(value.into())
1019+
}
1020+
}
10011021
impl From<Result> for ResultFromClient {
10021022
fn from(value: Result) -> Self {
10031023
Self::ClientResult(value.into())
@@ -1087,6 +1107,41 @@ impl From<LoggingMessageNotification> for NotificationFromServer {
10871107
Self::ServerNotification(value.into())
10881108
}
10891109
}
1110+
impl From<CancelledNotification> for ServerJsonrpcNotification {
1111+
fn from(value: CancelledNotification) -> Self {
1112+
Self::new(value.into())
1113+
}
1114+
}
1115+
impl From<ProgressNotification> for ServerJsonrpcNotification {
1116+
fn from(value: ProgressNotification) -> Self {
1117+
Self::new(value.into())
1118+
}
1119+
}
1120+
impl From<ResourceListChangedNotification> for ServerJsonrpcNotification {
1121+
fn from(value: ResourceListChangedNotification) -> Self {
1122+
Self::new(value.into())
1123+
}
1124+
}
1125+
impl From<ResourceUpdatedNotification> for ServerJsonrpcNotification {
1126+
fn from(value: ResourceUpdatedNotification) -> Self {
1127+
Self::new(value.into())
1128+
}
1129+
}
1130+
impl From<PromptListChangedNotification> for ServerJsonrpcNotification {
1131+
fn from(value: PromptListChangedNotification) -> Self {
1132+
Self::new(value.into())
1133+
}
1134+
}
1135+
impl From<ToolListChangedNotification> for ServerJsonrpcNotification {
1136+
fn from(value: ToolListChangedNotification) -> Self {
1137+
Self::new(value.into())
1138+
}
1139+
}
1140+
impl From<LoggingMessageNotification> for ServerJsonrpcNotification {
1141+
fn from(value: LoggingMessageNotification) -> Self {
1142+
Self::new(value.into())
1143+
}
1144+
}
10901145
impl From<PingRequest> for RequestFromServer {
10911146
fn from(value: PingRequest) -> Self {
10921147
Self::ServerRequest(value.into())

tests/test_serialize.rs

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -376,18 +376,37 @@ mod test_serialize {
376376

377377
#[test]
378378
fn test_client_initialized_notification() {
379-
let message: ClientMessage = ClientMessage::Notification(ClientJsonrpcNotification::new(
380-
NotificationFromClient::ClientNotification(ClientNotification::InitializedNotification(
381-
InitializedNotification::new(Some(InitializedNotificationParams { meta: None, extra: None })),
382-
)),
383-
));
379+
let init_notification =
380+
InitializedNotification::new(Some(InitializedNotificationParams { meta: None, extra: None }));
381+
382+
let message: ClientMessage =
383+
ClientMessage::Notification(ClientJsonrpcNotification::new(NotificationFromClient::ClientNotification(
384+
ClientNotification::InitializedNotification(init_notification.clone()),
385+
)));
384386

385387
let message: ClientMessage = re_serialize(message);
386388

387389
assert!(matches!(message, ClientMessage::Notification(client_message)
388390
if matches!(&client_message.notification,NotificationFromClient::ClientNotification(client_notification)
389391
if matches!( client_notification, ClientNotification::InitializedNotification(_)))
390392
));
393+
394+
// test From<InitializedNotification> for NotificationFromClient
395+
let message: ClientMessage =
396+
ClientMessage::Notification(ClientJsonrpcNotification::new(init_notification.clone().into()));
397+
398+
assert!(matches!(message, ClientMessage::Notification(client_message)
399+
if matches!(&client_message.notification,NotificationFromClient::ClientNotification(client_notification)
400+
if matches!( client_notification, ClientNotification::InitializedNotification(_)))
401+
));
402+
403+
// test From<InitializedNotification> for ClientJsonrpcNotification
404+
let message: ClientMessage = ClientMessage::Notification(init_notification.into());
405+
406+
assert!(matches!(message, ClientMessage::Notification(client_message)
407+
if matches!(&client_message.notification,NotificationFromClient::ClientNotification(client_notification)
408+
if matches!( client_notification, ClientNotification::InitializedNotification(_)))
409+
));
391410
}
392411

393412
#[test]
@@ -460,7 +479,16 @@ mod test_serialize {
460479
));
461480

462481
// test From<CancelledNotification> for NotificationFromServer
463-
let message: ServerMessage = ServerMessage::Notification(ServerJsonrpcNotification::new(cancel_notification.into()));
482+
let message: ServerMessage =
483+
ServerMessage::Notification(ServerJsonrpcNotification::new(cancel_notification.clone().into()));
484+
485+
assert!(matches!(message, ServerMessage::Notification(client_message)
486+
if matches!(&client_message.notification,NotificationFromServer::ServerNotification(client_notification)
487+
if matches!( client_notification, ServerNotification::CancelledNotification(_)))
488+
));
489+
490+
// test From<CancelledNotification> for ServerNotification
491+
let message: ServerMessage = ServerMessage::Notification(cancel_notification.into());
464492

465493
assert!(matches!(message, ServerMessage::Notification(client_message)
466494
if matches!(&client_message.notification,NotificationFromServer::ServerNotification(client_notification)

0 commit comments

Comments
 (0)