fix: cleanup zombie processes for child process client (#156)

* feat(client): cleanup of zombie processes in child process client

Using process wrap library, Process Group for Unix and Job Object for Windows

* fix: install extra dep based on feature, update examples take owned command

Install process-wrap if transport-child-process feature is enabled. Update examples to take ownership
of the command instead of mutable reference

* fix: update other examples, comments and readme to take ownership of command

Updated more examples, comments and readme to take command instead of mutable ref.
Also small fix in cargo toml of example to use local path.

* refactor: add configure command ext

Added configure command ext to tokio process command so that
you can use .configure() to use inline commands for mcp stdio client.
Added warning if start kill process fails
This commit is contained in:
Humberto Yusta Gómez 2025-05-18 12:38:47 +02:00 • committed by GitHub
commit 64995cc40c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 115 additions and 77 deletions

View file

@ -2,7 +2,7 @@ use rmcp::{
ServiceExt,
service::QuitReason,
transport::{
SseServer, StreamableHttpClientTransport, TokioChildProcess,
ConfigureCommandExt, SseServer, StreamableHttpClientTransport, TokioChildProcess,
streamable_http_server::axum::StreamableHttpServer,
},
};
@ -59,9 +59,10 @@ async fn test_with_js_server() -> anyhow::Result<()> {
.spawn()?
.wait()
.await?;
let transport = TokioChildProcess::new(
tokio::process::Command::new("node").arg("tests/test_with_js/server.js"),
)?;
let transport =
TokioChildProcess::new(tokio::process::Command::new("node").configure(|cmd| {
cmd.arg("tests/test_with_js/server.js");
}))?;
let client = ().serve(transport).await?;
let resources = client.list_all_resources().await?;

View file

@ -1,6 +1,6 @@
use rmcp::{
ServiceExt,
transport::{SseServer, TokioChildProcess},
transport::{ConfigureCommandExt, SseServer, TokioChildProcess},
};
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
mod common;
@ -54,11 +54,9 @@ async fn test_with_python_server() -> anyhow::Result<()> {
.spawn()?
.wait()
.await?;
let transport = TokioChildProcess::new(
tokio::process::Command::new("uv")
.arg("run")
.arg("tests/test_with_python/server.py"),
)?;
let transport = TokioChildProcess::new(tokio::process::Command::new("uv").configure(|cmd| {
cmd.arg("run").arg("tests/test_with_python/server.py");
}))?;
let client = ().serve(transport).await?;
let resources = client.list_all_resources().await?;