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§
- Decline
Elicitation Handler - Default elicitation handler that declines all requests
- Elicitation
Request - Request structure for elicitation operations
- Elicitation
Response - Response structure for elicitation operations (MCP-compliant)
- Handler
Registry - Registry for managing client-side handlers
- LogMessage
- Log message from the server
- Logging
Progress Handler - Default progress handler that logs progress to tracing
- Logging
Resource Update Handler - Default resource update handler that logs changes
- Progress
Notification - Progress notification from server operations
- Resource
Update Notification - Resource update notification
- Tracing
LogHandler - Default log handler that routes server logs to tracing
Enums§
- Elicitation
Action - Elicitation response action indicating user’s choice
- Handler
Error - Errors that can occur during handler operations
- Resource
Change Type - Types of resource changes
Traits§
- Elicitation
Handler - Handler for server-initiated elicitation requests
- LogHandler
- Handler for server log messages
- Progress
Handler - Handler for server progress notifications
- Resource
Update Handler - Handler for resource update notifications