pub struct ProxyBuilder { /* private fields */ }Expand description
Implementations§
Source§impl ProxyBuilder
impl ProxyBuilder
Sourcepub fn new(name: impl Into<String>) -> Self
pub fn new(name: impl Into<String>) -> Self
Create a new proxy builder with the given name.
Defaults: version “0.1.0”, separator “/”, listen 127.0.0.1:8080.
Sourcepub fn version(self, version: impl Into<String>) -> Self
pub fn version(self, version: impl Into<String>) -> Self
Set the proxy version (default: “0.1.0”).
Sourcepub fn separator(self, separator: impl Into<String>) -> Self
pub fn separator(self, separator: impl Into<String>) -> Self
Set the namespace separator (default: “/”).
Sourcepub fn listen(self, host: impl Into<String>, port: u16) -> Self
pub fn listen(self, host: impl Into<String>, port: u16) -> Self
Set the listen address and port (default: 127.0.0.1:8080).
Sourcepub fn instructions(self, instructions: impl Into<String>) -> Self
pub fn instructions(self, instructions: impl Into<String>) -> Self
Set instructions text sent to MCP clients.
Sourcepub fn shutdown_timeout(self, timeout: Duration) -> Self
pub fn shutdown_timeout(self, timeout: Duration) -> Self
Set the graceful shutdown timeout (default: 30s).
Sourcepub fn hot_reload(self, enabled: bool) -> Self
pub fn hot_reload(self, enabled: bool) -> Self
Enable hot reload for watching config file changes.
Sourcepub fn global_rate_limit(self, requests: usize, period: Duration) -> Self
pub fn global_rate_limit(self, requests: usize, period: Duration) -> Self
Set a global rate limit across all backends.
Sourcepub fn stdio_backend(
self,
name: impl Into<String>,
command: impl Into<String>,
args: &[&str],
) -> Self
pub fn stdio_backend( self, name: impl Into<String>, command: impl Into<String>, args: &[&str], ) -> Self
Add a stdio backend (subprocess).
Sourcepub fn stdio_backend_with_env(
self,
name: impl Into<String>,
command: impl Into<String>,
args: &[&str],
env: HashMap<String, String>,
) -> Self
pub fn stdio_backend_with_env( self, name: impl Into<String>, command: impl Into<String>, args: &[&str], env: HashMap<String, String>, ) -> Self
Add a stdio backend with environment variables.
Sourcepub fn http_backend(
self,
name: impl Into<String>,
url: impl Into<String>,
) -> Self
pub fn http_backend( self, name: impl Into<String>, url: impl Into<String>, ) -> Self
Add an HTTP backend.
Sourcepub fn http_backend_with_token(
self,
name: impl Into<String>,
url: impl Into<String>,
token: impl Into<String>,
) -> Self
pub fn http_backend_with_token( self, name: impl Into<String>, url: impl Into<String>, token: impl Into<String>, ) -> Self
Add an HTTP backend with a bearer token.
Sourcepub fn configure_backend(self, f: impl FnOnce(&mut BackendConfig)) -> Self
pub fn configure_backend(self, f: impl FnOnce(&mut BackendConfig)) -> Self
Configure the last added backend with a per-backend modifier.
§Panics
Panics if no backends have been added.
Sourcepub fn bearer_auth(self, tokens: Vec<String>) -> Self
pub fn bearer_auth(self, tokens: Vec<String>) -> Self
Enable bearer token authentication. Enable bearer token authentication.
All tokens in this list have unrestricted access to all tools.
For per-token tool scoping, use scoped_bearer_auth.
Sourcepub fn scoped_bearer_auth(self, scoped_tokens: Vec<BearerTokenConfig>) -> Self
pub fn scoped_bearer_auth(self, scoped_tokens: Vec<BearerTokenConfig>) -> Self
Enable bearer token authentication with per-token tool scoping.
Each BearerTokenConfig can specify
allow_tools or deny_tools to restrict which tools that token can access.
Sourcepub fn coalesce_requests(self, enabled: bool) -> Self
pub fn coalesce_requests(self, enabled: bool) -> Self
Enable request coalescing.
Sourcepub fn max_argument_size(self, max_bytes: usize) -> Self
pub fn max_argument_size(self, max_bytes: usize) -> Self
Set the maximum argument size for validation.
Sourcepub fn audit_logging(self, enabled: bool) -> Self
pub fn audit_logging(self, enabled: bool) -> Self
Enable audit logging.
Sourcepub fn access_logging(self, enabled: bool) -> Self
pub fn access_logging(self, enabled: bool) -> Self
Enable access logging.
Sourcepub fn timeout(self, seconds: u64) -> Self
pub fn timeout(self, seconds: u64) -> Self
Set the timeout for the last added backend.
§Panics
Panics if no backends have been added.
§Example
use mcp_proxy::builder::ProxyBuilder;
let config = ProxyBuilder::new("my-proxy")
.http_backend("api", "http://api:8080")
.timeout(30)
.into_config();
assert_eq!(config.backends[0].timeout.as_ref().unwrap().seconds, 30);Sourcepub fn rate_limit(self, requests: usize, period_seconds: u64) -> Self
pub fn rate_limit(self, requests: usize, period_seconds: u64) -> Self
Set the rate limit for the last added backend.
§Panics
Panics if no backends have been added.
§Example
use mcp_proxy::builder::ProxyBuilder;
let config = ProxyBuilder::new("my-proxy")
.http_backend("api", "http://api:8080")
.rate_limit(100, 1)
.into_config();
let rl = config.backends[0].rate_limit.as_ref().unwrap();
assert_eq!(rl.requests, 100);
assert_eq!(rl.period_seconds, 1);Sourcepub fn circuit_breaker(self, failure_rate: f64) -> Self
pub fn circuit_breaker(self, failure_rate: f64) -> Self
Set the circuit breaker for the last added backend.
Uses sensible defaults for other fields: minimum 5 calls, 30-second wait duration, and 3 half-open calls.
§Panics
Panics if no backends have been added.
§Example
use mcp_proxy::builder::ProxyBuilder;
let config = ProxyBuilder::new("my-proxy")
.http_backend("api", "http://api:8080")
.circuit_breaker(0.5)
.into_config();
let cb = config.backends[0].circuit_breaker.as_ref().unwrap();
assert!((cb.failure_rate_threshold - 0.5).abs() < f64::EPSILON);Sourcepub fn expose_tools(self, tools: &[&str]) -> Self
pub fn expose_tools(self, tools: &[&str]) -> Self
Set the tool allowlist for the last added backend.
Only the listed tools will be exposed through the proxy.
§Panics
Panics if no backends have been added.
§Example
use mcp_proxy::builder::ProxyBuilder;
let config = ProxyBuilder::new("my-proxy")
.http_backend("api", "http://api:8080")
.expose_tools(&["read_file", "list_dir"])
.into_config();
assert_eq!(config.backends[0].expose_tools, vec!["read_file", "list_dir"]);Sourcepub fn hide_tools(self, tools: &[&str]) -> Self
pub fn hide_tools(self, tools: &[&str]) -> Self
Set the tool denylist for the last added backend.
The listed tools will be hidden from clients.
§Panics
Panics if no backends have been added.
§Example
use mcp_proxy::builder::ProxyBuilder;
let config = ProxyBuilder::new("my-proxy")
.http_backend("api", "http://api:8080")
.hide_tools(&["dangerous_op"])
.into_config();
assert_eq!(config.backends[0].hide_tools, vec!["dangerous_op"]);Sourcepub fn retry(self, max_retries: u32) -> Self
pub fn retry(self, max_retries: u32) -> Self
Set the retry policy for the last added backend.
Uses sensible defaults: 100ms initial backoff, 5000ms max backoff, no budget limit.
§Panics
Panics if no backends have been added.
§Example
use mcp_proxy::builder::ProxyBuilder;
let config = ProxyBuilder::new("my-proxy")
.http_backend("api", "http://api:8080")
.retry(3)
.into_config();
let retry = config.backends[0].retry.as_ref().unwrap();
assert_eq!(retry.max_retries, 3);Sourcepub fn into_config(self) -> ProxyConfig
pub fn into_config(self) -> ProxyConfig
Extract the built ProxyConfig without connecting to backends.
Useful for inspection, serialization, or passing to
Proxy::from_config() manually.
Auto Trait Implementations§
impl Freeze for ProxyBuilder
impl RefUnwindSafe for ProxyBuilder
impl Send for ProxyBuilder
impl Sync for ProxyBuilder
impl Unpin for ProxyBuilder
impl UnsafeUnpin for ProxyBuilder
impl UnwindSafe for ProxyBuilder
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