Skip to main content

Peer

Trait Peer 

Source
pub trait Peer: Send + Sync {
    // Required method
    fn notify(
        &self,
        notification: Notification,
    ) -> Pin<Box<dyn Future<Output = Result<(), McpError>> + Send + '_>>;

    // Provided method
    fn request(
        &self,
        method: Cow<'static, str>,
        params: Option<Value>,
    ) -> Pin<Box<dyn Future<Output = Result<Response, McpError>> + Send + '_>> { ... }
}
Expand description

Trait for sending messages to the peer (client or server).

This trait abstracts over the transport layer, allowing the context to send notifications without knowing the underlying transport.

Required Methods§

Source

fn notify( &self, notification: Notification, ) -> Pin<Box<dyn Future<Output = Result<(), McpError>> + Send + '_>>

Send a notification to the peer.

Provided Methods§

Source

fn request( &self, method: Cow<'static, str>, params: Option<Value>, ) -> Pin<Box<dyn Future<Output = Result<Response, McpError>> + Send + '_>>

Send a request to the peer and await its response.

Used for server-initiated requests such as elicitation and sampling. The implementation assigns the request id and correlates the response.

The default implementation returns an error: a peer that has no persistent bidirectional connection (for example a one-shot HTTP response) cannot make server-initiated requests.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl Peer for NoOpPeer

Source§

impl Peer for SessionPeer

Source§

impl<T> Peer for TransportPeer<T>
where T: Transport + 'static, <T as Transport>::Error: Into<McpError>,