pub struct SessionContext {
pub session_id: String,
pub get_state: Arc<dyn Fn(&str) -> Pin<Box<dyn Future<Output = Option<Value>> + Send + 'static>> + Send + Sync>,
pub set_state: Arc<dyn Fn(&str, Value) -> Pin<Box<dyn Future<Output = ()> + Send + 'static>> + Send + Sync>,
pub remove_state: Arc<dyn Fn(&str) -> Pin<Box<dyn Future<Output = Option<Value>> + Send + 'static>> + Send + Sync>,
pub is_initialized: Arc<dyn Fn() -> Pin<Box<dyn Future<Output = bool> + Send + 'static>> + Send + Sync>,
pub send_notification: Arc<dyn Fn(SessionEvent) -> Pin<Box<dyn Future<Output = ()> + Send + 'static>> + Send + Sync>,
pub broadcaster: Option<Arc<dyn Any + Send + Sync>>,
}Fields§
§session_id: StringUnique session identifier
get_state: Arc<dyn Fn(&str) -> Pin<Box<dyn Future<Output = Option<Value>> + Send + 'static>> + Send + Sync>Get session state value by key (async)
set_state: Arc<dyn Fn(&str, Value) -> Pin<Box<dyn Future<Output = ()> + Send + 'static>> + Send + Sync>Set session state value by key (async)
remove_state: Arc<dyn Fn(&str) -> Pin<Box<dyn Future<Output = Option<Value>> + Send + 'static>> + Send + Sync>Remove session state value by key (async)
is_initialized: Arc<dyn Fn() -> Pin<Box<dyn Future<Output = bool> + Send + 'static>> + Send + Sync>Check if session is initialized (async)
send_notification: Arc<dyn Fn(SessionEvent) -> Pin<Box<dyn Future<Output = ()> + Send + 'static>> + Send + Sync>Send notification to this session (async)
broadcaster: Option<Arc<dyn Any + Send + Sync>>NotificationBroadcaster for sending MCP-compliant notifications
Implementations§
Source§impl SessionContext
impl SessionContext
Sourcepub fn has_broadcaster(&self) -> bool
pub fn has_broadcaster(&self) -> bool
Check if this context has a broadcaster available
Sourcepub fn get_raw_broadcaster(&self) -> Option<Arc<dyn Any + Send + Sync>>
pub fn get_raw_broadcaster(&self) -> Option<Arc<dyn Any + Send + Sync>>
Get the raw broadcaster (as Any) - for use by framework internals
Sourcepub async fn get_typed_state<T>(&self, key: &str) -> Option<T>where
T: DeserializeOwned,
pub async fn get_typed_state<T>(&self, key: &str) -> Option<T>where
T: DeserializeOwned,
Convenience method to get typed session state (async)
Sourcepub async fn set_typed_state<T>(
&self,
key: &str,
value: T,
) -> Result<(), String>where
T: Serialize,
pub async fn set_typed_state<T>(
&self,
key: &str,
value: T,
) -> Result<(), String>where
T: Serialize,
Convenience method to set typed session state (async)
Sourcepub async fn notify(&self, event: SessionEvent)
pub async fn notify(&self, event: SessionEvent)
Send a custom notification to this session (async)
Sourcepub async fn notify_progress(
&self,
progress_token: impl Into<String>,
progress: u64,
)
pub async fn notify_progress( &self, progress_token: impl Into<String>, progress: u64, )
Send a progress notification
Sourcepub async fn notify_progress_with_total(
&self,
progress_token: impl Into<String>,
progress: u64,
total: u64,
)
pub async fn notify_progress_with_total( &self, progress_token: impl Into<String>, progress: u64, total: u64, )
Send a progress notification with total
Sourcepub async fn notify_log(
&self,
level: LoggingLevel,
data: Value,
logger: Option<String>,
meta: Option<HashMap<String, Value>>,
)
pub async fn notify_log( &self, level: LoggingLevel, data: Value, logger: Option<String>, meta: Option<HashMap<String, Value>>, )
Send a logging message notification (with session-aware level filtering)
Sourcepub async fn notify_resources_changed(&self)
pub async fn notify_resources_changed(&self)
Send a resource list changed notification
Sourcepub async fn notify_resource_updated(&self, uri: impl Into<String>)
pub async fn notify_resource_updated(&self, uri: impl Into<String>)
Send a resource updated notification
Sourcepub async fn notify_tools_changed(&self)
pub async fn notify_tools_changed(&self)
Send a tools list changed notification
Sourcepub async fn get_logging_level(&self) -> LoggingLevel
pub async fn get_logging_level(&self) -> LoggingLevel
Get the current logging level for this session (async)
Sourcepub async fn set_logging_level(&self, level: LoggingLevel)
pub async fn set_logging_level(&self, level: LoggingLevel)
Set the logging level for this session (async)
Sourcepub async fn should_log(&self, message_level: LoggingLevel) -> bool
pub async fn should_log(&self, message_level: LoggingLevel) -> bool
Check if a log message at the given level should be sent to this session (async)
Sourcepub fn should_log_sync(&self, message_level: LoggingLevel) -> bool
pub fn should_log_sync(&self, message_level: LoggingLevel) -> bool
Synchronous version of should_log for trait compatibility
Trait Implementations§
Source§impl Clone for SessionContext
impl Clone for SessionContext
Source§fn clone(&self) -> SessionContext
fn clone(&self) -> SessionContext
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl LoggingTarget for SessionContext
Implement LoggingTarget trait from turul-mcp-builders to enable session-aware logging
impl LoggingTarget for SessionContext
Implement LoggingTarget trait from turul-mcp-builders to enable session-aware logging
Source§fn should_log(&self, level: LoggingLevel) -> bool
fn should_log(&self, level: LoggingLevel) -> bool
Source§impl SessionView for SessionContext
Implement SessionView trait for SessionContext
(trait is defined in turul-mcp-session-storage)
impl SessionView for SessionContext
Implement SessionView trait for SessionContext (trait is defined in turul-mcp-session-storage)
This allows SessionContext to be used with middleware. Metadata is stored using a special prefix (“meta:”) to distinguish it from regular state.
Source§fn session_id(&self) -> &str
fn session_id(&self) -> &str
Source§fn get_state<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Option<Value>, String>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn get_state<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Option<Value>, String>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Source§fn set_state<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
value: Value,
) -> Pin<Box<dyn Future<Output = Result<(), String>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn set_state<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
value: Value,
) -> Pin<Box<dyn Future<Output = Result<(), String>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Auto Trait Implementations§
impl Freeze for SessionContext
impl !RefUnwindSafe for SessionContext
impl Send for SessionContext
impl Sync for SessionContext
impl Unpin for SessionContext
impl !UnwindSafe for SessionContext
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more