* 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
48 lines
1.5 KiB
Rust
48 lines
1.5 KiB
Rust
use anyhow::Result;
|
|
use rmcp::{
|
|
model::CallToolRequestParam,
|
|
service::ServiceExt,
|
|
transport::{ConfigureCommandExt, TokioChildProcess},
|
|
};
|
|
use tokio::process::Command;
|
|
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
|
|
|
|
#[tokio::main]
|
|
async fn main() -> Result<()> {
|
|
// Initialize logging
|
|
tracing_subscriber::registry()
|
|
.with(
|
|
tracing_subscriber::EnvFilter::try_from_default_env()
|
|
.unwrap_or_else(|_| format!("info,{}=debug", env!("CARGO_CRATE_NAME")).into()),
|
|
)
|
|
.with(tracing_subscriber::fmt::layer())
|
|
.init();
|
|
let service = ()
|
|
.serve(TokioChildProcess::new(Command::new("uvx").configure(
|
|
|cmd| {
|
|
cmd.arg("mcp-server-git");
|
|
},
|
|
))?)
|
|
.await?;
|
|
|
|
// or serve_client((), TokioChildProcess::new(cmd)?).await?;
|
|
|
|
// Initialize
|
|
let server_info = service.peer_info();
|
|
tracing::info!("Connected to server: {server_info:#?}");
|
|
|
|
// List tools
|
|
let tools = service.list_tools(Default::default()).await?;
|
|
tracing::info!("Available tools: {tools:#?}");
|
|
|
|
// Call tool 'git_status' with arguments = {"repo_path": "."}
|
|
let tool_result = service
|
|
.call_tool(CallToolRequestParam {
|
|
name: "git_status".into(),
|
|
arguments: serde_json::json!({ "repo_path": "." }).as_object().cloned(),
|
|
})
|
|
.await?;
|
|
tracing::info!("Tool result: {tool_result:#?}");
|
|
service.cancel().await?;
|
|
Ok(())
|
|
}
|