MCP TypeScript SDK
    Preparing search index...

    Interface TaskMessageQueueExperimental

    Interface for managing per-task FIFO message queues.

    Similar to TaskStore, this allows pluggable queue implementations (in-memory, Redis, other distributed queues, etc.).

    Each method accepts taskId and optional sessionId parameters to enable a single queue instance to manage messages for multiple tasks, with isolation based on task ID and session ID.

    All methods are async to support external storage implementations. All data in QueuedMessage must be JSON-serializable.

    interface TaskMessageQueue {
        dequeue(
            taskId: string,
            sessionId?: string,
        ): Promise<QueuedMessage | undefined>;
        dequeueAll(taskId: string, sessionId?: string): Promise<QueuedMessage[]>;
        enqueue(
            taskId: string,
            message: QueuedMessage,
            sessionId?: string,
            maxSize?: number,
        ): Promise<void>;
    }

    Implemented by

    Index

    Methods

    • Experimental

      Removes and returns the first message from the queue for a specific task.

      Parameters

      • taskId: string

        The task identifier

      • OptionalsessionId: string

        Optional session ID for binding the query to a specific session

      Returns Promise<QueuedMessage | undefined>

      The first message, or undefined if the queue is empty

    • Experimental

      Removes and returns all messages from the queue for a specific task. Used when tasks are cancelled or failed to clean up pending messages.

      Parameters

      • taskId: string

        The task identifier

      • OptionalsessionId: string

        Optional session ID for binding the query to a specific session

      Returns Promise<QueuedMessage[]>

      Array of all messages that were in the queue

    • Experimental

      Adds a message to the end of the queue for a specific task. Atomically checks queue size and throws if maxSize would be exceeded.

      Parameters

      • taskId: string

        The task identifier

      • message: QueuedMessage

        The message to enqueue

      • OptionalsessionId: string

        Optional session ID for binding the operation to a specific session

      • OptionalmaxSize: number

        Optional maximum queue size - if specified and queue is full, throws an error

      Returns Promise<void>

      Error if maxSize is specified and would be exceeded