Trait McpDispatch

Source
pub trait McpDispatch<R, S>:
    Send
    + Sync
    + 'static
where R: McpMessage + Clone + Send + Sync + DeserializeOwned + 'static, S: Clone + Send + Sync + Serialize + 'static,
{ // Required method fn send<'life0, 'async_trait>( &'life0 self, message: S, request_id: Option<RequestId>, request_timeout: Option<Duration>, ) -> Pin<Box<dyn Future<Output = Result<Option<R>, TransportError>> + Send + 'async_trait>> where 'life0: 'async_trait, Self: 'async_trait; }
Expand description

A trait for sending MCP messages.

It is intended to be implemented by types that send messages in the MCP protocol, such as servers or clients.

The McpDispatch trait requires two associated types:

  • R: The type of the response, which must implement the McpMessage trait and be capable of deserialization.
  • S: The type of the message to send, which must be serializable and cloneable.

Both associated types R and S must be Send, Sync, and 'static to ensure they can be used safely in an asynchronous context and across threads.

§Associated Types

  • R: The response type, which must implement the McpMessage trait, be Clone, Send, Sync, and be deserializable (DeserializeOwned).
  • S: The type of the message to send, which must be Clone, Send, Sync, and serializable (Serialize).

§Methods

§send

Sends a raw message represented by type S and optionally includes a request_id. The method returns a TransportResult<Option<R>>, where:

  • Option<R>: The response, which can be None or contain the response of type R.
  • TransportResult: Represents the result of the operation, which can include success or failure.

§Arguments

  • message: The message to send, of type S, which will be serialized before transmission.
  • request_id: An optional RequestId to associate with this message. It can be used for tracking or correlating the request with its response.

§Example

let sender: Box<dyn McpDispatch<MyResponse, MyMessage>> = …; let result = sender.send(my_message, Some(request_id)).await;

Required Methods§

Source

fn send<'life0, 'async_trait>( &'life0 self, message: S, request_id: Option<RequestId>, 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.

Implementors§