Skip to main content

rmcp/transport/streamable_http_server/session/
never.rs

1use futures::Stream;
2use thiserror::Error;
3
4use super::{ServerSseMessage, SessionId, SessionManager};
5use crate::{
6    RoleServer,
7    model::{ClientJsonRpcMessage, ServerJsonRpcMessage},
8    transport::Transport,
9};
10
11#[derive(Debug, Clone, Error)]
12#[error("Session management is not supported")]
13#[non_exhaustive]
14pub struct ErrorSessionManagementNotSupported;
15#[derive(Debug, Clone, Default)]
16#[non_exhaustive]
17pub struct NeverSessionManager {}
18#[non_exhaustive]
19pub enum NeverTransport {}
20impl Transport<RoleServer> for NeverTransport {
21    type Error = ErrorSessionManagementNotSupported;
22
23    fn send(
24        &mut self,
25        _item: ServerJsonRpcMessage,
26    ) -> impl Future<Output = Result<(), Self::Error>> + Send + 'static {
27        futures::future::ready(Err(ErrorSessionManagementNotSupported))
28    }
29
30    fn receive(&mut self) -> impl Future<Output = Option<ClientJsonRpcMessage>> {
31        futures::future::ready(None)
32    }
33
34    async fn close(&mut self) -> Result<(), Self::Error> {
35        Err(ErrorSessionManagementNotSupported)
36    }
37}
38
39impl SessionManager for NeverSessionManager {
40    type Error = ErrorSessionManagementNotSupported;
41    type Transport = NeverTransport;
42
43    fn create_session(
44        &self,
45    ) -> impl Future<Output = Result<(SessionId, Self::Transport), Self::Error>> + Send {
46        futures::future::ready(Err(ErrorSessionManagementNotSupported))
47    }
48
49    fn initialize_session(
50        &self,
51        _id: &SessionId,
52        _message: ClientJsonRpcMessage,
53    ) -> impl Future<Output = Result<ServerJsonRpcMessage, Self::Error>> + Send {
54        futures::future::ready(Err(ErrorSessionManagementNotSupported))
55    }
56
57    fn has_session(
58        &self,
59        _id: &SessionId,
60    ) -> impl Future<Output = Result<bool, Self::Error>> + Send {
61        futures::future::ready(Err(ErrorSessionManagementNotSupported))
62    }
63
64    fn close_session(
65        &self,
66        _id: &SessionId,
67    ) -> impl Future<Output = Result<(), Self::Error>> + Send {
68        futures::future::ready(Err(ErrorSessionManagementNotSupported))
69    }
70
71    fn create_stream(
72        &self,
73        _id: &SessionId,
74        _message: ClientJsonRpcMessage,
75    ) -> impl Future<
76        Output = Result<impl Stream<Item = ServerSseMessage> + Send + 'static, Self::Error>,
77    > + Send {
78        futures::future::ready(Result::<futures::stream::Pending<_>, _>::Err(
79            ErrorSessionManagementNotSupported,
80        ))
81    }
82    fn create_standalone_stream(
83        &self,
84        _id: &SessionId,
85    ) -> impl Future<
86        Output = Result<impl Stream<Item = ServerSseMessage> + Send + 'static, Self::Error>,
87    > + Send {
88        futures::future::ready(Result::<futures::stream::Pending<_>, _>::Err(
89            ErrorSessionManagementNotSupported,
90        ))
91    }
92    fn resume(
93        &self,
94        _id: &SessionId,
95        _last_event_id: String,
96    ) -> impl Future<
97        Output = Result<impl Stream<Item = ServerSseMessage> + Send + 'static, Self::Error>,
98    > + Send {
99        futures::future::ready(Result::<futures::stream::Pending<_>, _>::Err(
100            ErrorSessionManagementNotSupported,
101        ))
102    }
103    fn accept_message(
104        &self,
105        _id: &SessionId,
106        _message: ClientJsonRpcMessage,
107    ) -> impl Future<Output = Result<(), Self::Error>> + Send {
108        futures::future::ready(Err(ErrorSessionManagementNotSupported))
109    }
110}