Skip to main content

mcp_kit/server/
session.rs

1use uuid::Uuid;
2
3use crate::types::ClientInfo;
4
5/// Unique session identifier
6#[derive(Debug, Clone, PartialEq, Eq, Hash)]
7pub struct SessionId(pub String);
8
9impl SessionId {
10    pub fn new() -> Self {
11        Self(Uuid::new_v4().to_string())
12    }
13}
14
15impl Default for SessionId {
16    fn default() -> Self {
17        Self::new()
18    }
19}
20
21impl std::fmt::Display for SessionId {
22    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
23        write!(f, "{}", self.0)
24    }
25}
26
27/// Per-connection session data
28#[derive(Debug, Clone)]
29pub struct Session {
30    pub id: SessionId,
31    pub client_info: Option<ClientInfo>,
32    pub protocol_version: Option<String>,
33    pub initialized: bool,
34}
35
36impl Session {
37    pub fn new() -> Self {
38        Self {
39            id: SessionId::new(),
40            client_info: None,
41            protocol_version: None,
42            initialized: false,
43        }
44    }
45}
46
47impl Default for Session {
48    fn default() -> Self {
49        Self::new()
50    }
51}