1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//! # mcpr-proxy
//!
//! Proxy engine for mcpr: request routing, upstream forwarding, SSE streaming,
//! and widget CSP rewriting.
//!
//! This crate sits between MCP clients and upstream MCP servers. It classifies
//! requests, forwards them over HTTP, relays SSE streams, and rewrites widget
//! CSP metadata on the way back.
//!
//! ## Responsibilities
//!
//! - **Request routing** (`router`): Classify incoming HTTP requests into typed
//! variants — MCP JSON-RPC POST, MCP SSE GET, widget HTML, widget assets,
//! OAuth callbacks, or passthrough.
//!
//! - **Upstream forwarding** (`forwarding`): HTTP client with connection pooling,
//! semaphore-based concurrency limiting, configurable timeouts, and header
//! forwarding (auth, content-type, MCP session ID).
//!
//! - **SSE handling** (`sse`): Extract JSON from SSE-wrapped responses, re-wrap
//! JSON as SSE, and split upstream URLs into (base, path) components.
//!
//! - **Widget CSP** (`csp`, `rewrite`): Declarative CSP config with per-directive
//! modes and widget-scoped overrides. `csp::effective_domains` computes the
//! final domain list for one directive; `rewrite::rewrite_response` applies
//! that to every CSP array in a JSON-RPC response.
//!
//! - **Proxy state** (`state`): Shared runtime state tracking MCP upstream
//! health, tunnel status, widget discovery, cloud sync, and request counters.
//!
//! ## Module layout
//!
//! ```text
//! proxy/
//! ├── router.rs ClassifiedRequest, classify()
//! ├── forwarding.rs UpstreamClient, forward_request()
//! ├── sse.rs SSE extract/wrap helpers
//! ├── csp.rs CspConfig, DirectivePolicy, WidgetScoped, effective_domains
//! ├── rewrite.rs RewriteConfig, rewrite_response()
//! └── state.rs ProxyState, ConnectionStatus, SharedProxyState
//! ```
pub use ;
pub use ;
pub use ;