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>
impl Peer<RoleClient>
Sourcepub async fn set_response_cache_config(&self, config: ClientCacheConfig)
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.
Sourcepub async fn response_cache_config(&self) -> ClientCacheConfig
pub async fn response_cache_config(&self) -> ClientCacheConfig
Returns a snapshot of the active response-cache configuration.
Sourcepub async fn clear_response_cache(&self)
pub async fn clear_response_cache(&self)
Clears every cached client response without changing the configuration.
Source§impl Peer<RoleClient>
impl Peer<RoleClient>
Sourcepub async fn listen(
&self,
notifications: SubscriptionFilter,
) -> Result<Subscription, ServiceError>
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.
Sourcepub async fn listen_with_capacity(
&self,
notifications: SubscriptionFilter,
channel_capacity: NonZero<usize>,
) -> Result<Subscription, ServiceError>
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.
Sourcepub async fn discover(
&self,
meta: RequestMetaObject,
) -> Result<DiscoverResult, ServiceError>
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.
Sourcepub async fn call_tool_once(
&self,
params: CallToolRequestParams,
) -> Result<CallToolResponse, ServiceError>
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.
Sourcepub async fn get_task(
&self,
params: GetTaskParams,
) -> Result<GetTaskResult, ServiceError>
pub async fn get_task( &self, params: GetTaskParams, ) -> Result<GetTaskResult, ServiceError>
SEP-2663 tasks/get: poll the current state of a task.
Sourcepub async fn update_task(
&self,
params: UpdateTaskParams,
) -> Result<(), ServiceError>
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.
Sourcepub async fn cancel_task(
&self,
params: CancelTaskParams,
) -> Result<(), ServiceError>
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.
Sourcepub async fn get_prompt_once(
&self,
params: GetPromptRequestParams,
) -> Result<GetPromptResponse, ServiceError>
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.
Sourcepub async fn read_resource_once(
&self,
params: ReadResourceRequestParams,
) -> Result<ReadResourceResponse, ServiceError>
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.
pub async fn complete( &self, params: CompleteRequestParams, ) -> Result<CompleteResult, ServiceError>
pub async fn set_level( &self, params: SetLevelRequestParams, ) -> Result<(), ServiceError>
Logging is deprecated by SEP-2577 and will be removed in a future release. See https://github.com/modelcontextprotocol/modelcontextprotocol/pull/2577
pub async fn get_prompt( &self, params: GetPromptRequestParams, ) -> Result<GetPromptResult, ServiceError>
pub async fn subscribe( &self, params: SubscribeRequestParams, ) -> Result<(), ServiceError>
resources/subscribe is legacy-only; use Peer::listen for protocol version 2026-07-28
pub async fn unsubscribe( &self, params: UnsubscribeRequestParams, ) -> Result<(), ServiceError>
resources/unsubscribe is legacy-only; cancel the Subscription handle instead
pub async fn call_tool( &self, params: CallToolRequestParams, ) -> Result<CallToolResult, ServiceError>
pub async fn list_prompts( &self, params: Option<PaginatedRequestParams>, ) -> Result<ListPromptsResult, ServiceError>
pub async fn list_resources( &self, params: Option<PaginatedRequestParams>, ) -> Result<ListResourcesResult, ServiceError>
pub async fn list_resource_templates( &self, params: Option<PaginatedRequestParams>, ) -> Result<ListResourceTemplatesResult, ServiceError>
pub async fn read_resource( &self, params: ReadResourceRequestParams, ) -> Result<ReadResourceResult, ServiceError>
pub async fn list_tools( &self, params: Option<PaginatedRequestParams>, ) -> Result<ListToolsResult, ServiceError>
pub async fn notify_cancelled( &self, params: CancelledNotificationParam, ) -> Result<(), ServiceError>
pub async fn notify_progress( &self, params: ProgressNotificationParam, ) -> Result<(), ServiceError>
pub async fn notify_initialized(&self) -> Result<(), ServiceError>
pub async fn notify_roots_list_changed(&self) -> Result<(), ServiceError>
Source§impl Peer<RoleClient>
impl Peer<RoleClient>
Sourcepub async fn list_all_tools(&self) -> Result<Vec<Tool>, ServiceError>
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.
Sourcepub async fn list_all_prompts(&self) -> Result<Vec<Prompt>, ServiceError>
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.
Sourcepub async fn list_all_resources(&self) -> Result<Vec<Resource>, ServiceError>
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.
Sourcepub async fn list_all_resource_templates(
&self,
) -> Result<Vec<ResourceTemplate>, ServiceError>
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.
Sourcepub 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>
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 completedargument_name- Name of the argument being completedcurrent_value- Current partial value of the argumentcontext- Optional context with previously resolved arguments
§Returns
CompletionInfo with suggestions for the specified prompt argument
Sourcepub 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>
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 completedargument_name- Name of the URI parameter being completedcurrent_value- Current partial value of the parametercontext- Optional context with previously resolved arguments
§Returns
CompletionInfo with suggestions for the specified resource URI argument
Sourcepub 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>
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.
Sourcepub 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>
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>
impl Peer<RoleServer>
Sourcepub fn supports_sampling_tools(&self) -> bool
pub fn supports_sampling_tools(&self) -> bool
Check if the client supports sampling tools capability.
Sourcepub 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
pub async fn create_message( &self, params: CreateMessageRequestParams, ) -> Result<CreateMessageResult, ServiceError>
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.
Sourcepub 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
pub async fn list_roots(&self) -> Result<ListRootsResult, ServiceError>
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.
pub async fn notify_cancelled( &self, params: CancelledNotificationParam, ) -> Result<(), ServiceError>
pub async fn notify_progress( &self, params: ProgressNotificationParam, ) -> Result<(), ServiceError>
pub async fn notify_logging_message( &self, params: LoggingMessageNotificationParam, ) -> Result<(), ServiceError>
Logging is deprecated by SEP-2577 and will be removed in a future release. See https://github.com/modelcontextprotocol/modelcontextprotocol/pull/2577
pub async fn notify_resource_updated( &self, params: ResourceUpdatedNotificationParam, ) -> Result<(), ServiceError>
pub async fn notify_resource_list_changed(&self) -> Result<(), ServiceError>
pub async fn notify_tool_list_changed(&self) -> Result<(), ServiceError>
pub async fn notify_prompt_list_changed(&self) -> Result<(), ServiceError>
Source§impl<R> Peer<R>where
R: ServiceRole,
impl<R> Peer<R>where
R: ServiceRole,
pub async fn send_notification( &self, notification: <R as ServiceRole>::Not, ) -> Result<(), ServiceError>
pub async fn send_request( &self, request: <R as ServiceRole>::Req, ) -> Result<<R as ServiceRole>::PeerResp, ServiceError>
pub async fn send_cancellable_request( &self, request: <R as ServiceRole>::Req, options: PeerRequestOptions, ) -> Result<RequestHandle<R>, ServiceError>
pub async fn send_request_with_option( &self, request: <R as ServiceRole>::Req, options: PeerRequestOptions, ) -> Result<RequestHandle<R>, ServiceError>
Sourcepub fn peer_info(&self) -> Option<Arc<<R as ServiceRole>::PeerInfo>>
pub fn peer_info(&self) -> Option<Arc<<R as ServiceRole>::PeerInfo>>
Snapshot of the peer’s handshake info.
Sourcepub fn set_peer_info(&self, info: <R as ServiceRole>::PeerInfo)
pub fn set_peer_info(&self, info: <R as ServiceRole>::PeerInfo)
Stores the peer’s handshake info, overwriting any previous value.