Files
zesdex/apps/infrastructure/src/mcp/transport.rs
T

45 lines
1.2 KiB
Rust
Raw Normal View History

//! MCP transport layer — manages child-process and HTTP-based transport
//! for connecting to MCP servers.
use std::process::{Child, Command, Stdio};
/// A running MCP server process connected via stdio.
pub struct McpTransport {
process: Option<Child>,
}
impl McpTransport {
pub fn start_child_process(command: &str, args: &[String]) -> anyhow::Result<Self> {
let child = Command::new(command)
.args(args)
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.stderr(Stdio::inherit())
.spawn()?;
Ok(McpTransport {
process: Some(child),
})
}
pub fn stop(&mut self) -> anyhow::Result<()> {
if let Some(mut child) = self.process.take() {
if let Err(e) = child.kill() {
tracing::warn!("MCP transport kill error: {e}");
}
let _ = child.wait();
}
Ok(())
}
}
impl Drop for McpTransport {
fn drop(&mut self) {
if let Some(mut child) = self.process.take() {
if let Err(e) = child.kill() {
tracing::warn!("MCP transport kill error: {e}");
}
let _ = child.wait();
}
}
}