diff --git a/crates/mcp-client/Cargo.toml b/crates/mcp-client/Cargo.toml index e54836da..baf194f4 100644 --- a/crates/mcp-client/Cargo.toml +++ b/crates/mcp-client/Cargo.toml @@ -14,7 +14,6 @@ eventsource-client = "0.12.0" futures = "0.3" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" -async-trait = "0.1.83" url = "2.5.4" thiserror = "1.0" anyhow = "1.0" diff --git a/crates/mcp-client/src/client.rs b/crates/mcp-client/src/client.rs index 0d722e55..9d93d7ac 100644 --- a/crates/mcp-client/src/client.rs +++ b/crates/mcp-client/src/client.rs @@ -5,7 +5,7 @@ use mcp_core::protocol::{ }; use serde::{Deserialize, Serialize}; use serde_json::Value; -use std::sync::atomic::{AtomicU64, Ordering}; +use std::{future::Future, sync::atomic::{AtomicU64, Ordering}}; use thiserror::Error; use tokio::sync::Mutex; use tower::{Service, ServiceExt}; // for Service::ready() @@ -75,28 +75,27 @@ pub struct InitializeParams { pub client_info: ClientInfo, } -#[async_trait::async_trait] pub trait McpClientTrait: Send + Sync { - async fn initialize( + fn initialize( &mut self, info: ClientInfo, capabilities: ClientCapabilities, - ) -> Result; + ) -> impl Future> + Send; - async fn list_resources( + fn list_resources( &self, next_cursor: Option, - ) -> Result; + ) -> impl Future> + Send; - async fn read_resource(&self, uri: &str) -> Result; + fn read_resource(&self, uri: &str) -> impl Future> + Send; - async fn list_tools(&self, next_cursor: Option) -> Result; + fn list_tools(&self, next_cursor: Option) -> impl Future> + Send; - async fn call_tool(&self, name: &str, arguments: Value) -> Result; + fn call_tool(&self, name: &str, arguments: Value) -> impl Future> + Send; - async fn list_prompts(&self, next_cursor: Option) -> Result; + fn list_prompts(&self, next_cursor: Option) -> impl Future> + Send; - async fn get_prompt(&self, name: &str, arguments: Value) -> Result; + fn get_prompt(&self, name: &str, arguments: Value) -> impl Future> + Send; } /// The MCP client is the interface for MCP operations. @@ -232,7 +231,6 @@ where } } -#[async_trait::async_trait] impl McpClientTrait for McpClient where S: Service + Clone + Send + Sync + 'static, diff --git a/crates/mcp-client/src/transport/mod.rs b/crates/mcp-client/src/transport/mod.rs index 25bcef74..d5f56155 100644 --- a/crates/mcp-client/src/transport/mod.rs +++ b/crates/mcp-client/src/transport/mod.rs @@ -1,8 +1,7 @@ -use async_trait::async_trait; use mcp_core::protocol::JsonRpcMessage; -use std::collections::HashMap; +use std::{collections::HashMap, future::Future}; use thiserror::Error; -use tokio::sync::{mpsc, oneshot, RwLock}; +use tokio::sync::{RwLock, mpsc, oneshot}; pub type BoxError = Box; /// A generic error type for transport operations. @@ -43,21 +42,22 @@ pub struct TransportMessage { } /// A generic asynchronous transport trait with channel-based communication -#[async_trait] pub trait Transport { type Handle: TransportHandle; /// Start the transport and establish the underlying connection. /// Returns the transport handle for sending messages. - async fn start(&self) -> Result; + fn start(&self) -> impl Future> + Send; /// Close the transport and free any resources. - async fn close(&self) -> Result<(), Error>; + fn close(&self) -> impl Future> + Send; } -#[async_trait] pub trait TransportHandle: Send + Sync + Clone + 'static { - async fn send(&self, message: JsonRpcMessage) -> Result; + fn send( + &self, + message: JsonRpcMessage, + ) -> impl Future> + Send; } // Helper function that contains the common send implementation diff --git a/crates/mcp-client/src/transport/sse.rs b/crates/mcp-client/src/transport/sse.rs index 90dc5f2f..e1afbff9 100644 --- a/crates/mcp-client/src/transport/sse.rs +++ b/crates/mcp-client/src/transport/sse.rs @@ -1,5 +1,4 @@ use crate::transport::{Error, PendingRequests, TransportMessage}; -use async_trait::async_trait; use eventsource_client::{Client, SSE}; use futures::TryStreamExt; use mcp_core::protocol::{JsonRpcMessage, JsonRpcRequest}; @@ -220,7 +219,6 @@ pub struct SseTransportHandle { sender: mpsc::Sender, } -#[async_trait::async_trait] impl TransportHandle for SseTransportHandle { async fn send(&self, message: JsonRpcMessage) -> Result { send_message(&self.sender, message).await @@ -262,7 +260,6 @@ impl SseTransport { } } -#[async_trait] impl Transport for SseTransport { type Handle = SseTransportHandle; diff --git a/crates/mcp-client/src/transport/stdio.rs b/crates/mcp-client/src/transport/stdio.rs index 7980816b..688e52ec 100644 --- a/crates/mcp-client/src/transport/stdio.rs +++ b/crates/mcp-client/src/transport/stdio.rs @@ -2,7 +2,6 @@ use std::collections::HashMap; use std::sync::Arc; use tokio::process::{Child, ChildStderr, ChildStdin, ChildStdout, Command}; -use async_trait::async_trait; use mcp_core::protocol::JsonRpcMessage; use tokio::io::{AsyncBufReadExt, AsyncReadExt, AsyncWriteExt, BufReader}; use tokio::sync::{mpsc, Mutex}; @@ -161,7 +160,6 @@ pub struct StdioTransportHandle { error_receiver: Arc>>, } -#[async_trait::async_trait] impl TransportHandle for StdioTransportHandle { async fn send(&self, message: JsonRpcMessage) -> Result { let result = send_message(&self.sender, message).await; @@ -244,7 +242,6 @@ impl StdioTransport { } } -#[async_trait] impl Transport for StdioTransport { type Handle = StdioTransportHandle; diff --git a/crates/mcp-core/Cargo.toml b/crates/mcp-core/Cargo.toml index 4550598a..7df327d3 100644 --- a/crates/mcp-core/Cargo.toml +++ b/crates/mcp-core/Cargo.toml @@ -8,7 +8,6 @@ description = "Core types for Model Context Protocol" [dependencies] -async-trait = "0.1" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" thiserror = "1.0" diff --git a/crates/mcp-core/src/handler.rs b/crates/mcp-core/src/handler.rs index 338fe94e..5f02157b 100644 --- a/crates/mcp-core/src/handler.rs +++ b/crates/mcp-core/src/handler.rs @@ -1,4 +1,5 @@ -use async_trait::async_trait; +use std::future::Future; + use schemars::JsonSchema; use serde::{Deserialize, Serialize}; use serde_json::Value; @@ -38,7 +39,6 @@ pub enum PromptError { } /// Trait for implementing MCP tools -#[async_trait] pub trait ToolHandler: Send + Sync + 'static { /// The name of the tool fn name(&self) -> &'static str; @@ -50,11 +50,10 @@ pub trait ToolHandler: Send + Sync + 'static { fn schema(&self) -> Value; /// Execute the tool with the given parameters - async fn call(&self, params: Value) -> ToolResult; + fn call(&self, params: Value) -> impl Future> + Send; } /// Trait for implementing MCP resources -#[async_trait] pub trait ResourceTemplateHandler: Send + Sync + 'static { /// The URL template for this resource fn template() -> &'static str; @@ -63,7 +62,7 @@ pub trait ResourceTemplateHandler: Send + Sync + 'static { fn schema() -> Value; /// Get the resource value - async fn get(&self, params: Value) -> ToolResult; + fn get(&self, params: Value) -> impl Future>; } /// Helper function to generate JSON schema for a type diff --git a/crates/mcp-macros/Cargo.toml b/crates/mcp-macros/Cargo.toml index 65a2046d..290efe75 100644 --- a/crates/mcp-macros/Cargo.toml +++ b/crates/mcp-macros/Cargo.toml @@ -13,12 +13,10 @@ proc-macro2 = "1.0" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" mcp-core = { path = "../mcp-core" } -async-trait = "0.1" schemars = "0.8" convert_case = "0.6.0" [dev-dependencies] tokio = { version = "1.0", features = ["full"] } -async-trait = "0.1" serde_json = "1.0" schemars = "0.8" diff --git a/crates/mcp-server/Cargo.toml b/crates/mcp-server/Cargo.toml index 6baa7fe8..4f57b278 100644 --- a/crates/mcp-server/Cargo.toml +++ b/crates/mcp-server/Cargo.toml @@ -22,4 +22,3 @@ pin-project = "1.1" tracing = "0.1" tracing-subscriber = { version = "0.3", features = ["env-filter"] } tracing-appender = "0.2" -async-trait = "0.1" diff --git a/examples/macros/Cargo.toml b/examples/macros/Cargo.toml index e7193160..868a8d70 100644 --- a/examples/macros/Cargo.toml +++ b/examples/macros/Cargo.toml @@ -10,7 +10,6 @@ mcp-macros = { path = "../../crates/mcp-macros" } tokio = { version = "1", features = ["full"] } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" -async-trait = "0.1" schemars = "0.8" [[example]]