Skip to main content

ClientHandler

Trait ClientHandler 

Source
pub trait ClientHandler: Send + Sync {
    // Provided methods
    fn on_connect<'life0, 'life1, 'async_trait>(
        &'life0 self,
        _context: &'life1 ClientCtx,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
    fn on_shutdown<'life0, 'life1, 'async_trait>(
        &'life0 self,
        _context: &'life1 ClientCtx,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
    fn pong<'life0, 'life1, 'async_trait>(
        &'life0 self,
        _context: &'life1 ClientCtx,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
    fn create_message<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        _context: &'life1 ClientCtx,
        _method: &'life2 str,
        _params: CreateMessageParams,
    ) -> Pin<Box<dyn Future<Output = Result<CreateMessageResult>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait { ... }
    fn list_roots<'life0, 'life1, 'async_trait>(
        &'life0 self,
        _context: &'life1 ClientCtx,
    ) -> Pin<Box<dyn Future<Output = Result<ListRootsResult>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
    fn elicit<'life0, 'life1, 'async_trait>(
        &'life0 self,
        _context: &'life1 ClientCtx,
        _params: ElicitRequestParams,
    ) -> Pin<Box<dyn Future<Output = Result<ElicitResult>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
    fn get_task<'life0, 'life1, 'async_trait>(
        &'life0 self,
        _context: &'life1 ClientCtx,
        _task_id: String,
    ) -> Pin<Box<dyn Future<Output = Result<GetTaskResult>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
    fn get_task_payload<'life0, 'life1, 'async_trait>(
        &'life0 self,
        _context: &'life1 ClientCtx,
        _task_id: String,
    ) -> Pin<Box<dyn Future<Output = Result<GetTaskPayloadResult>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
    fn list_tasks<'life0, 'life1, 'async_trait>(
        &'life0 self,
        _context: &'life1 ClientCtx,
        _cursor: Option<Cursor>,
    ) -> Pin<Box<dyn Future<Output = Result<ListTasksResult>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
    fn cancel_task<'life0, 'life1, 'async_trait>(
        &'life0 self,
        _context: &'life1 ClientCtx,
        _task_id: String,
    ) -> Pin<Box<dyn Future<Output = Result<CancelTaskResult>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
    fn notification<'life0, 'life1, 'async_trait>(
        &'life0 self,
        _context: &'life1 ClientCtx,
        _notification: ServerNotification,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
    fn handle_request<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        context: &'life1 ClientCtx,
        request: ServerRequest,
        method: &'life2 str,
    ) -> Pin<Box<dyn Future<Output = Result<Value>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait { ... }
}
Expand description

Handler trait that client implementers must implement.

Each client connection will have its own instance of the implementation. All methods take &self to allow concurrent request handling. Implementations should use interior mutability (Arc<Mutex<_>>, RwLock<_>, etc.) for any mutable state.

Provided Methods§

Source

fn on_connect<'life0, 'life1, 'async_trait>( &'life0 self, _context: &'life1 ClientCtx, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Called after the initialization handshake completes.

Source

fn on_shutdown<'life0, 'life1, 'async_trait>( &'life0 self, _context: &'life1 ClientCtx, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Called when the connection is being closed

Source

fn pong<'life0, 'life1, 'async_trait>( &'life0 self, _context: &'life1 ClientCtx, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Respond to a ping request from the server

Source

fn create_message<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, _context: &'life1 ClientCtx, _method: &'life2 str, _params: CreateMessageParams, ) -> Pin<Box<dyn Future<Output = Result<CreateMessageResult>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Request the server to create a model message.

Source

fn list_roots<'life0, 'life1, 'async_trait>( &'life0 self, _context: &'life1 ClientCtx, ) -> Pin<Box<dyn Future<Output = Result<ListRootsResult>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Request the server to list roots.

Source

fn elicit<'life0, 'life1, 'async_trait>( &'life0 self, _context: &'life1 ClientCtx, _params: ElicitRequestParams, ) -> Pin<Box<dyn Future<Output = Result<ElicitResult>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Request the server to elicit user input.

Source

fn get_task<'life0, 'life1, 'async_trait>( &'life0 self, _context: &'life1 ClientCtx, _task_id: String, ) -> Pin<Box<dyn Future<Output = Result<GetTaskResult>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Retrieve the state of a task.

Source

fn get_task_payload<'life0, 'life1, 'async_trait>( &'life0 self, _context: &'life1 ClientCtx, _task_id: String, ) -> Pin<Box<dyn Future<Output = Result<GetTaskPayloadResult>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Retrieve the result of a completed task.

Source

fn list_tasks<'life0, 'life1, 'async_trait>( &'life0 self, _context: &'life1 ClientCtx, _cursor: Option<Cursor>, ) -> Pin<Box<dyn Future<Output = Result<ListTasksResult>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

List tasks.

Source

fn cancel_task<'life0, 'life1, 'async_trait>( &'life0 self, _context: &'life1 ClientCtx, _task_id: String, ) -> Pin<Box<dyn Future<Output = Result<CancelTaskResult>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Cancel a task by ID.

Source

fn notification<'life0, 'life1, 'async_trait>( &'life0 self, _context: &'life1 ClientCtx, _notification: ServerNotification, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Handle a notification sent from the server

The default implementation ignores the notification. Implementations can override this method to react to server-initiated notifications.

Source

fn handle_request<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, context: &'life1 ClientCtx, request: ServerRequest, method: &'life2 str, ) -> Pin<Box<dyn Future<Output = Result<Value>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Dispatches a parsed server request to the appropriate handler method.

The default implementation matches on the request variant and calls the corresponding trait method. You can override this to implement global behaviors (middleware, logging) or to handle custom request types before delegating to the default logic.

Implementations on Foreign Types§

Source§

impl ClientHandler for ()

Default no-op implementation of ClientHandler for unit type

Implementors§