Skip to main content

SpawnValidator

Trait SpawnValidator 

Source
pub trait SpawnValidator: Send + Sync {
    // Required methods
    fn validate_command(&self, cmd: &str, args: &[String]) -> Result<(), String>;
    fn sanitize_env(&self, env: &mut HashMap<String, String>);
}
Expand description

Validates MCP server spawn commands and environment.

Consumers inject domain-specific safety policy (forbidden shells, dangerous env vars, path traversal checks) without modifying the SDK’s MCP client. The SDK calls validate_command before spawning and sanitize_env before passing the environment to the child process.

This trait is #[unstable] initially — the surface may evolve as we learn which signals consumers actually need.

Required Methods§

Source

fn validate_command(&self, cmd: &str, args: &[String]) -> Result<(), String>

Validate the command + args before spawn. Return Err(reason) to block the spawn (the error message is forwarded to the caller as McpError::SpawnValidation).

Source

fn sanitize_env(&self, env: &mut HashMap<String, String>)

Sanitize or strip dangerous environment variables before spawn.

Implementations SHOULD remove known loader-injection vectors (LD_PRELOAD, LD_LIBRARY_PATH, DYLD_INSERT_LIBRARIES, PYTHONPATH, etc.) and SHOULD resolve any relative paths in remaining vars to absolute. The default noop leaves the env untouched.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§