MCP TypeScript SDK
    Preparing search index...

    Class InMemoryTaskStoreExperimental

    A simple in-memory implementation of TaskStore for demonstration purposes.

    This implementation stores all tasks in memory and provides automatic cleanup based on the ttl duration specified in the task creation parameters.

    Note: This is not suitable for production use as all data is lost on restart. For production, consider implementing TaskStore with a database or distributed cache.

    Implements

    Index

    Constructors

    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

      • Optional_sessionId: string

      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

      Get all tasks (useful for debugging)

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

      • createdAt: string

        ISO 8601 timestamp when the task was created.

      • lastUpdatedAt: string

        ISO 8601 timestamp when the task was last updated.

      • OptionalpollInterval?: number
      • status: "working" | "input_required" | "completed" | "failed" | "cancelled"
      • OptionalstatusMessage?: string

        Optional diagnostic message for failed tasks or other status information.

      • taskId: string
      • ttl: number | null

        Time in milliseconds to keep task results available after completion. If null, the task has unlimited lifetime until manually cleaned up.

    • Experimental

      Gets the current status of a task.

      Parameters

      • taskId: string

        The task identifier

      • Optional_sessionId: string

      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

      • Optional_sessionId: string

      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

      • Optional_sessionId: string

      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.

      • Optional_sessionId: string

      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

      • Optional_sessionId: string

      Returns Promise<void>