pub trait PeerHandle: Send + Sync {
// Required methods
fn sample<'life0, 'async_trait>(
&'life0 self,
params: CreateMessageParams,
) -> Pin<Box<dyn Future<Output = Result<CreateMessageResult>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn list_roots<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<ListRootsResult>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn progress_notify<'life0, 'async_trait>(
&'life0 self,
token: ProgressToken,
progress: f64,
total: Option<f64>,
message: Option<String>,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
// Provided method
fn sample_with_tools<'life0, 'async_trait>(
&'life0 self,
params: CreateMessageParams,
) -> Pin<Box<dyn Future<Output = Result<CreateMessageResultWithTools>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait { ... }
}Expand description
Server-to-client back-channel accessible from inside request handlers.
Implementations delegate outbound RPCs to the client session that
originated the current inbound request. The trait is object-safe so
crate::RequestHandlerExtra can hold Option<Arc<dyn PeerHandle>>.
§Example
use pmcp::PeerHandle;
use std::sync::Arc;
let _roots = peer.list_roots().await?;Required Methods§
Sourcefn sample<'life0, 'async_trait>(
&'life0 self,
params: CreateMessageParams,
) -> Pin<Box<dyn Future<Output = Result<CreateMessageResult>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn sample<'life0, 'async_trait>(
&'life0 self,
params: CreateMessageParams,
) -> Pin<Box<dyn Future<Output = Result<CreateMessageResult>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Request the client to sample its LLM (sampling/createMessage).
Delegates through the enclosing Server’s outbound request
dispatcher. The response is deserialized into the typed
CreateMessageResult; malformed responses surface as a protocol
error (INTERNAL_ERROR).
Sourcefn list_roots<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<ListRootsResult>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn list_roots<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<ListRootsResult>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Request the client’s root list (roots/list).
Delegates through the enclosing Server’s outbound request
dispatcher. The response is deserialized into the typed
ListRootsResult.
Sourcefn progress_notify<'life0, 'async_trait>(
&'life0 self,
token: ProgressToken,
progress: f64,
total: Option<f64>,
message: Option<String>,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn progress_notify<'life0, 'async_trait>(
&'life0 self,
token: ProgressToken,
progress: f64,
total: Option<f64>,
message: Option<String>,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Send a progress notification (notifications/progress).
Best-effort: returns Ok(()) silently when no progress channel is
configured — matches the existing
crate::RequestHandlerExtra::report_progress no-op guard. This
phase does NOT attempt to surface transport errors on the progress
path; a follow-on phase may plumb notification_tx through the peer
implementation for live progress reporting.
Provided Methods§
Sourcefn sample_with_tools<'life0, 'async_trait>(
&'life0 self,
params: CreateMessageParams,
) -> Pin<Box<dyn Future<Output = Result<CreateMessageResultWithTools>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn sample_with_tools<'life0, 'async_trait>(
&'life0 self,
params: CreateMessageParams,
) -> Pin<Box<dyn Future<Output = Result<CreateMessageResultWithTools>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Request the client to sample its LLM with tool support
(sampling/createMessage, MCP 2025-11-25).
Returns a CreateMessageResultWithTools, whose content is an array
that can carry tool_use / tool_result blocks — unlike the
single-Content CreateMessageResult from PeerHandle::sample.
This is an ADDITIVE trait method with a default body that delegates to
PeerHandle::sample and lifts the single result into the WithTools
shape (via CreateMessageResultWithTools::from_single). Existing
PeerHandle implementors therefore keep compiling unchanged; the
dispatch-backed [crate::server::peer_impl::DispatchPeerHandle] overrides
it to decode a real CreateMessageResultWithTools (with a legacy
single-content fallback).
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".