Skip to main content

Peer

Struct Peer 

Source
pub struct Peer<R>
where R: ServiceRole,
{ /* private fields */ }
Expand description

An interface to fetch the remote client or server

For general purpose, call Peer::send_request or Peer::send_notification to send message to remote peer.

To create a cancellable request, call Peer::send_request_with_option.

Implementations§

Source§

impl Peer<RoleClient>

Source

pub async fn set_response_cache_config(&self, config: ClientCacheConfig)

Replaces the response-cache configuration.

Changing the private partition invalidates private entries from the old authorization context. Disabling the cache clears every entry. Any configuration change also suppresses writes from requests that were already in flight under the previous configuration.

Source

pub async fn response_cache_config(&self) -> ClientCacheConfig

Returns a snapshot of the active response-cache configuration.

Source

pub async fn clear_response_cache(&self)

Clears every cached client response without changing the configuration.

Source§

impl Peer<RoleClient>

Source

pub async fn listen( &self, notifications: SubscriptionFilter, ) -> Result<Subscription, ServiceError>

Open a long-lived notification subscription and wait for its acknowledgment.

Notifications routed to the returned Subscription are not also delivered through ClientHandler callbacks.

§Errors

Returns a service, transport, or protocol error when the request cannot be established or the acknowledgment is invalid.

Source

pub async fn listen_with_capacity( &self, notifications: SubscriptionFilter, channel_capacity: NonZero<usize>, ) -> Result<Subscription, ServiceError>

Open a subscription with an explicit notification buffer capacity.

Notifications routed to the returned Subscription are not also delivered through ClientHandler callbacks.

§Errors

Returns a service, transport, or protocol error when the request cannot be established or the acknowledgment is invalid.

Source

pub async fn discover( &self, meta: RequestMetaObject, ) -> Result<DiscoverResult, ServiceError>

Discover the server’s supported protocol versions and capabilities.

The high-level client currently exposes this peer only after initialization; pre-initialization probing is planned as follow-up work.

Source

pub async fn call_tool_once( &self, params: CallToolRequestParams, ) -> Result<CallToolResponse, ServiceError>

Send one tools/call request and return either a final result or an MRTR InputRequiredResult without driving any follow-up rounds.

Source

pub async fn get_task( &self, params: GetTaskParams, ) -> Result<GetTaskResult, ServiceError>

SEP-2663 tasks/get: poll the current state of a task.

Source

pub async fn update_task( &self, params: UpdateTaskParams, ) -> Result<(), ServiceError>

SEP-2663 tasks/update: deliver responses to outstanding in-task input requests. The acknowledgement is eventually consistent.

Source

pub async fn cancel_task( &self, params: CancelTaskParams, ) -> Result<(), ServiceError>

SEP-2663 tasks/cancel: signal intent to cancel a task. Cancellation is cooperative; the ack does not guarantee the task stops.

Source

pub async fn get_prompt_once( &self, params: GetPromptRequestParams, ) -> Result<GetPromptResponse, ServiceError>

Send one prompts/get request and return either a final result or an MRTR InputRequiredResult without driving any follow-up rounds.

Source

pub async fn read_resource_once( &self, params: ReadResourceRequestParams, ) -> Result<ReadResourceResponse, ServiceError>

Send one resources/read request and return either a final result or an MRTR InputRequiredResult without driving any follow-up rounds.

Source

pub async fn complete( &self, params: CompleteRequestParams, ) -> Result<CompleteResult, ServiceError>

Source

pub async fn set_level( &self, params: SetLevelRequestParams, ) -> Result<(), ServiceError>

👎Deprecated since 1.8.0:

Logging is deprecated by SEP-2577 and will be removed in a future release. See https://github.com/modelcontextprotocol/modelcontextprotocol/pull/2577

Source

pub async fn get_prompt( &self, params: GetPromptRequestParams, ) -> Result<GetPromptResult, ServiceError>

Source

pub async fn subscribe( &self, params: SubscribeRequestParams, ) -> Result<(), ServiceError>

👎Deprecated:

resources/subscribe is legacy-only; use Peer::listen for protocol version 2026-07-28

Source

pub async fn unsubscribe( &self, params: UnsubscribeRequestParams, ) -> Result<(), ServiceError>

👎Deprecated:

resources/unsubscribe is legacy-only; cancel the Subscription handle instead

Source

pub async fn call_tool( &self, params: CallToolRequestParams, ) -> Result<CallToolResult, ServiceError>

Source

pub async fn list_prompts( &self, params: Option<PaginatedRequestParams>, ) -> Result<ListPromptsResult, ServiceError>

Source

pub async fn list_resources( &self, params: Option<PaginatedRequestParams>, ) -> Result<ListResourcesResult, ServiceError>

Source

pub async fn list_resource_templates( &self, params: Option<PaginatedRequestParams>, ) -> Result<ListResourceTemplatesResult, ServiceError>

Source

pub async fn read_resource( &self, params: ReadResourceRequestParams, ) -> Result<ReadResourceResult, ServiceError>

Source

pub async fn list_tools( &self, params: Option<PaginatedRequestParams>, ) -> Result<ListToolsResult, ServiceError>

Source

pub async fn notify_cancelled( &self, params: CancelledNotificationParam, ) -> Result<(), ServiceError>

Source

pub async fn notify_progress( &self, params: ProgressNotificationParam, ) -> Result<(), ServiceError>

Source

pub async fn notify_initialized(&self) -> Result<(), ServiceError>

Source

pub async fn notify_roots_list_changed(&self) -> Result<(), ServiceError>

Source§

impl Peer<RoleClient>

Source

pub async fn list_all_tools(&self) -> Result<Vec<Tool>, ServiceError>

A wrapper method for Peer<RoleClient>::list_tools.

This function will call Peer<RoleClient>::list_tools multiple times until all tools are listed.

Source

pub async fn list_all_prompts(&self) -> Result<Vec<Prompt>, ServiceError>

A wrapper method for Peer<RoleClient>::list_prompts.

This function will call Peer<RoleClient>::list_prompts multiple times until all prompts are listed.

Source

pub async fn list_all_resources(&self) -> Result<Vec<Resource>, ServiceError>

A wrapper method for Peer<RoleClient>::list_resources.

This function will call Peer<RoleClient>::list_resources multiple times until all resources are listed.

Source

pub async fn list_all_resource_templates( &self, ) -> Result<Vec<ResourceTemplate>, ServiceError>

A wrapper method for Peer<RoleClient>::list_resource_templates.

This function will call Peer<RoleClient>::list_resource_templates multiple times until all resource templates are listed.

Source

pub async fn complete_prompt_argument( &self, prompt_name: impl Into<String>, argument_name: impl Into<String>, current_value: impl Into<String>, context: Option<CompletionContext>, ) -> Result<CompletionInfo, ServiceError>

Convenient method to get completion suggestions for a prompt argument

§Arguments
  • prompt_name - Name of the prompt being completed
  • argument_name - Name of the argument being completed
  • current_value - Current partial value of the argument
  • context - Optional context with previously resolved arguments
§Returns

CompletionInfo with suggestions for the specified prompt argument

Source

pub async fn complete_resource_argument( &self, uri_template: impl Into<String>, argument_name: impl Into<String>, current_value: impl Into<String>, context: Option<CompletionContext>, ) -> Result<CompletionInfo, ServiceError>

Convenient method to get completion suggestions for a resource URI argument

§Arguments
  • uri_template - URI template pattern being completed
  • argument_name - Name of the URI parameter being completed
  • current_value - Current partial value of the parameter
  • context - Optional context with previously resolved arguments
§Returns

CompletionInfo with suggestions for the specified resource URI argument

Source

pub async fn complete_prompt_simple( &self, prompt_name: impl Into<String>, argument_name: impl Into<String>, current_value: impl Into<String>, ) -> Result<Vec<String>, ServiceError>

Simple completion for a prompt argument without context

This is a convenience wrapper around complete_prompt_argument for simple completion scenarios that don’t require context awareness.

Source

pub async fn complete_resource_simple( &self, uri_template: impl Into<String>, argument_name: impl Into<String>, current_value: impl Into<String>, ) -> Result<Vec<String>, ServiceError>

Simple completion for a resource URI argument without context

This is a convenience wrapper around complete_resource_argument for simple completion scenarios that don’t require context awareness.

Source§

impl Peer<RoleServer>

Source

pub fn supports_sampling_tools(&self) -> bool

Check if the client supports sampling tools capability.

Source

pub async fn create_message( &self, params: CreateMessageRequestParams, ) -> Result<CreateMessageResult, ServiceError>

👎Deprecated since 1.8.0:

Sampling is deprecated by SEP-2577 and will be removed in a future release. See https://github.com/modelcontextprotocol/modelcontextprotocol/pull/2577

Errors on protocol 2026-07-28 or later, which forbids server-to-client requests; return an InputRequiredResult instead.

Source

pub async fn list_roots(&self) -> Result<ListRootsResult, ServiceError>

👎Deprecated since 1.8.0:

Roots is deprecated by SEP-2577 and will be removed in a future release. See https://github.com/modelcontextprotocol/modelcontextprotocol/pull/2577

Errors on protocol 2026-07-28 or later, which forbids server-to-client requests; return an InputRequiredResult instead.

Source

pub async fn notify_cancelled( &self, params: CancelledNotificationParam, ) -> Result<(), ServiceError>

Source

pub async fn notify_progress( &self, params: ProgressNotificationParam, ) -> Result<(), ServiceError>

Source

pub async fn notify_logging_message( &self, params: LoggingMessageNotificationParam, ) -> Result<(), ServiceError>

👎Deprecated since 1.8.0:

Logging is deprecated by SEP-2577 and will be removed in a future release. See https://github.com/modelcontextprotocol/modelcontextprotocol/pull/2577

Source

pub async fn notify_resource_updated( &self, params: ResourceUpdatedNotificationParam, ) -> Result<(), ServiceError>

Source

pub async fn notify_resource_list_changed(&self) -> Result<(), ServiceError>

Source

pub async fn notify_tool_list_changed(&self) -> Result<(), ServiceError>

Source

pub async fn notify_prompt_list_changed(&self) -> Result<(), ServiceError>

Source§

impl<R> Peer<R>
where R: ServiceRole,

Source

pub async fn send_notification( &self, notification: <R as ServiceRole>::Not, ) -> Result<(), ServiceError>

Source

pub async fn send_request( &self, request: <R as ServiceRole>::Req, ) -> Result<<R as ServiceRole>::PeerResp, ServiceError>

Source

pub async fn send_cancellable_request( &self, request: <R as ServiceRole>::Req, options: PeerRequestOptions, ) -> Result<RequestHandle<R>, ServiceError>

Source

pub async fn send_request_with_option( &self, request: <R as ServiceRole>::Req, options: PeerRequestOptions, ) -> Result<RequestHandle<R>, ServiceError>

Source

pub fn peer_info(&self) -> Option<Arc<<R as ServiceRole>::PeerInfo>>

Snapshot of the peer’s handshake info.

Source

pub fn set_peer_info(&self, info: <R as ServiceRole>::PeerInfo)

Stores the peer’s handshake info, overwriting any previous value.

Source

pub fn is_transport_closed(&self) -> bool

Trait Implementations§

Source§

impl<R> Clone for Peer<R>

Source§

fn clone(&self) -> Peer<R>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<R> Debug for Peer<R>
where R: ServiceRole,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<C> FromContextPart<C> for Peer<RoleServer>

Auto Trait Implementations§

§

impl<R> !RefUnwindSafe for Peer<R>

§

impl<R> !UnwindSafe for Peer<R>

§

impl<R> Freeze for Peer<R>
where Sender<PeerSinkMessage<R>>: Freeze, Arc<RwLock<Option<Arc<<R as ServiceRole>::PeerInfo>>>>: Freeze, Arc<RwLock<HashMap<NumberOrString, (Sender<<R as ServiceRole>::PeerNot>, usize)>>>: Freeze, Arc<RwLock<PeerResponseCacheState<R>>>: Freeze,

§

impl<R> Send for Peer<R>
where Sender<PeerSinkMessage<R>>: Send, Arc<RwLock<Option<Arc<<R as ServiceRole>::PeerInfo>>>>: Send, Arc<RwLock<HashMap<NumberOrString, (Sender<<R as ServiceRole>::PeerNot>, usize)>>>: Send, Arc<RwLock<PeerResponseCacheState<R>>>: Send,

§

impl<R> Sync for Peer<R>
where Sender<PeerSinkMessage<R>>: Sync, Arc<RwLock<Option<Arc<<R as ServiceRole>::PeerInfo>>>>: Sync, Arc<RwLock<HashMap<NumberOrString, (Sender<<R as ServiceRole>::PeerNot>, usize)>>>: Sync, Arc<RwLock<PeerResponseCacheState<R>>>: Sync,

§

impl<R> Unpin for Peer<R>
where Sender<PeerSinkMessage<R>>: Unpin, Arc<RwLock<Option<Arc<<R as ServiceRole>::PeerInfo>>>>: Unpin, Arc<RwLock<HashMap<NumberOrString, (Sender<<R as ServiceRole>::PeerNot>, usize)>>>: Unpin, Arc<RwLock<PeerResponseCacheState<R>>>: Unpin,

§

impl<R> UnsafeUnpin for Peer<R>
where Sender<PeerSinkMessage<R>>: UnsafeUnpin, Arc<RwLock<Option<Arc<<R as ServiceRole>::PeerInfo>>>>: UnsafeUnpin, Arc<RwLock<HashMap<NumberOrString, (Sender<<R as ServiceRole>::PeerNot>, usize)>>>: UnsafeUnpin, Arc<RwLock<PeerResponseCacheState<R>>>: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more