From a8f988f73febe5b8af23fa26a4ce0673e92f4b34 Mon Sep 17 00:00:00 2001 From: Ali Hashemi Date: Wed, 30 Apr 2025 21:52:14 -0300 Subject: [PATCH] fix: remove unnecessary error wrapper --- .github/workflows/ci.yml | 10 ++++++++++ .../rust-mcp-sdk/src/mcp_runtimes/client_runtime.rs | 7 +++---- .../rust-mcp-sdk/src/mcp_runtimes/server_runtime.rs | 6 +++--- crates/rust-mcp-sdk/src/mcp_traits/mcp_client.rs | 12 ++++++------ 4 files changed, 22 insertions(+), 13 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 20cfa56..882dd90 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,6 +21,16 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 + - name: Cache Rust + uses: actions/cache@v4 + with: + path: | + ~/.rustup/toolchains + ~/.cargo/registry + ~/.cargo/git + target + key: ${{ runner.os }}-rust-${{ steps.toolchain.outputs.cachekey }} + restore-keys: ${{ runner.os }}-rust- - name: Install Rust Toolchain uses: dtolnay/rust-toolchain@master 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 85e9304..36cb5dd 100644 --- a/crates/rust-mcp-sdk/src/mcp_runtimes/client_runtime.rs +++ b/crates/rust-mcp-sdk/src/mcp_runtimes/client_runtime.rs @@ -128,10 +128,9 @@ impl McpClient for ClientRuntime { let main_task = tokio::spawn(async move { let sender = self_clone.sender().await.read().await; - let sender = sender.as_ref().ok_or(crate::error::McpSdkError::SdkError( - schema_utils::SdkError::connection_closed(), - ))?; - + let sender = sender + .as_ref() + .ok_or(schema_utils::SdkError::connection_closed())?; while let Some(mcp_message) = stream.next().await { let self_ref = &*self_clone; diff --git a/crates/rust-mcp-sdk/src/mcp_runtimes/server_runtime.rs b/crates/rust-mcp-sdk/src/mcp_runtimes/server_runtime.rs index 1ec971d..afb0d46 100644 --- a/crates/rust-mcp-sdk/src/mcp_runtimes/server_runtime.rs +++ b/crates/rust-mcp-sdk/src/mcp_runtimes/server_runtime.rs @@ -84,9 +84,9 @@ impl McpServer for ServerRuntime { } let sender = self.sender().await.read().await; - let sender = sender.as_ref().ok_or(crate::error::McpSdkError::SdkError( - schema_utils::SdkError::connection_closed(), - ))?; + let sender = sender + .as_ref() + .ok_or(schema_utils::SdkError::connection_closed())?; self.handler.on_server_started(self).await; diff --git a/crates/rust-mcp-sdk/src/mcp_traits/mcp_client.rs b/crates/rust-mcp-sdk/src/mcp_traits/mcp_client.rs index 00af015..909dea9 100644 --- a/crates/rust-mcp-sdk/src/mcp_traits/mcp_client.rs +++ b/crates/rust-mcp-sdk/src/mcp_traits/mcp_client.rs @@ -172,9 +172,9 @@ pub trait McpClient: Sync + Send { /// Otherwise, it returns the result from the server. async fn request(&self, request: RequestFromClient) -> SdkResult { let sender = self.sender().await.read().await; - let sender = sender.as_ref().ok_or(crate::error::McpSdkError::SdkError( - schema_utils::SdkError::connection_closed(), - ))?; + let sender = sender + .as_ref() + .ok_or(schema_utils::SdkError::connection_closed())?; // Send the request and receive the response. let response = sender @@ -198,9 +198,9 @@ pub trait McpClient: Sync + Send { /// the transport layer and does not wait for any acknowledgement or result. async fn send_notification(&self, notification: NotificationFromClient) -> SdkResult<()> { let sender = self.sender().await.read().await; - let sender = sender.as_ref().ok_or(crate::error::McpSdkError::SdkError( - schema_utils::SdkError::connection_closed(), - ))?; + let sender = sender + .as_ref() + .ok_or(schema_utils::SdkError::connection_closed())?; sender .send( MessageFromClient::NotificationFromClient(notification),