pub trait McpDispatch<R, S, M, OM>:
Send
+ Sync
+ 'staticwhere
R: Clone + Send + Sync + DeserializeOwned + 'static,
S: Clone + Send + Sync + Serialize + 'static,
M: Clone + Send + Sync + DeserializeOwned + 'static,
OM: Clone + Send + Sync + DeserializeOwned + 'static,{
// Required methods
fn send_message<'life0, 'async_trait>(
&'life0 self,
message: S,
request_timeout: Option<Duration>,
) -> Pin<Box<dyn Future<Output = Result<Option<R>, TransportError>> + Send + 'async_trait>>
where 'life0: 'async_trait,
Self: 'async_trait;
fn send<'life0, 'async_trait>(
&'life0 self,
message: OM,
timeout: Option<Duration>,
) -> Pin<Box<dyn Future<Output = Result<Option<M>, TransportError>> + Send + 'async_trait>>
where 'life0: 'async_trait,
Self: 'async_trait;
fn send_batch<'life0, 'async_trait>(
&'life0 self,
message: Vec<OM>,
timeout: Option<Duration>,
) -> Pin<Box<dyn Future<Output = Result<Option<Vec<M>>, TransportError>> + Send + 'async_trait>>
where 'life0: 'async_trait,
Self: 'async_trait;
fn write_str<'life0, 'life1, 'async_trait>(
&'life0 self,
payload: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<(), TransportError>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait;
}
Expand description
A trait for dispatching MCP (Message Communication Protocol) messages.
This trait is designed to be implemented by components such as clients, servers, or transports that send and receive messages in the MCP protocol. It defines the interface for transmitting messages, optionally awaiting responses, writing raw payloads, and handling batch communication.
§Associated Types
R
: The response type expected from a message. This must implement deserialization and be safe for concurrent use in async contexts.S
: The type of the outgoing message sent directly to the wire. Must be serializable.M
: The internal message type used for responses received from a remote peer.OM
: The outgoing message type submitted to the dispatcher. This is the higher-level form ofS
used by clients or services submitting requests.
Required Methods§
Sourcefn send_message<'life0, 'async_trait>(
&'life0 self,
message: S,
request_timeout: Option<Duration>,
) -> Pin<Box<dyn Future<Output = Result<Option<R>, TransportError>> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
fn send_message<'life0, 'async_trait>(
&'life0 self,
message: S,
request_timeout: Option<Duration>,
) -> Pin<Box<dyn Future<Output = Result<Option<R>, TransportError>> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
Sends a raw message represented by type S
and optionally includes a request_id
.
The request_id
is used when sending a message in response to an MCP request.
It should match the request_id
of the original request.
fn send<'life0, 'async_trait>(
&'life0 self,
message: OM,
timeout: Option<Duration>,
) -> Pin<Box<dyn Future<Output = Result<Option<M>, TransportError>> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
fn send_batch<'life0, 'async_trait>(
&'life0 self,
message: Vec<OM>,
timeout: Option<Duration>,
) -> Pin<Box<dyn Future<Output = Result<Option<Vec<M>>, TransportError>> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
Sourcefn write_str<'life0, 'life1, 'async_trait>(
&'life0 self,
payload: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<(), TransportError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn write_str<'life0, 'life1, 'async_trait>(
&'life0 self,
payload: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<(), TransportError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
Writes a string payload to the underlying asynchronous writable stream, appending a newline character and flushing the stream afterward.