rust_mcp_sdk/mcp_http/
app_state.rs1use crate::mcp_traits::mcp_handler::McpServerHandler;
2use crate::session_store::SessionStore;
3use crate::{id_generator::FastIdGenerator, mcp_traits::IdGenerator, schema::InitializeResult};
4use rust_mcp_transport::event_store::EventStore;
5use rust_mcp_transport::{SessionId, TransportOptions};
6use std::{sync::Arc, time::Duration};
7
8#[derive(Clone)]
13pub struct McpAppState {
14 pub session_store: Arc<dyn SessionStore>,
15 pub id_generator: Arc<dyn IdGenerator<SessionId>>,
16 pub stream_id_gen: Arc<FastIdGenerator>,
17 pub server_details: Arc<InitializeResult>,
18 pub handler: Arc<dyn McpServerHandler>,
19 pub ping_interval: Duration,
20 pub transport_options: Arc<TransportOptions>,
21 pub enable_json_response: bool,
22 pub allowed_hosts: Option<Vec<String>>,
25 pub allowed_origins: Option<Vec<String>>,
28 pub dns_rebinding_protection: bool,
31 pub event_store: Option<Arc<dyn EventStore>>,
34}
35
36impl McpAppState {
37 pub fn needs_dns_protection(&self) -> bool {
38 self.dns_rebinding_protection
39 && (self.allowed_hosts.is_some() || self.allowed_origins.is_some())
40 }
41}