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;
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 /// Inbound concurrency cap applied at the axum boundary via
29 /// `tower::limit::ConcurrencyLimitLayer`. For a 1:1 proxy this is
30 /// effectively an upstream concurrency cap too.
31 pub max_concurrent_upstream: usize,
32
33 // ── response shaping ──
34 /// Lock-free: readers call `.load()` (sync, ~5 ns); a writer
35 /// wanting to swap config does `.store(Arc::new(new))`.
36 pub rewrite_config: Arc<ArcSwap<RewriteConfig>>,
37
38 // ── runtime tracking ──
39 pub sessions: MemorySessionStore,
40 pub schema_manager: Arc<SchemaManager<MemorySchemaStore>>,
41
42 // ── per-proxy health display + tunnel callbacks ──
43 pub health: SharedProxyHealth,
44
45 // ── observability (cloned handle, cheap to clone) ──
46 pub event_bus: EventBus,
47}