pub trait TaskHandler: Send + Sync {
// Required methods
fn list_tasks(
&self,
ctx: &Context<'_>,
) -> impl Future<Output = Result<ListTasksResult, McpError>> + Send;
fn get_task(
&self,
id: &TaskId,
ctx: &Context<'_>,
) -> impl Future<Output = Result<Option<GetTaskResult>, McpError>> + Send;
fn cancel_task(
&self,
id: &TaskId,
ctx: &Context<'_>,
) -> impl Future<Output = Result<Option<CancelTaskResult>, McpError>> + Send;
}Expand description
Handler for task-related operations.
Implement this trait to support long-running operations that can be tracked, monitored, and cancelled.
Required Methods§
Sourcefn list_tasks(
&self,
ctx: &Context<'_>,
) -> impl Future<Output = Result<ListTasksResult, McpError>> + Send
fn list_tasks( &self, ctx: &Context<'_>, ) -> impl Future<Output = Result<ListTasksResult, McpError>> + Send
List all tasks.
The ListTasksResult wrapper may carry nextCursor and result-level
_meta; Vec<Task>::into() produces one with neither. (Request-cursor
input for real pagination is not yet threaded — see #150.)
Sourcefn get_task(
&self,
id: &TaskId,
ctx: &Context<'_>,
) -> impl Future<Output = Result<Option<GetTaskResult>, McpError>> + Send
fn get_task( &self, id: &TaskId, ctx: &Context<'_>, ) -> impl Future<Output = Result<Option<GetTaskResult>, McpError>> + Send
Get the current state of a task.
Return Ok(None) for an unknown task. The GetTaskResult wrapper may
carry result-level _meta; Task::into() produces one with no metadata.
Sourcefn cancel_task(
&self,
id: &TaskId,
ctx: &Context<'_>,
) -> impl Future<Output = Result<Option<CancelTaskResult>, McpError>> + Send
fn cancel_task( &self, id: &TaskId, ctx: &Context<'_>, ) -> impl Future<Output = Result<Option<CancelTaskResult>, McpError>> + Send
Cancel a running task, returning its post-cancellation state.
Ok(Some(result))— cancellation accepted;resultis the task’s state afterwards (and may carry result-level_meta).Ok(None)— no such task.Err(..)— the task exists but cancellation failed (an internal error).
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".