Trait Transport

Source
pub trait Transport: Send + Sync {
    // Required methods
    fn send_request<'life0, 'async_trait>(
        &'life0 mut self,
        request: JsonRpcRequest,
    ) -> Pin<Box<dyn Future<Output = McpResult<JsonRpcResponse>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn send_notification<'life0, 'async_trait>(
        &'life0 mut self,
        notification: JsonRpcNotification,
    ) -> Pin<Box<dyn Future<Output = McpResult<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn receive_notification<'life0, 'async_trait>(
        &'life0 mut self,
    ) -> Pin<Box<dyn Future<Output = McpResult<Option<JsonRpcNotification>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn close<'life0, 'async_trait>(
        &'life0 mut self,
    ) -> Pin<Box<dyn Future<Output = McpResult<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;

    // Provided methods
    fn is_connected(&self) -> bool { ... }
    fn connection_info(&self) -> String { ... }
}
Expand description

Transport trait for MCP clients

This trait defines the interface for sending requests and receiving responses in a client-side MCP connection.

Required Methods§

Source

fn send_request<'life0, 'async_trait>( &'life0 mut self, request: JsonRpcRequest, ) -> Pin<Box<dyn Future<Output = McpResult<JsonRpcResponse>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Send a JSON-RPC request and wait for a response

§Arguments
  • request - The JSON-RPC request to send
§Returns

Result containing the JSON-RPC response or an error

Source

fn send_notification<'life0, 'async_trait>( &'life0 mut self, notification: JsonRpcNotification, ) -> Pin<Box<dyn Future<Output = McpResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Send a JSON-RPC notification (no response expected)

§Arguments
  • notification - The JSON-RPC notification to send
§Returns

Result indicating success or an error

Source

fn receive_notification<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = McpResult<Option<JsonRpcNotification>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Receive a notification from the server (non-blocking)

§Returns

Result containing an optional notification or an error

Source

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

Close the transport connection

§Returns

Result indicating success or an error

Provided Methods§

Source

fn is_connected(&self) -> bool

Check if the transport is connected

§Returns

True if the transport is connected and ready for communication

Source

fn connection_info(&self) -> String

Get connection information for debugging

§Returns

String describing the connection

Implementors§