Session & SessionManager
Session & SessionManager
The session management layer tracks active MCP sessions tied to SignalWire call
IDs. Each session wraps an MCPClient
process and is automatically cleaned up when it expires or when the underlying
process dies.
Session
A dataclass representing a single active MCP session. Sessions are created by
SessionManager.create_session()
and should not be instantiated directly.
Properties
session_id
Unique identifier for the session, typically a SignalWire call ID.
service_name
Name of the MCP service this session is connected to.
process
The MCPClient instance
managing the MCP server process for this session.
created_at
Timestamp when the session was created.
last_accessed
Timestamp of the most recent activity on this session. Updated automatically
when the session is retrieved via
get_session().
timeout
Session timeout in seconds. The session is considered expired when
last_accessed + timeout is in the past.
metadata
Arbitrary metadata attached to the session.
is_expired
Read-only property. Returns True if the session has exceeded its timeout
since the last access.
is_alive
Read-only property. Returns True if the underlying MCP client process is
still running.
touch
touch() -> None
Update last_accessed to the current time, resetting the expiration clock.
Called automatically by
get_session().
SessionManager
Manages the full lifecycle of MCP sessions including creation, retrieval, cleanup, and resource limits. Runs a background thread that periodically removes expired or dead sessions.