turul_rpc_server/session.rs
1use serde_json::Value;
2use std::collections::HashMap;
3use std::sync::Arc;
4
5/// Minimal session context for JSON-RPC handlers.
6///
7/// Provides basic session information without imposing a transport.
8/// Designed to be passed by value (it is `Clone`) into handlers.
9///
10/// ## Field semantics
11///
12/// - `session_id`: opaque session identifier; format is caller's choice.
13/// - `metadata`: free-form key/value bag, persisted by the caller's
14/// session storage if any.
15/// - `broadcaster`: optional type-erased back-channel installed by the
16/// transport. Stored as `Arc<dyn Any + Send + Sync>` so this crate does
17/// not depend on any specific notification channel implementation.
18/// Downstream code (e.g. an MCP server) downcasts to its own concrete
19/// type.
20/// - `timestamp`: Unix milliseconds when the context was created.
21/// - `extensions`: request-scoped key/value bag for auth claims, middleware
22/// data, etc. Populated by the transport layer; never persisted.
23#[derive(Debug, Clone)]
24pub struct SessionContext {
25 /// Unique session identifier.
26 pub session_id: String,
27 /// Session metadata.
28 pub metadata: HashMap<String, Value>,
29 /// Optional type-erased broadcaster for session notifications.
30 ///
31 /// Stored as `Arc<dyn Any>` to avoid coupling this crate to any
32 /// specific notification channel type. Transport layers downcast as
33 /// needed.
34 pub broadcaster: Option<Arc<dyn std::any::Any + Send + Sync>>,
35 /// Session timestamp (Unix milliseconds).
36 pub timestamp: u64,
37 /// Request-scoped extensions (auth claims, middleware data).
38 ///
39 /// Populated by the transport layer; never persisted to session
40 /// storage by `turul-rpc`.
41 pub extensions: HashMap<String, Value>,
42}