Skip to main content

build_server_config

Function build_server_config 

Source
pub fn build_server_config(
    server: Option<String>,
    args: Vec<String>,
    env: Vec<String>,
    cwd: Option<String>,
    http: Option<String>,
    sse: Option<String>,
    headers: Vec<String>,
) -> Result<(ServerId, ServerConfig)>
Expand description

Builds ServerConfig from CLI arguments.

Parses CLI arguments into a ServerConfig for connecting to an MCP server.

§Arguments

  • server - Server command (binary name or path)
  • args - Arguments to pass to the server command
  • env - Environment variables in KEY=VALUE format
  • cwd - Working directory for the server process
  • http - HTTP transport URL
  • sse - SSE transport URL
  • headers - HTTP headers in KEY=VALUE format

§Errors

Returns an error if environment variables or headers are not in KEY=VALUE format.

§Panics

Panics if server is None when using stdio transport (i.e., when neither http nor sse is provided). This is enforced by CLI argument validation.

§Examples

use mcp_execution_cli::commands::common::build_server_config;

// Stdio transport
let (id, config) = build_server_config(
    Some("github-mcp-server".to_string()),
    vec!["stdio".to_string()],
    vec!["TOKEN=abc".to_string()],
    None,
    None,
    None,
    vec![],
).unwrap();

assert_eq!(id.as_str(), "github-mcp-server");
assert_eq!(config.args(), &["stdio"]);