MCP TypeScript SDK
    Preparing search index...

    Interface TaskStoreExperimental

    Interface for storing and retrieving task state and results.

    Similar to Transport, this allows pluggable task storage implementations (in-memory, database, distributed cache, etc.).

    interface TaskStore {
        createTask(
            taskParams: CreateTaskOptions,
            requestId: RequestId,
            request: {
                method: string;
                params?: {
                    _meta?: {
                        "io.modelcontextprotocol/related-task"?: { taskId: string };
                        progressToken?: string | number;
                        [key: string]: unknown;
                    };
                    [key: string]: unknown;
                };
            },
            sessionId?: string,
        ): Promise<
            {
                createdAt: string;
                lastUpdatedAt: string;
                pollInterval?: number;
                status: | "working"
                | "input_required"
                | "completed"
                | "failed"
                | "cancelled";
                statusMessage?: string;
                taskId: string;
                ttl: number
                | null;
            },
        >;
        getTask(
            taskId: string,
            sessionId?: string,
        ): Promise<
            | {
                createdAt: string;
                lastUpdatedAt: string;
                pollInterval?: number;
                status: | "working"
                | "input_required"
                | "completed"
                | "failed"
                | "cancelled";
                statusMessage?: string;
                taskId: string;
                ttl: number
                | null;
            }
            | null,
        >;
        getTaskResult(
            taskId: string,
            sessionId?: string,
        ): Promise<
            {
                _meta?: {
                    "io.modelcontextprotocol/related-task"?: { taskId: string };
                    progressToken?: string | number;
                    [key: string]: unknown;
                };
                [key: string]: unknown;
            },
        >;
        listTasks(
            cursor?: string,
            sessionId?: string,
        ): Promise<
            {
                nextCursor?: string;
                tasks: {
                    createdAt: string;
                    lastUpdatedAt: string;
                    pollInterval?: number;
                    status: | "working"
                    | "input_required"
                    | "completed"
                    | "failed"
                    | "cancelled";
                    statusMessage?: string;
                    taskId: string;
                    ttl: number
                    | null;
                }[];
            },
        >;
        storeTaskResult(
            taskId: string,
            status: "completed" | "failed",
            result: {
                _meta?: {
                    "io.modelcontextprotocol/related-task"?: { taskId: string };
                    progressToken?: string | number;
                    [key: string]: unknown;
                };
                [key: string]: unknown;
            },
            sessionId?: string,
        ): Promise<void>;
        updateTaskStatus(
            taskId: string,
            status:
                | "working"
                | "input_required"
                | "completed"
                | "failed"
                | "cancelled",
            statusMessage?: string,
            sessionId?: string,
        ): Promise<void>;
    }

    Implemented by

    Index

    Methods

    • Experimental

      Creates a new task with the given creation parameters and original request. The implementation must generate a unique taskId and createdAt timestamp.

      TTL Management:

      • The implementation receives the TTL suggested by the requestor via taskParams.ttl
      • The implementation MAY override the requested TTL (e.g., to enforce limits)
      • The actual TTL used MUST be returned in the Task object
      • Null TTL indicates unlimited task lifetime (no automatic cleanup)
      • Cleanup SHOULD occur automatically after TTL expires, regardless of task status

      Parameters

      • taskParams: CreateTaskOptions

        The task creation parameters from the request (ttl, pollInterval)

      • requestId: RequestId

        The JSON-RPC request ID

      • request: {
            method: string;
            params?: {
                _meta?: {
                    "io.modelcontextprotocol/related-task"?: { taskId: string };
                    progressToken?: string | number;
                    [key: string]: unknown;
                };
                [key: string]: unknown;
            };
        }

        The original request that triggered task creation

      • OptionalsessionId: string

        Optional session ID for binding the task to a specific session

      Returns Promise<
          {
              createdAt: string;
              lastUpdatedAt: string;
              pollInterval?: number;
              status: | "working"
              | "input_required"
              | "completed"
              | "failed"
              | "cancelled";
              statusMessage?: string;
              taskId: string;
              ttl: number
              | null;
          },
      >

      The created task object

    • Experimental

      Gets the current status of a task.

      Parameters

      • taskId: string

        The task identifier

      • OptionalsessionId: string

        Optional session ID for binding the query to a specific session

      Returns Promise<
          | {
              createdAt: string;
              lastUpdatedAt: string;
              pollInterval?: number;
              status: | "working"
              | "input_required"
              | "completed"
              | "failed"
              | "cancelled";
              statusMessage?: string;
              taskId: string;
              ttl: number
              | null;
          }
          | null,
      >

      The task object, or null if it does not exist

    • Experimental

      Retrieves the stored result of a task.

      Parameters

      • taskId: string

        The task identifier

      • OptionalsessionId: string

        Optional session ID for binding the query to a specific session

      Returns Promise<
          {
              _meta?: {
                  "io.modelcontextprotocol/related-task"?: { taskId: string };
                  progressToken?: string | number;
                  [key: string]: unknown;
              };
              [key: string]: unknown;
          },
      >

      The stored result

    • Experimental

      Lists tasks, optionally starting from a pagination cursor.

      Parameters

      • Optionalcursor: string

        Optional cursor for pagination

      • OptionalsessionId: string

        Optional session ID for binding the query to a specific session

      Returns Promise<
          {
              nextCursor?: string;
              tasks: {
                  createdAt: string;
                  lastUpdatedAt: string;
                  pollInterval?: number;
                  status: | "working"
                  | "input_required"
                  | "completed"
                  | "failed"
                  | "cancelled";
                  statusMessage?: string;
                  taskId: string;
                  ttl: number
                  | null;
              }[];
          },
      >

      An object containing the tasks array and an optional nextCursor

    • Experimental

      Stores the result of a task and sets its final status.

      Parameters

      • taskId: string

        The task identifier

      • status: "completed" | "failed"

        The final status: 'completed' for success, 'failed' for errors

      • result: {
            _meta?: {
                "io.modelcontextprotocol/related-task"?: { taskId: string };
                progressToken?: string | number;
                [key: string]: unknown;
            };
            [key: string]: unknown;
        }

        The result to store

        • [key: string]: unknown
        • Optional_meta?: {
              "io.modelcontextprotocol/related-task"?: { taskId: string };
              progressToken?: string | number;
              [key: string]: unknown;
          }

          See MCP specification for notes on _meta usage.

          • Optionalio.modelcontextprotocol/related-task?: { taskId: string }

            If specified, this request is related to the provided task.

          • OptionalprogressToken?: string | number

            If specified, the caller is requesting out-of-band progress notifications for this request (as represented by notifications/progress). The value of this parameter is an opaque token that will be attached to any subsequent notifications. The receiver is not obligated to provide these notifications.

      • OptionalsessionId: string

        Optional session ID for binding the operation to a specific session

      Returns Promise<void>

    • Experimental

      Updates a task's status (e.g., to 'cancelled', 'failed', 'completed').

      Parameters

      • taskId: string

        The task identifier

      • status: "working" | "input_required" | "completed" | "failed" | "cancelled"

        The new status

      • OptionalstatusMessage: string

        Optional diagnostic message for failed tasks or other status information

      • OptionalsessionId: string

        Optional session ID for binding the operation to a specific session

      Returns Promise<void>