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 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_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 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 subscribe( &self, params: SubscribeRequestParams, ) -> Result<(), ServiceError>
pub async fn unsubscribe( &self, params: UnsubscribeRequestParams, ) -> Result<(), ServiceError>
pub async fn call_tool( &self, params: CallToolRequestParams, ) -> Result<CallToolResult, 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.
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
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
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.