From 0aa759ca0b2227618ee1d7849572f55bfffabae0 Mon Sep 17 00:00:00 2001 From: Adri Date: Fri, 27 Jun 2025 11:28:31 +0200 Subject: [PATCH 1/2] Test tracing instead of eprint --- .../rust-mcp-sdk/src/mcp_handlers/mcp_client_handler.rs | 3 ++- .../src/mcp_handlers/mcp_client_handler_core.rs | 3 ++- crates/rust-mcp-sdk/src/mcp_runtimes/client_runtime.rs | 3 ++- crates/rust-mcp-transport/src/client_sse.rs | 3 ++- crates/rust-mcp-transport/src/mcp_stream.rs | 8 ++++++-- crates/rust-mcp-transport/src/utils/sse_stream.rs | 8 ++++++-- 6 files changed, 20 insertions(+), 8 deletions(-) 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 c7e11bc..60c3f6f 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,8 @@ pub trait ClientHandler: Send + Sync + 'static { runtime: &dyn McpClient, ) -> std::result::Result<(), RpcError> { if !runtime.is_shut_down().await { - eprintln!("Process error: {}", error_message); + tracing::error!("Process error: {}", error_message); + //eprintln!("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 0c29016..fcbe129 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,8 @@ pub trait ClientHandlerCore: Send + Sync + 'static { runtime: &dyn McpClient, ) -> std::result::Result<(), RpcError> { if !runtime.is_shut_down().await { - eprintln!("Process error: {}", error_message); + tracing::error!("Process error: {}", error_message); + //eprintln!("Process error: {}", error_message); } Ok(()) } 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 d6e1e86..5e9347e 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,8 @@ impl McpClient for ClientRuntime { break; } Err(e) => { - eprintln!("Error reading from std_err: {}", e); + tracing::error!("Error reading from std_err: {}", e); + //eprintln!("Error reading from std_err: {}", e); break; } } diff --git a/crates/rust-mcp-transport/src/client_sse.rs b/crates/rust-mcp-transport/src/client_sse.rs index cadf03a..ead4c3b 100644 --- a/crates/rust-mcp-transport/src/client_sse.rs +++ b/crates/rust-mcp-transport/src/client_sse.rs @@ -258,7 +258,8 @@ 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 { - eprintln!("Failed to POST message: {:?}", e); + tracing::error!("Failed to POST message: {:?}", e); + //eprintln!("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 f5ed223..ed2f1c9 100644 --- a/crates/rust-mcp-transport/src/mcp_stream.rs +++ b/crates/rust-mcp-transport/src/mcp_stream.rs @@ -123,10 +123,14 @@ impl MCPStream { //An error that is unrelated to a request. tx.send(message).map_err(GenericSendError::new)?; } else { - eprintln!( - "Error: Received response does not correspond to any request. {:?}", + tracing::warn!( + "Received response or error without a matching request: {:?}", &message.is_response() ); + //eprintln!( + // "Error: Received response does not correspond to any request. {:?}", + // &message.is_response() + //); } } } else { diff --git a/crates/rust-mcp-transport/src/utils/sse_stream.rs b/crates/rust-mcp-transport/src/utils/sse_stream.rs index e71ff18..c796861 100644 --- a/crates/rust-mcp-transport/src/utils/sse_stream.rs +++ b/crates/rust-mcp-transport/src/utils/sse_stream.rs @@ -67,7 +67,8 @@ impl SseStream { { Ok(resp) => resp, Err(e) => { - eprintln!("Failed to connect to SSE: {}", e); + tracing::error!("Failed to connect to SSE: {}", e); + //eprintln!("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() { @@ -159,7 +160,10 @@ impl SseStream { if !content.is_empty() { let bytes = Bytes::copy_from_slice(content.as_bytes()); if self.read_tx.send(bytes).await.is_err() { - eprintln!("Readable stream closed, shutting down SSE task"); + tracing::error!( + "Readable stream closed, shutting down SSE task" + ); + //eprintln!("Readable stream closed, shutting down SSE task"); if !endpoint_event_received { if let Some(tx) = endpoint_event_tx.take() { let _ = tx.send(None); From a292d5433cf5673021db502c84d43154b1d25f42 Mon Sep 17 00:00:00 2001 From: Adri Date: Fri, 27 Jun 2025 11:32:21 +0200 Subject: [PATCH 2/2] remove comments --- crates/rust-mcp-sdk/src/mcp_handlers/mcp_client_handler.rs | 1 - .../rust-mcp-sdk/src/mcp_handlers/mcp_client_handler_core.rs | 1 - crates/rust-mcp-sdk/src/mcp_runtimes/client_runtime.rs | 1 - crates/rust-mcp-transport/src/client_sse.rs | 1 - crates/rust-mcp-transport/src/mcp_stream.rs | 4 ---- crates/rust-mcp-transport/src/utils/sse_stream.rs | 2 -- 6 files changed, 10 deletions(-) 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 60c3f6f..4f6f93b 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 @@ -145,7 +145,6 @@ pub trait ClientHandler: Send + Sync + 'static { ) -> std::result::Result<(), RpcError> { if !runtime.is_shut_down().await { tracing::error!("Process error: {}", error_message); - //eprintln!("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 fcbe129..ee07028 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 @@ -49,7 +49,6 @@ pub trait ClientHandlerCore: Send + Sync + 'static { ) -> std::result::Result<(), RpcError> { if !runtime.is_shut_down().await { tracing::error!("Process error: {}", error_message); - //eprintln!("Process error: {}", error_message); } Ok(()) } 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 5e9347e..ff95e15 100644 --- a/crates/rust-mcp-sdk/src/mcp_runtimes/client_runtime.rs +++ b/crates/rust-mcp-sdk/src/mcp_runtimes/client_runtime.rs @@ -119,7 +119,6 @@ impl McpClient for ClientRuntime { } Err(e) => { tracing::error!("Error reading from std_err: {}", e); - //eprintln!("Error reading from std_err: {}", e); break; } } diff --git a/crates/rust-mcp-transport/src/client_sse.rs b/crates/rust-mcp-transport/src/client_sse.rs index ead4c3b..b8e55eb 100644 --- a/crates/rust-mcp-transport/src/client_sse.rs +++ b/crates/rust-mcp-transport/src/client_sse.rs @@ -259,7 +259,6 @@ where 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); - //eprintln!("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 ed2f1c9..0d3067f 100644 --- a/crates/rust-mcp-transport/src/mcp_stream.rs +++ b/crates/rust-mcp-transport/src/mcp_stream.rs @@ -127,10 +127,6 @@ impl MCPStream { "Received response or error without a matching request: {:?}", &message.is_response() ); - //eprintln!( - // "Error: Received response does not correspond to any request. {:?}", - // &message.is_response() - //); } } } else { diff --git a/crates/rust-mcp-transport/src/utils/sse_stream.rs b/crates/rust-mcp-transport/src/utils/sse_stream.rs index c796861..cad8791 100644 --- a/crates/rust-mcp-transport/src/utils/sse_stream.rs +++ b/crates/rust-mcp-transport/src/utils/sse_stream.rs @@ -68,7 +68,6 @@ impl SseStream { Ok(resp) => resp, Err(e) => { tracing::error!("Failed to connect to SSE: {}", e); - //eprintln!("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() { @@ -163,7 +162,6 @@ impl SseStream { tracing::error!( "Readable stream closed, shutting down SSE task" ); - //eprintln!("Readable stream closed, shutting down SSE task"); if !endpoint_event_received { if let Some(tx) = endpoint_event_tx.take() { let _ = tx.send(None);