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();
// HTTP transport
let config = ServerConfig::builder()
.http_transport("https://api.example.com/mcp".to_string())
.header("Authorization".to_string(), "Bearer token".to_string())
.build();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();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();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();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();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();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();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();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();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();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();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();Sourcepub fn build(self) -> ServerConfig
pub fn build(self) -> ServerConfig
Sourcepub fn try_build(self) -> Result<ServerConfig, String>
pub fn try_build(self) -> Result<ServerConfig, String>
Attempts to build the ServerConfig, returning an error if invalid.
§Errors
Returns an error if:
- Command is not set for stdio transport
- URL is not set for HTTP transport
§Examples
use mcp_execution_core::ServerConfig;
let result = ServerConfig::builder()
.command("docker".to_string())
.try_build();
assert!(result.is_ok());Trait Implementations§
Source§impl Clone for ServerConfigBuilder
impl Clone for ServerConfigBuilder
Source§fn clone(&self) -> ServerConfigBuilder
fn clone(&self) -> ServerConfigBuilder
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more