mod line;
use std::collections::HashSet;
use serde_json::Value;
use turbomcp_core::types::core::ProtocolVersion;
#[derive(Debug, Clone)]
pub(crate) enum SessionState {
Uninitialized,
Initialized(InitializedSessionState),
}
#[derive(Debug, Clone)]
pub(crate) struct InitializedSessionState {
protocol_version: ProtocolVersion,
seen_request_ids: HashSet<String>,
}
impl InitializedSessionState {
pub(crate) fn new(
protocol_version: ProtocolVersion,
initialize_request_id: Option<&Value>,
) -> Self {
let mut seen_request_ids = HashSet::new();
if let Some(request_id) = initialize_request_id.and_then(request_id_key) {
seen_request_ids.insert(request_id);
}
Self {
protocol_version,
seen_request_ids,
}
}
pub(crate) fn protocol_version(&self) -> &ProtocolVersion {
&self.protocol_version
}
pub(crate) fn register_request_id(&mut self, request_id: Option<&Value>) -> bool {
let Some(request_id) = request_id.and_then(request_id_key) else {
return true;
};
self.seen_request_ids.insert(request_id)
}
}
pub(crate) fn request_id_key(id: &Value) -> Option<String> {
serde_json::to_string(id).ok()
}
#[cfg(feature = "stdio")]
pub mod stdio;
#[cfg(feature = "tcp")]
pub mod tcp;
#[cfg(feature = "unix")]
pub mod unix;
#[cfg(feature = "channel")]
pub mod channel;
#[cfg(feature = "http")]
pub mod http;
#[cfg(feature = "websocket")]
pub mod websocket;
pub use line::{LineReader, LineTransportRunner, LineWriter};
pub use crate::config::DEFAULT_MAX_MESSAGE_SIZE;
pub const MAX_MESSAGE_SIZE: usize = DEFAULT_MAX_MESSAGE_SIZE;