feat(transport): add builder & expose child stderr (#305)
This commit is contained in:
parent
31155a440c
commit
69712e321a
2 changed files with 122 additions and 32 deletions
|
|
@ -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(())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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"""
|
||||
|
|
|
|||
Loading…
Reference in a new issue