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;
7use tokio::sync::RwLock;
8
9use crate::event::EventBus;
10use crate::protocol::schema_manager::{MemorySchemaStore, SchemaManager};
11use crate::protocol::session::MemorySessionStore;
12
13use super::RewriteConfig;
14use super::forwarding::UpstreamClient;
15use super::health::SharedProxyHealth;
16use super::widgets::WidgetSource;
17
18/// Everything one running proxy needs to serve a request end-to-end.
19pub struct ProxyState {
20    /// Proxy name used to tag events and look up per-proxy resources.
21    pub name: String,
22
23    // ── forwarding ──
24    pub mcp_upstream: String,
25    pub upstream: UpstreamClient,
26    pub max_request_body: usize,
27    pub max_response_body: usize,
28
29    // ── response shaping ──
30    pub rewrite_config: Arc<RwLock<RewriteConfig>>,
31    pub widget_source: Option<WidgetSource>,
32
33    // ── runtime tracking ──
34    pub sessions: MemorySessionStore,
35    pub schema_manager: Arc<SchemaManager<MemorySchemaStore>>,
36
37    // ── per-proxy health display + tunnel callbacks ──
38    pub health: SharedProxyHealth,
39
40    // ── observability (cloned handle, cheap to clone) ──
41    pub event_bus: EventBus,
42}