From 77dd6aef307ee6fa6dfa419c26d418e2b565a4db Mon Sep 17 00:00:00 2001 From: Vaiz <4908982+Vaiz@users.noreply.github.com> Date: Sat, 28 Jun 2025 22:46:05 +0200 Subject: [PATCH] clippy fixes --- crates/rust-mcp-macros/src/utils.rs | 3 +-- .../src/hyper_servers/routes/fallback_routes.rs | 2 +- .../src/mcp_handlers/mcp_client_handler.rs | 2 +- .../src/mcp_handlers/mcp_client_handler_core.rs | 2 +- .../src/mcp_handlers/mcp_server_handler.rs | 2 +- crates/rust-mcp-sdk/src/mcp_runtimes/client_runtime.rs | 2 +- .../server_runtime/mcp_server_runtime_core.rs | 2 +- crates/rust-mcp-sdk/src/utils.rs | 5 +---- crates/rust-mcp-sdk/tests/test_server_sse.rs | 6 +++--- crates/rust-mcp-transport/src/client_sse.rs | 10 +++++----- crates/rust-mcp-transport/src/mcp_stream.rs | 3 +-- crates/rust-mcp-transport/src/utils.rs | 8 ++++---- crates/rust-mcp-transport/src/utils/http_utils.rs | 2 +- crates/rust-mcp-transport/src/utils/sse_stream.rs | 2 +- examples/hello-world-mcp-server-core/src/handler.rs | 2 +- examples/hello-world-server-core-sse/src/handler.rs | 2 +- .../simple-mcp-client-core-sse/src/inquiry_utils.rs | 2 +- examples/simple-mcp-client-core/src/inquiry_utils.rs | 2 +- examples/simple-mcp-client-sse/src/inquiry_utils.rs | 2 +- examples/simple-mcp-client/src/inquiry_utils.rs | 2 +- 20 files changed, 29 insertions(+), 34 deletions(-) diff --git a/crates/rust-mcp-macros/src/utils.rs b/crates/rust-mcp-macros/src/utils.rs index b479ee9..0d4bbed 100644 --- a/crates/rust-mcp-macros/src/utils.rs +++ b/crates/rust-mcp-macros/src/utils.rs @@ -460,8 +460,7 @@ mod tests { let ty: syn::Type = syn::parse_str(ty_str).unwrap(); assert!( !might_be_struct(&ty), - "Expected '{}' to be not a struct", - ty_str + "Expected '{ty_str}' to be not a struct" ); } } diff --git a/crates/rust-mcp-sdk/src/hyper_servers/routes/fallback_routes.rs b/crates/rust-mcp-sdk/src/hyper_servers/routes/fallback_routes.rs index d6ae240..b76d5dc 100644 --- a/crates/rust-mcp-sdk/src/hyper_servers/routes/fallback_routes.rs +++ b/crates/rust-mcp-sdk/src/hyper_servers/routes/fallback_routes.rs @@ -10,6 +10,6 @@ pub fn routes() -> Router { pub async fn not_found(uri: Uri) -> (StatusCode, String) { ( StatusCode::INTERNAL_SERVER_ERROR, - format!("Server Error!\r\n uri: {}", uri), + format!("Server Error!\r\n uri: {uri}"), ) } diff --git a/crates/rust-mcp-sdk/src/mcp_handlers/mcp_client_handler.rs b/crates/rust-mcp-sdk/src/mcp_handlers/mcp_client_handler.rs index 4f6f93b..5f218bd 100644 --- a/crates/rust-mcp-sdk/src/mcp_handlers/mcp_client_handler.rs +++ b/crates/rust-mcp-sdk/src/mcp_handlers/mcp_client_handler.rs @@ -144,7 +144,7 @@ pub trait ClientHandler: Send + Sync + 'static { runtime: &dyn McpClient, ) -> std::result::Result<(), RpcError> { if !runtime.is_shut_down().await { - tracing::error!("Process error: {}", error_message); + tracing::error!("Process error: {error_message}"); } Ok(()) } diff --git a/crates/rust-mcp-sdk/src/mcp_handlers/mcp_client_handler_core.rs b/crates/rust-mcp-sdk/src/mcp_handlers/mcp_client_handler_core.rs index ee07028..3bbe5c9 100644 --- a/crates/rust-mcp-sdk/src/mcp_handlers/mcp_client_handler_core.rs +++ b/crates/rust-mcp-sdk/src/mcp_handlers/mcp_client_handler_core.rs @@ -48,7 +48,7 @@ pub trait ClientHandlerCore: Send + Sync + 'static { runtime: &dyn McpClient, ) -> std::result::Result<(), RpcError> { if !runtime.is_shut_down().await { - tracing::error!("Process error: {}", error_message); + tracing::error!("Process error: {error_message}"); } Ok(()) } diff --git a/crates/rust-mcp-sdk/src/mcp_handlers/mcp_server_handler.rs b/crates/rust-mcp-sdk/src/mcp_handlers/mcp_server_handler.rs index aa362e0..f1e129a 100644 --- a/crates/rust-mcp-sdk/src/mcp_handlers/mcp_server_handler.rs +++ b/crates/rust-mcp-sdk/src/mcp_handlers/mcp_server_handler.rs @@ -33,7 +33,7 @@ pub trait ServerHandler: Send + Sync + 'static { ) -> std::result::Result { runtime .set_client_details(initialize_request.params.clone()) - .map_err(|err| RpcError::internal_error().with_message(format!("{}", err)))?; + .map_err(|err| RpcError::internal_error().with_message(format!("{err}")))?; let mut server_info = runtime.server_info().to_owned(); // Provide compatibility for clients using older MCP protocol versions. diff --git a/crates/rust-mcp-sdk/src/mcp_runtimes/client_runtime.rs b/crates/rust-mcp-sdk/src/mcp_runtimes/client_runtime.rs index ff95e15..fb81612 100644 --- a/crates/rust-mcp-sdk/src/mcp_runtimes/client_runtime.rs +++ b/crates/rust-mcp-sdk/src/mcp_runtimes/client_runtime.rs @@ -118,7 +118,7 @@ impl McpClient for ClientRuntime { break; } Err(e) => { - tracing::error!("Error reading from std_err: {}", e); + tracing::error!("Error reading from std_err: {e}"); break; } } diff --git a/crates/rust-mcp-sdk/src/mcp_runtimes/server_runtime/mcp_server_runtime_core.rs b/crates/rust-mcp-sdk/src/mcp_runtimes/server_runtime/mcp_server_runtime_core.rs index 445322a..b2e021c 100644 --- a/crates/rust-mcp-sdk/src/mcp_runtimes/server_runtime/mcp_server_runtime_core.rs +++ b/crates/rust-mcp-sdk/src/mcp_runtimes/server_runtime/mcp_server_runtime_core.rs @@ -70,7 +70,7 @@ impl McpServerHandler for RuntimeCoreInternalHandler> // keep a copy of the InitializeRequestParams which includes client_info and capabilities runtime .set_client_details(initialize_request.params.clone()) - .map_err(|err| RpcError::internal_error().with_message(format!("{}", err)))?; + .map_err(|err| RpcError::internal_error().with_message(format!("{err}")))?; } // handle request and get the result diff --git a/crates/rust-mcp-sdk/src/utils.rs b/crates/rust-mcp-sdk/src/utils.rs index f0cfb70..e5b7206 100644 --- a/crates/rust-mcp-sdk/src/utils.rs +++ b/crates/rust-mcp-sdk/src/utils.rs @@ -21,10 +21,7 @@ use crate::error::{McpSdkError, SdkResult}; /// assert_eq!(msg, "Server does not support resources (required for resources/list)"); /// ``` pub fn format_assertion_message(entity: &str, capability: &str, method_name: &str) -> String { - format!( - "{} does not support {} (required for {})", - entity, capability, method_name - ) + format!("{entity} does not support {capability} (required for {method_name})") } /// Checks if the client and server protocol versions are compatible by ensuring they are equal. diff --git a/crates/rust-mcp-sdk/tests/test_server_sse.rs b/crates/rust-mcp-sdk/tests/test_server_sse.rs index 1d43811..1148cca 100644 --- a/crates/rust-mcp-sdk/tests/test_server_sse.rs +++ b/crates/rust-mcp-sdk/tests/test_server_sse.rs @@ -42,7 +42,7 @@ mod tets_server_sse { sleep(Duration::from_millis(750)).await; let client = Client::new(); - println!("connecting to : {}", server_endpoint); + println!("connecting to : {server_endpoint}"); // Act: Connect to the SSE endpoint and read the event stream let response = client .get(server_endpoint) @@ -105,7 +105,7 @@ mod tets_server_sse { sleep(Duration::from_millis(750)).await; let client = Client::new(); - println!("connecting to : {}", server_endpoint); + println!("connecting to : {server_endpoint}"); // Act: Connect to the SSE endpoint and read the event stream let response = client .get(server_endpoint) @@ -171,7 +171,7 @@ mod tets_server_sse { sleep(Duration::from_millis(750)).await; let client = Client::new(); - println!("connecting to : {}", server_endpoint); + println!("connecting to : {server_endpoint}"); // Act: Connect to the SSE endpoint and read the event stream let response = client .get(server_endpoint) diff --git a/crates/rust-mcp-transport/src/client_sse.rs b/crates/rust-mcp-transport/src/client_sse.rs index b8e55eb..310c07d 100644 --- a/crates/rust-mcp-transport/src/client_sse.rs +++ b/crates/rust-mcp-transport/src/client_sse.rs @@ -125,11 +125,11 @@ impl ClientSseTransport { let mut header_map = HeaderMap::new(); for (key, value) in headers { - let header_name = key.parse::().map_err(|e| { - TransportError::InvalidOptions(format!("Invalid header name: {}", e)) - })?; + let header_name = key + .parse::() + .map_err(|e| TransportError::InvalidOptions(format!("Invalid header name: {e}")))?; let header_value = HeaderValue::from_str(value).map_err(|e| { - TransportError::InvalidOptions(format!("Invalid header value: {}", e)) + TransportError::InvalidOptions(format!("Invalid header value: {e}")) })?; header_map.insert(header_name, header_value); } @@ -258,7 +258,7 @@ where // trim the trailing \n before making a request let body = String::from_utf8_lossy(&data).trim().to_string(); if let Err(e) = http_post(&client_clone, &post_url, body, &custom_headers).await { - tracing::error!("Failed to POST message: {:?}", e); + tracing::error!("Failed to POST message: {e:?}"); } }, None => break, // Exit if channel is closed diff --git a/crates/rust-mcp-transport/src/mcp_stream.rs b/crates/rust-mcp-transport/src/mcp_stream.rs index 0d3067f..e32de05 100644 --- a/crates/rust-mcp-transport/src/mcp_stream.rs +++ b/crates/rust-mcp-transport/src/mcp_stream.rs @@ -140,8 +140,7 @@ impl MCPStream { Err(e) => { // Handle error in reading from readable_std return Err(TransportError::ProcessError(format!( - "Error reading from readable_std: {}", - e + "Error reading from readable_std: {e}" ))); } } diff --git a/crates/rust-mcp-transport/src/utils.rs b/crates/rust-mcp-transport/src/utils.rs index e95aab4..218d517 100644 --- a/crates/rust-mcp-transport/src/utils.rs +++ b/crates/rust-mcp-transport/src/utils.rs @@ -67,14 +67,14 @@ pub(crate) fn endpoint_with_session_id(endpoint: &str, session_id: &SessionId) - // Build the query string let new_query = match query { - Some(q) if !q.is_empty() => format!("{}&sessionId={}", q, session_id), - _ => format!("sessionId={}", session_id), + Some(q) if !q.is_empty() => format!("{q}&sessionId={session_id}"), + _ => format!("sessionId={session_id}"), }; // Construct final URL match fragment { - Some(f) => format!("{}?{}#{}", path, new_query, f), - None => format!("{}?{}", path, new_query), + Some(f) => format!("{path}?{new_query}#{f}"), + None => format!("{path}?{new_query}"), } } diff --git a/crates/rust-mcp-transport/src/utils/http_utils.rs b/crates/rust-mcp-transport/src/utils/http_utils.rs index f8403e7..701dcb0 100644 --- a/crates/rust-mcp-transport/src/utils/http_utils.rs +++ b/crates/rust-mcp-transport/src/utils/http_utils.rs @@ -46,7 +46,7 @@ pub fn extract_origin(url: &str) -> Option { let host_port = &rest[..end]; // Reconstruct origin - Some(format!("{}://{}", scheme, host_port)) + Some(format!("{scheme}://{host_port}")) } #[cfg(test)] diff --git a/crates/rust-mcp-transport/src/utils/sse_stream.rs b/crates/rust-mcp-transport/src/utils/sse_stream.rs index cad8791..014ad12 100644 --- a/crates/rust-mcp-transport/src/utils/sse_stream.rs +++ b/crates/rust-mcp-transport/src/utils/sse_stream.rs @@ -67,7 +67,7 @@ impl SseStream { { Ok(resp) => resp, Err(e) => { - tracing::error!("Failed to connect to SSE: {}", e); + tracing::error!("Failed to connect to SSE: {e}"); if retry_count >= self.max_retries { tracing::error!("Max retries reached, giving up"); if let Some(tx) = endpoint_event_tx.take() { diff --git a/examples/hello-world-mcp-server-core/src/handler.rs b/examples/hello-world-mcp-server-core/src/handler.rs index 2927ba1..fcde15e 100644 --- a/examples/hello-world-mcp-server-core/src/handler.rs +++ b/examples/hello-world-mcp-server-core/src/handler.rs @@ -78,7 +78,7 @@ impl ServerHandlerCore for MyServerHandler { // Return Method not found for any other requests _ => Err(RpcError::method_not_found() - .with_message(format!("No handler is implemented for '{}'.", method_name,))), + .with_message(format!("No handler is implemented for '{method_name}'.",))), }, // Handle custom requests RequestFromClient::CustomRequest(_) => Err(RpcError::method_not_found() diff --git a/examples/hello-world-server-core-sse/src/handler.rs b/examples/hello-world-server-core-sse/src/handler.rs index 410d53a..82b0b2b 100644 --- a/examples/hello-world-server-core-sse/src/handler.rs +++ b/examples/hello-world-server-core-sse/src/handler.rs @@ -77,7 +77,7 @@ impl ServerHandlerCore for MyServerHandler { // Return Method not found for any other requests _ => Err(RpcError::method_not_found() - .with_message(format!("No handler is implemented for '{}'.", method_name,))), + .with_message(format!("No handler is implemented for '{method_name}'.",))), }, // Handle custom requests RequestFromClient::CustomRequest(_) => Err(RpcError::method_not_found() diff --git a/examples/simple-mcp-client-core-sse/src/inquiry_utils.rs b/examples/simple-mcp-client-core-sse/src/inquiry_utils.rs index 9ef39e7..a8e7c9c 100644 --- a/examples/simple-mcp-client-core-sse/src/inquiry_utils.rs +++ b/examples/simple-mcp-client-core-sse/src/inquiry_utils.rs @@ -202,7 +202,7 @@ impl InquiryUtils { let max_pings = n; println!(); for ping_index in 1..=max_pings { - print!("Ping the server ({} out of {})...", ping_index, max_pings); + print!("Ping the server ({ping_index} out of {max_pings})..."); std::io::stdout().flush().unwrap(); let ping_result = self.client.ping(None).await; print!( diff --git a/examples/simple-mcp-client-core/src/inquiry_utils.rs b/examples/simple-mcp-client-core/src/inquiry_utils.rs index 9ef39e7..a8e7c9c 100644 --- a/examples/simple-mcp-client-core/src/inquiry_utils.rs +++ b/examples/simple-mcp-client-core/src/inquiry_utils.rs @@ -202,7 +202,7 @@ impl InquiryUtils { let max_pings = n; println!(); for ping_index in 1..=max_pings { - print!("Ping the server ({} out of {})...", ping_index, max_pings); + print!("Ping the server ({ping_index} out of {max_pings})..."); std::io::stdout().flush().unwrap(); let ping_result = self.client.ping(None).await; print!( diff --git a/examples/simple-mcp-client-sse/src/inquiry_utils.rs b/examples/simple-mcp-client-sse/src/inquiry_utils.rs index 9ef39e7..a8e7c9c 100644 --- a/examples/simple-mcp-client-sse/src/inquiry_utils.rs +++ b/examples/simple-mcp-client-sse/src/inquiry_utils.rs @@ -202,7 +202,7 @@ impl InquiryUtils { let max_pings = n; println!(); for ping_index in 1..=max_pings { - print!("Ping the server ({} out of {})...", ping_index, max_pings); + print!("Ping the server ({ping_index} out of {max_pings})..."); std::io::stdout().flush().unwrap(); let ping_result = self.client.ping(None).await; print!( diff --git a/examples/simple-mcp-client/src/inquiry_utils.rs b/examples/simple-mcp-client/src/inquiry_utils.rs index 9ef39e7..a8e7c9c 100644 --- a/examples/simple-mcp-client/src/inquiry_utils.rs +++ b/examples/simple-mcp-client/src/inquiry_utils.rs @@ -202,7 +202,7 @@ impl InquiryUtils { let max_pings = n; println!(); for ping_index in 1..=max_pings { - print!("Ping the server ({} out of {})...", ping_index, max_pings); + print!("Ping the server ({ping_index} out of {max_pings})..."); std::io::stdout().flush().unwrap(); let ping_result = self.client.ping(None).await; print!(