-
Notifications
You must be signed in to change notification settings - Fork 452
Description
Describe the bug
The completed tasks are erased from OperationProcessor
To Reproduce
Steps to reproduce the behavior:
tasks/getrequest returnstask: Noneafter task completion.tasks/resultrequest returns error after task completion.
Expected behavior
tasks/getrequest should return aTaskobject withstatus: "completed".tasks/resultrequest should return the task result.
Additional context
I am using the latest commit (32a68aa) because the published version 0.14.0 does not include the enum-variant reordering fix.
rmcp = { git = "https://github.com/modelcontextprotocol/rust-sdk", features = ["macros", "client", "rmcp/transport-streamable-http-client-reqwest"] }Fix
This is caused by std::mem::take from the OperationProcessor::collect_completed_results, which clears OperationProcessor::completed_results.
rust-sdk/crates/rmcp/src/task_manager.rs
Lines 197 to 206 in 32a68aa
| /// Collect completed results from running tasks and remove them from the running tasks map. | |
| pub fn collect_completed_results(&mut self) -> Vec<TaskResult> { | |
| if let Some(receiver) = &mut self.task_result_receiver { | |
| while let Ok(result) = receiver.try_recv() { | |
| self.running_tasks.remove(&result.descriptor.operation_id); | |
| self.completed_results.push(result); | |
| } | |
| } | |
| std::mem::take(&mut self.completed_results) | |
| } |
The solution would be simply to not return anything from this function. While this would be a breaking change, this method is only used in a single test code, and I doubt anyone was calling this method directly without using the #[tool_handler] macro.