pub struct StdioClientTransport { /* private fields */ }Expand description
Client transport that communicates with a subprocess via stdio.
Spawns a child process and communicates using line-delimited JSON-RPC
messages over stdin (write) and stdout (read). By default stderr is
inherited so server debug output appears in the client’s terminal. A
caller using Self::spawn_command may redirect or pipe it instead.
Implementations§
Source§impl StdioClientTransport
impl StdioClientTransport
Sourcepub async fn spawn(program: &str, args: &[&str]) -> Result<Self>
pub async fn spawn(program: &str, args: &[&str]) -> Result<Self>
Spawn a new subprocess and connect to it.
§Errors
Returns an error if the process fails to spawn or if stdin/stdout handles cannot be acquired.
Sourcepub async fn spawn_command(cmd: &mut Command) -> Result<Self>
pub async fn spawn_command(cmd: &mut Command) -> Result<Self>
Spawn from a pre-configured Command.
This allows setting environment variables, working directory, and other process configuration before spawning.
Stdin and stdout are automatically set to piped. Stderr keeps the
Command configuration; its default is inherited.
§Example
use tokio::process::Command;
use tower_mcp::client::StdioClientTransport;
let mut cmd = Command::new("npx");
cmd.args(["-y", "@modelcontextprotocol/server-github"])
.env("GITHUB_TOKEN", "ghp_...");
let transport = StdioClientTransport::spawn_command(&mut cmd).await?;Sourcepub fn take_stderr(&mut self) -> Option<ChildStderr>
pub fn take_stderr(&mut self) -> Option<ChildStderr>
Take the child’s piped stderr handle, if the command configured one.
This returns None when stderr is inherited, redirected elsewhere, or
has already been taken. It is useful for clients that need to integrate
server diagnostics with their own terminal or logging UI.
Sourcepub fn from_child(child: Child) -> Result<Self>
pub fn from_child(child: Child) -> Result<Self>
Create from an existing child process.
The child must have piped stdin and stdout.