#[non_exhaustive]pub struct TaskResumeContext {
pub tool_name: String,
pub arguments: Value,
pub input_responses: InputResponses,
pub cancellation_token: Option<CancellationToken>,
}Expand description
What a resumed task needs to run its handler again.
The client answers a task through tasks/update, not by retrying
tools/call, so the server re-invokes the handler itself and must supply
what the client would otherwise have resent.
The handler runs from the top rather than continuing where it stopped, so
the arguments are the original ones, unmodified, and input_responses
accumulates across every round rather than holding only the latest answer.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.tool_name: StringTool to re-invoke.
arguments: ValueThe original call arguments, unchanged.
input_responses: InputResponsesEvery answer accumulated so far, keyed as the requests were issued.
cancellation_token: Option<CancellationToken>Cancellation and expiry signal for the resumed execution, when the store attached one.
External stores should provide a clone of the token returned by
TaskStore::create_task, or another token wired to the same durable
cancellation and expiry source, via
with_cancellation_token.
The router fails the replay loudly when this is None, because a
disconnected handler could otherwise run beyond the task deadline.
Implementations§
Source§impl TaskResumeContext
impl TaskResumeContext
Sourcepub fn new(
tool_name: impl Into<String>,
arguments: Value,
input_responses: InputResponses,
) -> Self
pub fn new( tool_name: impl Into<String>, arguments: Value, input_responses: InputResponses, ) -> Self
Create the context needed to resume a task handler.
External TaskStore implementations use this when reconstructing a
task from durable state in TaskStore::resume_context. This keeps
the original three-argument constructor source-compatible, but leaves
cancellation_token as None; attach the
task’s lifecycle token with
with_cancellation_token before
returning it to the router.
§Example
use tower_mcp::async_task::TaskResumeContext;
let resume = TaskResumeContext::new(
"build_report",
serde_json::json!({"format": "pdf"}),
Default::default(),
);
assert_eq!(resume.tool_name, "build_report");Sourcepub fn with_cancellation_token(self, token: CancellationToken) -> Self
pub fn with_cancellation_token(self, token: CancellationToken) -> Self
Attach the cancellation and expiry signal for replayed execution.
Self::new intentionally keeps its original three arguments for
source compatibility. Stores that support resumption should call this
builder with the token associated with the task so expiry can stop a
replayed handler even when that handler does not poll cooperatively.
Trait Implementations§
Source§impl Clone for TaskResumeContext
impl Clone for TaskResumeContext
Source§fn clone(&self) -> TaskResumeContext
fn clone(&self) -> TaskResumeContext
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more