pub struct ServerConfigBuilder { /* private fields */ }Expand description
Builder for constructing ServerConfig instances.
Provides a fluent API for building server configurations with optional arguments, environment variables, and HTTP settings.
§Examples
use mcp_execution_core::ServerConfig;
// Stdio transport
let config = ServerConfig::builder()
.command("mcp-server".to_string())
.arg("--verbose".to_string())
.env("DEBUG".to_string(), "1".to_string())
.build().unwrap();
// HTTP transport
let config = ServerConfig::builder()
.http_transport("https://api.example.com/mcp".to_string())
.header("Authorization".to_string(), "Bearer token".to_string())
.build().unwrap();Like ServerConfig itself, this builder accumulates env/headers
before secrets they may carry are known to be well-formed, so its
Debug impl redacts values the same way — see the redaction note on
ServerConfig’s doc comment.
Implementations§
Source§impl ServerConfigBuilder
impl ServerConfigBuilder
Sourcepub fn command(self, command: String) -> Self
pub fn command(self, command: String) -> Self
Sets the command to execute.
§Examples
use mcp_execution_core::ServerConfig;
let config = ServerConfig::builder()
.command("docker".to_string())
.build().unwrap();Sourcepub fn arg(self, arg: String) -> Self
pub fn arg(self, arg: String) -> Self
Adds a single argument.
§Examples
use mcp_execution_core::ServerConfig;
let config = ServerConfig::builder()
.command("docker".to_string())
.arg("run".to_string())
.arg("--rm".to_string())
.build().unwrap();Sourcepub fn args(self, args: Vec<String>) -> Self
pub fn args(self, args: Vec<String>) -> Self
Sets all arguments at once, replacing any previously added.
§Examples
use mcp_execution_core::ServerConfig;
let config = ServerConfig::builder()
.command("docker".to_string())
.args(vec!["run".to_string(), "--rm".to_string()])
.build().unwrap();Sourcepub fn env(self, key: String, value: String) -> Self
pub fn env(self, key: String, value: String) -> Self
Adds a single environment variable.
§Examples
use mcp_execution_core::ServerConfig;
let config = ServerConfig::builder()
.command("mcp-server".to_string())
.env("LOG_LEVEL".to_string(), "debug".to_string())
.build().unwrap();Sourcepub fn environment(self, env: HashMap<String, String>) -> Self
pub fn environment(self, env: HashMap<String, String>) -> Self
Sets all environment variables at once, replacing any previously added.
§Examples
use mcp_execution_core::ServerConfig;
use std::collections::HashMap;
let mut env_map = HashMap::new();
env_map.insert("DEBUG".to_string(), "1".to_string());
let config = ServerConfig::builder()
.command("mcp-server".to_string())
.environment(env_map)
.build().unwrap();Sourcepub fn cwd(self, cwd: PathBuf) -> Self
pub fn cwd(self, cwd: PathBuf) -> Self
Sets the working directory for the subprocess.
§Examples
use mcp_execution_core::ServerConfig;
use std::path::PathBuf;
let config = ServerConfig::builder()
.command("mcp-server".to_string())
.cwd(PathBuf::from("/tmp"))
.build().unwrap();Sourcepub fn http_transport(self, url: String) -> Self
pub fn http_transport(self, url: String) -> Self
Configures HTTP transport with the given URL.
This sets the transport type to HTTP and configures the endpoint URL.
§Examples
use mcp_execution_core::ServerConfig;
let config = ServerConfig::builder()
.http_transport("https://api.example.com/mcp".to_string())
.build().unwrap();Sourcepub fn sse_transport(self, url: String) -> Self
pub fn sse_transport(self, url: String) -> Self
Configures SSE transport with the given URL.
This sets the transport type to SSE (Server-Sent Events) and configures the endpoint URL.
§Examples
use mcp_execution_core::ServerConfig;
let config = ServerConfig::builder()
.sse_transport("https://api.example.com/sse".to_string())
.build().unwrap();Sourcepub fn url(self, url: String) -> Self
pub fn url(self, url: String) -> Self
Sets the URL for HTTP transport.
§Examples
use mcp_execution_core::ServerConfig;
let config = ServerConfig::builder()
.http_transport("https://api.example.com/mcp".to_string())
.url("https://api.example.com/mcp/v2".to_string())
.build().unwrap();Sourcepub fn header(self, key: String, value: String) -> Self
pub fn header(self, key: String, value: String) -> Self
Adds a single HTTP header.
§Examples
use mcp_execution_core::ServerConfig;
let config = ServerConfig::builder()
.http_transport("https://api.example.com/mcp".to_string())
.header("Authorization".to_string(), "Bearer token".to_string())
.build().unwrap();Sourcepub fn headers(self, headers: HashMap<String, String>) -> Self
pub fn headers(self, headers: HashMap<String, String>) -> Self
Sets all HTTP headers at once, replacing any previously added.
§Examples
use mcp_execution_core::ServerConfig;
use std::collections::HashMap;
let mut headers = HashMap::new();
headers.insert("Authorization".to_string(), "Bearer token".to_string());
let config = ServerConfig::builder()
.http_transport("https://api.example.com/mcp".to_string())
.headers(headers)
.build().unwrap();Sourcepub const fn connect_timeout(self, timeout: Duration) -> Self
pub const fn connect_timeout(self, timeout: Duration) -> Self
Sets the connection (handshake) timeout, overriding the 30-second default.
§Examples
use mcp_execution_core::ServerConfig;
use std::time::Duration;
let config = ServerConfig::builder()
.command("docker".to_string())
.connect_timeout(Duration::from_secs(5))
.build().unwrap();
assert_eq!(config.connect_timeout(), Duration::from_secs(5));Sourcepub const fn discover_timeout(self, timeout: Duration) -> Self
pub const fn discover_timeout(self, timeout: Duration) -> Self
Sets the tool discovery timeout, overriding the 30-second default.
§Examples
use mcp_execution_core::ServerConfig;
use std::time::Duration;
let config = ServerConfig::builder()
.command("docker".to_string())
.discover_timeout(Duration::from_secs(5))
.build().unwrap();
assert_eq!(config.discover_timeout(), Duration::from_secs(5));Sourcepub fn build(self) -> Result<ServerConfig>
pub fn build(self) -> Result<ServerConfig>
Builds and validates the ServerConfig.
This is the only way to obtain a ServerConfig through the builder: beyond the
structural checks (command/url presence), it also runs the full security validation
performed by validate_server_config — shell metacharacters, forbidden environment
variables, URL scheme, and header safety — before returning. A ServerConfig built
through this method therefore cannot exist without having passed security
validation. Unlike before #313, this is now also a type-level guarantee: every other
way to obtain a ServerConfig (a struct literal, serde_json::from_str) is closed —
see ServerConfig’s own “Security” section.
§Errors
Returns Error::ValidationError if:
- Command is not set (or is empty) for stdio transport
- URL is not set for HTTP/SSE transport
Returns Error::SecurityViolation or Error::ValidationError for any
reason documented on validate_server_config (forbidden shell
metacharacters, forbidden environment variables, invalid URL scheme,
unsafe headers, out-of-bounds timeouts, etc.).
§Examples
use mcp_execution_core::ServerConfig;
let config = ServerConfig::builder()
.command("docker".to_string())
.build()
.unwrap();
// Rejected at construction time — no separate validation step needed.
let err = ServerConfig::builder()
.command("docker".to_string())
.arg("run; rm -rf /".to_string())
.build()
.unwrap_err();
assert!(err.is_security_error());Trait Implementations§
Source§impl Clone for ServerConfigBuilder
impl Clone for ServerConfigBuilder
Source§fn clone(&self) -> ServerConfigBuilder
fn clone(&self) -> ServerConfigBuilder
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more