MCP TypeScript SDK
    Preparing search index...

    Class ExperimentalClientTasks<RequestT, NotificationT, ResultT>Experimental

    Experimental task features for MCP clients.

    Access via client.experimental.tasks:

    const stream = client.experimental.tasks.callToolStream({ name: 'tool', arguments: {} });
    const task = await client.experimental.tasks.getTask(taskId);

    Type Parameters

    Index

    Constructors

    • Experimental

      Type Parameters

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

      Parameters

      Returns ExperimentalClientTasks<RequestT, NotificationT, ResultT>

    Methods

    • Experimental

      Calls a tool and returns an AsyncGenerator that yields response messages. The generator is guaranteed to end with either a 'result' or 'error' message.

      This method provides streaming access to tool execution, allowing you to observe intermediate task status updates for long-running tool calls. Automatically validates structured output if the tool has an outputSchema.

      Type Parameters

      • T extends
            | ZodObject<
                {
                    _meta: ZodOptional<
                        ZodObject<
                            {
                                "io.modelcontextprotocol/related-task": ZodOptional<
                                    ZodObject<{ taskId: ZodString }, $strip>,
                                >;
                                progressToken: ZodOptional<ZodUnion<readonly [ZodString, ZodNumber]>>;
                            },
                            $loose,
                        >,
                    >;
                    content: ZodDefault<
                        ZodArray<
                            ZodUnion<
                                readonly [
                                    ZodObject<
                                        {
                                            _meta: ZodOptional<ZodRecord<(...), (...)>>;
                                            annotations: ZodOptional<ZodObject<(...), (...)>>;
                                            text: ZodString;
                                            type: ZodLiteral<"text">;
                                        },
                                        $strip,
                                    >,
                                    ZodObject<
                                        {
                                            _meta: ZodOptional<ZodRecord<(...), (...)>>;
                                            annotations: ZodOptional<ZodObject<(...), (...)>>;
                                            data: ZodString;
                                            mimeType: ZodString;
                                            type: ZodLiteral<"image">;
                                        },
                                        $strip,
                                    >,
                                    ZodObject<
                                        {
                                            _meta: ZodOptional<ZodRecord<(...), (...)>>;
                                            annotations: ZodOptional<ZodObject<(...), (...)>>;
                                            data: ZodString;
                                            mimeType: ZodString;
                                            type: ZodLiteral<"audio">;
                                        },
                                        $strip,
                                    >,
                                    ZodObject<
                                        {
                                            _meta: ZodOptional<ZodObject<(...), (...)>>;
                                            annotations: ZodOptional<ZodObject<(...), (...)>>;
                                            description: ZodOptional<ZodString>;
                                            icons: ZodOptional<ZodArray<(...)>>;
                                            mimeType: ZodOptional<ZodString>;
                                            name: ZodString;
                                            title: ZodOptional<ZodString>;
                                            type: ZodLiteral<"resource_link">;
                                            uri: ZodString;
                                        },
                                        $strip,
                                    >,
                                    ZodObject<
                                        {
                                            _meta: ZodOptional<ZodRecord<(...), (...)>>;
                                            annotations: ZodOptional<ZodObject<(...), (...)>>;
                                            resource: ZodUnion<readonly [(...), (...)]>;
                                            type: ZodLiteral<"resource">;
                                        },
                                        $strip,
                                    >,
                                ],
                            >,
                        >,
                    >;
                    isError: ZodOptional<ZodBoolean>;
                    structuredContent: ZodOptional<ZodRecord<ZodString, ZodUnknown>>;
                },
                $loose,
            >
            | ZodUnion<
                [
                    ZodObject<
                        {
                            _meta: ZodOptional<
                                ZodObject<
                                    {
                                        "io.modelcontextprotocol/related-task": ZodOptional<
                                            ZodObject<{ taskId: ... }, $strip>,
                                        >;
                                        progressToken: ZodOptional<ZodUnion<readonly [(...), (...)]>>;
                                    },
                                    $loose,
                                >,
                            >;
                            content: ZodDefault<
                                ZodArray<
                                    ZodUnion<
                                        readonly [
                                            ZodObject<
                                                { _meta: ...; annotations: ...; text: ...; type: ... },
                                                $strip,
                                            >,
                                            ZodObject<
                                                {
                                                    _meta: ...;
                                                    annotations: ...;
                                                    data: ...;
                                                    mimeType: ...;
                                                    type: ...;
                                                },
                                                $strip,
                                            >,
                                            ZodObject<
                                                {
                                                    _meta: ...;
                                                    annotations: ...;
                                                    data: ...;
                                                    mimeType: ...;
                                                    type: ...;
                                                },
                                                $strip,
                                            >,
                                            ZodObject<
                                                {
                                                    _meta: ...;
                                                    annotations: ...;
                                                    description: ...;
                                                    icons: ...;
                                                    mimeType: ...;
                                                    name: ...;
                                                    title: ...;
                                                    type: ...;
                                                    uri: ...;
                                                },
                                                $strip,
                                            >,
                                            ZodObject<
                                                { _meta: ...; annotations: ...; resource: ...; type: ... },
                                                $strip,
                                            >,
                                        ],
                                    >,
                                >,
                            >;
                            isError: ZodOptional<ZodBoolean>;
                            structuredContent: ZodOptional<ZodRecord<ZodString, ZodUnknown>>;
                        },
                        $loose,
                    >,
                    ZodObject<
                        {
                            _meta: ZodOptional<
                                ZodObject<
                                    {
                                        "io.modelcontextprotocol/related-task": ZodOptional<
                                            ZodObject<{ taskId: ... }, $strip>,
                                        >;
                                        progressToken: ZodOptional<ZodUnion<readonly [(...), (...)]>>;
                                    },
                                    $loose,
                                >,
                            >;
                            toolResult: ZodUnknown;
                        },
                        $loose,
                    >,
                ],
            >

      Parameters

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

        Tool call parameters (name and arguments)

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

          See General fields: _meta 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.

        • Optionalarguments?: { [key: string]: unknown }

          Arguments to pass to the tool.

        • name: string

          The name of the tool to call.

        • Optionaltask?: { ttl?: number }

          If specified, the caller is requesting task-augmented execution for this request. The request will return a CreateTaskResult immediately, and the actual result can be retrieved later via tasks/result.

          Task augmentation is subject to capability negotiation - receivers MUST declare support for task augmentation of specific request types in their capabilities.

      • resultSchema: T = ...

        Zod schema for validating the result (defaults to CallToolResultSchema)

      • Optionaloptions: RequestOptions

        Optional request options (timeout, signal, task creation params, etc.)

      Returns AsyncGenerator<ResponseMessage<SchemaOutput<T>>, void, void>

      AsyncGenerator that yields ResponseMessage objects

      const stream = client.experimental.tasks.callToolStream({ name: 'myTool', arguments: {} });
      for await (const message of stream) {
      switch (message.type) {
      case 'taskCreated':
      console.log('Tool execution started:', message.task.taskId);
      break;
      case 'taskStatus':
      console.log('Tool status:', message.task.status);
      break;
      case 'result':
      console.log('Tool result:', message.result);
      break;
      case 'error':
      console.error('Tool error:', message.error);
      break;
      }
      }
    • Experimental

      Cancels a running task.

      Parameters

      • taskId: string

        The task identifier

      • Optionaloptions: RequestOptions

        Optional request options

      Returns Promise<
          {
              _meta?: {
                  "io.modelcontextprotocol/related-task"?: { taskId: string };
                  progressToken?: string | number;
                  [key: string]: unknown;
              };
              createdAt: string;
              lastUpdatedAt: string;
              pollInterval?: number;
              status: | "working"
              | "input_required"
              | "completed"
              | "failed"
              | "cancelled";
              statusMessage?: string;
              taskId: string;
              ttl: number
              | null;
          },
      >

    • Experimental

      Gets the current status of a task.

      Parameters

      • taskId: string

        The task identifier

      • Optionaloptions: RequestOptions

        Optional request options

      Returns Promise<
          {
              _meta?: {
                  "io.modelcontextprotocol/related-task"?: { taskId: string };
                  progressToken?: string | number;
                  [key: string]: unknown;
              };
              createdAt: string;
              lastUpdatedAt: string;
              pollInterval?: number;
              status: | "working"
              | "input_required"
              | "completed"
              | "failed"
              | "cancelled";
              statusMessage?: string;
              taskId: string;
              ttl: number
              | null;
          },
      >

      The task status

    • Experimental

      Retrieves the result of a completed task.

      Type Parameters

      • T extends AnyObjectSchema

      Parameters

      • taskId: string

        The task identifier

      • OptionalresultSchema: T

        Zod schema for validating the result

      • Optionaloptions: RequestOptions

        Optional request options

      Returns Promise<SchemaOutput<T>>

      The task result

    • Experimental

      Lists tasks with optional pagination.

      Parameters

      • Optionalcursor: string

        Optional pagination cursor

      • Optionaloptions: RequestOptions

        Optional request options

      Returns Promise<
          {
              _meta?: {
                  "io.modelcontextprotocol/related-task"?: { taskId: string };
                  progressToken?: string | number;
                  [key: string]: unknown;
              };
              nextCursor?: string;
              tasks: {
                  createdAt: string;
                  lastUpdatedAt: string;
                  pollInterval?: number;
                  status: | "working"
                  | "input_required"
                  | "completed"
                  | "failed"
                  | "cancelled";
                  statusMessage?: string;
                  taskId: string;
                  ttl: number
                  | null;
              }[];
              [key: string]: unknown;
          },
      >

      List of tasks with optional next cursor

    • Experimental

      Sends a request and returns an AsyncGenerator that yields response messages. The generator is guaranteed to end with either a 'result' or 'error' message.

      This method provides streaming access to request processing, allowing you to observe intermediate task status updates for task-augmented requests.

      Type Parameters

      • T extends AnyObjectSchema

      Parameters

      • request: ClientRequest | RequestT

        The request to send

      • resultSchema: T

        Zod schema for validating the result

      • Optionaloptions: RequestOptions

        Optional request options (timeout, signal, task creation params, etc.)

      Returns AsyncGenerator<ResponseMessage<SchemaOutput<T>>, void, void>

      AsyncGenerator that yields ResponseMessage objects