Skip to main content

TaskHandler

Trait TaskHandler 

Source
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§

Source

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.)

Source

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.

Source

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; result is 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".

Implementations on Foreign Types§

Source§

impl<T: TaskHandler> TaskHandler for Arc<T>

Source§

fn list_tasks( &self, ctx: &Context<'_>, ) -> impl Future<Output = Result<ListTasksResult, McpError>> + Send

Source§

fn get_task( &self, id: &TaskId, ctx: &Context<'_>, ) -> impl Future<Output = Result<Option<GetTaskResult>, McpError>> + Send

Source§

fn cancel_task( &self, id: &TaskId, ctx: &Context<'_>, ) -> impl Future<Output = Result<Option<CancelTaskResult>, McpError>> + Send

Implementors§