Trait McpServer

Source
pub trait McpServer: Sync + Send {
Show 27 methods // Required methods fn start<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = SdkResult<()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn set_client_details( &self, client_details: InitializeRequestParams, ) -> SdkResult<()>; fn server_info(&self) -> &InitializeResult; fn client_info(&self) -> Option<InitializeRequestParams>; fn sender<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = &RwLock<Option<MessageDispatcher<ClientMessage>>>> + Send + 'async_trait>> where MessageDispatcher<ClientMessage>: McpDispatch<ClientMessage, MessageFromServer>, Self: 'async_trait, 'life0: 'async_trait; fn stderr_message<'life0, 'async_trait>( &'life0 self, message: String, ) -> Pin<Box<dyn Future<Output = SdkResult<()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; // Provided methods fn get_client_info(&self) -> Option<InitializeRequestParams> { ... } fn get_server_info(&self) -> &InitializeResult { ... } fn is_initialized(&self) -> bool { ... } fn client_version(&self) -> Option<Implementation> { ... } fn capabilities(&self) -> &ServerCapabilities { ... } fn request<'life0, 'async_trait>( &'life0 self, request: RequestFromServer, timeout: Option<Duration>, ) -> Pin<Box<dyn Future<Output = SdkResult<ResultFromClient>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait { ... } fn send_notification<'life0, 'async_trait>( &'life0 self, notification: NotificationFromServer, ) -> Pin<Box<dyn Future<Output = SdkResult<()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait { ... } fn list_roots<'life0, 'async_trait>( &'life0 self, params: Option<ListRootsRequestParams>, ) -> Pin<Box<dyn Future<Output = SdkResult<ListRootsResult>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait { ... } fn send_logging_message<'life0, 'async_trait>( &'life0 self, params: LoggingMessageNotificationParams, ) -> Pin<Box<dyn Future<Output = SdkResult<()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait { ... } fn send_prompt_list_changed<'life0, 'async_trait>( &'life0 self, params: Option<PromptListChangedNotificationParams>, ) -> Pin<Box<dyn Future<Output = SdkResult<()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait { ... } fn send_resource_list_changed<'life0, 'async_trait>( &'life0 self, params: Option<ResourceListChangedNotificationParams>, ) -> Pin<Box<dyn Future<Output = SdkResult<()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait { ... } fn send_resource_updated<'life0, 'async_trait>( &'life0 self, params: ResourceUpdatedNotificationParams, ) -> Pin<Box<dyn Future<Output = SdkResult<()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait { ... } fn send_tool_list_changed<'life0, 'async_trait>( &'life0 self, params: Option<ToolListChangedNotificationParams>, ) -> Pin<Box<dyn Future<Output = SdkResult<()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait { ... } fn ping<'life0, 'async_trait>( &'life0 self, timeout: Option<Duration>, ) -> Pin<Box<dyn Future<Output = SdkResult<Result>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait { ... } fn create_message<'life0, 'async_trait>( &'life0 self, params: CreateMessageRequestParams, ) -> Pin<Box<dyn Future<Output = SdkResult<CreateMessageResult>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait { ... } fn client_supports_sampling(&self) -> Option<bool> { ... } fn client_supports_root_list(&self) -> Option<bool> { ... } fn client_supports_experimental(&self) -> Option<bool> { ... } fn assert_client_capabilities( &self, request_method: &String, ) -> Result<(), RpcError> { ... } fn assert_server_notification_capabilities( &self, notification_method: &String, ) -> Result<(), RpcError> { ... } fn assert_server_request_capabilities( &self, request_method: &String, ) -> Result<(), RpcError> { ... }
}

Required Methods§

Source

fn start<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = SdkResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source

fn set_client_details( &self, client_details: InitializeRequestParams, ) -> SdkResult<()>

Source

fn server_info(&self) -> &InitializeResult

Source

fn client_info(&self) -> Option<InitializeRequestParams>

Source

fn sender<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = &RwLock<Option<MessageDispatcher<ClientMessage>>>> + Send + 'async_trait>>
where MessageDispatcher<ClientMessage>: McpDispatch<ClientMessage, MessageFromServer>, Self: 'async_trait, 'life0: 'async_trait,

Source

fn stderr_message<'life0, 'async_trait>( &'life0 self, message: String, ) -> Pin<Box<dyn Future<Output = SdkResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Sends a message to the standard error output (stderr) asynchronously.

Provided Methods§

Source

fn get_client_info(&self) -> Option<InitializeRequestParams>

👎Deprecated since 0.2.0: Use client_info() instead.
Source

fn get_server_info(&self) -> &InitializeResult

👎Deprecated since 0.2.0: Use server_info() instead.
Source

fn is_initialized(&self) -> bool

Checks whether the server has been initialized with client

Source

fn client_version(&self) -> Option<Implementation>

Returns the client’s name and version information once initialization is complete. This method retrieves the client details, if available, after successful initialization.

Source

fn capabilities(&self) -> &ServerCapabilities

Returns the server’s capabilities.

Source

fn request<'life0, 'async_trait>( &'life0 self, request: RequestFromServer, timeout: Option<Duration>, ) -> Pin<Box<dyn Future<Output = SdkResult<ResultFromClient>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Sends a request to the client and processes the response.

This function sends a RequestFromServer message to the client, waits for the response, and handles the result. If the response is empty or of an invalid type, an error is returned. Otherwise, it returns the result from the client.

Source

fn send_notification<'life0, 'async_trait>( &'life0 self, notification: NotificationFromServer, ) -> Pin<Box<dyn Future<Output = SdkResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Sends a notification. This is a one-way message that is not expected to return any response. The method asynchronously sends the notification using the transport layer and does not wait for any acknowledgement or result.

Source

fn list_roots<'life0, 'async_trait>( &'life0 self, params: Option<ListRootsRequestParams>, ) -> Pin<Box<dyn Future<Output = SdkResult<ListRootsResult>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Request a list of root URIs from the client. Roots allow servers to ask for specific directories or files to operate on. A common example for roots is providing a set of repositories or directories a server should operate on. This request is typically used when the server needs to understand the file system structure or access specific locations that the client has permission to read from

Source

fn send_logging_message<'life0, 'async_trait>( &'life0 self, params: LoggingMessageNotificationParams, ) -> Pin<Box<dyn Future<Output = SdkResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Send log message notification from server to client. If no logging/setLevel request has been sent from the client, the server MAY decide which messages to send automatically.

Source

fn send_prompt_list_changed<'life0, 'async_trait>( &'life0 self, params: Option<PromptListChangedNotificationParams>, ) -> Pin<Box<dyn Future<Output = SdkResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

An optional notification from the server to the client, informing it that the list of prompts it offers has changed. This may be issued by servers without any previous subscription from the client.

Source

fn send_resource_list_changed<'life0, 'async_trait>( &'life0 self, params: Option<ResourceListChangedNotificationParams>, ) -> Pin<Box<dyn Future<Output = SdkResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

An optional notification from the server to the client, informing it that the list of resources it can read from has changed. This may be issued by servers without any previous subscription from the client.

Source

fn send_resource_updated<'life0, 'async_trait>( &'life0 self, params: ResourceUpdatedNotificationParams, ) -> Pin<Box<dyn Future<Output = SdkResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

A notification from the server to the client, informing it that a resource has changed and may need to be read again. This should only be sent if the client previously sent a resources/subscribe request.

Source

fn send_tool_list_changed<'life0, 'async_trait>( &'life0 self, params: Option<ToolListChangedNotificationParams>, ) -> Pin<Box<dyn Future<Output = SdkResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

An optional notification from the server to the client, informing it that the list of tools it offers has changed. This may be issued by servers without any previous subscription from the client.

Source

fn ping<'life0, 'async_trait>( &'life0 self, timeout: Option<Duration>, ) -> Pin<Box<dyn Future<Output = SdkResult<Result>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

A ping request to check that the other party is still alive. The receiver must promptly respond, or else may be disconnected.

This function creates a PingRequest with no specific parameters, sends the request and awaits the response Once the response is received, it attempts to convert it into the expected result type.

§Returns

A SdkResult containing the rust_mcp_schema::Result if the request is successful. If the request or conversion fails, an error is returned.

Source

fn create_message<'life0, 'async_trait>( &'life0 self, params: CreateMessageRequestParams, ) -> Pin<Box<dyn Future<Output = SdkResult<CreateMessageResult>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

A request from the server to sample an LLM via the client. The client has full discretion over which model to select. The client should also inform the user before beginning sampling, to allow them to inspect the request (human in the loop) and decide whether to approve it.

Source

fn client_supports_sampling(&self) -> Option<bool>

Checks if the client supports sampling.

This function retrieves the client information and checks if the client has sampling capabilities listed. If the client info has not been retrieved yet, it returns None. Otherwise, it returns Some(true) if sampling is supported, or Some(false) if not.

§Returns
  • None if client information is not yet available.
  • Some(true) if sampling is supported by the client.
  • Some(false) if sampling is not supported by the client.
Source

fn client_supports_root_list(&self) -> Option<bool>

Checks if the client supports listing roots.

This function retrieves the client information and checks if the client has listing roots capabilities listed. If the client info has not been retrieved yet, it returns None. Otherwise, it returns Some(true) if listing roots is supported, or Some(false) if not.

§Returns
  • None if client information is not yet available.
  • Some(true) if listing roots is supported by the client.
  • Some(false) if listing roots is not supported by the client.
Source

fn client_supports_experimental(&self) -> Option<bool>

Checks if the client has experimental capabilities available.

This function retrieves the client information and checks if the client has experimental listed in its capabilities. If the client info has not been retrieved yet, it returns None. Otherwise, it returns Some(true) if experimental is available, or Some(false) if not.

§Returns
  • None if client information is not yet available.
  • Some(true) if experimental capabilities are available on the client.
  • Some(false) if no experimental capabilities are available on the client.
Source

fn assert_client_capabilities( &self, request_method: &String, ) -> Result<(), RpcError>

Asserts that client capabilities are available for a given server request.

This method verifies that the client capabilities required to process the specified server request have been retrieved and are accessible. It returns an error if the capabilities are not available.

This can be utilized to avoid sending requests when the opposing party lacks support for them.

Source

fn assert_server_notification_capabilities( &self, notification_method: &String, ) -> Result<(), RpcError>

Source

fn assert_server_request_capabilities( &self, request_method: &String, ) -> Result<(), RpcError>

Implementors§