Module handlers

Module handlers 

Source
Expand description

Handler traits for bidirectional communication in MCP client

This module provides handler traits and registration mechanisms for processing server-initiated requests. The MCP protocol is bidirectional, meaning servers can also send requests to clients for various purposes like elicitation, progress reporting, logging, and resource updates.

§Handler Types

  • ElicitationHandler: Handle user input requests from servers
  • ProgressHandler: Process progress notifications from long-running operations
  • LogHandler: Route server log messages to client logging systems
  • ResourceUpdateHandler: Handle notifications when resources change

§Usage

use turbomcp_client::handlers::{ElicitationHandler, ElicitationRequest, ElicitationResponse, HandlerError};
use async_trait::async_trait;

// Implement elicitation handler
#[derive(Debug)]
struct MyElicitationHandler;

#[async_trait]
impl ElicitationHandler for MyElicitationHandler {
    async fn handle_elicitation(
        &self,
        request: ElicitationRequest,
    ) -> Result<ElicitationResponse, HandlerError> {
        // Present schema to user and collect input
        // Return user's response
        todo!("Implement user interaction")
    }
}

Structs§

DeclineElicitationHandler
Default elicitation handler that declines all requests
ElicitationRequest
Request structure for elicitation operations
ElicitationResponse
Response structure for elicitation operations (MCP-compliant)
HandlerRegistry
Registry for managing client-side handlers
LogMessage
Log message from the server
LoggingProgressHandler
Default progress handler that logs progress to tracing
LoggingResourceUpdateHandler
Default resource update handler that logs changes
ProgressNotification
Progress notification from server operations
ResourceUpdateNotification
Resource update notification
TracingLogHandler
Default log handler that routes server logs to tracing

Enums§

ElicitationAction
Elicitation response action indicating user’s choice
HandlerError
Errors that can occur during handler operations
ResourceChangeType
Types of resource changes

Traits§

ElicitationHandler
Handler for server-initiated elicitation requests
LogHandler
Handler for server log messages
ProgressHandler
Handler for server progress notifications
ResourceUpdateHandler
Handler for resource update notifications

Type Aliases§

HandlerResult