ServerConfigBuilder

Struct ServerConfigBuilder 

Source
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

Source

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();
Source

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();
Source

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();
Source

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();
Source

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();
Source

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();
Source

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();
Source

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();
Source

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();
Source

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();
Source

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();
Source

pub fn build(self) -> ServerConfig

Builds the ServerConfig.

§Panics

Panics if:

  • Command was not set for stdio transport
  • URL was not set for HTTP transport

Use try_build() for fallible construction.

§Examples
use mcp_execution_core::ServerConfig;

let config = ServerConfig::builder()
    .command("docker".to_string())
    .build();
Source

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

Source§

fn clone(&self) -> ServerConfigBuilder

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ServerConfigBuilder

Source§

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

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

impl Default for ServerConfigBuilder

Source§

fn default() -> ServerConfigBuilder

Returns the “default value” for a type. 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.