pub struct ProxyConfig {
pub proxy: ProxySettings,
pub backends: Vec<BackendConfig>,
pub auth: Option<AuthConfig>,
pub performance: PerformanceConfig,
pub security: SecurityConfig,
pub cache: CacheBackendConfig,
pub observability: ObservabilityConfig,
pub composite_tools: Vec<CompositeToolConfig>,
pub source_path: Option<PathBuf>,
}Expand description
Top-level proxy configuration, typically loaded from a TOML file.
Fields§
§proxy: ProxySettingsCore proxy settings (name, version, listen address).
backends: Vec<BackendConfig>Backend MCP servers to proxy.
auth: Option<AuthConfig>Inbound authentication configuration.
performance: PerformanceConfigPerformance tuning options.
security: SecurityConfigSecurity policies.
cache: CacheBackendConfigGlobal cache backend configuration.
observability: ObservabilityConfigLogging, metrics, and tracing configuration.
composite_tools: Vec<CompositeToolConfig>Composite tools that fan out to multiple backend tools.
source_path: Option<PathBuf>Path to the config file (set during load, not serialized).
Implementations§
Source§impl ProxyConfig
impl ProxyConfig
Sourcepub fn load(path: &Path) -> Result<Self>
pub fn load(path: &Path) -> Result<Self>
Load and validate a config from a file path.
If import_backends is set in the config, backends from the referenced
.mcp.json file are merged (TOML backends take precedence on name conflicts).
Sourcepub fn from_mcp_json(path: &Path) -> Result<Self>
pub fn from_mcp_json(path: &Path) -> Result<Self>
Build a minimal ProxyConfig from a .mcp.json file.
This is a convenience mode for quick local development. The proxy name
is derived from the file’s parent directory (or the filename itself),
and the server listens on 127.0.0.1:8080 with no middleware or auth.
§Examples
use std::path::Path;
use mcp_proxy::ProxyConfig;
let config = ProxyConfig::from_mcp_json(Path::new(".mcp.json")).unwrap();
assert_eq!(config.proxy.listen.host, "127.0.0.1");
assert_eq!(config.proxy.listen.port, 8080);Sourcepub fn parse(toml: &str) -> Result<Self>
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);Sourcepub fn parse_yaml(yaml: &str) -> Result<Self>
pub fn parse_yaml(yaml: &str) -> Result<Self>
Parse and validate a config from a YAML string.
§Examples
use mcp_proxy::ProxyConfig;
let config = ProxyConfig::parse_yaml(r#"
proxy:
name: my-proxy
listen:
host: "127.0.0.1"
port: 8080
backends:
- name: echo
transport: stdio
command: echo
"#).unwrap();
assert_eq!(config.proxy.name, "my-proxy");Sourcepub fn resolve_env_vars(&mut self)
pub fn resolve_env_vars(&mut self)
Resolve environment variable references in config values.
Replaces ${VAR_NAME} with the value of the environment variable.
Sourcepub fn check_env_vars(&self) -> Vec<String>
pub fn check_env_vars(&self) -> Vec<String>
Check for ${VAR} references where the environment variable is not set.
Returns a list of human-readable warning strings. This method does not modify the config or fail – it only reports potential issues.
§Example
use mcp_proxy::config::ProxyConfig;
let toml = r#"
[proxy]
name = "test"
[proxy.listen]
[[backends]]
name = "svc"
transport = "stdio"
command = "echo"
bearer_token = "${UNSET_VAR}"
"#;
let config = ProxyConfig::parse(toml).unwrap();
let warnings = config.check_env_vars();
assert!(!warnings.is_empty());Trait Implementations§
Source§impl Debug for ProxyConfig
impl Debug for ProxyConfig
Source§impl<'de> Deserialize<'de> for ProxyConfig
impl<'de> Deserialize<'de> for ProxyConfig
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for ProxyConfig
impl RefUnwindSafe for ProxyConfig
impl Send for ProxyConfig
impl Sync for ProxyConfig
impl Unpin for ProxyConfig
impl UnsafeUnpin for ProxyConfig
impl UnwindSafe for ProxyConfig
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more