pub trait Transport<R, S, M, OR, OM>:
Send
+ Sync
+ 'staticwhere
R: Clone + Send + Sync + DeserializeOwned + 'static,
S: Clone + Send + Sync + Serialize + 'static,
M: Clone + Send + Sync + DeserializeOwned + 'static,
OR: Clone + Send + Sync + Serialize + 'static,
OM: Clone + Send + Sync + DeserializeOwned + 'static,{
// Required methods
fn start<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<ReceiverStream<R>, TransportError>> + Send + 'async_trait>>
where 'life0: 'async_trait,
MessageDispatcher<M>: McpDispatch<R, OR, M, OM>,
Self: 'async_trait;
fn message_sender(&self) -> Arc<RwLock<Option<MessageDispatcher<M>>>>;
fn error_stream(&self) -> &RwLock<Option<IoStream>>;
fn shut_down<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), TransportError>> + Send + 'async_trait>>
where 'life0: 'async_trait,
Self: 'async_trait;
fn is_shut_down<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>
where 'life0: 'async_trait,
Self: 'async_trait;
fn consume_string_payload<'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 pending_request_tx<'life0, 'life1, 'async_trait>(
&'life0 self,
request_id: &'life1 RequestId,
) -> Pin<Box<dyn Future<Output = Option<Sender<M>>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait;
fn keep_alive<'life0, 'async_trait>(
&'life0 self,
interval: Duration,
disconnect_tx: Sender<()>,
) -> Pin<Box<dyn Future<Output = Result<JoinHandle<()>, TransportError>> + Send + 'async_trait>>
where 'life0: 'async_trait,
Self: 'async_trait;
}
Expand description
A trait representing the transport layer for the MCP (Message Communication Protocol).
This trait abstracts the transport layer functionality required to send and receive messages within an MCP-based system. It provides methods to initialize the transport, send and receive messages, handle errors, manage pending requests, and implement keep-alive functionality.
§Associated Types
R
: The type of message expected to be received from the transport layer. Must be deserializable.S
: The type of message to be sent over the transport layer. Must be serializable.M
: The internal message type used by the dispatcher. Typically this wraps or transformsR
.OR
: The outbound response type expected to be produced by the dispatcher when handling incoming messages.OM
: The outbound message type that the dispatcher expects to send as a reply to received messages.