Trait Transport

Source
pub trait Transport:
    Send
    + Sync
    + 'static {
    // Required methods
    fn open<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn close<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn poll_message<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<Option<Message>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn request(
        &self,
        method: &str,
        params: Option<Value>,
        options: RequestOptions,
    ) -> Pin<Box<dyn Future<Output = Result<JsonRpcResponse>> + Send + Sync>>;
    fn send_notification<'life0, 'life1, 'async_trait>(
        &'life0 self,
        method: &'life1 str,
        params: Option<Value>,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn send_response<'life0, 'async_trait>(
        &'life0 self,
        id: RequestId,
        result: Option<Value>,
        error: Option<JsonRpcError>,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
}
Expand description

Core trait that defines operations for MCP transports.

This trait abstracts the transport layer, allowing the protocol to work with different communication mechanisms (SSE, stdio, etc.).

Required Methods§

Source

fn open<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Opens the transport connection.

This initializes the transport and prepares it for communication.

§Returns

A Result indicating success or failure

Source

fn close<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Closes the transport connection.

This terminates the transport and releases any resources.

§Returns

A Result indicating success or failure

Source

fn poll_message<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Option<Message>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Polls for incoming messages.

This checks for any new messages from the other endpoint.

§Returns

A Result containing an Option<Message> if a message is available

Source

fn request( &self, method: &str, params: Option<Value>, options: RequestOptions, ) -> Pin<Box<dyn Future<Output = Result<JsonRpcResponse>> + Send + Sync>>

Sends a request and waits for the response.

§Arguments
  • method - The method name for the request
  • params - Optional parameters for the request
  • options - Request options (like timeout)
§Returns

A Future that resolves to a Result containing the response

Source

fn send_notification<'life0, 'life1, 'async_trait>( &'life0 self, method: &'life1 str, params: Option<Value>, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Sends a notification.

Unlike requests, notifications do not expect a response.

§Arguments
  • method - The method name for the notification
  • params - Optional parameters for the notification
§Returns

A Result indicating success or failure

Source

fn send_response<'life0, 'async_trait>( &'life0 self, id: RequestId, result: Option<Value>, error: Option<JsonRpcError>, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Sends a response to a request.

§Arguments
  • id - The ID of the request being responded to
  • result - Optional successful result
  • error - Optional error information
§Returns

A Result indicating success or failure

Implementors§