Skip to content

Commit 2cfd6f8

Browse files
committed
get rid of async-trait
1 parent c0bd94d commit 2cfd6f8

File tree

10 files changed

+22
-37
lines changed

10 files changed

+22
-37
lines changed

crates/mcp-client/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ eventsource-client = "0.12.0"
1414
futures = "0.3"
1515
serde = { version = "1.0", features = ["derive"] }
1616
serde_json = "1.0"
17-
async-trait = "0.1.83"
1817
url = "2.5.4"
1918
thiserror = "1.0"
2019
anyhow = "1.0"

crates/mcp-client/src/client.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use mcp_core::protocol::{
55
};
66
use serde::{Deserialize, Serialize};
77
use serde_json::Value;
8-
use std::sync::atomic::{AtomicU64, Ordering};
8+
use std::{future::Future, sync::atomic::{AtomicU64, Ordering}};
99
use thiserror::Error;
1010
use tokio::sync::Mutex;
1111
use tower::{Service, ServiceExt}; // for Service::ready()
@@ -75,28 +75,27 @@ pub struct InitializeParams {
7575
pub client_info: ClientInfo,
7676
}
7777

78-
#[async_trait::async_trait]
7978
pub trait McpClientTrait: Send + Sync {
80-
async fn initialize(
79+
fn initialize(
8180
&mut self,
8281
info: ClientInfo,
8382
capabilities: ClientCapabilities,
84-
) -> Result<InitializeResult, Error>;
83+
) -> impl Future<Output = Result<InitializeResult, Error>> + Send;
8584

86-
async fn list_resources(
85+
fn list_resources(
8786
&self,
8887
next_cursor: Option<String>,
89-
) -> Result<ListResourcesResult, Error>;
88+
) -> impl Future<Output = Result<ListResourcesResult, Error>> + Send;
9089

91-
async fn read_resource(&self, uri: &str) -> Result<ReadResourceResult, Error>;
90+
fn read_resource(&self, uri: &str) -> impl Future<Output = Result<ReadResourceResult, Error>> + Send;
9291

93-
async fn list_tools(&self, next_cursor: Option<String>) -> Result<ListToolsResult, Error>;
92+
fn list_tools(&self, next_cursor: Option<String>) -> impl Future<Output = Result<ListToolsResult, Error>> + Send;
9493

95-
async fn call_tool(&self, name: &str, arguments: Value) -> Result<CallToolResult, Error>;
94+
fn call_tool(&self, name: &str, arguments: Value) -> impl Future<Output = Result<CallToolResult, Error>> + Send;
9695

97-
async fn list_prompts(&self, next_cursor: Option<String>) -> Result<ListPromptsResult, Error>;
96+
fn list_prompts(&self, next_cursor: Option<String>) -> impl Future<Output = Result<ListPromptsResult, Error>> + Send;
9897

99-
async fn get_prompt(&self, name: &str, arguments: Value) -> Result<GetPromptResult, Error>;
98+
fn get_prompt(&self, name: &str, arguments: Value) -> impl Future<Output = Result<GetPromptResult, Error>> + Send;
10099
}
101100

102101
/// The MCP client is the interface for MCP operations.
@@ -232,7 +231,6 @@ where
232231
}
233232
}
234233

235-
#[async_trait::async_trait]
236234
impl<S> McpClientTrait for McpClient<S>
237235
where
238236
S: Service<JsonRpcMessage, Response = JsonRpcMessage> + Clone + Send + Sync + 'static,

crates/mcp-client/src/transport/mod.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
use async_trait::async_trait;
21
use mcp_core::protocol::JsonRpcMessage;
3-
use std::collections::HashMap;
2+
use std::{collections::HashMap, future::Future};
43
use thiserror::Error;
5-
use tokio::sync::{mpsc, oneshot, RwLock};
4+
use tokio::sync::{RwLock, mpsc, oneshot};
65

76
pub type BoxError = Box<dyn std::error::Error + Sync + Send>;
87
/// A generic error type for transport operations.
@@ -43,21 +42,22 @@ pub struct TransportMessage {
4342
}
4443

4544
/// A generic asynchronous transport trait with channel-based communication
46-
#[async_trait]
4745
pub trait Transport {
4846
type Handle: TransportHandle;
4947

5048
/// Start the transport and establish the underlying connection.
5149
/// Returns the transport handle for sending messages.
52-
async fn start(&self) -> Result<Self::Handle, Error>;
50+
fn start(&self) -> impl Future<Output = Result<Self::Handle, Error>> + Send;
5351

5452
/// Close the transport and free any resources.
55-
async fn close(&self) -> Result<(), Error>;
53+
fn close(&self) -> impl Future<Output = Result<(), Error>> + Send;
5654
}
5755

58-
#[async_trait]
5956
pub trait TransportHandle: Send + Sync + Clone + 'static {
60-
async fn send(&self, message: JsonRpcMessage) -> Result<JsonRpcMessage, Error>;
57+
fn send(
58+
&self,
59+
message: JsonRpcMessage,
60+
) -> impl Future<Output = Result<JsonRpcMessage, Error>> + Send;
6161
}
6262

6363
// Helper function that contains the common send implementation

crates/mcp-client/src/transport/sse.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use crate::transport::{Error, PendingRequests, TransportMessage};
2-
use async_trait::async_trait;
32
use eventsource_client::{Client, SSE};
43
use futures::TryStreamExt;
54
use mcp_core::protocol::{JsonRpcMessage, JsonRpcRequest};
@@ -220,7 +219,6 @@ pub struct SseTransportHandle {
220219
sender: mpsc::Sender<TransportMessage>,
221220
}
222221

223-
#[async_trait::async_trait]
224222
impl TransportHandle for SseTransportHandle {
225223
async fn send(&self, message: JsonRpcMessage) -> Result<JsonRpcMessage, Error> {
226224
send_message(&self.sender, message).await
@@ -262,7 +260,6 @@ impl SseTransport {
262260
}
263261
}
264262

265-
#[async_trait]
266263
impl Transport for SseTransport {
267264
type Handle = SseTransportHandle;
268265

crates/mcp-client/src/transport/stdio.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use std::collections::HashMap;
22
use std::sync::Arc;
33
use tokio::process::{Child, ChildStderr, ChildStdin, ChildStdout, Command};
44

5-
use async_trait::async_trait;
65
use mcp_core::protocol::JsonRpcMessage;
76
use tokio::io::{AsyncBufReadExt, AsyncReadExt, AsyncWriteExt, BufReader};
87
use tokio::sync::{mpsc, Mutex};
@@ -161,7 +160,6 @@ pub struct StdioTransportHandle {
161160
error_receiver: Arc<Mutex<mpsc::Receiver<Error>>>,
162161
}
163162

164-
#[async_trait::async_trait]
165163
impl TransportHandle for StdioTransportHandle {
166164
async fn send(&self, message: JsonRpcMessage) -> Result<JsonRpcMessage, Error> {
167165
let result = send_message(&self.sender, message).await;
@@ -244,7 +242,6 @@ impl StdioTransport {
244242
}
245243
}
246244

247-
#[async_trait]
248245
impl Transport for StdioTransport {
249246
type Handle = StdioTransportHandle;
250247

crates/mcp-core/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ description = "Core types for Model Context Protocol"
88

99

1010
[dependencies]
11-
async-trait = "0.1"
1211
serde = { version = "1.0", features = ["derive"] }
1312
serde_json = "1.0"
1413
thiserror = "1.0"

crates/mcp-core/src/handler.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
use async_trait::async_trait;
1+
use std::future::Future;
2+
23
use schemars::JsonSchema;
34
use serde::{Deserialize, Serialize};
45
use serde_json::Value;
@@ -38,7 +39,6 @@ pub enum PromptError {
3839
}
3940

4041
/// Trait for implementing MCP tools
41-
#[async_trait]
4242
pub trait ToolHandler: Send + Sync + 'static {
4343
/// The name of the tool
4444
fn name(&self) -> &'static str;
@@ -50,11 +50,10 @@ pub trait ToolHandler: Send + Sync + 'static {
5050
fn schema(&self) -> Value;
5151

5252
/// Execute the tool with the given parameters
53-
async fn call(&self, params: Value) -> ToolResult<Value>;
53+
fn call(&self, params: Value) -> impl Future<Output = ToolResult<Value>> + Send;
5454
}
5555

5656
/// Trait for implementing MCP resources
57-
#[async_trait]
5857
pub trait ResourceTemplateHandler: Send + Sync + 'static {
5958
/// The URL template for this resource
6059
fn template() -> &'static str;
@@ -63,7 +62,7 @@ pub trait ResourceTemplateHandler: Send + Sync + 'static {
6362
fn schema() -> Value;
6463

6564
/// Get the resource value
66-
async fn get(&self, params: Value) -> ToolResult<String>;
65+
fn get(&self, params: Value) -> impl Future<Output = ToolResult<String>>;
6766
}
6867

6968
/// Helper function to generate JSON schema for a type

crates/mcp-macros/Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,10 @@ proc-macro2 = "1.0"
1313
serde = { version = "1.0", features = ["derive"] }
1414
serde_json = "1.0"
1515
mcp-core = { path = "../mcp-core" }
16-
async-trait = "0.1"
1716
schemars = "0.8"
1817
convert_case = "0.6.0"
1918

2019
[dev-dependencies]
2120
tokio = { version = "1.0", features = ["full"] }
22-
async-trait = "0.1"
2321
serde_json = "1.0"
2422
schemars = "0.8"

crates/mcp-server/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,3 @@ pin-project = "1.1"
2222
tracing = "0.1"
2323
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
2424
tracing-appender = "0.2"
25-
async-trait = "0.1"

examples/macros/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ mcp-macros = { path = "../../crates/mcp-macros" }
1010
tokio = { version = "1", features = ["full"] }
1111
serde = { version = "1.0", features = ["derive"] }
1212
serde_json = "1.0"
13-
async-trait = "0.1"
1413
schemars = "0.8"
1514

1615
[[example]]

0 commit comments

Comments
 (0)