Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion crates/mcp-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
22 changes: 10 additions & 12 deletions crates/mcp-client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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<InitializeResult, Error>;
) -> impl Future<Output = Result<InitializeResult, Error>> + Send;

async fn list_resources(
fn list_resources(
&self,
next_cursor: Option<String>,
) -> Result<ListResourcesResult, Error>;
) -> impl Future<Output = Result<ListResourcesResult, Error>> + Send;

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

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

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

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

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

/// The MCP client is the interface for MCP operations.
Expand Down Expand Up @@ -232,7 +231,6 @@ where
}
}

#[async_trait::async_trait]
impl<S> McpClientTrait for McpClient<S>
where
S: Service<JsonRpcMessage, Response = JsonRpcMessage> + Clone + Send + Sync + 'static,
Expand Down
16 changes: 8 additions & 8 deletions crates/mcp-client/src/transport/mod.rs
Original file line number Diff line number Diff line change
@@ -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<dyn std::error::Error + Sync + Send>;
/// A generic error type for transport operations.
Expand Down Expand Up @@ -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<Self::Handle, Error>;
fn start(&self) -> impl Future<Output = Result<Self::Handle, Error>> + Send;

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

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

// Helper function that contains the common send implementation
Expand Down
3 changes: 0 additions & 3 deletions crates/mcp-client/src/transport/sse.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -220,7 +219,6 @@ pub struct SseTransportHandle {
sender: mpsc::Sender<TransportMessage>,
}

#[async_trait::async_trait]
impl TransportHandle for SseTransportHandle {
async fn send(&self, message: JsonRpcMessage) -> Result<JsonRpcMessage, Error> {
send_message(&self.sender, message).await
Expand Down Expand Up @@ -262,7 +260,6 @@ impl SseTransport {
}
}

#[async_trait]
impl Transport for SseTransport {
type Handle = SseTransportHandle;

Expand Down
3 changes: 0 additions & 3 deletions crates/mcp-client/src/transport/stdio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -161,7 +160,6 @@ pub struct StdioTransportHandle {
error_receiver: Arc<Mutex<mpsc::Receiver<Error>>>,
}

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

#[async_trait]
impl Transport for StdioTransport {
type Handle = StdioTransportHandle;

Expand Down
1 change: 0 additions & 1 deletion crates/mcp-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
9 changes: 4 additions & 5 deletions crates/mcp-core/src/handler.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use async_trait::async_trait;
use std::future::Future;

use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use serde_json::Value;
Expand Down Expand Up @@ -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;
Expand All @@ -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<Value>;
fn call(&self, params: Value) -> impl Future<Output = ToolResult<Value>> + Send;
}

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

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

/// Helper function to generate JSON schema for a type
Expand Down
2 changes: 0 additions & 2 deletions crates/mcp-macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
1 change: 0 additions & 1 deletion crates/mcp-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
1 change: 0 additions & 1 deletion examples/macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]]
Expand Down
Loading