Skip to content

Commit f141060

Browse files
authored
fix: custom result deserialization conflic with rust_mcp_schema::Result (#44)
* fix: CustomResult deserialization * update draft * update clippy command * update clipply allow depricated * typo
1 parent c2408c1 commit f141060

File tree

8 files changed

+34
-29
lines changed

8 files changed

+34
-29
lines changed

.cargo/config.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ run_clippy = [
66
"--features",
77
"latest schema_utils",
88
"--fix",
9+
"--allow-dirty",
910
"--",
11+
"-A",
12+
"deprecated",
1013
"-D",
1114
"warnings",
1215
]

scripts/run_clippy.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ COMMON_FEATURES_STR="${COMMON_FEATURES[*]}"
1111

1212
for FEATURE in "${SCHEMA_VERSION_FEATURES[@]}"; do
1313
echo "🚀 Running Clippy with: --features \"$COMMON_FEATURES_STR $FEATURE\""
14-
cargo clippy --all-targets --no-default-features --features "$COMMON_FEATURES_STR $FEATURE" -- -D warnings
14+
cargo clippy --all-targets --no-default-features --features "$COMMON_FEATURES_STR $FEATURE" -- -A deprecated -D warnings
1515

1616
# stop on failure
1717
if [ $? -ne 0 ]; then

src/generated_schema/2024_11_05/mcp_schema.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
/// modify or extend the implementations as needed, but please do so at your own risk.
66
///
77
/// Generated from : <https://github.com/modelcontextprotocol/specification.git>
8-
/// Hash : bb1446ff1810a0df57989d78366d626d2c01b9d7
9-
/// Generated at : 2025-03-02 12:41:59
8+
/// Hash : 6828f3ef6300b25dd2aaff2a2e5e81188bdbd22e
9+
/// Generated at : 2025-03-08 08:33:48
1010
/// ----------------------------------------------------------------------------
1111
///
1212
/// MCP Protocol Version
@@ -5155,7 +5155,7 @@ impl ::std::convert::From<Result> for ServerResult {
51555155
/// ],
51565156
/// "properties": {
51575157
/// "level": {
5158-
/// "description": "The level of logging that the client wants to receive from the server. The server should send all logs at this level and higher (i.e., more severe) to the client as notifications/logging/message.",
5158+
/// "description": "The level of logging that the client wants to receive from the server. The server should send all logs at this level and higher (i.e., more severe) to the client as notifications/message.",
51595159
/// "$ref": "#/definitions/LoggingLevel"
51605160
/// }
51615161
/// }
@@ -5192,7 +5192,7 @@ impl SetLevelRequest {
51925192
/// ],
51935193
/// "properties": {
51945194
/// "level": {
5195-
/// "description": "The level of logging that the client wants to receive from the server. The server should send all logs at this level and higher (i.e., more severe) to the client as notifications/logging/message.",
5195+
/// "description": "The level of logging that the client wants to receive from the server. The server should send all logs at this level and higher (i.e., more severe) to the client as notifications/message.",
51965196
/// "$ref": "#/definitions/LoggingLevel"
51975197
/// }
51985198
/// }
@@ -5201,7 +5201,7 @@ impl SetLevelRequest {
52015201
/// </details>
52025202
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
52035203
pub struct SetLevelRequestParams {
5204-
///The level of logging that the client wants to receive from the server. The server should send all logs at this level and higher (i.e., more severe) to the client as notifications/logging/message.
5204+
///The level of logging that the client wants to receive from the server. The server should send all logs at this level and higher (i.e., more severe) to the client as notifications/message.
52055205
pub level: LoggingLevel,
52065206
}
52075207
///Sent from the client to request resources/updated notifications from the server whenever a particular resource changes.

src/generated_schema/2024_11_05/schema_utils.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,7 @@ impl FromStr for ClientJsonrpcResponse {
587587
#[serde(untagged)]
588588
pub enum ResultFromClient {
589589
ClientResult(ClientResult),
590+
#[deprecated(since = "0.1.8", note = "Use `ClientResult::Result` with extra attributes instead.")]
590591
CustomResult(serde_json::Value),
591592
}
592593

@@ -1106,6 +1107,7 @@ impl FromStr for ServerJsonrpcResponse {
11061107
#[serde(untagged)]
11071108
pub enum ResultFromServer {
11081109
ServerResult(ServerResult),
1110+
#[deprecated(since = "0.1.8", note = "Use `ServerResult::Result` with extra attributes instead.")]
11091111
CustomResult(serde_json::Value),
11101112
}
11111113

@@ -1142,13 +1144,7 @@ impl<'de> serde::Deserialize<'de> for ResultFromServer {
11421144
let result = ServerResult::deserialize(&raw_value);
11431145

11441146
match result {
1145-
Ok(server_result) => {
1146-
if matches!(server_result, ServerResult::Result(_)) {
1147-
Ok(Self::CustomResult(raw_value))
1148-
} else {
1149-
Ok(Self::ServerResult(server_result))
1150-
}
1151-
}
1147+
Ok(server_result) => Ok(Self::ServerResult(server_result)),
11521148
Err(_) => Ok(Self::CustomResult(raw_value)),
11531149
}
11541150
}

src/generated_schema/draft/mcp_schema.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
/// modify or extend the implementations as needed, but please do so at your own risk.
66
///
77
/// Generated from : <https://github.com/modelcontextprotocol/specification.git>
8-
/// Hash : bb1446ff1810a0df57989d78366d626d2c01b9d7
9-
/// Generated at : 2025-03-02 12:41:59
8+
/// Hash : 6828f3ef6300b25dd2aaff2a2e5e81188bdbd22e
9+
/// Generated at : 2025-03-08 08:33:48
1010
/// ----------------------------------------------------------------------------
1111
///
1212
/// MCP Protocol Version
@@ -5289,7 +5289,7 @@ impl ::std::convert::From<Result> for ServerResult {
52895289
/// ],
52905290
/// "properties": {
52915291
/// "level": {
5292-
/// "description": "The level of logging that the client wants to receive from the server. The server should send all logs at this level and higher (i.e., more severe) to the client as notifications/logging/message.",
5292+
/// "description": "The level of logging that the client wants to receive from the server. The server should send all logs at this level and higher (i.e., more severe) to the client as notifications/message.",
52935293
/// "$ref": "#/definitions/LoggingLevel"
52945294
/// }
52955295
/// }
@@ -5326,7 +5326,7 @@ impl SetLevelRequest {
53265326
/// ],
53275327
/// "properties": {
53285328
/// "level": {
5329-
/// "description": "The level of logging that the client wants to receive from the server. The server should send all logs at this level and higher (i.e., more severe) to the client as notifications/logging/message.",
5329+
/// "description": "The level of logging that the client wants to receive from the server. The server should send all logs at this level and higher (i.e., more severe) to the client as notifications/message.",
53305330
/// "$ref": "#/definitions/LoggingLevel"
53315331
/// }
53325332
/// }
@@ -5335,7 +5335,7 @@ impl SetLevelRequest {
53355335
/// </details>
53365336
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
53375337
pub struct SetLevelRequestParams {
5338-
///The level of logging that the client wants to receive from the server. The server should send all logs at this level and higher (i.e., more severe) to the client as notifications/logging/message.
5338+
///The level of logging that the client wants to receive from the server. The server should send all logs at this level and higher (i.e., more severe) to the client as notifications/message.
53395339
pub level: LoggingLevel,
53405340
}
53415341
///Sent from the client to request resources/updated notifications from the server whenever a particular resource changes.

src/generated_schema/draft/schema_utils.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1142,13 +1142,7 @@ impl<'de> serde::Deserialize<'de> for ResultFromServer {
11421142
let result = ServerResult::deserialize(&raw_value);
11431143

11441144
match result {
1145-
Ok(server_result) => {
1146-
if matches!(server_result, ServerResult::Result(_)) {
1147-
Ok(Self::CustomResult(raw_value))
1148-
} else {
1149-
Ok(Self::ServerResult(server_result))
1150-
}
1151-
}
1145+
Ok(server_result) => Ok(Self::ServerResult(server_result)),
11521146
Err(_) => Ok(Self::CustomResult(raw_value)),
11531147
}
11541148
}

tests/test_deserialize.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ mod test_deserialize {
222222
fn test_server_ping_result() {
223223
let message = get_message("res_ping");
224224
assert!(matches!(message, ServerMessage::Response(server_message)
225-
if matches!(&server_message.result, ResultFromServer::CustomResult(_server_result))
225+
if matches!(&server_message.result, ResultFromServer::ServerResult(_server_result))
226226
));
227227
}
228228

tests/test_serialize.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -387,17 +387,29 @@ mod test_serialize {
387387

388388
#[test]
389389
fn test_server_custom_result() {
390+
let custom_result: serde_json::Map<String, serde_json::Value> = json!({
391+
"custom_key":"custom_value",
392+
"custom_number": 15.21
393+
})
394+
.as_object()
395+
.unwrap()
396+
.clone();
397+
390398
let message: ServerMessage = ServerMessage::Response(ServerJsonrpcResponse::new(
391399
RequestId::Integer(15),
392-
ResultFromServer::CustomResult(json!({
393-
"result":{},"jsonrpc":"2.0","id":15
400+
ResultFromServer::ServerResult(ServerResult::Result(Result {
401+
meta: None,
402+
extra: Some(custom_result),
394403
})),
395404
));
396405

397406
let message: ServerMessage = re_serialize(message);
398407

399408
assert!(matches!(message, ServerMessage::Response(server_message)
400-
if matches!(&server_message.result, ResultFromServer::CustomResult(_))
409+
if matches!(&server_message.result, ResultFromServer::ServerResult(server_result)
410+
if matches!(server_result, ServerResult::Result(result)
411+
if result.extra.is_some()
412+
))
401413
));
402414
}
403415

0 commit comments

Comments
 (0)