feat(transport): add builder & expose child stderr (#305)

This commit is contained in:
Brendan Graham 2025-07-04 18:14:43 -07:00 • committed by GitHub
commit 69712e321a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 122 additions and 32 deletions

View file

@ -1,9 +1,11 @@
use std::process::Stdio;
use axum::Router;
use rmcp::{
ServiceExt,
transport::{ConfigureCommandExt, SseServer, TokioChildProcess, sse_server::SseServerConfig},
};
use tokio::time::timeout;
use tokio::{io::AsyncReadExt, time::timeout};
use tokio_util::sync::CancellationToken;
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
mod common;
@ -119,3 +121,35 @@ async fn test_with_python_server() -> anyhow::Result<()> {
client.cancel().await?;
Ok(())
}
#[tokio::test]
async fn test_with_python_server_stderr() -> anyhow::Result<()> {
init().await?;
let (transport, stderr) =
TokioChildProcess::builder(tokio::process::Command::new("uv").configure(|cmd| {
cmd.arg("run")
.arg("server.py")
.current_dir("tests/test_with_python");
}))
.stderr(Stdio::piped())
.spawn()?;
let mut stderr = stderr.expect("stderr must be piped");
let stderr_task = tokio::spawn(async move {
let mut buffer = String::new();
stderr.read_to_string(&mut buffer).await?;
Ok::<_, std::io::Error>(buffer)
});
let client = ().serve(transport).await?;
let _ = client.list_all_resources().await?;
let _ = client.list_all_tools().await?;
client.cancel().await?;
let stderr_output = stderr_task.await??;
assert!(stderr_output.contains("server starting up..."));
Ok(())
}

View file

@ -1,7 +1,12 @@
from fastmcp import FastMCP
import sys
mcp = FastMCP("Demo")
print("server starting up...", file=sys.stderr)
@mcp.tool()
def add(a: int, b: int) -> int:
"""Add two numbers"""