MCP TypeScript SDK
    Preparing search index...

    Class Client<RequestT, NotificationT, ResultT>

    An MCP client on top of a pluggable transport.

    The client will automatically begin the initialization flow with the server when connect() is called.

    To use with custom types, extend the base Request/Notification/Result types and pass them as type parameters:

    // Custom schemas
    const CustomRequestSchema = RequestSchema.extend({...})
    const CustomNotificationSchema = NotificationSchema.extend({...})
    const CustomResultSchema = ResultSchema.extend({...})

    // Type aliases
    type CustomRequest = z.infer<typeof CustomRequestSchema>
    type CustomNotification = z.infer<typeof CustomNotificationSchema>
    type CustomResult = z.infer<typeof CustomResultSchema>

    // Create typed client
    const client = new Client<CustomRequest, CustomNotification, CustomResult>({
    name: "CustomClient",
    version: "1.0.0"
    })

    Type Parameters

    Hierarchy (View Summary)

    Index

    Constructors

    • Initializes this client with the given name and version information.

      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

      • _clientInfo: {
            description?: string;
            icons?: {
                mimeType?: string;
                sizes?: string[];
                src: string;
                theme?: "light" | "dark";
            }[];
            name: string;
            title?: string;
            version: string;
            websiteUrl?: string;
        }
        • Optionaldescription?: string

          An optional human-readable description of what this implementation does.

          This can be used by clients or servers to provide context about their purpose and capabilities. For example, a server might describe the types of resources or tools it provides, while a client might describe its intended use case.

        • Optionalicons?: { mimeType?: string; sizes?: string[]; src: string; theme?: "light" | "dark" }[]

          Optional set of sized icons that the client can display in a user interface.

          Clients that support rendering icons MUST support at least the following MIME types:

          • image/png - PNG images (safe, universal compatibility)
          • image/jpeg (and image/jpg) - JPEG images (safe, universal compatibility)

          Clients that support rendering icons SHOULD also support:

          • image/svg+xml - SVG images (scalable but requires security precautions)
          • image/webp - WebP images (modern, efficient format)
        • name: string

          Intended for programmatic or logical use, but used as a display name in past specs or fallback

        • Optionaltitle?: string

          Intended for UI and end-user contexts — optimized to be human-readable and easily understood, even by those unfamiliar with domain-specific terminology.

          If not provided, the name should be used for display (except for Tool, where annotations.title should be given precedence over using name, if present).

        • version: string
        • OptionalwebsiteUrl?: string

          An optional URL of the website for this implementation.

      • Optionaloptions: ClientOptions

      Returns Client<RequestT, NotificationT, ResultT>

    Properties

    fallbackNotificationHandler?: (
        notification: {
            method: string;
            params?: {
                _meta?: {
                    "io.modelcontextprotocol/related-task"?: { taskId: string };
                    progressToken?: string | number;
                    [key: string]: unknown;
                };
                [key: string]: unknown;
            };
        },
    ) => Promise<void>

    A handler to invoke for any notification types that do not have their own handler installed.

    fallbackRequestHandler?: (
        request: {
            id: string | number;
            jsonrpc: "2.0";
            method: string;
            params?: {
                _meta?: {
                    "io.modelcontextprotocol/related-task"?: { taskId: string };
                    progressToken?: string | number;
                    [key: string]: unknown;
                };
                [key: string]: unknown;
            };
        },
        extra: RequestHandlerExtra<
            RequestT
            | ClientRequest,
            NotificationT | ClientNotification,
        >,
    ) => Promise<ResultT | ClientResult>

    A handler to invoke for any request types that do not have their own handler installed.

    onclose?: () => void

    Callback for when the connection is closed for any reason.

    This is invoked when close() is called as well.

    onerror?: (error: Error) => void

    Callback for when an error occurs.

    Note that errors are not necessarily fatal; they are used for reporting any kind of exceptional condition out of band.

    Accessors

    Methods

    • Asserts that a request handler has not already been set for the given method, in preparation for a new one being automatically installed.

      Parameters

      • method: string

      Returns void

    • Parameters

      • capability:
            | "experimental"
            | "tools"
            | "tasks"
            | "logging"
            | "completions"
            | "prompts"
            | "resources"
      • method: string

      Returns void

    • A method to check if a request handler is supported by the local side, for the given method to be handled.

      This should be implemented by subclasses.

      Parameters

      • method: string

      Returns void

    • A method to check if task creation is supported for the given request method.

      This should be implemented by subclasses.

      Parameters

      • method: string

      Returns void

    • A method to check if task handler is supported by the local side, for the given method to be handled.

      This should be implemented by subclasses.

      Parameters

      • method: string

      Returns void

    • Calls a tool and waits for the result. Automatically validates structured output if the tool has an outputSchema.

      For task-based execution with streaming behavior, use client.experimental.tasks.callToolStream() instead.

      Parameters

      • params: {
            _meta?: {
                "io.modelcontextprotocol/related-task"?: { taskId: string };
                progressToken?: string | number;
                [key: string]: unknown;
            };
            arguments?: { [key: string]: unknown };
            name: string;
            task?: { ttl?: number };
        }
        • 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:
            | 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,
                    >,
                ],
            > = CallToolResultSchema
      • Optionaloptions: RequestOptions

      Returns Promise<
          | {
              _meta?: {
                  "io.modelcontextprotocol/related-task"?: { taskId: string };
                  progressToken?: string | number;
                  [key: string]: unknown;
              };
              content: (
                  | {
                      _meta?: Record<string, unknown>;
                      annotations?: {
                          audience?: ((...) | (...))[];
                          lastModified?: string;
                          priority?: number;
                      };
                      text: string;
                      type: "text";
                  }
                  | {
                      _meta?: Record<string, unknown>;
                      annotations?: {
                          audience?: ((...) | (...))[];
                          lastModified?: string;
                          priority?: number;
                      };
                      data: string;
                      mimeType: string;
                      type: "image";
                  }
                  | {
                      _meta?: Record<string, unknown>;
                      annotations?: {
                          audience?: ((...) | (...))[];
                          lastModified?: string;
                          priority?: number;
                      };
                      data: string;
                      mimeType: string;
                      type: "audio";
                  }
                  | {
                      _meta?: { [key: string]: unknown };
                      annotations?: {
                          audience?: ((...) | (...))[];
                          lastModified?: string;
                          priority?: number;
                      };
                      description?: string;
                      icons?: {
                          mimeType?: string;
                          sizes?: (...)[];
                          src: string;
                          theme?: "light" | "dark";
                      }[];
                      mimeType?: string;
                      name: string;
                      title?: string;
                      type: "resource_link";
                      uri: string;
                  }
                  | {
                      _meta?: Record<string, unknown>;
                      annotations?: {
                          audience?: ((...) | (...))[];
                          lastModified?: string;
                          priority?: number;
                      };
                      resource: | {
                          _meta?: Record<string, unknown>;
                          mimeType?: string;
                          text: string;
                          uri: string;
                      }
                      | {
                          _meta?: Record<string, unknown>;
                          blob: string;
                          mimeType?: string;
                          uri: string;
                      };
                      type: "resource";
                  }
              )[];
              isError?: boolean;
              structuredContent?: Record<string, unknown>;
              [key: string]: unknown;
          }
          | {
              _meta?: {
                  "io.modelcontextprotocol/related-task"?: { taskId: string };
                  progressToken?: string | number;
                  [key: string]: unknown;
              };
              toolResult: unknown;
              [key: string]: unknown;
          },
      >

    • Experimental

      Cancels a specific task.

      Use client.experimental.tasks.cancelTask() to access this method.

      Parameters

      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;
          },
      >

    • Parameters

      • params: {
            _meta?: {
                "io.modelcontextprotocol/related-task"?: { taskId: string };
                progressToken?: string | number;
                [key: string]: unknown;
            };
            argument: { name: string; value: string };
            context?: { arguments?: { [key: string]: string } };
            ref:
                | { name: string; type: "ref/prompt" }
                | { type: "ref/resource"; uri: string };
        }
        • 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.

        • argument: { name: string; value: string }

          The argument's information

          • name: string

            The name of the argument

          • value: string

            The value of the argument to use for completion matching.

        • Optionalcontext?: { arguments?: { [key: string]: string } }
          • Optionalarguments?: { [key: string]: string }

            Previously-resolved variables in a URI template or prompt.

        • ref: { name: string; type: "ref/prompt" } | { type: "ref/resource"; uri: string }
      • Optionaloptions: RequestOptions

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

    • Attaches to the given transport, starts it, and starts listening for messages.

      The Protocol object assumes ownership of the Transport, replacing any callbacks that have already been set, and expects that it is the only user of the Transport instance going forward.

      Parameters

      Returns Promise<void>

    • After initialization has completed, this may be populated with information about the server's instructions.

      Returns string | undefined

    • Parameters

      • params: {
            _meta?: {
                "io.modelcontextprotocol/related-task"?: { taskId: string };
                progressToken?: string | number;
                [key: string]: unknown;
            };
            arguments?: { [key: string]: string };
            name: string;
        }
        • 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]: string }

          Arguments to use for templating the prompt.

        • name: string

          The name of the prompt or prompt template.

      • Optionaloptions: RequestOptions

      Returns Promise<
          {
              _meta?: {
                  "io.modelcontextprotocol/related-task"?: { taskId: string };
                  progressToken?: string | number;
                  [key: string]: unknown;
              };
              description?: string;
              messages: {
                  content: | {
                      _meta?: Record<string, unknown>;
                      annotations?: {
                          audience?: ((...) | (...))[];
                          lastModified?: string;
                          priority?: number;
                      };
                      text: string;
                      type: "text";
                  }
                  | {
                      _meta?: Record<string, unknown>;
                      annotations?: {
                          audience?: ((...) | (...))[];
                          lastModified?: string;
                          priority?: number;
                      };
                      data: string;
                      mimeType: string;
                      type: "image";
                  }
                  | {
                      _meta?: Record<string, unknown>;
                      annotations?: {
                          audience?: ((...) | (...))[];
                          lastModified?: string;
                          priority?: number;
                      };
                      data: string;
                      mimeType: string;
                      type: "audio";
                  }
                  | {
                      _meta?: { [key: string]: unknown };
                      annotations?: {
                          audience?: ((...) | (...))[];
                          lastModified?: string;
                          priority?: number;
                      };
                      description?: string;
                      icons?: {
                          mimeType?: string;
                          sizes?: (...)[];
                          src: string;
                          theme?: "light" | "dark";
                      }[];
                      mimeType?: string;
                      name: string;
                      title?: string;
                      type: "resource_link";
                      uri: string;
                  }
                  | {
                      _meta?: Record<string, unknown>;
                      annotations?: {
                          audience?: ((...) | (...))[];
                          lastModified?: string;
                          priority?: number;
                      };
                      resource: | {
                          _meta?: Record<string, unknown>;
                          mimeType?: string;
                          text: string;
                          uri: string;
                      }
                      | {
                          _meta?: Record<string, unknown>;
                          blob: string;
                          mimeType?: string;
                          uri: string;
                      };
                      type: "resource";
                  };
                  role: "user"
                  | "assistant";
              }[];
              [key: string]: unknown;
          },
      >

    • After initialization has completed, this will be populated with the server's reported capabilities.

      Returns
          | {
              completions?: object;
              experimental?: { [key: string]: object };
              logging?: object;
              prompts?: { listChanged?: boolean };
              resources?: { listChanged?: boolean; subscribe?: boolean };
              tasks?: {
                  cancel?: object;
                  list?: object;
                  requests?: {
                      tools?: { call?: object; [key: string]: unknown };
                      [key: string]: unknown;
                  };
                  [key: string]: unknown;
              };
              tools?: { listChanged?: boolean };
          }
          | undefined

      • {
            completions?: object;
            experimental?: { [key: string]: object };
            logging?: object;
            prompts?: { listChanged?: boolean };
            resources?: { listChanged?: boolean; subscribe?: boolean };
            tasks?: {
                cancel?: object;
                list?: object;
                requests?: {
                    tools?: { call?: object; [key: string]: unknown };
                    [key: string]: unknown;
                };
                [key: string]: unknown;
            };
            tools?: { listChanged?: boolean };
        }
        • Optionalcompletions?: object

          Present if the server supports sending completions to the client.

        • Optionalexperimental?: { [key: string]: object }

          Experimental, non-standard capabilities that the server supports.

        • Optionallogging?: object

          Present if the server supports sending log messages to the client.

        • Optionalprompts?: { listChanged?: boolean }

          Present if the server offers any prompt templates.

          • OptionallistChanged?: boolean

            Whether this server supports issuing notifications for changes to the prompt list.

        • Optionalresources?: { listChanged?: boolean; subscribe?: boolean }

          Present if the server offers any resources to read.

          • OptionallistChanged?: boolean

            Whether this server supports issuing notifications for changes to the resource list.

          • Optionalsubscribe?: boolean

            Whether this server supports clients subscribing to resource updates.

        • Optionaltasks?: {
              cancel?: object;
              list?: object;
              requests?: {
                  tools?: { call?: object; [key: string]: unknown };
                  [key: string]: unknown;
              };
              [key: string]: unknown;
          }

          Present if the server supports task creation.

          • Optionalcancel?: object

            Present if the server supports cancelling tasks.

          • Optionallist?: object

            Present if the server supports listing tasks.

          • Optionalrequests?: { tools?: { call?: object; [key: string]: unknown }; [key: string]: unknown }

            Capabilities for task creation on specific request types.

            • Optionaltools?: { call?: object; [key: string]: unknown }

              Task support for tool requests.

        • Optionaltools?: { listChanged?: boolean }

          Present if the server offers any tools to call.

          • OptionallistChanged?: boolean

            Whether this server supports issuing notifications for changes to the tool list.

      • undefined
    • After initialization has completed, this will be populated with information about the server's name and version.

      Returns
          | {
              description?: string;
              icons?: {
                  mimeType?: string;
                  sizes?: string[];
                  src: string;
                  theme?: "light"
                  | "dark";
              }[];
              name: string;
              title?: string;
              version: string;
              websiteUrl?: string;
          }
          | undefined

      • {
            description?: string;
            icons?: {
                mimeType?: string;
                sizes?: string[];
                src: string;
                theme?: "light" | "dark";
            }[];
            name: string;
            title?: string;
            version: string;
            websiteUrl?: string;
        }
        • Optionaldescription?: string

          An optional human-readable description of what this implementation does.

          This can be used by clients or servers to provide context about their purpose and capabilities. For example, a server might describe the types of resources or tools it provides, while a client might describe its intended use case.

        • Optionalicons?: { mimeType?: string; sizes?: string[]; src: string; theme?: "light" | "dark" }[]

          Optional set of sized icons that the client can display in a user interface.

          Clients that support rendering icons MUST support at least the following MIME types:

          • image/png - PNG images (safe, universal compatibility)
          • image/jpeg (and image/jpg) - JPEG images (safe, universal compatibility)

          Clients that support rendering icons SHOULD also support:

          • image/svg+xml - SVG images (scalable but requires security precautions)
          • image/webp - WebP images (modern, efficient format)
        • name: string

          Intended for programmatic or logical use, but used as a display name in past specs or fallback

        • Optionaltitle?: string

          Intended for UI and end-user contexts — optimized to be human-readable and easily understood, even by those unfamiliar with domain-specific terminology.

          If not provided, the name should be used for display (except for Tool, where annotations.title should be given precedence over using name, if present).

        • version: string
        • OptionalwebsiteUrl?: string

          An optional URL of the website for this implementation.

      • undefined
    • Experimental

      Gets the current status of a task.

      Use client.experimental.tasks.getTask() to access this method.

      Parameters

      • params: {
            _meta?: {
                "io.modelcontextprotocol/related-task"?: { taskId: string };
                progressToken?: string | number;
                [key: string]: unknown;
            };
            taskId: string;
        }
        • 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.

        • taskId: string
      • Optionaloptions: RequestOptions

      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

      Retrieves the result of a completed task.

      Use client.experimental.tasks.getTaskResult() to access this method.

      Type Parameters

      • T extends AnySchema

      Parameters

      • params: {
            _meta?: {
                "io.modelcontextprotocol/related-task"?: { taskId: string };
                progressToken?: string | number;
                [key: string]: unknown;
            };
            taskId: string;
        }
        • 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.

        • taskId: string
      • resultSchema: T
      • Optionaloptions: RequestOptions

      Returns Promise<SchemaOutput<T>>

    • Parameters

      • Optionalparams: {
            _meta?: {
                "io.modelcontextprotocol/related-task"?: { taskId: string };
                progressToken?: string | number;
                [key: string]: unknown;
            };
            cursor?: string;
        }
        • 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.

        • Optionalcursor?: string

          An opaque token representing the current pagination position. If provided, the server should return results starting after this cursor.

      • Optionaloptions: RequestOptions

      Returns Promise<
          {
              _meta?: {
                  "io.modelcontextprotocol/related-task"?: { taskId: string };
                  progressToken?: string | number;
                  [key: string]: unknown;
              };
              nextCursor?: string;
              prompts: {
                  _meta?: { [key: string]: unknown };
                  arguments?: { description?: string; name: string; required?: boolean }[];
                  description?: string;
                  icons?: {
                      mimeType?: string;
                      sizes?: string[];
                      src: string;
                      theme?: "light" | "dark";
                  }[];
                  name: string;
                  title?: string;
              }[];
              [key: string]: unknown;
          },
      >

    • Parameters

      • Optionalparams: {
            _meta?: {
                "io.modelcontextprotocol/related-task"?: { taskId: string };
                progressToken?: string | number;
                [key: string]: unknown;
            };
            cursor?: string;
        }
        • 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.

        • Optionalcursor?: string

          An opaque token representing the current pagination position. If provided, the server should return results starting after this cursor.

      • Optionaloptions: RequestOptions

      Returns Promise<
          {
              _meta?: {
                  "io.modelcontextprotocol/related-task"?: { taskId: string };
                  progressToken?: string | number;
                  [key: string]: unknown;
              };
              nextCursor?: string;
              resources: {
                  _meta?: { [key: string]: unknown };
                  annotations?: {
                      audience?: ("user" | "assistant")[];
                      lastModified?: string;
                      priority?: number;
                  };
                  description?: string;
                  icons?: {
                      mimeType?: string;
                      sizes?: string[];
                      src: string;
                      theme?: "light"
                      | "dark";
                  }[];
                  mimeType?: string;
                  name: string;
                  title?: string;
                  uri: string;
              }[];
              [key: string]: unknown;
          },
      >

    • Parameters

      • Optionalparams: {
            _meta?: {
                "io.modelcontextprotocol/related-task"?: { taskId: string };
                progressToken?: string | number;
                [key: string]: unknown;
            };
            cursor?: string;
        }
        • 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.

        • Optionalcursor?: string

          An opaque token representing the current pagination position. If provided, the server should return results starting after this cursor.

      • Optionaloptions: RequestOptions

      Returns Promise<
          {
              _meta?: {
                  "io.modelcontextprotocol/related-task"?: { taskId: string };
                  progressToken?: string | number;
                  [key: string]: unknown;
              };
              nextCursor?: string;
              resourceTemplates: {
                  _meta?: { [key: string]: unknown };
                  annotations?: {
                      audience?: ("user" | "assistant")[];
                      lastModified?: string;
                      priority?: number;
                  };
                  description?: string;
                  icons?: {
                      mimeType?: string;
                      sizes?: string[];
                      src: string;
                      theme?: "light"
                      | "dark";
                  }[];
                  mimeType?: string;
                  name: string;
                  title?: string;
                  uriTemplate: string;
              }[];
              [key: string]: unknown;
          },
      >

    • Experimental

      Lists tasks, optionally starting from a pagination cursor.

      Use client.experimental.tasks.listTasks() to access this method.

      Parameters

      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;
          },
      >

    • Parameters

      • Optionalparams: {
            _meta?: {
                "io.modelcontextprotocol/related-task"?: { taskId: string };
                progressToken?: string | number;
                [key: string]: unknown;
            };
            cursor?: string;
        }
        • 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.

        • Optionalcursor?: string

          An opaque token representing the current pagination position. If provided, the server should return results starting after this cursor.

      • Optionaloptions: RequestOptions

      Returns Promise<
          {
              _meta?: {
                  "io.modelcontextprotocol/related-task"?: { taskId: string };
                  progressToken?: string | number;
                  [key: string]: unknown;
              };
              nextCursor?: string;
              tools: {
                  _meta?: Record<string, unknown>;
                  annotations?: {
                      destructiveHint?: boolean;
                      idempotentHint?: boolean;
                      openWorldHint?: boolean;
                      readOnlyHint?: boolean;
                      title?: string;
                  };
                  description?: string;
                  execution?: { taskSupport?: "optional"
                  | "required"
                  | "forbidden" };
                  icons?: {
                      mimeType?: string;
                      sizes?: string[];
                      src: string;
                      theme?: "light" | "dark";
                  }[];
                  inputSchema: {
                      properties?: Record<string, object>;
                      required?: string[];
                      type: "object";
                      [key: string]: unknown;
                  };
                  name: string;
                  outputSchema?: {
                      properties?: Record<string, object>;
                      required?: string[];
                      type: "object";
                      [key: string]: unknown;
                  };
                  title?: string;
              }[];
              [key: string]: unknown;
          },
      >

    • Parameters

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

    • Parameters

      • params: {
            _meta?: {
                "io.modelcontextprotocol/related-task"?: { taskId: string };
                progressToken?: string | number;
                [key: string]: unknown;
            };
            uri: string;
        }
        • 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.

        • uri: string

          The URI of the resource to read. The URI can use any protocol; it is up to the server how to interpret it.

          uri

      • Optionaloptions: RequestOptions

      Returns Promise<
          {
              _meta?: {
                  "io.modelcontextprotocol/related-task"?: { taskId: string };
                  progressToken?: string | number;
                  [key: string]: unknown;
              };
              contents: (
                  | {
                      _meta?: Record<string, unknown>;
                      mimeType?: string;
                      text: string;
                      uri: string;
                  }
                  | {
                      _meta?: Record<string, unknown>;
                      blob: string;
                      mimeType?: string;
                      uri: string;
                  }
              )[];
              [key: string]: unknown;
          },
      >

    • Registers new capabilities. This can only be called before connecting to a transport.

      The new capabilities will be merged with any existing capabilities previously given (e.g., at initialization).

      Parameters

      • capabilities: {
            elicitation?: {
                form?: { applyDefaults?: boolean; [key: string]: unknown };
                url?: object;
                [key: string]: unknown;
            };
            experimental?: { [key: string]: object };
            roots?: { listChanged?: boolean };
            sampling?: { context?: object; tools?: object };
            tasks?: {
                cancel?: object;
                list?: object;
                requests?: {
                    elicitation?: { create?: object; [key: string]: unknown };
                    sampling?: { createMessage?: object; [key: string]: unknown };
                    [key: string]: unknown;
                };
                [key: string]: unknown;
            };
        }
        • Optionalelicitation?: {
              form?: { applyDefaults?: boolean; [key: string]: unknown };
              url?: object;
              [key: string]: unknown;
          }

          Present if the client supports eliciting user input.

        • Optionalexperimental?: { [key: string]: object }

          Experimental, non-standard capabilities that the client supports.

        • Optionalroots?: { listChanged?: boolean }

          Present if the client supports listing roots.

          • OptionallistChanged?: boolean

            Whether the client supports issuing notifications for changes to the roots list.

        • Optionalsampling?: { context?: object; tools?: object }

          Present if the client supports sampling from an LLM.

          • Optionalcontext?: object

            Present if the client supports context inclusion via includeContext parameter. If not declared, servers SHOULD only use includeContext: "none" (or omit it).

          • Optionaltools?: object

            Present if the client supports tool use via tools and toolChoice parameters.

        • Optionaltasks?: {
              cancel?: object;
              list?: object;
              requests?: {
                  elicitation?: { create?: object; [key: string]: unknown };
                  sampling?: { createMessage?: object; [key: string]: unknown };
                  [key: string]: unknown;
              };
              [key: string]: unknown;
          }

          Present if the client supports task creation.

          • Optionalcancel?: object

            Present if the client supports cancelling tasks.

          • Optionallist?: object

            Present if the client supports listing tasks.

          • Optionalrequests?: {
                elicitation?: { create?: object; [key: string]: unknown };
                sampling?: { createMessage?: object; [key: string]: unknown };
                [key: string]: unknown;
            }

            Capabilities for task creation on specific request types.

            • Optionalelicitation?: { create?: object; [key: string]: unknown }

              Task support for elicitation requests.

            • Optionalsampling?: { createMessage?: object; [key: string]: unknown }

              Task support for sampling requests.

      Returns void

    • 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.

      Type Parameters

      • T extends AnySchema

      Parameters

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

      const stream = protocol.requestStream(request, resultSchema, options);
      for await (const message of stream) {
      switch (message.type) {
      case 'taskCreated':
      console.log('Task created:', message.task.taskId);
      break;
      case 'taskStatus':
      console.log('Task status:', message.task.status);
      break;
      case 'result':
      console.log('Final result:', message.result);
      break;
      case 'error':
      console.error('Error:', message.error);
      break;
      }
      }

      Use client.experimental.tasks.requestStream() to access this method.

    • Parameters

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

    • Registers a handler to invoke when this protocol object receives a notification with the given method.

      Note that this will replace any previous notification handler for the same method.

      Type Parameters

      • T extends AnyObjectSchema

      Parameters

      • notificationSchema: T
      • handler: (notification: SchemaOutput<T>) => void | Promise<void>

      Returns void

    • Parameters

      • params: {
            _meta?: {
                "io.modelcontextprotocol/related-task"?: { taskId: string };
                progressToken?: string | number;
                [key: string]: unknown;
            };
            uri: string;
        }
        • 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.

        • uri: string

          The URI of the resource to read. The URI can use any protocol; it is up to the server how to interpret it.

          uri

      • Optionaloptions: RequestOptions

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

    • Parameters

      • params: {
            _meta?: {
                "io.modelcontextprotocol/related-task"?: { taskId: string };
                progressToken?: string | number;
                [key: string]: unknown;
            };
            uri: string;
        }
        • 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.

        • uri: string

          The URI of the resource to read. The URI can use any protocol; it is up to the server how to interpret it.

          uri

      • Optionaloptions: RequestOptions

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