Skip to main content

mcpr_core/proxy/
proxy_state.rs

1//! [`ProxyState`] — everything one running proxy instance needs to serve
2//! traffic: upstream client, rewrite config, sessions, schema manager,
3//! per-proxy health, event bus handle. Request handlers take
4//! `Arc<ProxyState>`.
5
6use std::sync::Arc;
7
8use arc_swap::ArcSwap;
9
10use crate::event::EventBus;
11use crate::protocol::schema_manager::{MemorySchemaStore, SchemaManager};
12use crate::protocol::session::MemorySessionStore;
13
14use super::RewriteConfig;
15use super::forwarding::UpstreamClient;
16use super::health::SharedProxyHealth;
17use super::widgets::WidgetSource;
18
19/// Everything one running proxy needs to serve a request end-to-end.
20pub struct ProxyState {
21    /// Proxy name used to tag events and look up per-proxy resources.
22    pub name: String,
23
24    // ── forwarding ──
25    pub mcp_upstream: String,
26    pub upstream: UpstreamClient,
27    pub max_request_body: usize,
28    pub max_response_body: usize,
29
30    // ── response shaping ──
31    /// Lock-free: readers call `.load()` (sync, ~5 ns); a writer
32    /// wanting to swap config does `.store(Arc::new(new))`.
33    pub rewrite_config: Arc<ArcSwap<RewriteConfig>>,
34    pub widget_source: Option<WidgetSource>,
35
36    // ── runtime tracking ──
37    pub sessions: MemorySessionStore,
38    pub schema_manager: Arc<SchemaManager<MemorySchemaStore>>,
39
40    // ── per-proxy health display + tunnel callbacks ──
41    pub health: SharedProxyHealth,
42
43    // ── observability (cloned handle, cheap to clone) ──
44    pub event_bus: EventBus,
45}