Skip to main content

ProxyConfig

Struct ProxyConfig 

Source
pub struct ProxyConfig {
    pub proxy: ProxySettings,
    pub backends: Vec<BackendConfig>,
    pub auth: Option<AuthConfig>,
    pub performance: PerformanceConfig,
    pub security: SecurityConfig,
    pub observability: ObservabilityConfig,
}
Expand description

Top-level proxy configuration, typically loaded from a TOML file.

Fields§

§proxy: ProxySettings

Core proxy settings (name, version, listen address).

§backends: Vec<BackendConfig>

Backend MCP servers to proxy.

§auth: Option<AuthConfig>

Inbound authentication configuration.

§performance: PerformanceConfig

Performance tuning options.

§security: SecurityConfig

Security policies.

§observability: ObservabilityConfig

Logging, metrics, and tracing configuration.

Implementations§

Source§

impl ProxyConfig

Source

pub fn load(path: &Path) -> Result<Self>

Load and validate a config from a file path.

Examples found in repository?
examples/library-mode.rs (line 37)
29async fn main() -> Result<()> {
30    tracing_subscriber::fmt()
31        .with_env_filter("tower_mcp=info,mcp_proxy=info")
32        .init();
33
34    let cli = Cli::parse();
35
36    // Load and resolve config
37    let mut config = mcp_proxy::ProxyConfig::load(&cli.config)?;
38    config.resolve_env_vars();
39
40    let addr = format!("{}:{}", config.proxy.listen.host, config.proxy.listen.port);
41
42    // Build the proxy
43    let proxy = mcp_proxy::Proxy::from_config(config).await?;
44
45    // Extract the router (includes MCP transport + admin API)
46    let (proxy_router, _session_handle) = proxy.into_router();
47
48    // Build custom application routes
49    let app_routes = Router::new().route("/app/status", get(app_status));
50
51    // Merge proxy router with custom routes
52    let app = proxy_router.merge(app_routes);
53
54    tracing::info!(listen = %addr, "Library mode example ready");
55
56    let listener = tokio::net::TcpListener::bind(&addr).await?;
57    axum::serve(listener, app).await?;
58
59    Ok(())
60}
Source

pub fn parse(toml: &str) -> Result<Self>

Parse and validate a config from a TOML string.

§Examples
use mcp_proxy::ProxyConfig;

let config = ProxyConfig::parse(r#"
    [proxy]
    name = "my-proxy"
    [proxy.listen]

    [[backends]]
    name = "echo"
    transport = "stdio"
    command = "echo"
"#).unwrap();

assert_eq!(config.proxy.name, "my-proxy");
assert_eq!(config.backends.len(), 1);
Source

pub fn resolve_env_vars(&mut self)

Resolve environment variable references in config values. Replaces ${VAR_NAME} with the value of the environment variable.

Examples found in repository?
examples/library-mode.rs (line 38)
29async fn main() -> Result<()> {
30    tracing_subscriber::fmt()
31        .with_env_filter("tower_mcp=info,mcp_proxy=info")
32        .init();
33
34    let cli = Cli::parse();
35
36    // Load and resolve config
37    let mut config = mcp_proxy::ProxyConfig::load(&cli.config)?;
38    config.resolve_env_vars();
39
40    let addr = format!("{}:{}", config.proxy.listen.host, config.proxy.listen.port);
41
42    // Build the proxy
43    let proxy = mcp_proxy::Proxy::from_config(config).await?;
44
45    // Extract the router (includes MCP transport + admin API)
46    let (proxy_router, _session_handle) = proxy.into_router();
47
48    // Build custom application routes
49    let app_routes = Router::new().route("/app/status", get(app_status));
50
51    // Merge proxy router with custom routes
52    let app = proxy_router.merge(app_routes);
53
54    tracing::info!(listen = %addr, "Library mode example ready");
55
56    let listener = tokio::net::TcpListener::bind(&addr).await?;
57    axum::serve(listener, app).await?;
58
59    Ok(())
60}

Trait Implementations§

Source§

impl Debug for ProxyConfig

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for ProxyConfig

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for ProxyConfig

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,