Skip to content

fix: custom result deserialization conflic with rust_mcp_schema::Result #44

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ run_clippy = [
"--features",
"latest schema_utils",
"--fix",
"--allow-dirty",
"--",
"-A",
"deprecated",
"-D",
"warnings",
]
Expand Down
2 changes: 1 addition & 1 deletion scripts/run_clippy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ COMMON_FEATURES_STR="${COMMON_FEATURES[*]}"

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

# stop on failure
if [ $? -ne 0 ]; then
Expand Down
10 changes: 5 additions & 5 deletions src/generated_schema/2024_11_05/mcp_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
/// modify or extend the implementations as needed, but please do so at your own risk.
///
/// Generated from : <https://github.com/modelcontextprotocol/specification.git>
/// Hash : bb1446ff1810a0df57989d78366d626d2c01b9d7
/// Generated at : 2025-03-02 12:41:59
/// Hash : 6828f3ef6300b25dd2aaff2a2e5e81188bdbd22e
/// Generated at : 2025-03-08 08:33:48
/// ----------------------------------------------------------------------------
///
/// MCP Protocol Version
Expand Down Expand Up @@ -5155,7 +5155,7 @@ impl ::std::convert::From<Result> for ServerResult {
/// ],
/// "properties": {
/// "level": {
/// "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.",
/// "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.",
/// "$ref": "#/definitions/LoggingLevel"
/// }
/// }
Expand Down Expand Up @@ -5192,7 +5192,7 @@ impl SetLevelRequest {
/// ],
/// "properties": {
/// "level": {
/// "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.",
/// "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.",
/// "$ref": "#/definitions/LoggingLevel"
/// }
/// }
Expand All @@ -5201,7 +5201,7 @@ impl SetLevelRequest {
/// </details>
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
pub struct SetLevelRequestParams {
///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.
///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.
pub level: LoggingLevel,
}
///Sent from the client to request resources/updated notifications from the server whenever a particular resource changes.
Expand Down
10 changes: 3 additions & 7 deletions src/generated_schema/2024_11_05/schema_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,7 @@ impl FromStr for ClientJsonrpcResponse {
#[serde(untagged)]
pub enum ResultFromClient {
ClientResult(ClientResult),
#[deprecated(since = "0.1.8", note = "Use `ClientResult::Result` with extra attributes instead.")]
CustomResult(serde_json::Value),
}

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

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

match result {
Ok(server_result) => {
if matches!(server_result, ServerResult::Result(_)) {
Ok(Self::CustomResult(raw_value))
} else {
Ok(Self::ServerResult(server_result))
}
}
Ok(server_result) => Ok(Self::ServerResult(server_result)),
Err(_) => Ok(Self::CustomResult(raw_value)),
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/generated_schema/draft/mcp_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
/// modify or extend the implementations as needed, but please do so at your own risk.
///
/// Generated from : <https://github.com/modelcontextprotocol/specification.git>
/// Hash : bb1446ff1810a0df57989d78366d626d2c01b9d7
/// Generated at : 2025-03-02 12:41:59
/// Hash : 6828f3ef6300b25dd2aaff2a2e5e81188bdbd22e
/// Generated at : 2025-03-08 08:33:48
/// ----------------------------------------------------------------------------
///
/// MCP Protocol Version
Expand Down Expand Up @@ -5289,7 +5289,7 @@ impl ::std::convert::From<Result> for ServerResult {
/// ],
/// "properties": {
/// "level": {
/// "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.",
/// "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.",
/// "$ref": "#/definitions/LoggingLevel"
/// }
/// }
Expand Down Expand Up @@ -5326,7 +5326,7 @@ impl SetLevelRequest {
/// ],
/// "properties": {
/// "level": {
/// "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.",
/// "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.",
/// "$ref": "#/definitions/LoggingLevel"
/// }
/// }
Expand All @@ -5335,7 +5335,7 @@ impl SetLevelRequest {
/// </details>
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
pub struct SetLevelRequestParams {
///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.
///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.
pub level: LoggingLevel,
}
///Sent from the client to request resources/updated notifications from the server whenever a particular resource changes.
Expand Down
8 changes: 1 addition & 7 deletions src/generated_schema/draft/schema_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1142,13 +1142,7 @@ impl<'de> serde::Deserialize<'de> for ResultFromServer {
let result = ServerResult::deserialize(&raw_value);

match result {
Ok(server_result) => {
if matches!(server_result, ServerResult::Result(_)) {
Ok(Self::CustomResult(raw_value))
} else {
Ok(Self::ServerResult(server_result))
}
}
Ok(server_result) => Ok(Self::ServerResult(server_result)),
Err(_) => Ok(Self::CustomResult(raw_value)),
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/test_deserialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ mod test_deserialize {
fn test_server_ping_result() {
let message = get_message("res_ping");
assert!(matches!(message, ServerMessage::Response(server_message)
if matches!(&server_message.result, ResultFromServer::CustomResult(_server_result))
if matches!(&server_message.result, ResultFromServer::ServerResult(_server_result))
));
}

Expand Down
18 changes: 15 additions & 3 deletions tests/test_serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,17 +387,29 @@ mod test_serialize {

#[test]
fn test_server_custom_result() {
let custom_result: serde_json::Map<String, serde_json::Value> = json!({
"custom_key":"custom_value",
"custom_number": 15.21
})
.as_object()
.unwrap()
.clone();

let message: ServerMessage = ServerMessage::Response(ServerJsonrpcResponse::new(
RequestId::Integer(15),
ResultFromServer::CustomResult(json!({
"result":{},"jsonrpc":"2.0","id":15
ResultFromServer::ServerResult(ServerResult::Result(Result {
meta: None,
extra: Some(custom_result),
})),
));

let message: ServerMessage = re_serialize(message);

assert!(matches!(message, ServerMessage::Response(server_message)
if matches!(&server_message.result, ResultFromServer::CustomResult(_))
if matches!(&server_message.result, ResultFromServer::ServerResult(server_result)
if matches!(server_result, ServerResult::Result(result)
if result.extra.is_some()
))
));
}

Expand Down