pub struct StreamManager { /* private fields */ }
Expand description
Enhanced stream manager with resumability support (MCP spec compliant)
Implementations§
Source§impl StreamManager
impl StreamManager
Sourcepub fn new(storage: Arc<BoxedSessionStorage>) -> Self
pub fn new(storage: Arc<BoxedSessionStorage>) -> Self
Create new stream manager with session storage backend
Sourcepub fn with_config(
storage: Arc<BoxedSessionStorage>,
config: StreamConfig,
) -> Self
pub fn with_config( storage: Arc<BoxedSessionStorage>, config: StreamConfig, ) -> Self
Create stream manager with custom configuration
Sourcepub async fn handle_sse_connection(
&self,
session_id: String,
connection_id: ConnectionId,
last_event_id: Option<u64>,
) -> Result<Response<UnsyncBoxBody<Bytes, Error>>, StreamError>
pub async fn handle_sse_connection( &self, session_id: String, connection_id: ConnectionId, last_event_id: Option<u64>, ) -> Result<Response<UnsyncBoxBody<Bytes, Error>>, StreamError>
Handle SSE connection request with proper resumability
Sourcepub async fn register_streaming_connection(
&self,
session_id: &str,
connection_id: ConnectionId,
sender: Sender<SseEvent>,
) -> Result<(), StreamError>
pub async fn register_streaming_connection( &self, session_id: &str, connection_id: ConnectionId, sender: Sender<SseEvent>, ) -> Result<(), StreamError>
Register a streaming connection to receive events for a session (public API for POST streaming)
Sourcepub async fn unregister_connection(
&self,
session_id: &str,
connection_id: &ConnectionId,
)
pub async fn unregister_connection( &self, session_id: &str, connection_id: &ConnectionId, )
Remove a connection when it’s closed
Sourcepub async fn close_session_connections(&self, session_id: &str) -> usize
pub async fn close_session_connections(&self, session_id: &str) -> usize
Close all SSE connections for a session (useful for session termination)
Sourcepub async fn has_connections(&self, session_id: &str) -> bool
pub async fn has_connections(&self, session_id: &str) -> bool
Check if a session has any active SSE connections
Sourcepub async fn broadcast_to_session(
&self,
session_id: &str,
event_type: String,
data: Value,
) -> Result<u64, StreamError>
pub async fn broadcast_to_session( &self, session_id: &str, event_type: String, data: Value, ) -> Result<u64, StreamError>
Send event to specific session (MCP compliant - ONE connection only)
Sourcepub async fn broadcast_to_session_with_options(
&self,
session_id: &str,
event_type: String,
data: Value,
store_when_no_connections: bool,
) -> Result<u64, StreamError>
pub async fn broadcast_to_session_with_options( &self, session_id: &str, event_type: String, data: Value, store_when_no_connections: bool, ) -> Result<u64, StreamError>
Send event to specific session with option to suppress when no connections exist
Sourcepub async fn broadcast_to_all_sessions(
&self,
event_type: String,
data: Value,
) -> Result<Vec<String>, StreamError>
pub async fn broadcast_to_all_sessions( &self, event_type: String, data: Value, ) -> Result<Vec<String>, StreamError>
Broadcast to all sessions (for server-wide notifications)
Sourcepub async fn cleanup_connections(&self) -> usize
pub async fn cleanup_connections(&self) -> usize
Clean up closed connections
Sourcepub async fn create_post_sse_stream(
&self,
session_id: String,
response: JsonRpcResponse,
) -> Result<Response<BoxBody<Bytes, Infallible>>, StreamError>
pub async fn create_post_sse_stream( &self, session_id: String, response: JsonRpcResponse, ) -> Result<Response<BoxBody<Bytes, Infallible>>, StreamError>
Create SSE stream for POST requests (MCP Streamable HTTP)
Sourcepub async fn subscribe_to_notifications(
&self,
session_id: &str,
notification_types: Vec<String>,
)
pub async fn subscribe_to_notifications( &self, session_id: &str, notification_types: Vec<String>, )
Subscribe a session to specific notification types
Sourcepub async fn unsubscribe_from_notifications(
&self,
session_id: &str,
notification_types: Vec<String>,
)
pub async fn unsubscribe_from_notifications( &self, session_id: &str, notification_types: Vec<String>, )
Unsubscribe a session from specific notification types
Sourcepub async fn is_subscribed(
&self,
session_id: &str,
notification_type: &str,
) -> bool
pub async fn is_subscribed( &self, session_id: &str, notification_type: &str, ) -> bool
Check if a session is subscribed to a specific notification type
Sourcepub async fn get_subscriptions(&self, session_id: &str) -> HashSet<String>
pub async fn get_subscriptions(&self, session_id: &str) -> HashSet<String>
Get all subscriptions for a session
Sourcepub async fn clear_subscriptions(&self, session_id: &str)
pub async fn clear_subscriptions(&self, session_id: &str)
Clear all subscriptions for a session (used during session cleanup)
Sourcepub fn get_config(&self) -> &StreamConfig
pub fn get_config(&self) -> &StreamConfig
Get the stream configuration (for testing and debugging)
Sourcepub async fn get_stats(&self) -> StreamStats
pub async fn get_stats(&self) -> StreamStats
Get statistics about active streams