fix: align progress timeout token (#909)

This commit is contained in:
Dale Seo 2026-06-22 10:59:32 -04:00 • committed by GitHub
commit 443677ca31
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -10,7 +10,10 @@ use std::{
use rmcp::{
ClientHandler, Peer, RoleServer, ServiceError, ServiceExt,
model::{CallToolRequestParams, ClientRequest, Meta, ProgressNotificationParam, Request},
model::{
CallToolRequestParams, ClientRequest, Meta, NumberOrString, ProgressNotificationParam,
ProgressToken, Request,
},
service::PeerRequestOptions,
tool, tool_router,
};
@ -32,12 +35,6 @@ impl ClientHandler for ProgressCountingClient {
struct ProgressTimeoutServer;
impl ProgressTimeoutServer {
fn new() -> Self {
Self
}
}
#[tool_router(server_handler)]
impl ProgressTimeoutServer {
#[tool]
@ -83,9 +80,7 @@ impl ProgressTimeoutServer {
tokio::time::sleep(Duration::from_millis(50)).await;
let _ = client
.notify_progress(ProgressNotificationParam {
progress_token: rmcp::model::ProgressToken(
rmcp::model::NumberOrString::Number(999_999),
),
progress_token: ProgressToken(NumberOrString::Number(999_999)),
progress: step as f64,
total: Some(4.0),
message: Some("unrelated".into()),
@ -99,7 +94,7 @@ impl ProgressTimeoutServer {
async fn start_pair()
-> anyhow::Result<rmcp::service::RunningService<rmcp::RoleClient, ProgressCountingClient>> {
let server = ProgressTimeoutServer::new();
let server = ProgressTimeoutServer;
let client = ProgressCountingClient::default();
let (transport_server, transport_client) = tokio::io::duplex(4096);
@ -172,6 +167,21 @@ async fn matching_progress_resets_timeout_when_enabled() -> anyhow::Result<()> {
Ok(())
}
#[tokio::test]
async fn generated_progress_token_overrides_option_meta_token() -> anyhow::Result<()> {
let client = start_pair().await?;
let mut options =
PeerRequestOptions::with_timeout(Duration::from_millis(75)).reset_timeout_on_progress();
options.meta = Some(Meta::with_progress_token(ProgressToken(
NumberOrString::Number(999_999),
)));
let result = call_tool_with_options(&client, "delayed_with_progress", options).await;
assert!(result.is_ok());
Ok(())
}
#[tokio::test]
async fn max_total_timeout_wins_over_progress_reset() -> anyhow::Result<()> {
let client = start_pair().await?;