Module mcp_session

Module mcp_session 

Source
Expand description

Streamable HTTP session management for MCP transport

This module implements a lightweight session management system for MCP streamable HTTP with SSE support.

Structs§

Session
Per-session state
SessionHandle
A handle to a session’s message stream

Functions§

broadcast_to_all
Send the given JSON-RPC message to every active session.
disconnect_all
Disconnect all sessions
expire_old
Expire any sessions older than max_age, dropping them from the map.
get_receiver
Get a session’s receiver for SSE streaming
get_sender
Fetch and “touch” the sender for this session, extending its lifetime. Returns None if the session does not exist or has already expired.
new_session
Create a brand new session. Returns the session_id and a Receiver<String> you can use to drive an SSE stream.
remove_session
Explicitly remove/terminate a session. You can call this on client disconnect or after HTTP GET SSE finishes.
send_to_session
Send the given JSON-RPC message to a specific session
session_count
Get count of active sessions
session_exists
Check if a session exists and touch it
spawn_session_cleanup
Spawn session cleanup task for automatic session management

Type Aliases§

SessionMap