Skip to main content

Crate turul_mcp_task_storage

Crate turul_mcp_task_storage 

Source
Expand description

§Task Storage Abstractions and Implementations

Pluggable task storage backends for MCP servers with durable state machines.

MCP 2025-11-25 introduces Tasks — durable state machines for long-running operations (tool calls, sampling, elicitation). This crate provides the TaskStorage trait and an in-memory implementation for development and testing.

§Quick Start

use turul_mcp_task_storage::prelude::*;

let storage = InMemoryTaskStorage::new();

// Create a task
let task = TaskRecord {
    task_id: InMemoryTaskStorage::generate_task_id(),
    session_id: Some("session-123".to_string()),
    status: turul_mcp_protocol::TaskStatus::Working,
    status_message: Some("Processing...".to_string()),
    created_at: chrono::Utc::now().to_rfc3339(),
    last_updated_at: chrono::Utc::now().to_rfc3339(),
    ttl: Some(60_000),
    poll_interval: Some(5_000),
    original_method: "tools/call".to_string(),
    original_params: None,
    result: None,
    meta: None,
};

let created = storage.create_task(task).await?;

// Update status with state machine enforcement
let completed = storage.update_task_status(
    &created.task_id,
    turul_mcp_protocol::TaskStatus::Completed,
    Some("Done!".to_string()),
).await?;

§Architecture

  • TaskStorage trait: Core abstraction for task CRUD, status updates, pagination
  • TaskRecord: Persistence model (serializable, no runtime handles)
  • TaskOutcome: Success/Error result stored for tasks/result retrieval
  • State machine: Validates transitions per MCP spec lifecycle

Re-exports§

pub use error::TaskStorageError;
pub use in_memory::InMemoryTaskConfig;
pub use in_memory::InMemoryTaskStorage;
pub use state_machine::is_terminal;
pub use state_machine::validate_transition;
pub use traits::TaskListPage;
pub use traits::TaskOutcome;
pub use traits::TaskRecord;
pub use traits::TaskStorage;

Modules§

error
Unified error types for task storage operations.
in_memory
In-memory task storage backend.
prelude
Prelude module for convenient imports.
state_machine
Task state machine enforcement.
traits
Core task storage trait and data models.

Functions§

create_default_storage
Create a default in-memory task storage instance for development and testing.
create_memory_storage
Create an in-memory task storage with custom configuration.