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§
Provided Methods§
Sourcefn request(
&self,
method: Cow<'static, str>,
params: Option<Value>,
) -> Pin<Box<dyn Future<Output = Result<Response, McpError>> + Send + '_>>
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".