pub struct Context { /* private fields */ }Expand description
Context for tool and handler execution
Provides access to server functionality like progress tracking, logging, and request metadata.
Implementations§
Source§impl Context
impl Context
Sourcepub fn with_session_id(self, session_id: String) -> Self
pub fn with_session_id(self, session_id: String) -> Self
Create a context with session ID
Sourcepub fn with_request_id(self, request_id: String) -> Self
pub fn with_request_id(self, request_id: String) -> Self
Create a context with request ID
Sourcepub fn with_metadata(self, key: String, value: Value) -> Self
pub fn with_metadata(self, key: String, value: Value) -> Self
Add metadata to the context
Sourcepub fn with_logger_config(self, config: LoggerConfig) -> Self
pub fn with_logger_config(self, config: LoggerConfig) -> Self
Configure the logger for this context
Sourcepub fn with_notification_sender(
self,
sender: Arc<dyn Fn(JsonRpcMessage) -> Pin<Box<dyn Future<Output = MCPResult<()>> + Send>> + Send + Sync>,
) -> Self
pub fn with_notification_sender( self, sender: Arc<dyn Fn(JsonRpcMessage) -> Pin<Box<dyn Future<Output = MCPResult<()>> + Send>> + Send + Sync>, ) -> Self
Set the notification sender
Sourcepub fn with_cancellation_manager(
self,
manager: Arc<CancellationManager>,
) -> Self
pub fn with_cancellation_manager( self, manager: Arc<CancellationManager>, ) -> Self
Set the cancellation manager
Sourcepub fn session_id(&self) -> Option<&str>
pub fn session_id(&self) -> Option<&str>
Get the session ID
Sourcepub fn request_id(&self) -> Option<&str>
pub fn request_id(&self) -> Option<&str>
Get the request ID
Sourcepub fn get_metadata(&self, key: &str) -> Option<&Value>
pub fn get_metadata(&self, key: &str) -> Option<&Value>
Get metadata value
Sourcepub fn set_log_level(&mut self, level: LogLevel)
pub fn set_log_level(&mut self, level: LogLevel)
Set the minimum log level
Sourcepub fn get_log_level(&self) -> &LogLevel
pub fn get_log_level(&self) -> &LogLevel
Get the current minimum log level
Sourcepub async fn progress(
&self,
message: &str,
progress: f64,
total: Option<f64>,
) -> Result<(), Box<dyn Error + Send + Sync>>
pub async fn progress( &self, message: &str, progress: f64, total: Option<f64>, ) -> Result<(), Box<dyn Error + Send + Sync>>
Send a progress update
§Arguments
message- Progress messageprogress- Current progress value (0.0 to 1.0)total- Optional total value
Sourcepub async fn log_debug(
&self,
message: &str,
) -> Result<(), Box<dyn Error + Send + Sync>>
pub async fn log_debug( &self, message: &str, ) -> Result<(), Box<dyn Error + Send + Sync>>
Log a debug message
Sourcepub async fn log_debug_structured(
&self,
message: &str,
data: Value,
) -> Result<(), Box<dyn Error + Send + Sync>>
pub async fn log_debug_structured( &self, message: &str, data: Value, ) -> Result<(), Box<dyn Error + Send + Sync>>
Log a debug message with structured data
Sourcepub async fn log_info(
&self,
message: &str,
) -> Result<(), Box<dyn Error + Send + Sync>>
pub async fn log_info( &self, message: &str, ) -> Result<(), Box<dyn Error + Send + Sync>>
Log an info message
Sourcepub async fn log_info_structured(
&self,
message: &str,
data: Value,
) -> Result<(), Box<dyn Error + Send + Sync>>
pub async fn log_info_structured( &self, message: &str, data: Value, ) -> Result<(), Box<dyn Error + Send + Sync>>
Log an info message with structured data
Sourcepub async fn log_notice(
&self,
message: &str,
) -> Result<(), Box<dyn Error + Send + Sync>>
pub async fn log_notice( &self, message: &str, ) -> Result<(), Box<dyn Error + Send + Sync>>
Log a notice message
Sourcepub async fn log_notice_structured(
&self,
message: &str,
data: Value,
) -> Result<(), Box<dyn Error + Send + Sync>>
pub async fn log_notice_structured( &self, message: &str, data: Value, ) -> Result<(), Box<dyn Error + Send + Sync>>
Log a notice message with structured data
Sourcepub async fn log_warn(
&self,
message: &str,
) -> Result<(), Box<dyn Error + Send + Sync>>
pub async fn log_warn( &self, message: &str, ) -> Result<(), Box<dyn Error + Send + Sync>>
Log a warning message
Sourcepub async fn log_warn_structured(
&self,
message: &str,
data: Value,
) -> Result<(), Box<dyn Error + Send + Sync>>
pub async fn log_warn_structured( &self, message: &str, data: Value, ) -> Result<(), Box<dyn Error + Send + Sync>>
Log a warning message with structured data
Sourcepub async fn log_error(
&self,
message: &str,
) -> Result<(), Box<dyn Error + Send + Sync>>
pub async fn log_error( &self, message: &str, ) -> Result<(), Box<dyn Error + Send + Sync>>
Log an error message
Sourcepub async fn log_error_structured(
&self,
message: &str,
data: Value,
) -> Result<(), Box<dyn Error + Send + Sync>>
pub async fn log_error_structured( &self, message: &str, data: Value, ) -> Result<(), Box<dyn Error + Send + Sync>>
Log an error message with structured data
Sourcepub async fn log_critical(
&self,
message: &str,
) -> Result<(), Box<dyn Error + Send + Sync>>
pub async fn log_critical( &self, message: &str, ) -> Result<(), Box<dyn Error + Send + Sync>>
Log a critical message
Sourcepub async fn log_critical_structured(
&self,
message: &str,
data: Value,
) -> Result<(), Box<dyn Error + Send + Sync>>
pub async fn log_critical_structured( &self, message: &str, data: Value, ) -> Result<(), Box<dyn Error + Send + Sync>>
Log a critical message with structured data
Sourcepub async fn log_alert(
&self,
message: &str,
) -> Result<(), Box<dyn Error + Send + Sync>>
pub async fn log_alert( &self, message: &str, ) -> Result<(), Box<dyn Error + Send + Sync>>
Log an alert message
Sourcepub async fn log_alert_structured(
&self,
message: &str,
data: Value,
) -> Result<(), Box<dyn Error + Send + Sync>>
pub async fn log_alert_structured( &self, message: &str, data: Value, ) -> Result<(), Box<dyn Error + Send + Sync>>
Log an alert message with structured data
Sourcepub async fn log_emergency(
&self,
message: &str,
) -> Result<(), Box<dyn Error + Send + Sync>>
pub async fn log_emergency( &self, message: &str, ) -> Result<(), Box<dyn Error + Send + Sync>>
Log an emergency message
Sourcepub async fn log_emergency_structured(
&self,
message: &str,
data: Value,
) -> Result<(), Box<dyn Error + Send + Sync>>
pub async fn log_emergency_structured( &self, message: &str, data: Value, ) -> Result<(), Box<dyn Error + Send + Sync>>
Log an emergency message with structured data
Sourcepub async fn is_cancelled(&self) -> bool
pub async fn is_cancelled(&self) -> bool
Check if the current request has been cancelled