Skip to main content

mcpkit_rs/model/
task.rs

1use serde::{Deserialize, Serialize};
2use serde_json::Value;
3
4/// Canonical task lifecycle status as defined by SEP-1686.
5#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Default)]
6#[serde(rename_all = "snake_case")]
7#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
8pub enum TaskStatus {
9    /// The receiver accepted the request and is currently working on it.
10    #[default]
11    Working,
12    /// The receiver requires additional input before work can continue.
13    InputRequired,
14    /// The underlying operation completed successfully and the result is ready.
15    Completed,
16    /// The underlying operation failed and will not continue.
17    Failed,
18    /// The task was cancelled and will not continue processing.
19    Cancelled,
20}
21
22/// Final result for a succeeded task (returned from `tasks/result`).
23#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
24#[serde(rename_all = "camelCase")]
25#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
26pub struct TaskResult {
27    /// MIME type or custom content-type identifier.
28    pub content_type: String,
29    /// The actual result payload, matching the underlying request's schema.
30    pub value: Value,
31    /// Optional short summary for UI surfaces.
32    #[serde(skip_serializing_if = "Option::is_none")]
33    pub summary: Option<String>,
34}
35
36/// Primary Task object that surfaces metadata during the task lifecycle.
37#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default)]
38#[serde(rename_all = "camelCase")]
39#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
40pub struct Task {
41    /// Unique task identifier generated by the receiver.
42    pub task_id: String,
43    /// Current lifecycle status (see [`TaskStatus`]).
44    pub status: TaskStatus,
45    /// Optional human-readable status message for UI surfaces.
46    #[serde(skip_serializing_if = "Option::is_none")]
47    pub status_message: Option<String>,
48    /// ISO-8601 creation timestamp.
49    pub created_at: String,
50    /// ISO-8601 timestamp for the most recent status change.
51    #[serde(skip_serializing_if = "Option::is_none")]
52    pub last_updated_at: Option<String>,
53    /// Retention window in milliseconds that the receiver agreed to honor.
54    #[serde(skip_serializing_if = "Option::is_none")]
55    pub ttl: Option<u64>,
56    /// Suggested polling interval (milliseconds).
57    #[serde(skip_serializing_if = "Option::is_none")]
58    pub poll_interval: Option<u64>,
59}
60
61/// Wrapper returned by task-augmented requests (CreateTaskResult in SEP-1686).
62#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
63#[serde(rename_all = "camelCase")]
64#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
65pub struct CreateTaskResult {
66    pub task: Task,
67}
68
69/// Paginated list of tasks
70#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
71#[serde(rename_all = "camelCase")]
72#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
73pub struct TaskList {
74    pub tasks: Vec<Task>,
75    #[serde(skip_serializing_if = "Option::is_none")]
76    pub next_cursor: Option<String>,
77    #[serde(skip_serializing_if = "Option::is_none")]
78    pub total: Option<u64>,
79}