pub struct ProxyAwareSessionManager { /* private fields */ }Expand description
感知代理状态的 SessionManager
职责:
- 委托 LocalSessionManager 处理核心 session 逻辑
- 维护 session → backend_version 映射
- 在 resume 时检查版本一致性
- 版本不匹配时使 session 失效
Implementations§
Source§impl ProxyAwareSessionManager
impl ProxyAwareSessionManager
pub fn new(handler: Arc<ProxyHandler>) -> Self
pub fn with_keep_alive(handler: Arc<ProxyHandler>, keep_alive: Duration) -> Self
Sourcepub fn with_max_sessions(self, max_sessions: Option<usize>) -> Self
pub fn with_max_sessions(self, max_sessions: Option<usize>) -> Self
Limit the number of concurrent sessions (None = unlimited).
Trait Implementations§
Source§impl SessionManager for ProxyAwareSessionManager
impl SessionManager for ProxyAwareSessionManager
type Error = LocalSessionManagerError
type Transport = WorkerTransport<LocalSessionWorker>
Source§async fn create_session(
&self,
) -> Result<(SessionId, Self::Transport), Self::Error>
async fn create_session( &self, ) -> Result<(SessionId, Self::Transport), Self::Error>
Create a new session and return its ID together with the transport
that will be used to exchange MCP messages within this session.
Source§async fn initialize_session(
&self,
id: &SessionId,
message: ClientJsonRpcMessage,
) -> Result<ServerJsonRpcMessage, Self::Error>
async fn initialize_session( &self, id: &SessionId, message: ClientJsonRpcMessage, ) -> Result<ServerJsonRpcMessage, Self::Error>
Forward the first message (the
initialize request) to the session.Source§async fn has_session(&self, id: &SessionId) -> Result<bool, Self::Error>
async fn has_session(&self, id: &SessionId) -> Result<bool, Self::Error>
Return
true if a session with the given ID exists and is active.Source§async fn close_session(&self, id: &SessionId) -> Result<(), Self::Error>
async fn close_session(&self, id: &SessionId) -> Result<(), Self::Error>
Close and remove the session. Corresponds to an HTTP DELETE request
with
Mcp-Session-Id.Source§async fn create_stream(
&self,
id: &SessionId,
message: ClientJsonRpcMessage,
) -> Result<impl Stream<Item = ServerSseMessage> + Send + 'static, Self::Error>
async fn create_stream( &self, id: &SessionId, message: ClientJsonRpcMessage, ) -> Result<impl Stream<Item = ServerSseMessage> + Send + 'static, Self::Error>
Route a client request into the session and return an SSE stream
carrying the server’s response(s).
Source§async fn accept_message(
&self,
id: &SessionId,
message: ClientJsonRpcMessage,
) -> Result<(), Self::Error>
async fn accept_message( &self, id: &SessionId, message: ClientJsonRpcMessage, ) -> Result<(), Self::Error>
Accept a notification, response, or error message from the client
without producing a response stream.
Source§async fn create_standalone_stream(
&self,
id: &SessionId,
) -> Result<impl Stream<Item = ServerSseMessage> + Send + 'static, Self::Error>
async fn create_standalone_stream( &self, id: &SessionId, ) -> Result<impl Stream<Item = ServerSseMessage> + Send + 'static, Self::Error>
Create an SSE stream not tied to a specific client request (HTTP GET).
Source§async fn resume(
&self,
id: &SessionId,
last_event_id: String,
) -> Result<impl Stream<Item = ServerSseMessage> + Send + 'static, Self::Error>
async fn resume( &self, id: &SessionId, last_event_id: String, ) -> Result<impl Stream<Item = ServerSseMessage> + Send + 'static, Self::Error>
Resume an SSE stream from the given
Last-Event-ID, replaying any
events the client missed.Source§fn restore_session(
&self,
_id: Arc<str>,
) -> impl Future<Output = Result<RestoreOutcome<Self::Transport>, Self::Error>> + Send
fn restore_session( &self, _id: Arc<str>, ) -> impl Future<Output = Result<RestoreOutcome<Self::Transport>, Self::Error>> + Send
Attempt to restore a previously-known session from external state,
creating a fresh in-memory session worker with the given
id. Read moreSource§fn event_store(&self) -> Option<Arc<dyn EventStore>>
fn event_store(&self) -> Option<Arc<dyn EventStore>>
Return the shared event store used for resumable SSE streams.
Auto Trait Implementations§
impl !Freeze for ProxyAwareSessionManager
impl !RefUnwindSafe for ProxyAwareSessionManager
impl !UnwindSafe for ProxyAwareSessionManager
impl Send for ProxyAwareSessionManager
impl Sync for ProxyAwareSessionManager
impl Unpin for ProxyAwareSessionManager
impl UnsafeUnpin for ProxyAwareSessionManager
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
Mutably borrows from an owned value. Read more