pub struct MessageContext<T = ()> { /* private fields */ }Expand description
Message context for session and metadata management
This structure carries session information and metadata for each message, enabling proper handling of multi-session transports like HTTP.
§Examples
use airsprotocols_mcp::protocol::MessageContext;
use chrono::Utc;
// Default generic context (for STDIO)
let context = MessageContext::<()>::new("session-123".to_string())
.with_remote_addr("192.168.1.100:8080".to_string())
.with_user_agent("airsprotocols-mcp-client/1.0".to_string());
assert_eq!(context.session_id(), Some("session-123"));
assert_eq!(context.remote_addr(), Some("192.168.1.100:8080"));Implementations§
Source§impl<T> MessageContext<T>
impl<T> MessageContext<T>
Sourcepub fn new_with_transport_data(
session_id: impl Into<String>,
transport_data: T,
) -> Self
pub fn new_with_transport_data( session_id: impl Into<String>, transport_data: T, ) -> Self
Create a new message context with transport-specific data
Sourcepub fn new(session_id: impl Into<String>) -> Selfwhere
T: Default,
pub fn new(session_id: impl Into<String>) -> Selfwhere
T: Default,
Create a new message context without transport data (for simple transports)
Sourcepub fn without_session() -> Selfwhere
T: Default,
pub fn without_session() -> Selfwhere
T: Default,
Create a new message context without session ID or transport data
Sourcepub fn session_id(&self) -> Option<&str>
pub fn session_id(&self) -> Option<&str>
Get session ID
Sourcepub fn remote_addr(&self) -> Option<&str>
pub fn remote_addr(&self) -> Option<&str>
Get remote address
Sourcepub fn get_metadata(&self, key: &str) -> Option<&str>
pub fn get_metadata(&self, key: &str) -> Option<&str>
Get metadata value
Sourcepub fn with_remote_addr(self, addr: String) -> Self
pub fn with_remote_addr(self, addr: String) -> Self
Set remote address
Sourcepub fn with_metadata(self, key: String, value: String) -> Self
pub fn with_metadata(self, key: String, value: String) -> Self
Add metadata
Sourcepub fn with_user_agent(self, user_agent: String) -> Self
pub fn with_user_agent(self, user_agent: String) -> Self
Convenience method to add user agent
Sourcepub fn with_content_type(self, content_type: String) -> Self
pub fn with_content_type(self, content_type: String) -> Self
Convenience method to add content type
Sourcepub fn transport_data(&self) -> Option<&T>
pub fn transport_data(&self) -> Option<&T>
Get transport-specific data
Returns a reference to the transport-specific data if it exists. This allows handlers to access transport-specific context information.
Sourcepub fn with_transport_data(self, data: T) -> Self
pub fn with_transport_data(self, data: T) -> Self
Set transport-specific data
Adds or updates transport-specific data for this context.
Sourcepub fn has_transport_data(&self) -> bool
pub fn has_transport_data(&self) -> bool
Check if transport data is available
Returns true if this context contains transport-specific data.
Trait Implementations§
Source§impl<T: Clone> Clone for MessageContext<T>
impl<T: Clone> Clone for MessageContext<T>
Source§fn clone(&self) -> MessageContext<T>
fn clone(&self) -> MessageContext<T>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more