MCP Apps
    Preparing search index...

    Class AppBridge

    Host-side bridge for communicating with a single View (App).

    AppBridge extends the base MCP SDK's public Protocol class and acts as a proxy between the host application and a view running in an iframe. When a separate MCP client is provided to the constructor, it automatically forwards MCP server capabilities (tools, resources, prompts) to the view. It also handles the Apps initialization handshake.

    View ↔ AppBridge ↔ Host ↔ MCP Server

    The bridge proxies requests from the view to the MCP server and forwards responses back. It also sends host-initiated notifications like tool input and results to the view.

    1. Create: Instantiate AppBridge with MCP client and capabilities
    2. Connect: Call connect() with transport to establish communication
    3. Wait for init: View sends initialize request, bridge responds
    4. Send data: Call sendToolInput, sendToolResult, etc.
    5. Teardown: Call teardownResource before unmounting iframe
    // Create MCP client for the server
    const client = new Client({
    name: "MyHost",
    version: "1.0.0",
    });
    await client.connect(serverTransport);

    // Create bridge for the View
    const bridge = new AppBridge(
    client,
    { name: "MyHost", version: "1.0.0" },
    { openLinks: {}, serverTools: {}, logging: {} },
    );

    // Set up iframe and connect
    const iframe = document.getElementById("app") as HTMLIFrameElement;
    const transport = new PostMessageTransport(
    iframe.contentWindow!,
    iframe.contentWindow!,
    );

    bridge.oninitialized = () => {
    console.log("View initialized");
    // Now safe to send tool input
    bridge.sendToolInput({ arguments: { location: "NYC" } });
    };

    await bridge.connect(transport);

    Hierarchy

    • Protocol<BaseContext>
      • AppBridge
    Index

    Accessors

    • get oncalltool(): | (
          (
              params: {
                  _meta?: {
                      "io.modelcontextprotocol/related-task"?: { taskId: string };
                      progressToken?: string | number;
                      [key: string]: unknown;
                  };
                  arguments?: { [key: string]: unknown };
                  name: string;
                  task?: { ttl?: number };
              },
              extra: BaseContext,
          ) => Promise<
              {
                  _meta?: {
                      "io.modelcontextprotocol/serverInfo"?: {
                          description?: string;
                          icons?: { mimeType?: ...; sizes?: ...; src: ...; theme?: ... }[];
                          name: string;
                          title?: string;
                          version: string;
                          websiteUrl?: string;
                      };
                      [key: string]: unknown;
                  };
                  content: (
                      | {
                          _meta?: { [key: string]: unknown };
                          annotations?: {
                              audience?: (...)[];
                              lastModified?: string;
                              priority?: number;
                          };
                          text: string;
                          type: "text";
                      }
                      | {
                          _meta?: { [key: string]: unknown };
                          annotations?: {
                              audience?: (...)[];
                              lastModified?: string;
                              priority?: number;
                          };
                          data: string;
                          mimeType: string;
                          type: "image";
                      }
                      | {
                          _meta?: { [key: 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?: (...)
                              | (...);
                              sizes?: (...) | (...);
                              src: string;
                              theme?: (...) | (...) | (...);
                          }[];
                          mimeType?: string;
                          name: string;
                          size?: number;
                          title?: string;
                          type: "resource_link";
                          uri: string;
                      }
                      | {
                          _meta?: { [key: string]: unknown };
                          annotations?: {
                              audience?: (...)[];
                              lastModified?: string;
                              priority?: number;
                          };
                          resource: | {
                              _meta?: { [key: ...]: ... };
                              mimeType?: string;
                              text: string;
                              uri: string;
                          }
                          | {
                              _meta?: { [key: ...]: ... };
                              blob: string;
                              mimeType?: string;
                              uri: string;
                          };
                          type: "resource";
                      }
                  )[];
                  isError?: boolean;
                  structuredContent?: unknown;
                  [key: string]: unknown;
              },
          >
      )
      | undefined

      Returns
          | (
              (
                  params: {
                      _meta?: {
                          "io.modelcontextprotocol/related-task"?: { taskId: string };
                          progressToken?: string | number;
                          [key: string]: unknown;
                      };
                      arguments?: { [key: string]: unknown };
                      name: string;
                      task?: { ttl?: number };
                  },
                  extra: BaseContext,
              ) => Promise<
                  {
                      _meta?: {
                          "io.modelcontextprotocol/serverInfo"?: {
                              description?: string;
                              icons?: { mimeType?: ...; sizes?: ...; src: ...; theme?: ... }[];
                              name: string;
                              title?: string;
                              version: string;
                              websiteUrl?: string;
                          };
                          [key: string]: unknown;
                      };
                      content: (
                          | {
                              _meta?: { [key: string]: unknown };
                              annotations?: {
                                  audience?: (...)[];
                                  lastModified?: string;
                                  priority?: number;
                              };
                              text: string;
                              type: "text";
                          }
                          | {
                              _meta?: { [key: string]: unknown };
                              annotations?: {
                                  audience?: (...)[];
                                  lastModified?: string;
                                  priority?: number;
                              };
                              data: string;
                              mimeType: string;
                              type: "image";
                          }
                          | {
                              _meta?: { [key: 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?: (...)
                                  | (...);
                                  sizes?: (...) | (...);
                                  src: string;
                                  theme?: (...) | (...) | (...);
                              }[];
                              mimeType?: string;
                              name: string;
                              size?: number;
                              title?: string;
                              type: "resource_link";
                              uri: string;
                          }
                          | {
                              _meta?: { [key: string]: unknown };
                              annotations?: {
                                  audience?: (...)[];
                                  lastModified?: string;
                                  priority?: number;
                              };
                              resource: | {
                                  _meta?: { [key: ...]: ... };
                                  mimeType?: string;
                                  text: string;
                                  uri: string;
                              }
                              | {
                                  _meta?: { [key: ...]: ... };
                                  blob: string;
                                  mimeType?: string;
                                  uri: string;
                              };
                              type: "resource";
                          }
                      )[];
                      isError?: boolean;
                      structuredContent?: unknown;
                      [key: string]: unknown;
                  },
              >
          )
          | undefined

    • set oncalltool(
          callback:
              | (
                  (
                      params: {
                          _meta?: {
                              "io.modelcontextprotocol/related-task"?: { taskId: string };
                              progressToken?: string | number;
                              [key: string]: unknown;
                          };
                          arguments?: { [key: string]: unknown };
                          name: string;
                          task?: { ttl?: number };
                      },
                      extra: BaseContext,
                  ) => Promise<
                      {
                          _meta?: {
                              "io.modelcontextprotocol/serverInfo"?: {
                                  description?: string;
                                  icons?: { mimeType?: ...; sizes?: ...; src: ...; theme?: ... }[];
                                  name: string;
                                  title?: string;
                                  version: string;
                                  websiteUrl?: string;
                              };
                              [key: string]: unknown;
                          };
                          content: (
                              | {
                                  _meta?: { [key: string]: unknown };
                                  annotations?: {
                                      audience?: (...)[];
                                      lastModified?: string;
                                      priority?: number;
                                  };
                                  text: string;
                                  type: "text";
                              }
                              | {
                                  _meta?: { [key: string]: unknown };
                                  annotations?: {
                                      audience?: (...)[];
                                      lastModified?: string;
                                      priority?: number;
                                  };
                                  data: string;
                                  mimeType: string;
                                  type: "image";
                              }
                              | {
                                  _meta?: { [key: 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?: (...)
                                      | (...);
                                      sizes?: (...) | (...);
                                      src: string;
                                      theme?: (...) | (...) | (...);
                                  }[];
                                  mimeType?: string;
                                  name: string;
                                  size?: number;
                                  title?: string;
                                  type: "resource_link";
                                  uri: string;
                              }
                              | {
                                  _meta?: { [key: string]: unknown };
                                  annotations?: {
                                      audience?: (...)[];
                                      lastModified?: string;
                                      priority?: number;
                                  };
                                  resource: | {
                                      _meta?: { [key: ...]: ... };
                                      mimeType?: string;
                                      text: string;
                                      uri: string;
                                  }
                                  | {
                                      _meta?: { [key: ...]: ... };
                                      blob: string;
                                      mimeType?: string;
                                      uri: string;
                                  };
                                  type: "resource";
                              }
                          )[];
                          isError?: boolean;
                          structuredContent?: unknown;
                          [key: string]: unknown;
                      },
                  >
              )
              | undefined,
      ): void

      Parameters

      • callback:
            | (
                (
                    params: {
                        _meta?: {
                            "io.modelcontextprotocol/related-task"?: { taskId: string };
                            progressToken?: string | number;
                            [key: string]: unknown;
                        };
                        arguments?: { [key: string]: unknown };
                        name: string;
                        task?: { ttl?: number };
                    },
                    extra: BaseContext,
                ) => Promise<
                    {
                        _meta?: {
                            "io.modelcontextprotocol/serverInfo"?: {
                                description?: string;
                                icons?: { mimeType?: ...; sizes?: ...; src: ...; theme?: ... }[];
                                name: string;
                                title?: string;
                                version: string;
                                websiteUrl?: string;
                            };
                            [key: string]: unknown;
                        };
                        content: (
                            | {
                                _meta?: { [key: string]: unknown };
                                annotations?: {
                                    audience?: (...)[];
                                    lastModified?: string;
                                    priority?: number;
                                };
                                text: string;
                                type: "text";
                            }
                            | {
                                _meta?: { [key: string]: unknown };
                                annotations?: {
                                    audience?: (...)[];
                                    lastModified?: string;
                                    priority?: number;
                                };
                                data: string;
                                mimeType: string;
                                type: "image";
                            }
                            | {
                                _meta?: { [key: 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?: (...)
                                    | (...);
                                    sizes?: (...) | (...);
                                    src: string;
                                    theme?: (...) | (...) | (...);
                                }[];
                                mimeType?: string;
                                name: string;
                                size?: number;
                                title?: string;
                                type: "resource_link";
                                uri: string;
                            }
                            | {
                                _meta?: { [key: string]: unknown };
                                annotations?: {
                                    audience?: (...)[];
                                    lastModified?: string;
                                    priority?: number;
                                };
                                resource: | {
                                    _meta?: { [key: ...]: ... };
                                    mimeType?: string;
                                    text: string;
                                    uri: string;
                                }
                                | {
                                    _meta?: { [key: ...]: ... };
                                    blob: string;
                                    mimeType?: string;
                                    uri: string;
                                };
                                type: "resource";
                            }
                        )[];
                        isError?: boolean;
                        structuredContent?: unknown;
                        [key: string]: unknown;
                    },
                >
            )
            | undefined

      Returns void

    • get oncreatesamplingmessage(): | (
          (
              params: {
                  _meta?: {
                      "io.modelcontextprotocol/related-task"?: { taskId: string };
                      progressToken?: string | number;
                      [key: string]: unknown;
                  };
                  includeContext?: "none"
                  | "thisServer"
                  | "allServers";
                  maxTokens: number;
                  messages: {
                      _meta?: { [key: string]: unknown };
                      content:
                          | {
                              _meta?: { [key: string]: unknown };
                              annotations?: {
                                  audience?: (...)[];
                                  lastModified?: string;
                                  priority?: number;
                              };
                              text: string;
                              type: "text";
                          }
                          | {
                              _meta?: { [key: string]: unknown };
                              annotations?: {
                                  audience?: (...)[];
                                  lastModified?: string;
                                  priority?: number;
                              };
                              data: string;
                              mimeType: string;
                              type: "image";
                          }
                          | {
                              _meta?: { [key: string]: unknown };
                              annotations?: {
                                  audience?: (...)[];
                                  lastModified?: string;
                                  priority?: number;
                              };
                              data: string;
                              mimeType: string;
                              type: "audio";
                          }
                          | {
                              _meta?: { [key: string]: unknown };
                              id: string;
                              input: { [key: string]: unknown };
                              name: string;
                              type: "tool_use";
                          }
                          | {
                              _meta?: { [key: string]: unknown };
                              content: (
                                  | {
                                      _meta?: (...)
                                      | (...);
                                      annotations?: (...) | (...);
                                      text: string;
                                      type: "text";
                                  }
                                  | {
                                      _meta?: (...)
                                      | (...);
                                      annotations?: (...) | (...);
                                      data: string;
                                      mimeType: string;
                                      type: "image";
                                  }
                                  | {
                                      _meta?: (...)
                                      | (...);
                                      annotations?: (...) | (...);
                                      data: string;
                                      mimeType: string;
                                      type: "audio";
                                  }
                                  | {
                                      _meta?: (...)
                                      | (...);
                                      annotations?: (...) | (...);
                                      description?: (...) | (...);
                                      icons?: (...) | (...);
                                      mimeType?: (...) | (...);
                                      name: string;
                                      size?: (...) | (...);
                                      title?: (...) | (...);
                                      type: "resource_link";
                                      uri: string;
                                  }
                                  | {
                                      _meta?: (...)
                                      | (...);
                                      annotations?: (...) | (...);
                                      resource: (...) | (...);
                                      type: "resource";
                                  }
                              )[];
                              isError?: boolean;
                              structuredContent?: unknown;
                              toolUseId: string;
                              type: "tool_result";
                          }
                          | (
                              | {
                                  _meta?: { [key: ...]: ... };
                                  annotations?: { audience?: ...; lastModified?: ...; priority?: ... };
                                  text: string;
                                  type: "text";
                              }
                              | {
                                  _meta?: { [key: ...]: ... };
                                  annotations?: { audience?: ...; lastModified?: ...; priority?: ... };
                                  data: string;
                                  mimeType: string;
                                  type: "image";
                              }
                              | {
                                  _meta?: { [key: ...]: ... };
                                  annotations?: { audience?: ...; lastModified?: ...; priority?: ... };
                                  data: string;
                                  mimeType: string;
                                  type: "audio";
                              }
                              | {
                                  _meta?: { [key: ...]: ... };
                                  id: string;
                                  input: { [key: string]: unknown };
                                  name: string;
                                  type: "tool_use";
                              }
                              | {
                                  _meta?: { [key: ...]: ... };
                                  content: ((...) | (...) | (...) | (...) | (...))[];
                                  isError?: boolean;
                                  structuredContent?: unknown;
                                  toolUseId: string;
                                  type: "tool_result";
                              }
                          )[];
                      role: "user"
                      | "assistant";
                  }[];
                  metadata?: {
                      [key: string]: | string
                      | number
                      | boolean
                      | (
                          { [x: string]: string | number | boolean | ... | (string | number | boolean | ... | (string | number | boolean | ... | (string | number | boolean | ... | (string | number | boolean | ... | (string | ... 4 more ... | null)[] | null)[] | null)[] | null)[] | null)[] | null; }
                      )
                      | (
                          string | number | boolean | { [x: string]: string | number | boolean | ... | (string | number | boolean | ... | (string | number | boolean | ... | (string | number | boolean | ... | (string | ... 4 more ... | null)[] | null)[] | null)[] | null)[] | null; } | (string | ... 4 more ... | null)[] | null
                      )[]
                      | null;
                  };
                  modelPreferences?: {
                      costPriority?: number;
                      hints?: { name?: string }[];
                      intelligencePriority?: number;
                      speedPriority?: number;
                  };
                  stopSequences?: string[];
                  systemPrompt?: string;
                  task?: { ttl?: number };
                  temperature?: number;
                  toolChoice?: { mode?: "required" | "none" | "auto" };
                  tools?: {
                      _meta?: { [key: string]: unknown };
                      annotations?: {
                          destructiveHint?: boolean;
                          idempotentHint?: boolean;
                          openWorldHint?: boolean;
                          readOnlyHint?: boolean;
                          title?: string;
                      };
                      description?: string;
                      execution?: { taskSupport?: "optional"
                      | "required"
                      | "forbidden" };
                      icons?: {
                          mimeType?: string;
                          sizes?: (...)[];
                          src: string;
                          theme?: "light" | "dark";
                      }[];
                      inputSchema: {
                          properties?: {
                              [key: string]: | string
                              | number
                              | boolean
                              | { [key: ...]: ... }
                              | (...)[]
                              | null;
                          };
                          required?: string[];
                          type: "object";
                          [key: string]: unknown;
                      };
                      name: string;
                      outputSchema?: { $schema?: string; [key: string]: unknown };
                      title?: string;
                  }[];
              },
              extra: BaseContext,
          ) => Promise<
              | {
                  _meta?: {
                      "io.modelcontextprotocol/serverInfo"?: {
                          description?: string;
                          icons?: (...)[];
                          name: string;
                          title?: string;
                          version: string;
                          websiteUrl?: string;
                      };
                      [key: string]: unknown;
                  };
                  content: | {
                      _meta?: { [key: string]: unknown };
                      annotations?: {
                          audience?: (...)[];
                          lastModified?: string;
                          priority?: number;
                      };
                      text: string;
                      type: "text";
                  }
                  | {
                      _meta?: { [key: string]: unknown };
                      annotations?: {
                          audience?: (...)[];
                          lastModified?: string;
                          priority?: number;
                      };
                      data: string;
                      mimeType: string;
                      type: "image";
                  }
                  | {
                      _meta?: { [key: string]: unknown };
                      annotations?: {
                          audience?: (...)[];
                          lastModified?: string;
                          priority?: number;
                      };
                      data: string;
                      mimeType: string;
                      type: "audio";
                  };
                  model: string;
                  role: "user"
                  | "assistant";
                  stopReason?: string;
                  [key: string]: unknown;
              }
              | {
                  _meta?: {
                      "io.modelcontextprotocol/serverInfo"?: {
                          description?: string;
                          icons?: (...)[];
                          name: string;
                          title?: string;
                          version: string;
                          websiteUrl?: string;
                      };
                      [key: string]: unknown;
                  };
                  content: | {
                      _meta?: { [key: string]: unknown };
                      annotations?: {
                          audience?: (...)[];
                          lastModified?: string;
                          priority?: number;
                      };
                      text: string;
                      type: "text";
                  }
                  | {
                      _meta?: { [key: string]: unknown };
                      annotations?: {
                          audience?: (...)[];
                          lastModified?: string;
                          priority?: number;
                      };
                      data: string;
                      mimeType: string;
                      type: "image";
                  }
                  | {
                      _meta?: { [key: string]: unknown };
                      annotations?: {
                          audience?: (...)[];
                          lastModified?: string;
                          priority?: number;
                      };
                      data: string;
                      mimeType: string;
                      type: "audio";
                  }
                  | {
                      _meta?: { [key: string]: unknown };
                      id: string;
                      input: { [key: string]: unknown };
                      name: string;
                      type: "tool_use";
                  }
                  | {
                      _meta?: { [key: string]: unknown };
                      content: (
                          | {
                              _meta?: (...)
                              | (...);
                              annotations?: (...) | (...);
                              text: string;
                              type: "text";
                          }
                          | {
                              _meta?: (...)
                              | (...);
                              annotations?: (...) | (...);
                              data: string;
                              mimeType: string;
                              type: "image";
                          }
                          | {
                              _meta?: (...)
                              | (...);
                              annotations?: (...) | (...);
                              data: string;
                              mimeType: string;
                              type: "audio";
                          }
                          | {
                              _meta?: (...)
                              | (...);
                              annotations?: (...) | (...);
                              description?: (...) | (...);
                              icons?: (...) | (...);
                              mimeType?: (...) | (...);
                              name: string;
                              size?: (...) | (...);
                              title?: (...) | (...);
                              type: "resource_link";
                              uri: string;
                          }
                          | {
                              _meta?: (...)
                              | (...);
                              annotations?: (...) | (...);
                              resource: (...) | (...);
                              type: "resource";
                          }
                      )[];
                      isError?: boolean;
                      structuredContent?: unknown;
                      toolUseId: string;
                      type: "tool_result";
                  }
                  | (
                      | {
                          _meta?: { [key: ...]: ... };
                          annotations?: { audience?: ...; lastModified?: ...; priority?: ... };
                          text: string;
                          type: "text";
                      }
                      | {
                          _meta?: { [key: ...]: ... };
                          annotations?: { audience?: ...; lastModified?: ...; priority?: ... };
                          data: string;
                          mimeType: string;
                          type: "image";
                      }
                      | {
                          _meta?: { [key: ...]: ... };
                          annotations?: { audience?: ...; lastModified?: ...; priority?: ... };
                          data: string;
                          mimeType: string;
                          type: "audio";
                      }
                      | {
                          _meta?: { [key: ...]: ... };
                          id: string;
                          input: { [key: string]: unknown };
                          name: string;
                          type: "tool_use";
                      }
                      | {
                          _meta?: { [key: ...]: ... };
                          content: ((...) | (...) | (...) | (...) | (...))[];
                          isError?: boolean;
                          structuredContent?: unknown;
                          toolUseId: string;
                          type: "tool_result";
                      }
                  )[];
                  model: string;
                  role: "user"
                  | "assistant";
                  stopReason?: string;
                  [key: string]: unknown;
              },
          >
      )
      | undefined

      Returns
          | (
              (
                  params: {
                      _meta?: {
                          "io.modelcontextprotocol/related-task"?: { taskId: string };
                          progressToken?: string | number;
                          [key: string]: unknown;
                      };
                      includeContext?: "none"
                      | "thisServer"
                      | "allServers";
                      maxTokens: number;
                      messages: {
                          _meta?: { [key: string]: unknown };
                          content:
                              | {
                                  _meta?: { [key: string]: unknown };
                                  annotations?: {
                                      audience?: (...)[];
                                      lastModified?: string;
                                      priority?: number;
                                  };
                                  text: string;
                                  type: "text";
                              }
                              | {
                                  _meta?: { [key: string]: unknown };
                                  annotations?: {
                                      audience?: (...)[];
                                      lastModified?: string;
                                      priority?: number;
                                  };
                                  data: string;
                                  mimeType: string;
                                  type: "image";
                              }
                              | {
                                  _meta?: { [key: string]: unknown };
                                  annotations?: {
                                      audience?: (...)[];
                                      lastModified?: string;
                                      priority?: number;
                                  };
                                  data: string;
                                  mimeType: string;
                                  type: "audio";
                              }
                              | {
                                  _meta?: { [key: string]: unknown };
                                  id: string;
                                  input: { [key: string]: unknown };
                                  name: string;
                                  type: "tool_use";
                              }
                              | {
                                  _meta?: { [key: string]: unknown };
                                  content: (
                                      | {
                                          _meta?: (...)
                                          | (...);
                                          annotations?: (...) | (...);
                                          text: string;
                                          type: "text";
                                      }
                                      | {
                                          _meta?: (...)
                                          | (...);
                                          annotations?: (...) | (...);
                                          data: string;
                                          mimeType: string;
                                          type: "image";
                                      }
                                      | {
                                          _meta?: (...)
                                          | (...);
                                          annotations?: (...) | (...);
                                          data: string;
                                          mimeType: string;
                                          type: "audio";
                                      }
                                      | {
                                          _meta?: (...)
                                          | (...);
                                          annotations?: (...) | (...);
                                          description?: (...) | (...);
                                          icons?: (...) | (...);
                                          mimeType?: (...) | (...);
                                          name: string;
                                          size?: (...) | (...);
                                          title?: (...) | (...);
                                          type: "resource_link";
                                          uri: string;
                                      }
                                      | {
                                          _meta?: (...)
                                          | (...);
                                          annotations?: (...) | (...);
                                          resource: (...) | (...);
                                          type: "resource";
                                      }
                                  )[];
                                  isError?: boolean;
                                  structuredContent?: unknown;
                                  toolUseId: string;
                                  type: "tool_result";
                              }
                              | (
                                  | {
                                      _meta?: { [key: ...]: ... };
                                      annotations?: { audience?: ...; lastModified?: ...; priority?: ... };
                                      text: string;
                                      type: "text";
                                  }
                                  | {
                                      _meta?: { [key: ...]: ... };
                                      annotations?: { audience?: ...; lastModified?: ...; priority?: ... };
                                      data: string;
                                      mimeType: string;
                                      type: "image";
                                  }
                                  | {
                                      _meta?: { [key: ...]: ... };
                                      annotations?: { audience?: ...; lastModified?: ...; priority?: ... };
                                      data: string;
                                      mimeType: string;
                                      type: "audio";
                                  }
                                  | {
                                      _meta?: { [key: ...]: ... };
                                      id: string;
                                      input: { [key: string]: unknown };
                                      name: string;
                                      type: "tool_use";
                                  }
                                  | {
                                      _meta?: { [key: ...]: ... };
                                      content: ((...) | (...) | (...) | (...) | (...))[];
                                      isError?: boolean;
                                      structuredContent?: unknown;
                                      toolUseId: string;
                                      type: "tool_result";
                                  }
                              )[];
                          role: "user"
                          | "assistant";
                      }[];
                      metadata?: {
                          [key: string]: | string
                          | number
                          | boolean
                          | (
                              { [x: string]: string | number | boolean | ... | (string | number | boolean | ... | (string | number | boolean | ... | (string | number | boolean | ... | (string | number | boolean | ... | (string | ... 4 more ... | null)[] | null)[] | null)[] | null)[] | null)[] | null; }
                          )
                          | (
                              string | number | boolean | { [x: string]: string | number | boolean | ... | (string | number | boolean | ... | (string | number | boolean | ... | (string | number | boolean | ... | (string | ... 4 more ... | null)[] | null)[] | null)[] | null)[] | null; } | (string | ... 4 more ... | null)[] | null
                          )[]
                          | null;
                      };
                      modelPreferences?: {
                          costPriority?: number;
                          hints?: { name?: string }[];
                          intelligencePriority?: number;
                          speedPriority?: number;
                      };
                      stopSequences?: string[];
                      systemPrompt?: string;
                      task?: { ttl?: number };
                      temperature?: number;
                      toolChoice?: { mode?: "required" | "none" | "auto" };
                      tools?: {
                          _meta?: { [key: string]: unknown };
                          annotations?: {
                              destructiveHint?: boolean;
                              idempotentHint?: boolean;
                              openWorldHint?: boolean;
                              readOnlyHint?: boolean;
                              title?: string;
                          };
                          description?: string;
                          execution?: { taskSupport?: "optional"
                          | "required"
                          | "forbidden" };
                          icons?: {
                              mimeType?: string;
                              sizes?: (...)[];
                              src: string;
                              theme?: "light" | "dark";
                          }[];
                          inputSchema: {
                              properties?: {
                                  [key: string]: | string
                                  | number
                                  | boolean
                                  | { [key: ...]: ... }
                                  | (...)[]
                                  | null;
                              };
                              required?: string[];
                              type: "object";
                              [key: string]: unknown;
                          };
                          name: string;
                          outputSchema?: { $schema?: string; [key: string]: unknown };
                          title?: string;
                      }[];
                  },
                  extra: BaseContext,
              ) => Promise<
                  | {
                      _meta?: {
                          "io.modelcontextprotocol/serverInfo"?: {
                              description?: string;
                              icons?: (...)[];
                              name: string;
                              title?: string;
                              version: string;
                              websiteUrl?: string;
                          };
                          [key: string]: unknown;
                      };
                      content: | {
                          _meta?: { [key: string]: unknown };
                          annotations?: {
                              audience?: (...)[];
                              lastModified?: string;
                              priority?: number;
                          };
                          text: string;
                          type: "text";
                      }
                      | {
                          _meta?: { [key: string]: unknown };
                          annotations?: {
                              audience?: (...)[];
                              lastModified?: string;
                              priority?: number;
                          };
                          data: string;
                          mimeType: string;
                          type: "image";
                      }
                      | {
                          _meta?: { [key: string]: unknown };
                          annotations?: {
                              audience?: (...)[];
                              lastModified?: string;
                              priority?: number;
                          };
                          data: string;
                          mimeType: string;
                          type: "audio";
                      };
                      model: string;
                      role: "user"
                      | "assistant";
                      stopReason?: string;
                      [key: string]: unknown;
                  }
                  | {
                      _meta?: {
                          "io.modelcontextprotocol/serverInfo"?: {
                              description?: string;
                              icons?: (...)[];
                              name: string;
                              title?: string;
                              version: string;
                              websiteUrl?: string;
                          };
                          [key: string]: unknown;
                      };
                      content: | {
                          _meta?: { [key: string]: unknown };
                          annotations?: {
                              audience?: (...)[];
                              lastModified?: string;
                              priority?: number;
                          };
                          text: string;
                          type: "text";
                      }
                      | {
                          _meta?: { [key: string]: unknown };
                          annotations?: {
                              audience?: (...)[];
                              lastModified?: string;
                              priority?: number;
                          };
                          data: string;
                          mimeType: string;
                          type: "image";
                      }
                      | {
                          _meta?: { [key: string]: unknown };
                          annotations?: {
                              audience?: (...)[];
                              lastModified?: string;
                              priority?: number;
                          };
                          data: string;
                          mimeType: string;
                          type: "audio";
                      }
                      | {
                          _meta?: { [key: string]: unknown };
                          id: string;
                          input: { [key: string]: unknown };
                          name: string;
                          type: "tool_use";
                      }
                      | {
                          _meta?: { [key: string]: unknown };
                          content: (
                              | {
                                  _meta?: (...)
                                  | (...);
                                  annotations?: (...) | (...);
                                  text: string;
                                  type: "text";
                              }
                              | {
                                  _meta?: (...)
                                  | (...);
                                  annotations?: (...) | (...);
                                  data: string;
                                  mimeType: string;
                                  type: "image";
                              }
                              | {
                                  _meta?: (...)
                                  | (...);
                                  annotations?: (...) | (...);
                                  data: string;
                                  mimeType: string;
                                  type: "audio";
                              }
                              | {
                                  _meta?: (...)
                                  | (...);
                                  annotations?: (...) | (...);
                                  description?: (...) | (...);
                                  icons?: (...) | (...);
                                  mimeType?: (...) | (...);
                                  name: string;
                                  size?: (...) | (...);
                                  title?: (...) | (...);
                                  type: "resource_link";
                                  uri: string;
                              }
                              | {
                                  _meta?: (...)
                                  | (...);
                                  annotations?: (...) | (...);
                                  resource: (...) | (...);
                                  type: "resource";
                              }
                          )[];
                          isError?: boolean;
                          structuredContent?: unknown;
                          toolUseId: string;
                          type: "tool_result";
                      }
                      | (
                          | {
                              _meta?: { [key: ...]: ... };
                              annotations?: { audience?: ...; lastModified?: ...; priority?: ... };
                              text: string;
                              type: "text";
                          }
                          | {
                              _meta?: { [key: ...]: ... };
                              annotations?: { audience?: ...; lastModified?: ...; priority?: ... };
                              data: string;
                              mimeType: string;
                              type: "image";
                          }
                          | {
                              _meta?: { [key: ...]: ... };
                              annotations?: { audience?: ...; lastModified?: ...; priority?: ... };
                              data: string;
                              mimeType: string;
                              type: "audio";
                          }
                          | {
                              _meta?: { [key: ...]: ... };
                              id: string;
                              input: { [key: string]: unknown };
                              name: string;
                              type: "tool_use";
                          }
                          | {
                              _meta?: { [key: ...]: ... };
                              content: ((...) | (...) | (...) | (...) | (...))[];
                              isError?: boolean;
                              structuredContent?: unknown;
                              toolUseId: string;
                              type: "tool_result";
                          }
                      )[];
                      model: string;
                      role: "user"
                      | "assistant";
                      stopReason?: string;
                      [key: string]: unknown;
                  },
              >
          )
          | undefined

    • set oncreatesamplingmessage(
          callback:
              | (
                  (
                      params: {
                          _meta?: {
                              "io.modelcontextprotocol/related-task"?: { taskId: string };
                              progressToken?: string | number;
                              [key: string]: unknown;
                          };
                          includeContext?: "none"
                          | "thisServer"
                          | "allServers";
                          maxTokens: number;
                          messages: {
                              _meta?: { [key: string]: unknown };
                              content:
                                  | {
                                      _meta?: { [key: string]: unknown };
                                      annotations?: {
                                          audience?: (...)[];
                                          lastModified?: string;
                                          priority?: number;
                                      };
                                      text: string;
                                      type: "text";
                                  }
                                  | {
                                      _meta?: { [key: string]: unknown };
                                      annotations?: {
                                          audience?: (...)[];
                                          lastModified?: string;
                                          priority?: number;
                                      };
                                      data: string;
                                      mimeType: string;
                                      type: "image";
                                  }
                                  | {
                                      _meta?: { [key: string]: unknown };
                                      annotations?: {
                                          audience?: (...)[];
                                          lastModified?: string;
                                          priority?: number;
                                      };
                                      data: string;
                                      mimeType: string;
                                      type: "audio";
                                  }
                                  | {
                                      _meta?: { [key: string]: unknown };
                                      id: string;
                                      input: { [key: string]: unknown };
                                      name: string;
                                      type: "tool_use";
                                  }
                                  | {
                                      _meta?: { [key: string]: unknown };
                                      content: (
                                          | {
                                              _meta?: (...)
                                              | (...);
                                              annotations?: (...) | (...);
                                              text: string;
                                              type: "text";
                                          }
                                          | {
                                              _meta?: (...)
                                              | (...);
                                              annotations?: (...) | (...);
                                              data: string;
                                              mimeType: string;
                                              type: "image";
                                          }
                                          | {
                                              _meta?: (...)
                                              | (...);
                                              annotations?: (...) | (...);
                                              data: string;
                                              mimeType: string;
                                              type: "audio";
                                          }
                                          | {
                                              _meta?: (...)
                                              | (...);
                                              annotations?: (...) | (...);
                                              description?: (...) | (...);
                                              icons?: (...) | (...);
                                              mimeType?: (...) | (...);
                                              name: string;
                                              size?: (...) | (...);
                                              title?: (...) | (...);
                                              type: "resource_link";
                                              uri: string;
                                          }
                                          | {
                                              _meta?: (...)
                                              | (...);
                                              annotations?: (...) | (...);
                                              resource: (...) | (...);
                                              type: "resource";
                                          }
                                      )[];
                                      isError?: boolean;
                                      structuredContent?: unknown;
                                      toolUseId: string;
                                      type: "tool_result";
                                  }
                                  | (
                                      | {
                                          _meta?: { [key: ...]: ... };
                                          annotations?: {
                                              audience?: ...;
                                              lastModified?: ...;
                                              priority?: ...;
                                          };
                                          text: string;
                                          type: "text";
                                      }
                                      | {
                                          _meta?: { [key: ...]: ... };
                                          annotations?: {
                                              audience?: ...;
                                              lastModified?: ...;
                                              priority?: ...;
                                          };
                                          data: string;
                                          mimeType: string;
                                          type: "image";
                                      }
                                      | {
                                          _meta?: { [key: ...]: ... };
                                          annotations?: {
                                              audience?: ...;
                                              lastModified?: ...;
                                              priority?: ...;
                                          };
                                          data: string;
                                          mimeType: string;
                                          type: "audio";
                                      }
                                      | {
                                          _meta?: { [key: ...]: ... };
                                          id: string;
                                          input: { [key: string]: unknown };
                                          name: string;
                                          type: "tool_use";
                                      }
                                      | {
                                          _meta?: { [key: ...]: ... };
                                          content: ((...) | (...) | (...) | (...) | (...))[];
                                          isError?: boolean;
                                          structuredContent?: unknown;
                                          toolUseId: string;
                                          type: "tool_result";
                                      }
                                  )[];
                              role: "user"
                              | "assistant";
                          }[];
                          metadata?: {
                              [key: string]: | string
                              | number
                              | boolean
                              | (
                                  { [x: string]: string | number | boolean | ... | (string | number | boolean | ... | (string | number | boolean | ... | (string | number | boolean | ... | (string | number | boolean | ... | (string | ... 4 more ... | null)[] | null)[] | null)[] | null)[] | null)[] | null; }
                              )
                              | (
                                  string | number | boolean | { [x: string]: string | number | boolean | ... | (string | number | boolean | ... | (string | number | boolean | ... | (string | number | boolean | ... | (string | ... 4 more ... | null)[] | null)[] | null)[] | null)[] | null; } | (string | ... 4 more ... | null)[] | null
                              )[]
                              | null;
                          };
                          modelPreferences?: {
                              costPriority?: number;
                              hints?: { name?: string }[];
                              intelligencePriority?: number;
                              speedPriority?: number;
                          };
                          stopSequences?: string[];
                          systemPrompt?: string;
                          task?: { ttl?: number };
                          temperature?: number;
                          toolChoice?: { mode?: "required" | "none" | "auto" };
                          tools?: {
                              _meta?: { [key: string]: unknown };
                              annotations?: {
                                  destructiveHint?: boolean;
                                  idempotentHint?: boolean;
                                  openWorldHint?: boolean;
                                  readOnlyHint?: boolean;
                                  title?: string;
                              };
                              description?: string;
                              execution?: { taskSupport?: "optional"
                              | "required"
                              | "forbidden" };
                              icons?: {
                                  mimeType?: string;
                                  sizes?: (...)[];
                                  src: string;
                                  theme?: "light" | "dark";
                              }[];
                              inputSchema: {
                                  properties?: {
                                      [key: string]: | string
                                      | number
                                      | boolean
                                      | { [key: ...]: ... }
                                      | (...)[]
                                      | null;
                                  };
                                  required?: string[];
                                  type: "object";
                                  [key: string]: unknown;
                              };
                              name: string;
                              outputSchema?: { $schema?: string; [key: string]: unknown };
                              title?: string;
                          }[];
                      },
                      extra: BaseContext,
                  ) => Promise<
                      | {
                          _meta?: {
                              "io.modelcontextprotocol/serverInfo"?: {
                                  description?: string;
                                  icons?: (...)[];
                                  name: string;
                                  title?: string;
                                  version: string;
                                  websiteUrl?: string;
                              };
                              [key: string]: unknown;
                          };
                          content: | {
                              _meta?: { [key: string]: unknown };
                              annotations?: {
                                  audience?: (...)[];
                                  lastModified?: string;
                                  priority?: number;
                              };
                              text: string;
                              type: "text";
                          }
                          | {
                              _meta?: { [key: string]: unknown };
                              annotations?: {
                                  audience?: (...)[];
                                  lastModified?: string;
                                  priority?: number;
                              };
                              data: string;
                              mimeType: string;
                              type: "image";
                          }
                          | {
                              _meta?: { [key: string]: unknown };
                              annotations?: {
                                  audience?: (...)[];
                                  lastModified?: string;
                                  priority?: number;
                              };
                              data: string;
                              mimeType: string;
                              type: "audio";
                          };
                          model: string;
                          role: "user"
                          | "assistant";
                          stopReason?: string;
                          [key: string]: unknown;
                      }
                      | {
                          _meta?: {
                              "io.modelcontextprotocol/serverInfo"?: {
                                  description?: string;
                                  icons?: (...)[];
                                  name: string;
                                  title?: string;
                                  version: string;
                                  websiteUrl?: string;
                              };
                              [key: string]: unknown;
                          };
                          content: | {
                              _meta?: { [key: string]: unknown };
                              annotations?: {
                                  audience?: (...)[];
                                  lastModified?: string;
                                  priority?: number;
                              };
                              text: string;
                              type: "text";
                          }
                          | {
                              _meta?: { [key: string]: unknown };
                              annotations?: {
                                  audience?: (...)[];
                                  lastModified?: string;
                                  priority?: number;
                              };
                              data: string;
                              mimeType: string;
                              type: "image";
                          }
                          | {
                              _meta?: { [key: string]: unknown };
                              annotations?: {
                                  audience?: (...)[];
                                  lastModified?: string;
                                  priority?: number;
                              };
                              data: string;
                              mimeType: string;
                              type: "audio";
                          }
                          | {
                              _meta?: { [key: string]: unknown };
                              id: string;
                              input: { [key: string]: unknown };
                              name: string;
                              type: "tool_use";
                          }
                          | {
                              _meta?: { [key: string]: unknown };
                              content: (
                                  | {
                                      _meta?: (...)
                                      | (...);
                                      annotations?: (...) | (...);
                                      text: string;
                                      type: "text";
                                  }
                                  | {
                                      _meta?: (...)
                                      | (...);
                                      annotations?: (...) | (...);
                                      data: string;
                                      mimeType: string;
                                      type: "image";
                                  }
                                  | {
                                      _meta?: (...)
                                      | (...);
                                      annotations?: (...) | (...);
                                      data: string;
                                      mimeType: string;
                                      type: "audio";
                                  }
                                  | {
                                      _meta?: (...)
                                      | (...);
                                      annotations?: (...) | (...);
                                      description?: (...) | (...);
                                      icons?: (...) | (...);
                                      mimeType?: (...) | (...);
                                      name: string;
                                      size?: (...) | (...);
                                      title?: (...) | (...);
                                      type: "resource_link";
                                      uri: string;
                                  }
                                  | {
                                      _meta?: (...)
                                      | (...);
                                      annotations?: (...) | (...);
                                      resource: (...) | (...);
                                      type: "resource";
                                  }
                              )[];
                              isError?: boolean;
                              structuredContent?: unknown;
                              toolUseId: string;
                              type: "tool_result";
                          }
                          | (
                              | {
                                  _meta?: { [key: ...]: ... };
                                  annotations?: { audience?: ...; lastModified?: ...; priority?: ... };
                                  text: string;
                                  type: "text";
                              }
                              | {
                                  _meta?: { [key: ...]: ... };
                                  annotations?: { audience?: ...; lastModified?: ...; priority?: ... };
                                  data: string;
                                  mimeType: string;
                                  type: "image";
                              }
                              | {
                                  _meta?: { [key: ...]: ... };
                                  annotations?: { audience?: ...; lastModified?: ...; priority?: ... };
                                  data: string;
                                  mimeType: string;
                                  type: "audio";
                              }
                              | {
                                  _meta?: { [key: ...]: ... };
                                  id: string;
                                  input: { [key: string]: unknown };
                                  name: string;
                                  type: "tool_use";
                              }
                              | {
                                  _meta?: { [key: ...]: ... };
                                  content: ((...) | (...) | (...) | (...) | (...))[];
                                  isError?: boolean;
                                  structuredContent?: unknown;
                                  toolUseId: string;
                                  type: "tool_result";
                              }
                          )[];
                          model: string;
                          role: "user"
                          | "assistant";
                          stopReason?: string;
                          [key: string]: unknown;
                      },
                  >
              )
              | undefined,
      ): void

      Parameters

      • callback:
            | (
                (
                    params: {
                        _meta?: {
                            "io.modelcontextprotocol/related-task"?: { taskId: string };
                            progressToken?: string | number;
                            [key: string]: unknown;
                        };
                        includeContext?: "none"
                        | "thisServer"
                        | "allServers";
                        maxTokens: number;
                        messages: {
                            _meta?: { [key: string]: unknown };
                            content:
                                | {
                                    _meta?: { [key: string]: unknown };
                                    annotations?: {
                                        audience?: (...)[];
                                        lastModified?: string;
                                        priority?: number;
                                    };
                                    text: string;
                                    type: "text";
                                }
                                | {
                                    _meta?: { [key: string]: unknown };
                                    annotations?: {
                                        audience?: (...)[];
                                        lastModified?: string;
                                        priority?: number;
                                    };
                                    data: string;
                                    mimeType: string;
                                    type: "image";
                                }
                                | {
                                    _meta?: { [key: string]: unknown };
                                    annotations?: {
                                        audience?: (...)[];
                                        lastModified?: string;
                                        priority?: number;
                                    };
                                    data: string;
                                    mimeType: string;
                                    type: "audio";
                                }
                                | {
                                    _meta?: { [key: string]: unknown };
                                    id: string;
                                    input: { [key: string]: unknown };
                                    name: string;
                                    type: "tool_use";
                                }
                                | {
                                    _meta?: { [key: string]: unknown };
                                    content: (
                                        | {
                                            _meta?: (...)
                                            | (...);
                                            annotations?: (...) | (...);
                                            text: string;
                                            type: "text";
                                        }
                                        | {
                                            _meta?: (...)
                                            | (...);
                                            annotations?: (...) | (...);
                                            data: string;
                                            mimeType: string;
                                            type: "image";
                                        }
                                        | {
                                            _meta?: (...)
                                            | (...);
                                            annotations?: (...) | (...);
                                            data: string;
                                            mimeType: string;
                                            type: "audio";
                                        }
                                        | {
                                            _meta?: (...)
                                            | (...);
                                            annotations?: (...) | (...);
                                            description?: (...) | (...);
                                            icons?: (...) | (...);
                                            mimeType?: (...) | (...);
                                            name: string;
                                            size?: (...) | (...);
                                            title?: (...) | (...);
                                            type: "resource_link";
                                            uri: string;
                                        }
                                        | {
                                            _meta?: (...)
                                            | (...);
                                            annotations?: (...) | (...);
                                            resource: (...) | (...);
                                            type: "resource";
                                        }
                                    )[];
                                    isError?: boolean;
                                    structuredContent?: unknown;
                                    toolUseId: string;
                                    type: "tool_result";
                                }
                                | (
                                    | {
                                        _meta?: { [key: ...]: ... };
                                        annotations?: { audience?: ...; lastModified?: ...; priority?: ... };
                                        text: string;
                                        type: "text";
                                    }
                                    | {
                                        _meta?: { [key: ...]: ... };
                                        annotations?: { audience?: ...; lastModified?: ...; priority?: ... };
                                        data: string;
                                        mimeType: string;
                                        type: "image";
                                    }
                                    | {
                                        _meta?: { [key: ...]: ... };
                                        annotations?: { audience?: ...; lastModified?: ...; priority?: ... };
                                        data: string;
                                        mimeType: string;
                                        type: "audio";
                                    }
                                    | {
                                        _meta?: { [key: ...]: ... };
                                        id: string;
                                        input: { [key: string]: unknown };
                                        name: string;
                                        type: "tool_use";
                                    }
                                    | {
                                        _meta?: { [key: ...]: ... };
                                        content: ((...) | (...) | (...) | (...) | (...))[];
                                        isError?: boolean;
                                        structuredContent?: unknown;
                                        toolUseId: string;
                                        type: "tool_result";
                                    }
                                )[];
                            role: "user"
                            | "assistant";
                        }[];
                        metadata?: {
                            [key: string]: | string
                            | number
                            | boolean
                            | (
                                { [x: string]: string | number | boolean | ... | (string | number | boolean | ... | (string | number | boolean | ... | (string | number | boolean | ... | (string | number | boolean | ... | (string | ... 4 more ... | null)[] | null)[] | null)[] | null)[] | null)[] | null; }
                            )
                            | (
                                string | number | boolean | { [x: string]: string | number | boolean | ... | (string | number | boolean | ... | (string | number | boolean | ... | (string | number | boolean | ... | (string | ... 4 more ... | null)[] | null)[] | null)[] | null)[] | null; } | (string | ... 4 more ... | null)[] | null
                            )[]
                            | null;
                        };
                        modelPreferences?: {
                            costPriority?: number;
                            hints?: { name?: string }[];
                            intelligencePriority?: number;
                            speedPriority?: number;
                        };
                        stopSequences?: string[];
                        systemPrompt?: string;
                        task?: { ttl?: number };
                        temperature?: number;
                        toolChoice?: { mode?: "required" | "none" | "auto" };
                        tools?: {
                            _meta?: { [key: string]: unknown };
                            annotations?: {
                                destructiveHint?: boolean;
                                idempotentHint?: boolean;
                                openWorldHint?: boolean;
                                readOnlyHint?: boolean;
                                title?: string;
                            };
                            description?: string;
                            execution?: { taskSupport?: "optional"
                            | "required"
                            | "forbidden" };
                            icons?: {
                                mimeType?: string;
                                sizes?: (...)[];
                                src: string;
                                theme?: "light" | "dark";
                            }[];
                            inputSchema: {
                                properties?: {
                                    [key: string]: | string
                                    | number
                                    | boolean
                                    | { [key: ...]: ... }
                                    | (...)[]
                                    | null;
                                };
                                required?: string[];
                                type: "object";
                                [key: string]: unknown;
                            };
                            name: string;
                            outputSchema?: { $schema?: string; [key: string]: unknown };
                            title?: string;
                        }[];
                    },
                    extra: BaseContext,
                ) => Promise<
                    | {
                        _meta?: {
                            "io.modelcontextprotocol/serverInfo"?: {
                                description?: string;
                                icons?: (...)[];
                                name: string;
                                title?: string;
                                version: string;
                                websiteUrl?: string;
                            };
                            [key: string]: unknown;
                        };
                        content: | {
                            _meta?: { [key: string]: unknown };
                            annotations?: {
                                audience?: (...)[];
                                lastModified?: string;
                                priority?: number;
                            };
                            text: string;
                            type: "text";
                        }
                        | {
                            _meta?: { [key: string]: unknown };
                            annotations?: {
                                audience?: (...)[];
                                lastModified?: string;
                                priority?: number;
                            };
                            data: string;
                            mimeType: string;
                            type: "image";
                        }
                        | {
                            _meta?: { [key: string]: unknown };
                            annotations?: {
                                audience?: (...)[];
                                lastModified?: string;
                                priority?: number;
                            };
                            data: string;
                            mimeType: string;
                            type: "audio";
                        };
                        model: string;
                        role: "user"
                        | "assistant";
                        stopReason?: string;
                        [key: string]: unknown;
                    }
                    | {
                        _meta?: {
                            "io.modelcontextprotocol/serverInfo"?: {
                                description?: string;
                                icons?: (...)[];
                                name: string;
                                title?: string;
                                version: string;
                                websiteUrl?: string;
                            };
                            [key: string]: unknown;
                        };
                        content: | {
                            _meta?: { [key: string]: unknown };
                            annotations?: {
                                audience?: (...)[];
                                lastModified?: string;
                                priority?: number;
                            };
                            text: string;
                            type: "text";
                        }
                        | {
                            _meta?: { [key: string]: unknown };
                            annotations?: {
                                audience?: (...)[];
                                lastModified?: string;
                                priority?: number;
                            };
                            data: string;
                            mimeType: string;
                            type: "image";
                        }
                        | {
                            _meta?: { [key: string]: unknown };
                            annotations?: {
                                audience?: (...)[];
                                lastModified?: string;
                                priority?: number;
                            };
                            data: string;
                            mimeType: string;
                            type: "audio";
                        }
                        | {
                            _meta?: { [key: string]: unknown };
                            id: string;
                            input: { [key: string]: unknown };
                            name: string;
                            type: "tool_use";
                        }
                        | {
                            _meta?: { [key: string]: unknown };
                            content: (
                                | {
                                    _meta?: (...)
                                    | (...);
                                    annotations?: (...) | (...);
                                    text: string;
                                    type: "text";
                                }
                                | {
                                    _meta?: (...)
                                    | (...);
                                    annotations?: (...) | (...);
                                    data: string;
                                    mimeType: string;
                                    type: "image";
                                }
                                | {
                                    _meta?: (...)
                                    | (...);
                                    annotations?: (...) | (...);
                                    data: string;
                                    mimeType: string;
                                    type: "audio";
                                }
                                | {
                                    _meta?: (...)
                                    | (...);
                                    annotations?: (...) | (...);
                                    description?: (...) | (...);
                                    icons?: (...) | (...);
                                    mimeType?: (...) | (...);
                                    name: string;
                                    size?: (...) | (...);
                                    title?: (...) | (...);
                                    type: "resource_link";
                                    uri: string;
                                }
                                | {
                                    _meta?: (...)
                                    | (...);
                                    annotations?: (...) | (...);
                                    resource: (...) | (...);
                                    type: "resource";
                                }
                            )[];
                            isError?: boolean;
                            structuredContent?: unknown;
                            toolUseId: string;
                            type: "tool_result";
                        }
                        | (
                            | {
                                _meta?: { [key: ...]: ... };
                                annotations?: { audience?: ...; lastModified?: ...; priority?: ... };
                                text: string;
                                type: "text";
                            }
                            | {
                                _meta?: { [key: ...]: ... };
                                annotations?: { audience?: ...; lastModified?: ...; priority?: ... };
                                data: string;
                                mimeType: string;
                                type: "image";
                            }
                            | {
                                _meta?: { [key: ...]: ... };
                                annotations?: { audience?: ...; lastModified?: ...; priority?: ... };
                                data: string;
                                mimeType: string;
                                type: "audio";
                            }
                            | {
                                _meta?: { [key: ...]: ... };
                                id: string;
                                input: { [key: string]: unknown };
                                name: string;
                                type: "tool_use";
                            }
                            | {
                                _meta?: { [key: ...]: ... };
                                content: ((...) | (...) | (...) | (...) | (...))[];
                                isError?: boolean;
                                structuredContent?: unknown;
                                toolUseId: string;
                                type: "tool_result";
                            }
                        )[];
                        model: string;
                        role: "user"
                        | "assistant";
                        stopReason?: string;
                        [key: string]: unknown;
                    },
                >
            )
            | undefined

      Returns void

    • get ondownloadfile(): | (
          (
              params: {
                  contents: (
                      | {
                          _meta?: { [key: string]: unknown };
                          annotations?: {
                              audience?: ((...) | (...))[];
                              lastModified?: string;
                              priority?: number;
                          };
                          resource: | {
                              _meta?: { [key: string]: unknown };
                              mimeType?: string;
                              text: string;
                              uri: string;
                          }
                          | {
                              _meta?: { [key: string]: unknown };
                              blob: string;
                              mimeType?: string;
                              uri: string;
                          };
                          type: "resource";
                      }
                      | {
                          _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;
                          size?: number;
                          title?: string;
                          type: "resource_link";
                          uri: string;
                      }
                  )[];
              },
              extra: BaseContext,
          ) => Promise<McpUiDownloadFileResult>
      )
      | undefined

      Returns
          | (
              (
                  params: {
                      contents: (
                          | {
                              _meta?: { [key: string]: unknown };
                              annotations?: {
                                  audience?: ((...) | (...))[];
                                  lastModified?: string;
                                  priority?: number;
                              };
                              resource: | {
                                  _meta?: { [key: string]: unknown };
                                  mimeType?: string;
                                  text: string;
                                  uri: string;
                              }
                              | {
                                  _meta?: { [key: string]: unknown };
                                  blob: string;
                                  mimeType?: string;
                                  uri: string;
                              };
                              type: "resource";
                          }
                          | {
                              _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;
                              size?: number;
                              title?: string;
                              type: "resource_link";
                              uri: string;
                          }
                      )[];
                  },
                  extra: BaseContext,
              ) => Promise<McpUiDownloadFileResult>
          )
          | undefined

    • set ondownloadfile(
          callback:
              | (
                  (
                      params: {
                          contents: (
                              | {
                                  _meta?: { [key: string]: unknown };
                                  annotations?: {
                                      audience?: ((...) | (...))[];
                                      lastModified?: string;
                                      priority?: number;
                                  };
                                  resource: | {
                                      _meta?: { [key: string]: unknown };
                                      mimeType?: string;
                                      text: string;
                                      uri: string;
                                  }
                                  | {
                                      _meta?: { [key: string]: unknown };
                                      blob: string;
                                      mimeType?: string;
                                      uri: string;
                                  };
                                  type: "resource";
                              }
                              | {
                                  _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;
                                  size?: number;
                                  title?: string;
                                  type: "resource_link";
                                  uri: string;
                              }
                          )[];
                      },
                      extra: BaseContext,
                  ) => Promise<McpUiDownloadFileResult>
              )
              | undefined,
      ): void

      Parameters

      • callback:
            | (
                (
                    params: {
                        contents: (
                            | {
                                _meta?: { [key: string]: unknown };
                                annotations?: {
                                    audience?: ((...) | (...))[];
                                    lastModified?: string;
                                    priority?: number;
                                };
                                resource: | {
                                    _meta?: { [key: string]: unknown };
                                    mimeType?: string;
                                    text: string;
                                    uri: string;
                                }
                                | {
                                    _meta?: { [key: string]: unknown };
                                    blob: string;
                                    mimeType?: string;
                                    uri: string;
                                };
                                type: "resource";
                            }
                            | {
                                _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;
                                size?: number;
                                title?: string;
                                type: "resource_link";
                                uri: string;
                            }
                        )[];
                    },
                    extra: BaseContext,
                ) => Promise<McpUiDownloadFileResult>
            )
            | undefined

      Returns void

    • get oninitialized(): ((params?: {}) => void) | undefined

      Called when the view completes initialization.

      Set this callback to be notified when the view has finished its initialization handshake and is ready to receive tool input and other data.

      Returns ((params?: {}) => void) | undefined

      bridge.oninitialized = () => {
      console.log("View ready");
      bridge.sendToolInput({ arguments: toolArgs });
      };

      Use addEventListener("initialized", handler) instead — it composes with other listeners and supports cleanup via removeEventListener.

    • set oninitialized(callback: ((params?: {}) => void) | undefined): void

      Parameters

      • callback: ((params?: {}) => void) | undefined

      Returns void

    • get onlistprompts(): | (
          (
              params:
                  | {
                      _meta?: {
                          "io.modelcontextprotocol/related-task"?: { taskId: string };
                          progressToken?: string | number;
                          [key: string]: unknown;
                      };
                      cursor?: string;
                  }
                  | undefined,
              extra: BaseContext,
          ) => Promise<
              {
                  _meta?: {
                      "io.modelcontextprotocol/serverInfo"?: {
                          description?: string;
                          icons?: { mimeType?: ...; sizes?: ...; src: ...; theme?: ... }[];
                          name: string;
                          title?: string;
                          version: string;
                          websiteUrl?: string;
                      };
                      [key: string]: unknown;
                  };
                  nextCursor?: string;
                  prompts: {
                      _meta?: { [key: string]: unknown };
                      arguments?: { description?: string; name: string; required?: boolean }[];
                      description?: string;
                      icons?: {
                          mimeType?: string;
                          sizes?: (...)[];
                          src: string;
                          theme?: "light" | "dark";
                      }[];
                      name: string;
                      title?: string;
                  }[];
                  [key: string]: unknown;
              },
          >
      )
      | undefined

      Returns
          | (
              (
                  params:
                      | {
                          _meta?: {
                              "io.modelcontextprotocol/related-task"?: { taskId: string };
                              progressToken?: string | number;
                              [key: string]: unknown;
                          };
                          cursor?: string;
                      }
                      | undefined,
                  extra: BaseContext,
              ) => Promise<
                  {
                      _meta?: {
                          "io.modelcontextprotocol/serverInfo"?: {
                              description?: string;
                              icons?: { mimeType?: ...; sizes?: ...; src: ...; theme?: ... }[];
                              name: string;
                              title?: string;
                              version: string;
                              websiteUrl?: string;
                          };
                          [key: string]: unknown;
                      };
                      nextCursor?: string;
                      prompts: {
                          _meta?: { [key: string]: unknown };
                          arguments?: { description?: string; name: string; required?: boolean }[];
                          description?: string;
                          icons?: {
                              mimeType?: string;
                              sizes?: (...)[];
                              src: string;
                              theme?: "light" | "dark";
                          }[];
                          name: string;
                          title?: string;
                      }[];
                      [key: string]: unknown;
                  },
              >
          )
          | undefined

    • set onlistprompts(
          callback:
              | (
                  (
                      params:
                          | {
                              _meta?: {
                                  "io.modelcontextprotocol/related-task"?: { taskId: string };
                                  progressToken?: string | number;
                                  [key: string]: unknown;
                              };
                              cursor?: string;
                          }
                          | undefined,
                      extra: BaseContext,
                  ) => Promise<
                      {
                          _meta?: {
                              "io.modelcontextprotocol/serverInfo"?: {
                                  description?: string;
                                  icons?: { mimeType?: ...; sizes?: ...; src: ...; theme?: ... }[];
                                  name: string;
                                  title?: string;
                                  version: string;
                                  websiteUrl?: string;
                              };
                              [key: string]: unknown;
                          };
                          nextCursor?: string;
                          prompts: {
                              _meta?: { [key: string]: unknown };
                              arguments?: { description?: string; name: string; required?: boolean }[];
                              description?: string;
                              icons?: {
                                  mimeType?: string;
                                  sizes?: (...)[];
                                  src: string;
                                  theme?: "light" | "dark";
                              }[];
                              name: string;
                              title?: string;
                          }[];
                          [key: string]: unknown;
                      },
                  >
              )
              | undefined,
      ): void

      Parameters

      • callback:
            | (
                (
                    params:
                        | {
                            _meta?: {
                                "io.modelcontextprotocol/related-task"?: { taskId: string };
                                progressToken?: string | number;
                                [key: string]: unknown;
                            };
                            cursor?: string;
                        }
                        | undefined,
                    extra: BaseContext,
                ) => Promise<
                    {
                        _meta?: {
                            "io.modelcontextprotocol/serverInfo"?: {
                                description?: string;
                                icons?: { mimeType?: ...; sizes?: ...; src: ...; theme?: ... }[];
                                name: string;
                                title?: string;
                                version: string;
                                websiteUrl?: string;
                            };
                            [key: string]: unknown;
                        };
                        nextCursor?: string;
                        prompts: {
                            _meta?: { [key: string]: unknown };
                            arguments?: { description?: string; name: string; required?: boolean }[];
                            description?: string;
                            icons?: {
                                mimeType?: string;
                                sizes?: (...)[];
                                src: string;
                                theme?: "light" | "dark";
                            }[];
                            name: string;
                            title?: string;
                        }[];
                        [key: string]: unknown;
                    },
                >
            )
            | undefined

      Returns void

    • get onlistresources(): | (
          (
              params:
                  | {
                      _meta?: {
                          "io.modelcontextprotocol/related-task"?: { taskId: string };
                          progressToken?: string | number;
                          [key: string]: unknown;
                      };
                      cursor?: string;
                  }
                  | undefined,
              extra: BaseContext,
          ) => Promise<
              {
                  _meta?: {
                      "io.modelcontextprotocol/serverInfo"?: {
                          description?: string;
                          icons?: { mimeType?: ...; sizes?: ...; src: ...; theme?: ... }[];
                          name: string;
                          title?: string;
                          version: string;
                          websiteUrl?: string;
                      };
                      [key: string]: unknown;
                  };
                  nextCursor?: string;
                  resources: {
                      _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;
                      size?: number;
                      title?: string;
                      uri: string;
                  }[];
                  [key: string]: unknown;
              },
          >
      )
      | undefined

      Returns
          | (
              (
                  params:
                      | {
                          _meta?: {
                              "io.modelcontextprotocol/related-task"?: { taskId: string };
                              progressToken?: string | number;
                              [key: string]: unknown;
                          };
                          cursor?: string;
                      }
                      | undefined,
                  extra: BaseContext,
              ) => Promise<
                  {
                      _meta?: {
                          "io.modelcontextprotocol/serverInfo"?: {
                              description?: string;
                              icons?: { mimeType?: ...; sizes?: ...; src: ...; theme?: ... }[];
                              name: string;
                              title?: string;
                              version: string;
                              websiteUrl?: string;
                          };
                          [key: string]: unknown;
                      };
                      nextCursor?: string;
                      resources: {
                          _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;
                          size?: number;
                          title?: string;
                          uri: string;
                      }[];
                      [key: string]: unknown;
                  },
              >
          )
          | undefined

    • set onlistresources(
          callback:
              | (
                  (
                      params:
                          | {
                              _meta?: {
                                  "io.modelcontextprotocol/related-task"?: { taskId: string };
                                  progressToken?: string | number;
                                  [key: string]: unknown;
                              };
                              cursor?: string;
                          }
                          | undefined,
                      extra: BaseContext,
                  ) => Promise<
                      {
                          _meta?: {
                              "io.modelcontextprotocol/serverInfo"?: {
                                  description?: string;
                                  icons?: { mimeType?: ...; sizes?: ...; src: ...; theme?: ... }[];
                                  name: string;
                                  title?: string;
                                  version: string;
                                  websiteUrl?: string;
                              };
                              [key: string]: unknown;
                          };
                          nextCursor?: string;
                          resources: {
                              _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;
                              size?: number;
                              title?: string;
                              uri: string;
                          }[];
                          [key: string]: unknown;
                      },
                  >
              )
              | undefined,
      ): void

      Parameters

      • callback:
            | (
                (
                    params:
                        | {
                            _meta?: {
                                "io.modelcontextprotocol/related-task"?: { taskId: string };
                                progressToken?: string | number;
                                [key: string]: unknown;
                            };
                            cursor?: string;
                        }
                        | undefined,
                    extra: BaseContext,
                ) => Promise<
                    {
                        _meta?: {
                            "io.modelcontextprotocol/serverInfo"?: {
                                description?: string;
                                icons?: { mimeType?: ...; sizes?: ...; src: ...; theme?: ... }[];
                                name: string;
                                title?: string;
                                version: string;
                                websiteUrl?: string;
                            };
                            [key: string]: unknown;
                        };
                        nextCursor?: string;
                        resources: {
                            _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;
                            size?: number;
                            title?: string;
                            uri: string;
                        }[];
                        [key: string]: unknown;
                    },
                >
            )
            | undefined

      Returns void

    • get onlistresourcetemplates(): | (
          (
              params:
                  | {
                      _meta?: {
                          "io.modelcontextprotocol/related-task"?: { taskId: string };
                          progressToken?: string | number;
                          [key: string]: unknown;
                      };
                      cursor?: string;
                  }
                  | undefined,
              extra: BaseContext,
          ) => Promise<
              {
                  _meta?: {
                      "io.modelcontextprotocol/serverInfo"?: {
                          description?: string;
                          icons?: { mimeType?: ...; sizes?: ...; src: ...; theme?: ... }[];
                          name: string;
                          title?: string;
                          version: string;
                          websiteUrl?: string;
                      };
                      [key: string]: unknown;
                  };
                  nextCursor?: string;
                  resourceTemplates: {
                      _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;
                      uriTemplate: string;
                  }[];
                  [key: string]: unknown;
              },
          >
      )
      | undefined

      Returns
          | (
              (
                  params:
                      | {
                          _meta?: {
                              "io.modelcontextprotocol/related-task"?: { taskId: string };
                              progressToken?: string | number;
                              [key: string]: unknown;
                          };
                          cursor?: string;
                      }
                      | undefined,
                  extra: BaseContext,
              ) => Promise<
                  {
                      _meta?: {
                          "io.modelcontextprotocol/serverInfo"?: {
                              description?: string;
                              icons?: { mimeType?: ...; sizes?: ...; src: ...; theme?: ... }[];
                              name: string;
                              title?: string;
                              version: string;
                              websiteUrl?: string;
                          };
                          [key: string]: unknown;
                      };
                      nextCursor?: string;
                      resourceTemplates: {
                          _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;
                          uriTemplate: string;
                      }[];
                      [key: string]: unknown;
                  },
              >
          )
          | undefined

    • set onlistresourcetemplates(
          callback:
              | (
                  (
                      params:
                          | {
                              _meta?: {
                                  "io.modelcontextprotocol/related-task"?: { taskId: string };
                                  progressToken?: string | number;
                                  [key: string]: unknown;
                              };
                              cursor?: string;
                          }
                          | undefined,
                      extra: BaseContext,
                  ) => Promise<
                      {
                          _meta?: {
                              "io.modelcontextprotocol/serverInfo"?: {
                                  description?: string;
                                  icons?: { mimeType?: ...; sizes?: ...; src: ...; theme?: ... }[];
                                  name: string;
                                  title?: string;
                                  version: string;
                                  websiteUrl?: string;
                              };
                              [key: string]: unknown;
                          };
                          nextCursor?: string;
                          resourceTemplates: {
                              _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;
                              uriTemplate: string;
                          }[];
                          [key: string]: unknown;
                      },
                  >
              )
              | undefined,
      ): void

      Parameters

      • callback:
            | (
                (
                    params:
                        | {
                            _meta?: {
                                "io.modelcontextprotocol/related-task"?: { taskId: string };
                                progressToken?: string | number;
                                [key: string]: unknown;
                            };
                            cursor?: string;
                        }
                        | undefined,
                    extra: BaseContext,
                ) => Promise<
                    {
                        _meta?: {
                            "io.modelcontextprotocol/serverInfo"?: {
                                description?: string;
                                icons?: { mimeType?: ...; sizes?: ...; src: ...; theme?: ... }[];
                                name: string;
                                title?: string;
                                version: string;
                                websiteUrl?: string;
                            };
                            [key: string]: unknown;
                        };
                        nextCursor?: string;
                        resourceTemplates: {
                            _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;
                            uriTemplate: string;
                        }[];
                        [key: string]: unknown;
                    },
                >
            )
            | undefined

      Returns void

    • get onloggingmessage(): | (
          (
              params: {
                  _meta?: {
                      "io.modelcontextprotocol/related-task"?: { taskId: string };
                      progressToken?: string | number;
                      [key: string]: unknown;
                  };
                  data: unknown;
                  level: | "error"
                  | "alert"
                  | "debug"
                  | "info"
                  | "notice"
                  | "warning"
                  | "critical"
                  | "emergency";
                  logger?: string;
              },
          ) => void
      )
      | undefined

      Register a handler for logging messages from the view.

      The view sends standard MCP notifications/message (logging) notifications to report debugging information, errors, warnings, and other telemetry to the host. The host can display these in a console, log them to a file, or send them to a monitoring service.

      This uses the standard MCP logging notification format, not a UI-specific message type.

      The handler receives LoggingMessageNotification["params"]:

      • level — "debug" | "info" | "notice" | "warning" | "error" | "critical" | "alert" | "emergency"
      • logger — optional logger name/identifier
      • data — log message and optional structured data

      Returns
          | (
              (
                  params: {
                      _meta?: {
                          "io.modelcontextprotocol/related-task"?: { taskId: string };
                          progressToken?: string | number;
                          [key: string]: unknown;
                      };
                      data: unknown;
                      level: | "error"
                      | "alert"
                      | "debug"
                      | "info"
                      | "notice"
                      | "warning"
                      | "critical"
                      | "emergency";
                      logger?: string;
                  },
              ) => void
          )
          | undefined

      bridge.onloggingmessage = ({ level, logger, data }) => {
      console[level === "error" ? "error" : "log"](
      `[${logger ?? "View"}] ${level.toUpperCase()}:`,
      data,
      );
      };

      Use addEventListener("loggingmessage", handler) instead — it composes with other listeners and supports cleanup via removeEventListener.

    • set onloggingmessage(
          callback:
              | (
                  (
                      params: {
                          _meta?: {
                              "io.modelcontextprotocol/related-task"?: { taskId: string };
                              progressToken?: string | number;
                              [key: string]: unknown;
                          };
                          data: unknown;
                          level: | "error"
                          | "alert"
                          | "debug"
                          | "info"
                          | "notice"
                          | "warning"
                          | "critical"
                          | "emergency";
                          logger?: string;
                      },
                  ) => void
              )
              | undefined,
      ): void

      Parameters

      • callback:
            | (
                (
                    params: {
                        _meta?: {
                            "io.modelcontextprotocol/related-task"?: { taskId: string };
                            progressToken?: string | number;
                            [key: string]: unknown;
                        };
                        data: unknown;
                        level: | "error"
                        | "alert"
                        | "debug"
                        | "info"
                        | "notice"
                        | "warning"
                        | "critical"
                        | "emergency";
                        logger?: string;
                    },
                ) => void
            )
            | undefined

      Returns void

    • get onmessage(): | (
          (
              params: { content: ContentBlock[]; role: "user" },
              extra: BaseContext,
          ) => Promise<McpUiMessageResult>
      )
      | undefined

      Returns
          | (
              (
                  params: { content: ContentBlock[]; role: "user" },
                  extra: BaseContext,
              ) => Promise<McpUiMessageResult>
          )
          | undefined

    • set onmessage(
          callback:
              | (
                  (
                      params: { content: ContentBlock[]; role: "user" },
                      extra: BaseContext,
                  ) => Promise<McpUiMessageResult>
              )
              | undefined,
      ): void

      Parameters

      • callback:
            | (
                (
                    params: { content: ContentBlock[]; role: "user" },
                    extra: BaseContext,
                ) => Promise<McpUiMessageResult>
            )
            | undefined

      Returns void

    • Returns
          | (
              (
                  params: { url: string },
                  extra: BaseContext,
              ) => Promise<McpUiOpenLinkResult>
          )
          | undefined

    • Parameters

      • callback:
            | (
                (
                    params: { url: string },
                    extra: BaseContext,
                ) => Promise<McpUiOpenLinkResult>
            )
            | undefined

      Returns void

    • get onreadresource(): | (
          (
              params: {
                  _meta?: {
                      "io.modelcontextprotocol/related-task"?: { taskId: string };
                      progressToken?: string | number;
                      [key: string]: unknown;
                  };
                  uri: string;
              },
              extra: BaseContext,
          ) => Promise<
              {
                  _meta?: {
                      "io.modelcontextprotocol/serverInfo"?: {
                          description?: string;
                          icons?: { mimeType?: ...; sizes?: ...; src: ...; theme?: ... }[];
                          name: string;
                          title?: string;
                          version: string;
                          websiteUrl?: string;
                      };
                      [key: string]: unknown;
                  };
                  contents: (
                      | {
                          _meta?: { [key: string]: unknown };
                          mimeType?: string;
                          text: string;
                          uri: string;
                      }
                      | {
                          _meta?: { [key: string]: unknown };
                          blob: string;
                          mimeType?: string;
                          uri: string;
                      }
                  )[];
                  [key: string]: unknown;
              },
          >
      )
      | undefined

      Returns
          | (
              (
                  params: {
                      _meta?: {
                          "io.modelcontextprotocol/related-task"?: { taskId: string };
                          progressToken?: string | number;
                          [key: string]: unknown;
                      };
                      uri: string;
                  },
                  extra: BaseContext,
              ) => Promise<
                  {
                      _meta?: {
                          "io.modelcontextprotocol/serverInfo"?: {
                              description?: string;
                              icons?: { mimeType?: ...; sizes?: ...; src: ...; theme?: ... }[];
                              name: string;
                              title?: string;
                              version: string;
                              websiteUrl?: string;
                          };
                          [key: string]: unknown;
                      };
                      contents: (
                          | {
                              _meta?: { [key: string]: unknown };
                              mimeType?: string;
                              text: string;
                              uri: string;
                          }
                          | {
                              _meta?: { [key: string]: unknown };
                              blob: string;
                              mimeType?: string;
                              uri: string;
                          }
                      )[];
                      [key: string]: unknown;
                  },
              >
          )
          | undefined

    • set onreadresource(
          callback:
              | (
                  (
                      params: {
                          _meta?: {
                              "io.modelcontextprotocol/related-task"?: { taskId: string };
                              progressToken?: string | number;
                              [key: string]: unknown;
                          };
                          uri: string;
                      },
                      extra: BaseContext,
                  ) => Promise<
                      {
                          _meta?: {
                              "io.modelcontextprotocol/serverInfo"?: {
                                  description?: string;
                                  icons?: { mimeType?: ...; sizes?: ...; src: ...; theme?: ... }[];
                                  name: string;
                                  title?: string;
                                  version: string;
                                  websiteUrl?: string;
                              };
                              [key: string]: unknown;
                          };
                          contents: (
                              | {
                                  _meta?: { [key: string]: unknown };
                                  mimeType?: string;
                                  text: string;
                                  uri: string;
                              }
                              | {
                                  _meta?: { [key: string]: unknown };
                                  blob: string;
                                  mimeType?: string;
                                  uri: string;
                              }
                          )[];
                          [key: string]: unknown;
                      },
                  >
              )
              | undefined,
      ): void

      Parameters

      • callback:
            | (
                (
                    params: {
                        _meta?: {
                            "io.modelcontextprotocol/related-task"?: { taskId: string };
                            progressToken?: string | number;
                            [key: string]: unknown;
                        };
                        uri: string;
                    },
                    extra: BaseContext,
                ) => Promise<
                    {
                        _meta?: {
                            "io.modelcontextprotocol/serverInfo"?: {
                                description?: string;
                                icons?: { mimeType?: ...; sizes?: ...; src: ...; theme?: ... }[];
                                name: string;
                                title?: string;
                                version: string;
                                websiteUrl?: string;
                            };
                            [key: string]: unknown;
                        };
                        contents: (
                            | {
                                _meta?: { [key: string]: unknown };
                                mimeType?: string;
                                text: string;
                                uri: string;
                            }
                            | {
                                _meta?: { [key: string]: unknown };
                                blob: string;
                                mimeType?: string;
                                uri: string;
                            }
                        )[];
                        [key: string]: unknown;
                    },
                >
            )
            | undefined

      Returns void

    • get onrequestteardown(): ((params: {} | undefined) => void) | undefined

      Register a handler for app-initiated teardown request notifications from the view.

      The view sends ui/notifications/request-teardown when it wants the host to tear it down. If the host decides to proceed, it should send ui/resource-teardown (via teardownResource) to allow the view to perform gracefull termination, then unmount the iframe after the view responds.

      Returns ((params: {} | undefined) => void) | undefined

      bridge.onrequestteardown = async (params) => {
      console.log("App requested teardown");
      // Initiate teardown to allow the app to persist unsaved state
      // Alternatively, the callback can early return to prevent teardown
      await bridge.teardownResource({});
      // Now safe to unmount the iframe
      iframe.remove();
      };

      Use addEventListener("requestteardown", handler) instead — it composes with other listeners and supports cleanup via removeEventListener.

    • set onrequestteardown(
          callback: ((params: {} | undefined) => void) | undefined,
      ): void

      Parameters

      • callback: ((params: {} | undefined) => void) | undefined

      Returns void

    • get onsandboxready(): ((params: {}) => void) | undefined
      Internal

      Register a handler for sandbox proxy ready notifications.

      This is an internal callback used by web-based hosts implementing the double-iframe sandbox architecture. The sandbox proxy sends ui/notifications/sandbox-proxy-ready after it loads and is ready to receive HTML content.

      When this fires, the host should call sendSandboxResourceReady with the HTML content to load into the inner sandboxed iframe.

      Returns ((params: {}) => void) | undefined

      bridge.onsandboxready = async () => {
      const resource = await mcpClient.request(
      { method: "resources/read", params: { uri: "ui://my-app" } }
      );

      bridge.sendSandboxResourceReady({
      html: resource.contents[0].text,
      sandbox: "allow-scripts"
      });
      };

      Use addEventListener("sandboxready", handler) instead — it composes with other listeners and supports cleanup via removeEventListener.

    • set onsandboxready(callback: ((params: {}) => void) | undefined): void

      Parameters

      • callback: ((params: {}) => void) | undefined

      Returns void

    • get onsizechange(): | ((params: { height?: number; width?: number }) => void)
      | undefined

      Register a handler for size change notifications from the view.

      The view sends ui/notifications/size-changed when its rendered content size changes, typically via ResizeObserver. Set this callback to dynamically adjust the iframe container dimensions based on the view's content.

      Note: This is for View → Host communication. To notify the View of host container dimension changes, use setHostContext.

      Returns ((params: { height?: number; width?: number }) => void) | undefined

      bridge.onsizechange = ({ width, height }) => {
      if (width != null) {
      iframe.style.width = `${width}px`;
      }
      if (height != null) {
      iframe.style.height = `${height}px`;
      }
      };

      Use addEventListener("sizechange", handler) instead — it composes with other listeners and supports cleanup via removeEventListener.

    • set onsizechange(
          callback:
              | ((params: { height?: number; width?: number }) => void)
              | undefined,
      ): void

      Parameters

      • callback: ((params: { height?: number; width?: number }) => void) | undefined

      Returns void

    • get onupdatemodelcontext(): | (
          (
              params: {
                  content?: ContentBlock[];
                  structuredContent?: Record<string, unknown>;
              },
              extra: BaseContext,
          ) => Promise<
              {
                  _meta?: {
                      "io.modelcontextprotocol/serverInfo"?: {
                          description?: string;
                          icons?: { mimeType?: ...; sizes?: ...; src: ...; theme?: ... }[];
                          name: string;
                          title?: string;
                          version: string;
                          websiteUrl?: string;
                      };
                      [key: string]: unknown;
                  };
              },
          >
      )
      | undefined

      Returns
          | (
              (
                  params: {
                      content?: ContentBlock[];
                      structuredContent?: Record<string, unknown>;
                  },
                  extra: BaseContext,
              ) => Promise<
                  {
                      _meta?: {
                          "io.modelcontextprotocol/serverInfo"?: {
                              description?: string;
                              icons?: { mimeType?: ...; sizes?: ...; src: ...; theme?: ... }[];
                              name: string;
                              title?: string;
                              version: string;
                              websiteUrl?: string;
                          };
                          [key: string]: unknown;
                      };
                  },
              >
          )
          | undefined

    • set onupdatemodelcontext(
          callback:
              | (
                  (
                      params: {
                          content?: ContentBlock[];
                          structuredContent?: Record<string, unknown>;
                      },
                      extra: BaseContext,
                  ) => Promise<
                      {
                          _meta?: {
                              "io.modelcontextprotocol/serverInfo"?: {
                                  description?: string;
                                  icons?: { mimeType?: ...; sizes?: ...; src: ...; theme?: ... }[];
                                  name: string;
                                  title?: string;
                                  version: string;
                                  websiteUrl?: string;
                              };
                              [key: string]: unknown;
                          };
                      },
                  >
              )
              | undefined,
      ): void

      Parameters

      • callback:
            | (
                (
                    params: {
                        content?: ContentBlock[];
                        structuredContent?: Record<string, unknown>;
                    },
                    extra: BaseContext,
                ) => Promise<
                    {
                        _meta?: {
                            "io.modelcontextprotocol/serverInfo"?: {
                                description?: string;
                                icons?: { mimeType?: ...; sizes?: ...; src: ...; theme?: ... }[];
                                name: string;
                                title?: string;
                                version: string;
                                websiteUrl?: string;
                            };
                            [key: string]: unknown;
                        };
                    },
                >
            )
            | undefined

      Returns void

    • get transport(): Transport | undefined

      Returns Transport | undefined

    Constructors

    • Create a new AppBridge instance.

      Parameters

      • _client: Client | null

        MCP client connected to the server, or null. When provided, connect will automatically set up forwarding of MCP requests/notifications between the View and the server. When null, you must register handlers manually using the oncalltool, onlistresources, etc. setters.

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

        Host application identification (name and version)

      • _hostCapabilities: McpUiHostCapabilities

        Features and capabilities the host supports

      • Optionaloptions: HostOptions

        Configuration options (ProtocolOptions from the base MCP SDK plus hostContext)

      Returns AppBridge

      const bridge = new AppBridge(
      mcpClient,
      { name: "MyHost", version: "1.0.0" },
      { openLinks: {}, serverTools: {}, logging: {} },
      );
      const bridge = new AppBridge(
      null,
      { name: "MyHost", version: "1.0.0" },
      { openLinks: {}, serverTools: {}, logging: {} },
      );
      bridge.oncalltool = async (params, extra) => {
      // Handle tool calls manually
      return { content: [] };
      };

    Methods

    • Protected accessor for a registered request handler. Used by role classes that dispatch synthesized requests through the same stored handler chain (e.g. the Client fulfilling an embedded multi-round-trip input request).

      Parameters

      • method: string

      Returns
          | (
              (
                  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;
                      };
                  },
                  ctx: BaseContext,
              ) => Promise<
                  {
                      _meta?: {
                          "io.modelcontextprotocol/serverInfo"?: {
                              description?: string;
                              icons?: { mimeType?: ...; sizes?: ...; src: ...; theme?: ... }[];
                              name: string;
                              title?: string;
                              version: string;
                              websiteUrl?: string;
                          };
                          [key: string]: unknown;
                      };
                      [key: string]: unknown;
                  },
              >
          )
          | undefined

    • Transport-close hook. Subclass overrides MUST call super._onclose() after their own cleanup — base teardown (response-handler settlement, timeout clearing, in-flight request abort) does not run otherwise.

      Returns void

    • Inbound-notification dispatch. Subclass overrides MUST delegate unmatched traffic to super._onnotification(rawNotification, extra) — an override that consumes only what it owns and falls through to base dispatch for everything else.

      Parameters

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

      Returns void

    • Inbound-response dispatch. Subclass overrides MUST delegate unmatched traffic to super._onresponse(response) — an override that consumes only what it owns and falls through to base dispatch for everything else.

      Parameters

      • response: JSONRPCResponse

      Returns void

    • The per-request _meta envelope this instance attaches to every outgoing request and notification, when one applies. The base implementation returns undefined (no envelope — the 2025-era posture, so legacy-era outbound traffic is byte-identical to a build without this seam). Client overrides it on a connection that negotiated a modern (2026-07-28+) era to return the reserved protocol-version / client-info / client-capabilities keys. User-supplied _meta keys take precedence over the auto-attached ones.

      Returns Readonly<Record<string, unknown>> | undefined

    • Hook for subclasses to supply the implementation identity the 2026-era encode seam stamps into outbound result _meta under io.modelcontextprotocol/serverInfo (spec PR #3002: servers SHOULD identify themselves on every response). The default is undefined — no stamp. Only Server overrides this: the key identifies the software producing a response, and the 2025-era codec never stamps anything regardless (the never-stamp guarantee).

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

    • Sends a request and waits for a response, using the provided schema for validation instead of the era registry's method-keyed entry.

      This is the internal implementation used by SDK methods whose result schema cannot be expressed as a method-keyed registry entry — the one surviving case is server.createMessage, whose result schema depends on the REQUEST params (tools vs no tools) — and by callers passing explicit compatibility schemas. Spec methods are still era-gated here: an explicit schema never smuggles a deleted method onto the wire.

      Type Parameters

      • T$1 extends StandardSchemaV1<unknown, unknown>

      Parameters

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

      Returns Promise<InferOutput<T$1>>

    • Extension point for non-complete decoded results in the response funnel: a result the wire codec discriminated into a kind other than 'complete' or 'invalid' is handed here for the role class to resolve. The base default surfaces it as a typed SdkErrorCode.UnsupportedResultType error (no retry).

      Intended consumers (named so the seam stays accountable):

      • the Client's multi-round-trip auto-fulfilment engine, which fulfils 'input_required' results through the registered elicitation/sampling/roots handlers and retries via flow.retry;
      • a future client-side terminal-result handler for subscriptions/listen, when the spec defines one.

      Server instances never receive input_required responses on their outbound legs and leave the base behavior in place.

      Type Parameters

      • T$1 extends StandardSchemaV1<unknown, unknown>

      Parameters

      • decoded: DecodedResult & { kind: "input_required" }
      • flow: NonCompleteResultFlow<T$1>

      Returns Promise<unknown>

    • Drop consult for inbound messages whose transport did not classify them at the edge — long-lived channels such as stdio, where a role class may need to decline traffic the negotiated era has no answer for (the client-side inbound-request drop on modern-era connections: the 2026-07-28 era has no server→client request channel, and on stdio the client must never write JSON-RPC responses).

      Consulted ONLY when the transport supplied no MessageExtraInfo.classification: edge-classified traffic never reaches the hook. Returning 'drop' discards the message without writing any response (requests are surfaced via onerror). The base implementation returns undefined: unclassified traffic keeps today's dispatch path unchanged. Era selection never happens here — era is instance state, owned by the serving entry that constructed and connected the instance.

      Parameters

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

      Returns "drop" | undefined

    • Protected accessor for the instance's negotiated wire codec, for role classes (Client/Server/McpServer) routing era-dependent behavior through the codec's function-only surface — samplingResultVariant, outboundEnvelope, projectCallToolResult — instead of branching on the protocol version themselves.

      Returns WireCodec

    • The base MCP SDK calls this hook for every standard and custom request handler registration. AppBridge uses it to preserve the existing warning when a View calls host methods before ui/notifications/initialized, without adding overload-forwarding adapters around setRequestHandler. ui/initialize and ping are exempt because they are valid before the Apps-ready gate. This wraps registered callbacks, not JSON-RPC dispatch.

      Parameters

      • method: string
      • handler: (
            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;
                };
            },
            context: BaseContext,
        ) => Promise<
            {
                _meta?: {
                    "io.modelcontextprotocol/serverInfo"?: {
                        description?: string;
                        icons?: {
                            mimeType?: (...)
                            | (...);
                            sizes?: (...) | (...);
                            src: string;
                            theme?: (...) | (...) | (...);
                        }[];
                        name: string;
                        title?: string;
                        version: string;
                        websiteUrl?: string;
                    };
                    [key: string]: unknown;
                };
                [key: string]: unknown;
            },
        >

      Returns (
          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;
              };
          },
          context: BaseContext,
      ) => Promise<
          {
              _meta?: {
                  "io.modelcontextprotocol/serverInfo"?: {
                      description?: string;
                      icons?: {
                          mimeType?: (...)
                          | (...);
                          sizes?: (...) | (...);
                          src: string;
                          theme?: (...) | (...) | (...);
                      }[];
                      name: string;
                      title?: string;
                      version: string;
                      websiteUrl?: string;
                  };
                  [key: string]: unknown;
              };
              [key: string]: unknown;
          },
      >

    • 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

    • Internal

      Verify that the view supports the capability required for the given request method.

      Parameters

      • _method: string

      Returns void

    • Internal

      Verify that the host supports the capability required for the given notification method.

      Parameters

      • _method: string

      Returns void

    • Internal

      Verify that a request handler is registered and supported for the given method.

      Parameters

      • _method: string

      Returns void

    • Internal

      Parameters

      • ctx: BaseContext

      Returns BaseContext

    • Call a tool on the view.

      Sends a tools/call request to the view and returns the result.

      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)

      • Optionaloptions: RequestOptions

        Request options (timeout, abort signal, etc.)

      Returns Promise<
          {
              _meta?: {
                  "io.modelcontextprotocol/serverInfo"?: {
                      description?: string;
                      icons?: {
                          mimeType?: string;
                          sizes?: (...)[];
                          src: string;
                          theme?: "light" | "dark";
                      }[];
                      name: string;
                      title?: string;
                      version: string;
                      websiteUrl?: string;
                  };
                  [key: string]: unknown;
              };
              content: (
                  | {
                      _meta?: { [key: string]: unknown };
                      annotations?: {
                          audience?: ("user" | "assistant")[];
                          lastModified?: string;
                          priority?: number;
                      };
                      text: string;
                      type: "text";
                  }
                  | {
                      _meta?: { [key: string]: unknown };
                      annotations?: {
                          audience?: ("user" | "assistant")[];
                          lastModified?: string;
                          priority?: number;
                      };
                      data: string;
                      mimeType: string;
                      type: "image";
                  }
                  | {
                      _meta?: { [key: string]: unknown };
                      annotations?: {
                          audience?: ("user" | "assistant")[];
                          lastModified?: string;
                          priority?: number;
                      };
                      data: string;
                      mimeType: string;
                      type: "audio";
                  }
                  | {
                      _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;
                      size?: number;
                      title?: string;
                      type: "resource_link";
                      uri: string;
                  }
                  | {
                      _meta?: { [key: string]: unknown };
                      annotations?: {
                          audience?: ("user" | "assistant")[];
                          lastModified?: string;
                          priority?: number;
                      };
                      resource: | {
                          _meta?: { [key: string]: unknown };
                          mimeType?: string;
                          text: string;
                          uri: string;
                      }
                      | {
                          _meta?: { [key: string]: unknown };
                          blob: string;
                          mimeType?: string;
                          uri: string;
                      };
                      type: "resource";
                  }
              )[];
              isError?: boolean;
              structuredContent?: unknown;
              [key: string]: unknown;
          },
      >

      Promise resolving to the tool call result

    • Closes the connection.

      Returns Promise<void>

    • Connect to the view via transport and optionally set up message forwarding.

      This method establishes the transport connection. If an MCP client was passed to the constructor, it also automatically sets up request/notification forwarding based on the MCP server's capabilities, proxying the following to the view:

      • Tools (tools/call, notifications/tools/list_changed)
      • Resources (resources/list, resources/read, resources/templates/list, notifications/resources/list_changed)
      • Prompts (prompts/list, notifications/prompts/list_changed)

      If no client was passed to the constructor, no automatic forwarding is set up and you must register handlers manually using the oncalltool, onlistresources, etc. setters.

      After calling connect, wait for the oninitialized callback before sending tool input and other data to the View.

      Parameters

      Returns Promise<void>

      Promise resolving when connection is established

      If a client was passed but server capabilities are not available. This occurs when connect() is called before the MCP client has completed its initialization with the server. Ensure await client.connect() completes before calling bridge.connect().

      const bridge = new AppBridge(mcpClient, hostInfo, capabilities);
      const transport = new PostMessageTransport(
      iframe.contentWindow!,
      iframe.contentWindow!,
      );

      bridge.oninitialized = () => {
      console.log("View ready");
      bridge.sendToolInput({ arguments: toolArgs });
      };

      await bridge.connect(transport);
      const bridge = new AppBridge(null, hostInfo, capabilities);

      // Register handlers manually
      bridge.oncalltool = async (params, extra) => {
      // Custom tool call handling
      return { content: [] };
      };

      await bridge.connect(transport);
    • Get the view's capabilities discovered during initialization.

      Returns the capabilities that the view advertised during its initialization request. Returns undefined if called before initialization completes.

      Returns McpUiAppCapabilities | undefined

      view capabilities, or undefined if not yet initialized

      bridge.oninitialized = () => {
      const caps = bridge.getAppCapabilities();
      if (caps?.tools) {
      console.log("View provides tools");
      }
      };

      McpUiAppCapabilities for the capabilities structure

    • Get the view's implementation info discovered during initialization.

      Returns the view's name and version as provided in its initialization request. Returns undefined if called before initialization completes.

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

      view implementation info, or undefined if not yet initialized

      bridge.oninitialized = () => {
      const appInfo = bridge.getAppVersion();
      if (appInfo) {
      console.log(`View: ${appInfo.name} v${appInfo.version}`);
      }
      };
    • List tools available on the view.

      Sends a tools/list request to the view and returns the result.

      Parameters

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

        List tools parameters (may include cursor for pagination)

      • Optionaloptions: RequestOptions

        Request options (timeout, abort signal, etc.)

      Returns Promise<
          {
              _meta?: {
                  "io.modelcontextprotocol/serverInfo"?: {
                      description?: string;
                      icons?: {
                          mimeType?: string;
                          sizes?: (...)[];
                          src: string;
                          theme?: "light" | "dark";
                      }[];
                      name: string;
                      title?: string;
                      version: string;
                      websiteUrl?: string;
                  };
                  [key: string]: unknown;
              };
              nextCursor?: string;
              tools: {
                  _meta?: { [key: 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?: {
                          [key: string]: | string
                          | number
                          | boolean
                          | {
                              [key: string]: string | number | boolean | { [x: string]: string | number | boolean | ... | (string | number | boolean | ... | (string | number | boolean | ... | (string | number | boolean | ... | (string | ... 4 more ... | null)[] | null)[] | null)[] | null)[] | null; } | (string | ... 4 more ... | null)[] | null;
                          }
                          | (
                              string | number | boolean | { [x: string]: string | number | boolean | ... | (string | number | boolean | ... | (string | number | boolean | ... | (string | number | boolean | ... | (string | ... 4 more ... | null)[] | null)[] | null)[] | null)[] | null; } | (string | ... 4 more ... | null)[] | null
                          )[]
                          | null;
                      };
                      required?: string[];
                      type: "object";
                      [key: string]: unknown;
                  };
                  name: string;
                  outputSchema?: { $schema?: string; [key: string]: unknown };
                  title?: string;
              }[];
              [key: string]: unknown;
          },
      >

      Promise resolving to the list of tools

    • Emits a notification, which is a one-way message that does not expect a response.

      Parameters

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

      Returns Promise<void>

    • Sends a request and waits for a response.

      For spec methods the result schema is resolved automatically from the method name and the return type is method-keyed. For custom (non-spec) methods, pass a resultSchema as the second argument; the response is validated against it and the return type is inferred from the schema.

      Do not use this method to emit notifications! Use notification() instead.

      Type Parameters

      • M$1 extends RequestMethod

      Parameters

      • request: { method: M$1; params?: Record<string, unknown> }
      • Optionaloptions: RequestOptions

      Returns Promise<ResultTypeMap[M$1]>

    • Sends a request and waits for a response.

      For spec methods the result schema is resolved automatically from the method name and the return type is method-keyed. For custom (non-spec) methods, pass a resultSchema as the second argument; the response is validated against it and the return type is inferred from the schema.

      Do not use this method to emit notifications! Use notification() instead.

      Type Parameters

      • T$1 extends StandardSchemaV1<unknown, unknown>

      Parameters

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

      Returns Promise<InferOutput<T$1>>

    • Low-level method to notify the view of host context changes.

      Most hosts should use setHostContext instead, which automatically detects changes and calls this method with only the modified fields. Use this directly only when you need fine-grained control over change detection.

      Parameters

      Returns void | Promise<void>

    • Notify the view that the MCP server's prompt list has changed.

      The host sends notifications/prompts/list_changed to the view when it receives this notification from the MCP server. This allows the view to refresh its prompt cache or UI accordingly.

      Parameters

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

        Optional notification params (typically empty)

      Returns Promise<void>

      // In your MCP client notification handler:
      mcpClient.setNotificationHandler("notifications/prompts/list_changed", () => {
      bridge.sendPromptListChanged();
      });

      PromptListChangedNotification from @modelcontextprotocol/client for the notification type

    • Notify the view that the MCP server's resource list has changed.

      The host sends notifications/resources/list_changed to the view when it receives this notification from the MCP server. This allows the view to refresh its resource cache or UI accordingly.

      Parameters

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

        Optional notification params (typically empty)

      Returns Promise<void>

      // In your MCP client notification handler:
      mcpClient.setNotificationHandler("notifications/resources/list_changed", () => {
      bridge.sendResourceListChanged();
      });

      ResourceListChangedNotification from @modelcontextprotocol/client for the notification type

    • Internal

      Send HTML resource to the sandbox proxy for secure loading.

      This is an internal method used by web-based hosts implementing the double-iframe sandbox architecture. After the sandbox proxy signals readiness via ui/notifications/sandbox-proxy-ready, the host sends this notification with the HTML content to load.

      Parameters

      • params: {
            csp?: McpUiResourceCsp;
            html: string;
            permissions?: McpUiResourcePermissions;
            sandbox?: string;
        }

        HTML content and sandbox configuration:

        • html: The HTML content to load into the sandboxed iframe
        • sandbox: Optional sandbox attribute value (e.g., "allow-scripts")
        • Optionalcsp?: McpUiResourceCsp

          CSP configuration from resource metadata.

        • html: string

          HTML content to load into the inner iframe.

        • Optionalpermissions?: McpUiResourcePermissions

          Sandbox permissions from resource metadata.

        • Optionalsandbox?: string

          Optional override for the inner iframe's sandbox attribute.

      Returns Promise<void>

      onsandboxready for handling the sandbox proxy ready notification

    • Notify the view that tool execution was cancelled.

      The host MUST send this notification if tool execution was cancelled for any reason, including user action, sampling error, classifier intervention, or any other interruption. This allows the view to update its state and display appropriate feedback to the user.

      Parameters

      • params: { reason?: string }

        Cancellation details object

        • reason: Human-readable explanation for why the tool was cancelled
        • Optionalreason?: string

          Optional reason for the cancellation (e.g., "user action", "timeout").

      Returns Promise<void>

      // User clicked "Cancel" button
      bridge.sendToolCancelled({ reason: "User cancelled the operation" });
      // Sampling error or timeout
      bridge.sendToolCancelled({ reason: "Request timeout after 30 seconds" });

      // Classifier intervention
      bridge.sendToolCancelled({ reason: "Content policy violation detected" });
    • Send complete tool arguments to the view.

      The host MUST send this notification after the View completes initialization (after oninitialized callback fires) and complete tool arguments become available. This notification is sent exactly once and is required before sendToolResult.

      Parameters

      • params: { arguments?: Record<string, unknown> }

        Complete tool call arguments

        • Optionalarguments?: Record<string, unknown>

          Complete tool call arguments as key-value pairs.

      Returns Promise<void>

      bridge.oninitialized = () => {
      bridge.sendToolInput({
      arguments: { location: "New York", units: "metric" },
      });
      };
    • Send streaming partial tool arguments to the view.

      The host MAY send this notification zero or more times while tool arguments are being streamed, before sendToolInput is called with complete arguments. This enables progressive rendering of tool arguments in the view.

      The arguments represent best-effort recovery of incomplete JSON. views SHOULD handle missing or changing fields gracefully between notifications.

      Parameters

      • params: { arguments?: Record<string, unknown> }

        Partial tool call arguments (may be incomplete)

        • Optionalarguments?: Record<string, unknown>

          Partial tool call arguments (incomplete, may change).

      Returns Promise<void>

      // As streaming progresses...
      bridge.sendToolInputPartial({ arguments: { loc: "N" } });
      bridge.sendToolInputPartial({ arguments: { location: "New" } });
      bridge.sendToolInputPartial({ arguments: { location: "New York" } });

      // When complete, send final input
      bridge.sendToolInput({
      arguments: { location: "New York", units: "metric" },
      });
    • Notify the view that the MCP server's tool list has changed.

      The host sends notifications/tools/list_changed to the view when it receives this notification from the MCP server. This allows the view to refresh its tool cache or UI accordingly.

      Parameters

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

        Optional notification params (typically empty)

      Returns Promise<void>

      // In your MCP client notification handler:
      mcpClient.setNotificationHandler("notifications/tools/list_changed", () => {
      bridge.sendToolListChanged();
      });

      ToolListChangedNotification from @modelcontextprotocol/client for the notification type

    • Send tool execution result to the view.

      The host MUST send this notification when tool execution completes successfully, provided the view is still displayed. If the view was closed before execution completes, the host MAY skip this notification. This must be sent after sendToolInput.

      Parameters

      • params: {
            _meta?: {
                "io.modelcontextprotocol/serverInfo"?: {
                    description?: string;
                    icons?: {
                        mimeType?: string;
                        sizes?: string[];
                        src: string;
                        theme?: "light" | "dark";
                    }[];
                    name: string;
                    title?: string;
                    version: string;
                    websiteUrl?: string;
                };
                [key: string]: unknown;
            };
            content: (
                | {
                    _meta?: { [key: string]: unknown };
                    annotations?: {
                        audience?: ("user" | "assistant")[];
                        lastModified?: string;
                        priority?: number;
                    };
                    text: string;
                    type: "text";
                }
                | {
                    _meta?: { [key: string]: unknown };
                    annotations?: {
                        audience?: ("user" | "assistant")[];
                        lastModified?: string;
                        priority?: number;
                    };
                    data: string;
                    mimeType: string;
                    type: "image";
                }
                | {
                    _meta?: { [key: string]: unknown };
                    annotations?: {
                        audience?: ("user" | "assistant")[];
                        lastModified?: string;
                        priority?: number;
                    };
                    data: string;
                    mimeType: string;
                    type: "audio";
                }
                | {
                    _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;
                    size?: number;
                    title?: string;
                    type: "resource_link";
                    uri: string;
                }
                | {
                    _meta?: { [key: string]: unknown };
                    annotations?: {
                        audience?: ("user" | "assistant")[];
                        lastModified?: string;
                        priority?: number;
                    };
                    resource: | {
                        _meta?: { [key: string]: unknown };
                        mimeType?: string;
                        text: string;
                        uri: string;
                    }
                    | {
                        _meta?: { [key: string]: unknown };
                        blob: string;
                        mimeType?: string;
                        uri: string;
                    };
                    type: "resource";
                }
            )[];
            isError?: boolean;
            structuredContent?: unknown;
            [key: string]: unknown;
        }

        Standard MCP tool execution result

      Returns Promise<void>

      const result = await mcpClient.request({
      method: "tools/call",
      params: { name: "get_weather", arguments: args },
      });
      bridge.sendToolResult(result);
    • Update the host context and notify the view of changes.

      Compares fields present in the new context with the current context and sends a ui/notifications/host-context-changed notification containing only fields that have been added or modified. If no fields have changed, no notification is sent. The new context fully replaces the internal state.

      Common use cases include notifying the view when:

      • Theme changes (light/dark mode toggle)
      • Viewport size changes (window resize)
      • Display mode changes (inline/fullscreen)
      • Locale or timezone changes

      Parameters

      Returns void

      bridge.setHostContext({ theme: "dark" });
      
      bridge.setHostContext({
      theme: "dark",
      containerDimensions: { maxHeight: 600, width: 800 },
      });
    • Request graceful shutdown of the view.

      The host MUST send this request before tearing down the UI resource (before unmounting the iframe). This gives the view an opportunity to save state, cancel pending operations, or show confirmation dialogs.

      The host SHOULD wait for the response before unmounting to prevent data loss.

      Parameters

      • params: {}

        Empty params object

      • Optionaloptions: RequestOptions

        Request options (timeout, etc.)

      Returns Promise<Record<string, unknown>>

      Promise resolving when view confirms readiness for teardown

      try {
      await bridge.teardownResource({});
      // View is ready, safe to unmount iframe
      iframe.remove();
      } catch (error) {
      console.error("Teardown failed:", error);
      }
    • Parameters

      • name: string
      • previous: unknown
      • next: unknown

      Returns void

    Properties

    _negotiatedProtocolVersion?: string

    The protocol version negotiated for the current connection (undefined before negotiation completes), which determines the wire era this instance speaks. Set by the SDK's negotiation and initialize paths (Client.connect, Server._oninitialize).

    _supportedProtocolVersions: string[]
    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;
            };
        },
        ctx: BaseContext,
    ) => Promise<
        {
            _meta?: {
                "io.modelcontextprotocol/serverInfo"?: {
                    description?: string;
                    icons?: { mimeType?: ...; sizes?: ...; src: ...; theme?: ... }[];
                    name: string;
                    title?: string;
                    version: string;
                    websiteUrl?: string;
                };
                [key: string]: unknown;
            };
            [key: string]: unknown;
        },
    >

    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.

    onping?: (
        params:
            | {
                _meta?: {
                    "io.modelcontextprotocol/related-task"?: { taskId: string };
                    progressToken?: string | number;
                    [key: string]: unknown;
                };
            }
            | undefined,
        extra: BaseContext,
    ) => void

    Optional handler for ping requests from the view.

    The View can send standard MCP ping requests to verify the connection is alive. The AppBridge automatically responds with an empty object, but this handler allows the host to observe or log ping activity.

    Unlike the other handlers which use setters, this is a direct property assignment. It is optional; if not set, pings are still handled automatically.

    Type Declaration

      • (
            params:
                | {
                    _meta?: {
                        "io.modelcontextprotocol/related-task"?: { taskId: string };
                        progressToken?: string | number;
                        [key: string]: unknown;
                    };
                }
                | undefined,
            extra: BaseContext,
        ): void
      • Parameters

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

          Empty params object from the ping request

        • extra: BaseContext

          Request metadata (abort signal, session info)

        Returns void

    bridge.onping = (params, extra) => {
    console.log("Received ping from view");
    };
    removeNotificationHandler: (method: string) => void = ...

    Removes the notification handler for the given method.

    removeRequestHandler: (method: string) => void = ...

    Removes the request handler for the given method.

    replaceRequestHandler: {
        <M$1 extends RequestMethod>(
            method: M$1,
            handler: (
                request: RequestTypeMap[M$1],
                ctx: BaseContext,
            ) => HandlerResultTypeMap[M$1] | Promise<HandlerResultTypeMap[M$1]>,
        ): void;
        <
            P extends StandardSchemaV1<unknown, unknown>,
            R extends StandardSchemaV1<unknown, unknown> | undefined = undefined,
        >(
            method: string,
            schemas: { params: P; result?: R },
            handler: (
                params: InferOutput<P>,
                ctx: BaseContext,
            ) => InferHandlerResult<R> | Promise<InferHandlerResult<R>>,
        ): void;
    } = ...

    Register a request handler with replace semantics, bypassing the double-set protection of setRequestHandler. Used by the on* request-handler setters.

    Type Declaration

      • <M$1 extends RequestMethod>(
            method: M$1,
            handler: (
                request: RequestTypeMap[M$1],
                ctx: BaseContext,
            ) => HandlerResultTypeMap[M$1] | Promise<HandlerResultTypeMap[M$1]>,
        ): void
      • Registers a handler to invoke when this protocol object receives a request with the given method.

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

        For spec methods, pass (method, handler); the request is parsed with the spec schema and the handler receives the typed Request. For custom (non-spec) methods, pass (method, schemas, handler); params are validated against schemas.params and the handler receives the parsed params object directly. Supplying schemas.result types the handler's return value.

        Type Parameters

        • M$1 extends RequestMethod

        Parameters

        • method: M$1
        • handler: (
              request: RequestTypeMap[M$1],
              ctx: BaseContext,
          ) => HandlerResultTypeMap[M$1] | Promise<HandlerResultTypeMap[M$1]>

        Returns void

        const SearchParams = z.object({ query: z.string(), limit: z.number().optional() });
        const SearchResult = z.object({ hits: z.array(z.string()) });

        protocol.setRequestHandler('acme/search', { params: SearchParams, result: SearchResult }, async (params, _ctx) => {
        return { hits: [`result for ${params.query}`] };
        });
      • <
            P extends StandardSchemaV1<unknown, unknown>,
            R extends StandardSchemaV1<unknown, unknown> | undefined = undefined,
        >(
            method: string,
            schemas: { params: P; result?: R },
            handler: (
                params: InferOutput<P>,
                ctx: BaseContext,
            ) => InferHandlerResult<R> | Promise<InferHandlerResult<R>>,
        ): void
      • Registers a handler to invoke when this protocol object receives a request with the given method.

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

        For spec methods, pass (method, handler); the request is parsed with the spec schema and the handler receives the typed Request. For custom (non-spec) methods, pass (method, schemas, handler); params are validated against schemas.params and the handler receives the parsed params object directly. Supplying schemas.result types the handler's return value.

        Type Parameters

        • P extends StandardSchemaV1<unknown, unknown>
        • R extends StandardSchemaV1<unknown, unknown> | undefined = undefined

        Parameters

        • method: string
        • schemas: { params: P; result?: R }
        • handler: (
              params: InferOutput<P>,
              ctx: BaseContext,
          ) => InferHandlerResult<R> | Promise<InferHandlerResult<R>>

        Returns void

        const SearchParams = z.object({ query: z.string(), limit: z.number().optional() });
        const SearchResult = z.object({ hits: z.array(z.string()) });

        protocol.setRequestHandler('acme/search', { params: SearchParams, result: SearchResult }, async (params, _ctx) => {
        return { hits: [`result for ${params.query}`] };
        });
    sendResourceTeardown: (
        params: {},
        options?: RequestOptions,
    ) => Promise<Record<string, unknown>> = ...

    Type Declaration

      • (params: {}, options?: RequestOptions): Promise<Record<string, unknown>>
      • Request graceful shutdown of the view.

        The host MUST send this request before tearing down the UI resource (before unmounting the iframe). This gives the view an opportunity to save state, cancel pending operations, or show confirmation dialogs.

        The host SHOULD wait for the response before unmounting to prevent data loss.

        Parameters

        • params: {}

          Empty params object

        • Optionaloptions: RequestOptions

          Request options (timeout, etc.)

        Returns Promise<Record<string, unknown>>

        Promise resolving when view confirms readiness for teardown

        try {
        await bridge.teardownResource({});
        // View is ready, safe to unmount iframe
        iframe.remove();
        } catch (error) {
        console.error("Teardown failed:", error);
        }

    Use teardownResource instead

    setNotificationHandler: LegacyNotificationHandlerSetter<
        {
            <M$1 extends NotificationMethod>(
                method: M$1,
                handler: (notification: NotificationTypeMap[M$1]) => void | Promise<void>,
            ): void;
            <P extends StandardSchemaV1<unknown, unknown>>(
                method: string,
                schemas: { params: P },
                handler: (
                    params: InferOutput<P>,
                    notification: {
                        method: string;
                        params?: {
                            _meta?: {
                                "io.modelcontextprotocol/related-task"?: { taskId: string };
                                progressToken?: string | number;
                                [key: string]: unknown;
                            };
                            [key: string]: unknown;
                        };
                    },
                ) => void
                | Promise<void>,
            ): void;
        },
    > = ...

    Registers a notification handler. Throws if a handler for the same method has already been registered — use the on* setter (replace semantics) or addEventListener (multi-listener) for mapped events.

    if a handler for this method is already registered.

    setRequestHandler: LegacyRequestHandlerSetter<
        {
            <M$1 extends RequestMethod>(
                method: M$1,
                handler: (
                    request: RequestTypeMap[M$1],
                    ctx: BaseContext,
                ) => HandlerResultTypeMap[M$1] | Promise<HandlerResultTypeMap[M$1]>,
            ): void;
            <
                P extends StandardSchemaV1<unknown, unknown>,
                R extends StandardSchemaV1<unknown, unknown> | undefined = undefined,
            >(
                method: string,
                schemas: { params: P; result?: R },
                handler: (
                    params: InferOutput<P>,
                    ctx: BaseContext,
                ) => InferHandlerResult<R> | Promise<InferHandlerResult<R>>,
            ): void;
        },
    > = ...

    Registers a request handler. Throws if a handler for the same method has already been registered — use the on* setter for replace semantics.

    if a handler for this method is already registered.