@blade-hq/agent-react 2612.0.0-beta.7 → 2612.0.0-beta.70

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (164) hide show
  1. package/README.md +33 -0
  2. package/dist/chat/AgentLoopBlock.d.ts +0 -2
  3. package/dist/chat/AskUserQuestionBlock.d.ts +3 -20
  4. package/dist/chat/AssistantTurnBlock.d.ts +1 -9
  5. package/dist/chat/AttachmentPreviewDialog.d.ts +0 -1
  6. package/dist/chat/ChatLoadingIndicator.d.ts +7 -0
  7. package/dist/chat/ContextAttachmentPills.d.ts +4 -0
  8. package/dist/chat/CurrentPlanPanel.d.ts +0 -3
  9. package/dist/chat/FileDeliveryCards.d.ts +0 -4
  10. package/dist/chat/FinalArtifactCards.d.ts +0 -1
  11. package/dist/chat/ImageLightbox.d.ts +1 -1
  12. package/dist/chat/LiteMessageList.d.ts +1 -3
  13. package/dist/chat/MessageFileAttachmentList.d.ts +0 -5
  14. package/dist/chat/QuestionnaireQuestionBlock.d.ts +11 -0
  15. package/dist/chat/SessionReplayBar.d.ts +0 -1
  16. package/dist/chat/TextAttachmentPills.d.ts +0 -3
  17. package/dist/chat/TurnNavRail.d.ts +0 -3
  18. package/dist/chat/WorkflowRunBlock.d.ts +21 -4
  19. package/dist/chat/ai-elements/shimmer.d.ts +0 -4
  20. package/dist/chat/customization.d.ts +1 -1
  21. package/dist/chat/index.d.ts +1 -1
  22. package/dist/chat/markdown/ExternalAnchor.d.ts +2 -2
  23. package/dist/chat/markdown/MarkdownContent.d.ts +3 -0
  24. package/dist/chat/message-list-blocks.d.ts +0 -1
  25. package/dist/chat/runtime/actions.d.ts +2 -2
  26. package/dist/chat/runtime/background-task-dismissals.d.ts +0 -1
  27. package/dist/chat/runtime/composer-channels.d.ts +0 -3
  28. package/dist/chat/runtime/input-cache-reset.d.ts +0 -5
  29. package/dist/chat/runtime/input-services.d.ts +10 -0
  30. package/dist/chat/runtime/session-source.d.ts +0 -5
  31. package/dist/chat/runtime/use-chat-actions.d.ts +0 -4
  32. package/dist/{chat-OCLOVB3H.css → chat-IHPRU35X.css} +5 -18
  33. package/dist/chat.css +5 -18
  34. package/dist/{chunk-MERN5XEM.js → chunk-2DPLLZOU.js} +2162 -13284
  35. package/dist/chunk-2DPLLZOU.js.map +1 -0
  36. package/dist/chunk-7MCGQH34.js +605 -0
  37. package/dist/chunk-7MCGQH34.js.map +1 -0
  38. package/dist/{chunk-67GHJQK5.js → chunk-HCW7SI5Q.js} +3897 -26116
  39. package/dist/chunk-HCW7SI5Q.js.map +1 -0
  40. package/dist/chunk-J72ZLILV.js +2317 -0
  41. package/dist/chunk-J72ZLILV.js.map +1 -0
  42. package/dist/chunk-QIR73CES.js +7917 -0
  43. package/dist/chunk-QIR73CES.js.map +1 -0
  44. package/dist/chunk-WRIMPZPN.js +4031 -0
  45. package/dist/chunk-WRIMPZPN.js.map +1 -0
  46. package/dist/chunk-XJ6ZA6LN.js +9480 -0
  47. package/dist/chunk-XJ6ZA6LN.js.map +1 -0
  48. package/dist/chunk-XP6T6SHZ.js +13622 -0
  49. package/dist/chunk-XP6T6SHZ.js.map +1 -0
  50. package/dist/components/AccountConnectors.d.ts +13 -0
  51. package/dist/components/BrowserConnectionDialog.d.ts +7 -0
  52. package/dist/components/ChatInput.d.ts +1 -15
  53. package/dist/components/ConnectorAuthorizationProgress.d.ts +6 -0
  54. package/dist/components/ConnectorConnection.d.ts +4 -0
  55. package/dist/components/ConnectorPanel.d.ts +3 -1
  56. package/dist/components/ConnectorRuntimeDiagnostics.d.ts +5 -0
  57. package/dist/components/DeviceConnection.d.ts +15 -0
  58. package/dist/components/FeishuCapabilitySelection.d.ts +14 -0
  59. package/dist/components/FeishuPermissionStatus.d.ts +5 -0
  60. package/dist/components/LlmAdvancedSettings.d.ts +0 -1
  61. package/dist/components/ManagedConnection.d.ts +9 -0
  62. package/dist/components/McpAppFrame.d.ts +17 -0
  63. package/dist/components/PlanUpdateBlock.d.ts +0 -1
  64. package/dist/components/SessionPluginConfigForm.d.ts +3 -1
  65. package/dist/components/SessionPluginIcon.d.ts +1 -0
  66. package/dist/components/plugin-connector.d.ts +1 -0
  67. package/dist/connectors.d.ts +2 -0
  68. package/dist/connectors.js +11 -0
  69. package/dist/connectors.js.map +1 -0
  70. package/dist/embed/blade-chat-element.d.ts +0 -8
  71. package/dist/embed/entry.d.ts +8 -19
  72. package/dist/hooks/use-message-pin.d.ts +1 -1
  73. package/dist/index.d.ts +2 -0
  74. package/dist/index.js +14 -3
  75. package/dist/internal.d.ts +6 -2
  76. package/dist/internal.js +49 -70
  77. package/dist/internal.js.map +1 -1
  78. package/dist/lib/message-shortcuts.d.ts +5 -0
  79. package/dist/questions.d.ts +7 -0
  80. package/dist/questions.js +908 -0
  81. package/dist/questions.js.map +1 -0
  82. package/dist/rich-input/ConnectButton.d.ts +7 -5
  83. package/dist/rich-input/FileCompletionMenu.d.ts +1 -2
  84. package/dist/rich-input/InputActionSubmenu.d.ts +10 -0
  85. package/dist/rich-input/SkillActionMenu.d.ts +10 -0
  86. package/dist/rich-input/SkillStatusBar.d.ts +0 -6
  87. package/dist/rich-input/extensions/skill-mention.d.ts +3 -20
  88. package/dist/rich-input/index.d.ts +3 -2
  89. package/dist/rich-input/lib/composer-content.d.ts +5 -1
  90. package/dist/rich-input/lib/plugin-suggestions.d.ts +5 -5
  91. package/dist/rich-input/lib/reference-candidates.d.ts +0 -1
  92. package/dist/rich-input/lib/skill-suggestions.d.ts +1 -1
  93. package/dist/rich-input/lib/user-home.d.ts +0 -17
  94. package/dist/rich-input/services.d.ts +1 -1
  95. package/dist/rich-input/voice/VoiceWaveform.d.ts +0 -3
  96. package/dist/rich-input.js +768 -1065
  97. package/dist/rich-input.js.map +1 -1
  98. package/dist/style.css +16 -55
  99. package/dist/style.full.css +23 -77
  100. package/dist/tool-details.d.ts +8 -0
  101. package/dist/tool-details.js +24 -0
  102. package/dist/tool-details.js.map +1 -0
  103. package/node_modules/@modelcontextprotocol/ext-apps/LICENSE +216 -0
  104. package/node_modules/@modelcontextprotocol/ext-apps/README.md +284 -0
  105. package/node_modules/@modelcontextprotocol/ext-apps/dist/docs/patterns.d.ts +9 -0
  106. package/node_modules/@modelcontextprotocol/ext-apps/dist/src/app-bridge.d.ts +1348 -0
  107. package/node_modules/@modelcontextprotocol/ext-apps/dist/src/app-bridge.examples.d.ts +9 -0
  108. package/node_modules/@modelcontextprotocol/ext-apps/dist/src/app-bridge.js +39 -0
  109. package/node_modules/@modelcontextprotocol/ext-apps/dist/src/app-bridge.test.d.ts +1 -0
  110. package/node_modules/@modelcontextprotocol/ext-apps/dist/src/app-with-deps.js +82 -0
  111. package/node_modules/@modelcontextprotocol/ext-apps/dist/src/app.d.ts +1214 -0
  112. package/node_modules/@modelcontextprotocol/ext-apps/dist/src/app.examples.d.ts +9 -0
  113. package/node_modules/@modelcontextprotocol/ext-apps/dist/src/app.js +39 -0
  114. package/node_modules/@modelcontextprotocol/ext-apps/dist/src/app.test.d.ts +1 -0
  115. package/node_modules/@modelcontextprotocol/ext-apps/dist/src/constants.d.ts +65 -0
  116. package/node_modules/@modelcontextprotocol/ext-apps/dist/src/events.d.ts +47 -0
  117. package/node_modules/@modelcontextprotocol/ext-apps/dist/src/events.test.d.ts +1 -0
  118. package/node_modules/@modelcontextprotocol/ext-apps/dist/src/generated/schema.d.ts +1047 -0
  119. package/node_modules/@modelcontextprotocol/ext-apps/dist/src/generated/schema.json +6170 -0
  120. package/node_modules/@modelcontextprotocol/ext-apps/dist/src/generated/schema.test.d.ts +41 -0
  121. package/node_modules/@modelcontextprotocol/ext-apps/dist/src/interop-v1.test.d.ts +1 -0
  122. package/node_modules/@modelcontextprotocol/ext-apps/dist/src/legacy-handlers.d.ts +66 -0
  123. package/node_modules/@modelcontextprotocol/ext-apps/dist/src/legacy-handlers.test.d.ts +1 -0
  124. package/node_modules/@modelcontextprotocol/ext-apps/dist/src/message-transport.d.ts +126 -0
  125. package/node_modules/@modelcontextprotocol/ext-apps/dist/src/message-transport.examples.d.ts +9 -0
  126. package/node_modules/@modelcontextprotocol/ext-apps/dist/src/message-transport.test.d.ts +1 -0
  127. package/node_modules/@modelcontextprotocol/ext-apps/dist/src/react/index.d.ts +37 -0
  128. package/node_modules/@modelcontextprotocol/ext-apps/dist/src/react/index.examples.d.ts +6 -0
  129. package/node_modules/@modelcontextprotocol/ext-apps/dist/src/react/index.js +39 -0
  130. package/node_modules/@modelcontextprotocol/ext-apps/dist/src/react/react-with-deps.js +82 -0
  131. package/node_modules/@modelcontextprotocol/ext-apps/dist/src/react/useApp.d.ts +115 -0
  132. package/node_modules/@modelcontextprotocol/ext-apps/dist/src/react/useApp.examples.d.ts +6 -0
  133. package/node_modules/@modelcontextprotocol/ext-apps/dist/src/react/useAutoResize.d.ts +54 -0
  134. package/node_modules/@modelcontextprotocol/ext-apps/dist/src/react/useAutoResize.examples.d.ts +6 -0
  135. package/node_modules/@modelcontextprotocol/ext-apps/dist/src/react/useDocumentTheme.d.ts +44 -0
  136. package/node_modules/@modelcontextprotocol/ext-apps/dist/src/react/useDocumentTheme.examples.d.ts +6 -0
  137. package/node_modules/@modelcontextprotocol/ext-apps/dist/src/react/useHostStyles.d.ts +113 -0
  138. package/node_modules/@modelcontextprotocol/ext-apps/dist/src/react/useHostStyles.examples.d.ts +6 -0
  139. package/node_modules/@modelcontextprotocol/ext-apps/dist/src/server/index.d.ts +381 -0
  140. package/node_modules/@modelcontextprotocol/ext-apps/dist/src/server/index.examples.d.ts +9 -0
  141. package/node_modules/@modelcontextprotocol/ext-apps/dist/src/server/index.js +1 -0
  142. package/node_modules/@modelcontextprotocol/ext-apps/dist/src/server/index.test.d.ts +1 -0
  143. package/node_modules/@modelcontextprotocol/ext-apps/dist/src/spec.types.d.ts +698 -0
  144. package/node_modules/@modelcontextprotocol/ext-apps/dist/src/standard-schema.d.ts +23 -0
  145. package/node_modules/@modelcontextprotocol/ext-apps/dist/src/styles.d.ts +184 -0
  146. package/node_modules/@modelcontextprotocol/ext-apps/dist/src/styles.examples.d.ts +9 -0
  147. package/node_modules/@modelcontextprotocol/ext-apps/dist/src/types.d.ts +33 -0
  148. package/node_modules/@modelcontextprotocol/ext-apps/dist/src/wire-compat.test.d.ts +1 -0
  149. package/node_modules/@modelcontextprotocol/ext-apps/package.json +144 -0
  150. package/node_modules/@standard-schema/spec/LICENSE +21 -0
  151. package/node_modules/@standard-schema/spec/README.md +198 -0
  152. package/node_modules/@standard-schema/spec/dist/index.cjs +18 -0
  153. package/node_modules/@standard-schema/spec/dist/index.d.cts +119 -0
  154. package/node_modules/@standard-schema/spec/dist/index.d.ts +119 -0
  155. package/node_modules/@standard-schema/spec/dist/index.js +0 -0
  156. package/node_modules/@standard-schema/spec/package.json +52 -0
  157. package/package.json +19 -3
  158. package/public-api.md +16 -4
  159. package/dist/chunk-67GHJQK5.js.map +0 -1
  160. package/dist/chunk-DPDXGYGM.js +0 -258
  161. package/dist/chunk-DPDXGYGM.js.map +0 -1
  162. package/dist/chunk-MERN5XEM.js.map +0 -1
  163. package/dist/lib/agent-computer-command.d.ts +0 -32
  164. package/dist/rich-input/extensions/workflow-mention.d.ts +0 -10
@@ -0,0 +1,1348 @@
1
+ import { Protocol, type BaseContext, type Client, type ProtocolOptions, type CallToolRequest, type CallToolResult, type CreateMessageRequest, type CreateMessageResult, type CreateMessageResultWithTools, type EmptyResult, type Implementation, type JSONRPCRequest, type ListPromptsRequest, type ListPromptsResult, type ListResourcesRequest, type ListResourcesResult, type ListResourceTemplatesRequest, type ListResourceTemplatesResult, type ListToolsRequest, type LoggingMessageNotification, type PingRequest, type PromptListChangedNotification, type ReadResourceRequest, type ReadResourceResult, type RequestOptions, type ResourceListChangedNotification, type Result, type Tool, type ToolListChangedNotification, type Transport } from "@modelcontextprotocol/client";
2
+ import { type LegacyNotificationHandlerSetter, type LegacyRequestHandlerSetter } from "./legacy-handlers.js";
3
+ import { type McpUiSandboxResourceReadyNotification, type McpUiSizeChangedNotification, type McpUiToolCancelledNotification, type McpUiToolInputNotification, type McpUiToolInputPartialNotification, type McpUiToolResultNotification, McpUiAppCapabilities, McpUiUpdateModelContextRequest, McpUiHostCapabilities, McpUiHostContext, McpUiHostContextChangedNotification, McpUiInitializedNotification, McpUiMessageRequest, McpUiMessageResult, McpUiOpenLinkRequest, McpUiOpenLinkResult, McpUiDownloadFileRequest, McpUiDownloadFileResult, McpUiResourceTeardownRequest, McpUiRequestTeardownNotification, McpUiSandboxProxyReadyNotification, McpUiRequestDisplayModeRequest, McpUiRequestDisplayModeResult, McpUiResourcePermissions } from "./types.js";
4
+ export * from "./types.js";
5
+ export { RESOURCE_URI_META_KEY, RESOURCE_MIME_TYPE } from "./constants.js";
6
+ export { PostMessageTransport } from "./message-transport.js";
7
+ /**
8
+ * Extract UI resource URI from tool metadata.
9
+ *
10
+ * Supports both the new nested format (`_meta.ui.resourceUri`) and the
11
+ * deprecated flat format (`_meta["ui/resourceUri"]`). The new nested format
12
+ * takes precedence if both are present.
13
+ *
14
+ * @param tool - A tool object with optional `_meta` property
15
+ * @returns The UI resource URI if valid, undefined if not present
16
+ * @throws Error if resourceUri is present but invalid (does not start with "ui://")
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * // New nested format (preferred)
21
+ * const uri = getToolUiResourceUri({
22
+ * _meta: { ui: { resourceUri: "ui://server/app.html" } }
23
+ * });
24
+ *
25
+ * // Deprecated flat format (still supported)
26
+ * const uri = getToolUiResourceUri({
27
+ * _meta: { "ui/resourceUri": "ui://server/app.html" }
28
+ * });
29
+ * ```
30
+ */
31
+ export declare function getToolUiResourceUri(tool: Partial<Tool>): string | undefined;
32
+ /**
33
+ * Check if a tool is visible to the model only.
34
+ *
35
+ * @param tool - Tool object with visibility metadata
36
+ * @returns True if the tool is visible to the model only, false otherwise
37
+ */
38
+ export declare function isToolVisibilityModelOnly(tool: Partial<Tool>): boolean;
39
+ /**
40
+ * Check if a tool is visible to the app only.
41
+ *
42
+ * @param tool - Tool object with visibility metadata
43
+ * @returns True if the tool is visible to the app only, false otherwise
44
+ */
45
+ export declare function isToolVisibilityAppOnly(tool: Partial<Tool>): boolean;
46
+ /**
47
+ * Build iframe `allow` attribute string from permissions.
48
+ *
49
+ * Maps McpUiResourcePermissions to the Permission Policy allow attribute
50
+ * format used by iframes (e.g., "microphone; clipboard-write").
51
+ *
52
+ * @param permissions - Permissions requested by the UI resource
53
+ * @returns Space-separated permission directives, or empty string if none
54
+ *
55
+ * @example
56
+ * ```typescript
57
+ * const allow = buildAllowAttribute({ microphone: {}, clipboardWrite: {} });
58
+ * // Returns: "microphone; clipboard-write"
59
+ * iframe.setAttribute("allow", allow);
60
+ * ```
61
+ */
62
+ export declare function buildAllowAttribute(permissions: McpUiResourcePermissions | undefined): string;
63
+ /**
64
+ * Options for configuring {@link AppBridge `AppBridge`} behavior.
65
+ *
66
+ * @property hostContext - Optional initial host context to provide to the view
67
+ *
68
+ * @see `ProtocolOptions` from @modelcontextprotocol/client for available options
69
+ * @see {@link McpUiHostContext `McpUiHostContext`} for the hostContext structure
70
+ */
71
+ export type HostOptions = Omit<ProtocolOptions, "supportedProtocolVersions"> & {
72
+ hostContext?: McpUiHostContext;
73
+ };
74
+ /**
75
+ * Protocol versions supported by this AppBridge implementation.
76
+ *
77
+ * The SDK automatically handles version negotiation during initialization.
78
+ * Hosts don't need to manage protocol versions manually.
79
+ */
80
+ export declare const SUPPORTED_PROTOCOL_VERSIONS: string[];
81
+ /**
82
+ * Extra metadata passed to request handlers.
83
+ *
84
+ * This type represents the additional context (`BaseContext`) provided by the
85
+ * base MCP SDK `Protocol` when handling requests.
86
+ *
87
+ * @internal
88
+ */
89
+ type RequestHandlerExtra = BaseContext;
90
+ /**
91
+ * Maps DOM-style event names to their notification `params` types.
92
+ *
93
+ * Used by {@link AppBridge `AppBridge`} to provide type-safe
94
+ * `addEventListener` / `removeEventListener` and singular `on*` handler
95
+ * support.
96
+ */
97
+ export type AppBridgeEventMap = {
98
+ sizechange: McpUiSizeChangedNotification["params"];
99
+ sandboxready: McpUiSandboxProxyReadyNotification["params"];
100
+ initialized: McpUiInitializedNotification["params"];
101
+ requestteardown: McpUiRequestTeardownNotification["params"];
102
+ loggingmessage: LoggingMessageNotification["params"];
103
+ };
104
+ /**
105
+ * Host-side bridge for communicating with a single View ({@link app!App `App`}).
106
+ *
107
+ * `AppBridge` extends the base MCP SDK's public `Protocol` class and acts as a
108
+ * proxy between the host application and a view running in an iframe. When a
109
+ * separate MCP client is provided to the constructor, it automatically forwards
110
+ * MCP server capabilities (tools, resources, prompts) to the view. It also
111
+ * handles the Apps initialization handshake.
112
+ *
113
+ * ## Architecture
114
+ *
115
+ * **View ↔ AppBridge ↔ Host ↔ MCP Server**
116
+ *
117
+ * The bridge proxies requests from the view to the MCP server and forwards
118
+ * responses back. It also sends host-initiated notifications like tool input
119
+ * and results to the view.
120
+ *
121
+ * ## Lifecycle
122
+ *
123
+ * 1. **Create**: Instantiate `AppBridge` with MCP client and capabilities
124
+ * 2. **Connect**: Call `connect()` with transport to establish communication
125
+ * 3. **Wait for init**: View sends initialize request, bridge responds
126
+ * 4. **Send data**: Call {@link sendToolInput `sendToolInput`}, {@link sendToolResult `sendToolResult`}, etc.
127
+ * 5. **Teardown**: Call {@link teardownResource `teardownResource`} before unmounting iframe
128
+ *
129
+ * @example Basic usage
130
+ * ```ts source="./app-bridge.examples.ts#AppBridge_basicUsage"
131
+ * // Create MCP client for the server
132
+ * const client = new Client({
133
+ * name: "MyHost",
134
+ * version: "1.0.0",
135
+ * });
136
+ * await client.connect(serverTransport);
137
+ *
138
+ * // Create bridge for the View
139
+ * const bridge = new AppBridge(
140
+ * client,
141
+ * { name: "MyHost", version: "1.0.0" },
142
+ * { openLinks: {}, serverTools: {}, logging: {} },
143
+ * );
144
+ *
145
+ * // Set up iframe and connect
146
+ * const iframe = document.getElementById("app") as HTMLIFrameElement;
147
+ * const transport = new PostMessageTransport(
148
+ * iframe.contentWindow!,
149
+ * iframe.contentWindow!,
150
+ * );
151
+ *
152
+ * bridge.oninitialized = () => {
153
+ * console.log("View initialized");
154
+ * // Now safe to send tool input
155
+ * bridge.sendToolInput({ arguments: { location: "NYC" } });
156
+ * };
157
+ *
158
+ * await bridge.connect(transport);
159
+ * ```
160
+ */
161
+ export declare class AppBridge extends Protocol<BaseContext> {
162
+ private _client;
163
+ private _hostInfo;
164
+ private _hostCapabilities;
165
+ private _appCapabilities?;
166
+ private _hostContext;
167
+ private _appInfo?;
168
+ private _initializedReceived;
169
+ private readonly _registeredEvents;
170
+ private readonly _events;
171
+ private readonly _methods;
172
+ /**
173
+ * Registers a request handler. Throws if a handler for the same method has
174
+ * already been registered — use the `on*` setter for replace semantics.
175
+ *
176
+ * @throws {Error} if a handler for this method is already registered.
177
+ */
178
+ setRequestHandler: LegacyRequestHandlerSetter<Protocol<BaseContext>["setRequestHandler"]>;
179
+ /**
180
+ * Registers a notification handler. Throws if a handler for the same method
181
+ * has already been registered — use the `on*` setter (replace semantics) or
182
+ * `addEventListener` (multi-listener) for mapped events.
183
+ *
184
+ * @throws {Error} if a handler for this method is already registered.
185
+ */
186
+ setNotificationHandler: LegacyNotificationHandlerSetter<Protocol<BaseContext>["setNotificationHandler"]>;
187
+ removeRequestHandler: Protocol<BaseContext>["removeRequestHandler"];
188
+ removeNotificationHandler: Protocol<BaseContext>["removeNotificationHandler"];
189
+ /**
190
+ * Register a request handler with replace semantics, bypassing the
191
+ * double-set protection of {@link setRequestHandler `setRequestHandler`}.
192
+ * Used by the `on*` request-handler setters.
193
+ */
194
+ protected replaceRequestHandler: Protocol<BaseContext>["setRequestHandler"];
195
+ /**
196
+ * The base MCP SDK calls this hook for every standard and custom request
197
+ * handler registration. AppBridge uses it to preserve the existing warning
198
+ * when a View calls host methods before `ui/notifications/initialized`,
199
+ * without adding overload-forwarding adapters around `setRequestHandler`.
200
+ * `ui/initialize` and `ping` are exempt because they are valid before the
201
+ * Apps-ready gate. This wraps registered callbacks, not JSON-RPC dispatch.
202
+ *
203
+ * @see {@link https://github.com/anthropics/claude-ai-mcp/issues/149 claude-ai-mcp#149}
204
+ */
205
+ protected _wrapHandler(method: string, handler: (request: JSONRPCRequest, context: BaseContext) => Promise<Result>): (request: JSONRPCRequest, context: BaseContext) => Promise<Result>;
206
+ private readonly eventSchemas;
207
+ protected setEventHandler<K extends keyof AppBridgeEventMap>(event: K, handler: ((params: AppBridgeEventMap[K]) => void) | undefined): void;
208
+ protected getEventHandler<K extends keyof AppBridgeEventMap>(event: K): ((params: AppBridgeEventMap[K]) => void) | undefined;
209
+ addEventListener<K extends keyof AppBridgeEventMap>(event: K, handler: (params: AppBridgeEventMap[K]) => void): void;
210
+ removeEventListener<K extends keyof AppBridgeEventMap>(event: K, handler: (params: AppBridgeEventMap[K]) => void): void;
211
+ private _ensureEventSlot;
212
+ protected warnIfRequestHandlerReplaced(name: string, previous: unknown, next: unknown): void;
213
+ /**
214
+ * Create a new AppBridge instance.
215
+ *
216
+ * @param _client - MCP client connected to the server, or `null`. When provided,
217
+ * {@link connect `connect`} will automatically set up forwarding of MCP requests/notifications
218
+ * between the View and the server. When `null`, you must register handlers
219
+ * manually using the {@link oncalltool `oncalltool`}, {@link onlistresources `onlistresources`}, etc. setters.
220
+ * @param _hostInfo - Host application identification (name and version)
221
+ * @param _hostCapabilities - Features and capabilities the host supports
222
+ * @param options - Configuration options (`ProtocolOptions` from the base MCP SDK plus `hostContext`)
223
+ *
224
+ * @example With MCP client (automatic forwarding)
225
+ * ```ts source="./app-bridge.examples.ts#AppBridge_constructor_withMcpClient"
226
+ * const bridge = new AppBridge(
227
+ * mcpClient,
228
+ * { name: "MyHost", version: "1.0.0" },
229
+ * { openLinks: {}, serverTools: {}, logging: {} },
230
+ * );
231
+ * ```
232
+ *
233
+ * @example Without MCP client (manual handlers)
234
+ * ```ts source="./app-bridge.examples.ts#AppBridge_constructor_withoutMcpClient"
235
+ * const bridge = new AppBridge(
236
+ * null,
237
+ * { name: "MyHost", version: "1.0.0" },
238
+ * { openLinks: {}, serverTools: {}, logging: {} },
239
+ * );
240
+ * bridge.oncalltool = async (params, extra) => {
241
+ * // Handle tool calls manually
242
+ * return { content: [] };
243
+ * };
244
+ * ```
245
+ */
246
+ constructor(_client: Client | null, _hostInfo: Implementation, _hostCapabilities: McpUiHostCapabilities, options?: HostOptions);
247
+ /** @internal */
248
+ protected buildContext(ctx: BaseContext): BaseContext;
249
+ /**
250
+ * Verify that the view supports the capability required for the given request method.
251
+ * @internal
252
+ */
253
+ protected assertCapabilityForMethod(_method: string): void;
254
+ /**
255
+ * Verify that a request handler is registered and supported for the given method.
256
+ * @internal
257
+ */
258
+ protected assertRequestHandlerCapability(_method: string): void;
259
+ /**
260
+ * Verify that the host supports the capability required for the given notification method.
261
+ * @internal
262
+ */
263
+ protected assertNotificationCapability(_method: string): void;
264
+ /**
265
+ * Get the view's capabilities discovered during initialization.
266
+ *
267
+ * Returns the capabilities that the view advertised during its
268
+ * initialization request. Returns `undefined` if called before
269
+ * initialization completes.
270
+ *
271
+ * @returns view capabilities, or `undefined` if not yet initialized
272
+ *
273
+ * @example Check view capabilities after initialization
274
+ * ```ts source="./app-bridge.examples.ts#AppBridge_getAppCapabilities_checkAfterInit"
275
+ * bridge.oninitialized = () => {
276
+ * const caps = bridge.getAppCapabilities();
277
+ * if (caps?.tools) {
278
+ * console.log("View provides tools");
279
+ * }
280
+ * };
281
+ * ```
282
+ *
283
+ * @see {@link McpUiAppCapabilities `McpUiAppCapabilities`} for the capabilities structure
284
+ */
285
+ getAppCapabilities(): McpUiAppCapabilities | undefined;
286
+ /**
287
+ * Get the view's implementation info discovered during initialization.
288
+ *
289
+ * Returns the view's name and version as provided in its initialization
290
+ * request. Returns `undefined` if called before initialization completes.
291
+ *
292
+ * @returns view implementation info, or `undefined` if not yet initialized
293
+ *
294
+ * @example Log view information after initialization
295
+ * ```ts source="./app-bridge.examples.ts#AppBridge_getAppVersion_logAfterInit"
296
+ * bridge.oninitialized = () => {
297
+ * const appInfo = bridge.getAppVersion();
298
+ * if (appInfo) {
299
+ * console.log(`View: ${appInfo.name} v${appInfo.version}`);
300
+ * }
301
+ * };
302
+ * ```
303
+ */
304
+ getAppVersion(): Implementation | undefined;
305
+ /**
306
+ * Optional handler for ping requests from the view.
307
+ *
308
+ * The View can send standard MCP `ping` requests to verify the connection
309
+ * is alive. The {@link AppBridge `AppBridge`} automatically responds with an empty object, but this
310
+ * handler allows the host to observe or log ping activity.
311
+ *
312
+ * Unlike the other handlers which use setters, this is a direct property
313
+ * assignment. It is optional; if not set, pings are still handled automatically.
314
+ *
315
+ * @param params - Empty params object from the ping request
316
+ * @param extra - Request metadata (abort signal, session info)
317
+ *
318
+ * @example
319
+ * ```ts source="./app-bridge.examples.ts#AppBridge_onping_handleRequest"
320
+ * bridge.onping = (params, extra) => {
321
+ * console.log("Received ping from view");
322
+ * };
323
+ * ```
324
+ */
325
+ onping?: (params: PingRequest["params"], extra: RequestHandlerExtra) => void;
326
+ /**
327
+ * Register a handler for size change notifications from the view.
328
+ *
329
+ * The view sends `ui/notifications/size-changed` when its rendered content
330
+ * size changes, typically via `ResizeObserver`. Set this callback to dynamically
331
+ * adjust the iframe container dimensions based on the view's content.
332
+ *
333
+ * Note: This is for View → Host communication. To notify the View of
334
+ * host container dimension changes, use {@link setHostContext `setHostContext`}.
335
+ *
336
+ * @example
337
+ * ```ts source="./app-bridge.examples.ts#AppBridge_onsizechange_handleResize"
338
+ * bridge.onsizechange = ({ width, height }) => {
339
+ * if (width != null) {
340
+ * iframe.style.width = `${width}px`;
341
+ * }
342
+ * if (height != null) {
343
+ * iframe.style.height = `${height}px`;
344
+ * }
345
+ * };
346
+ * ```
347
+ *
348
+ * @see {@link McpUiSizeChangedNotification `McpUiSizeChangedNotification`} for the notification type
349
+ * @see {@link app!App.sendSizeChanged `App.sendSizeChanged`} - the View method that sends these notifications
350
+ * @deprecated Use {@link addEventListener `addEventListener("sizechange", handler)`} instead — it composes with other listeners and supports cleanup via {@link removeEventListener `removeEventListener`}.
351
+ */
352
+ get onsizechange(): ((params: McpUiSizeChangedNotification["params"]) => void) | undefined;
353
+ set onsizechange(callback: ((params: McpUiSizeChangedNotification["params"]) => void) | undefined);
354
+ /**
355
+ * Register a handler for sandbox proxy ready notifications.
356
+ *
357
+ * This is an internal callback used by web-based hosts implementing the
358
+ * double-iframe sandbox architecture. The sandbox proxy sends
359
+ * `ui/notifications/sandbox-proxy-ready` after it loads and is ready to receive
360
+ * HTML content.
361
+ *
362
+ * When this fires, the host should call {@link sendSandboxResourceReady `sendSandboxResourceReady`} with
363
+ * the HTML content to load into the inner sandboxed iframe.
364
+ *
365
+ * @example
366
+ * ```typescript
367
+ * bridge.onsandboxready = async () => {
368
+ * const resource = await mcpClient.request(
369
+ * { method: "resources/read", params: { uri: "ui://my-app" } }
370
+ * );
371
+ *
372
+ * bridge.sendSandboxResourceReady({
373
+ * html: resource.contents[0].text,
374
+ * sandbox: "allow-scripts"
375
+ * });
376
+ * };
377
+ * ```
378
+ *
379
+ * @internal
380
+ * @see {@link McpUiSandboxProxyReadyNotification `McpUiSandboxProxyReadyNotification`} for the notification type
381
+ * @see {@link sendSandboxResourceReady `sendSandboxResourceReady`} for sending content to the sandbox
382
+ * @deprecated Use {@link addEventListener `addEventListener("sandboxready", handler)`} instead — it composes with other listeners and supports cleanup via {@link removeEventListener `removeEventListener`}.
383
+ */
384
+ get onsandboxready(): ((params: McpUiSandboxProxyReadyNotification["params"]) => void) | undefined;
385
+ set onsandboxready(callback: ((params: McpUiSandboxProxyReadyNotification["params"]) => void) | undefined);
386
+ /**
387
+ * Called when the view completes initialization.
388
+ *
389
+ * Set this callback to be notified when the view has finished its
390
+ * initialization handshake and is ready to receive tool input and other data.
391
+ *
392
+ * @example
393
+ * ```ts source="./app-bridge.examples.ts#AppBridge_oninitialized_sendToolInput"
394
+ * bridge.oninitialized = () => {
395
+ * console.log("View ready");
396
+ * bridge.sendToolInput({ arguments: toolArgs });
397
+ * };
398
+ * ```
399
+ *
400
+ * @see {@link McpUiInitializedNotification `McpUiInitializedNotification`} for the notification type
401
+ * @see {@link sendToolInput `sendToolInput`} for sending tool arguments to the View
402
+ * @deprecated Use {@link addEventListener `addEventListener("initialized", handler)`} instead — it composes with other listeners and supports cleanup via {@link removeEventListener `removeEventListener`}.
403
+ */
404
+ get oninitialized(): ((params?: McpUiInitializedNotification["params"]) => void) | undefined;
405
+ set oninitialized(callback: ((params?: McpUiInitializedNotification["params"]) => void) | undefined);
406
+ /**
407
+ * Register a handler for message requests from the view.
408
+ *
409
+ * The view sends `ui/message` requests when it wants to add a message to
410
+ * the host's chat interface. This enables interactive apps to communicate with
411
+ * the user through the conversation thread.
412
+ *
413
+ * The handler should process the message (add it to the chat) and return a
414
+ * result indicating success or failure. For security, the host should NOT
415
+ * return conversation content or follow-up results to prevent information
416
+ * leakage.
417
+ *
418
+ * @param callback - Handler that receives message params and returns a result
419
+ * - `params.role` - Message role (currently only "user" is supported)
420
+ * - `params.content` - Message content blocks (text, image, etc.)
421
+ * - `extra` - Request metadata (abort signal, session info)
422
+ * - Returns: `Promise<McpUiMessageResult>` with optional `isError` flag
423
+ *
424
+ * @example
425
+ * ```ts source="./app-bridge.examples.ts#AppBridge_onmessage_logMessage"
426
+ * bridge.onmessage = async ({ role, content }, extra) => {
427
+ * try {
428
+ * await chatManager.addMessage({ role, content, source: "app" });
429
+ * return {}; // Success
430
+ * } catch (error) {
431
+ * console.error("Failed to add message:", error);
432
+ * return { isError: true };
433
+ * }
434
+ * };
435
+ * ```
436
+ *
437
+ * @see {@link McpUiMessageRequest `McpUiMessageRequest`} for the request type
438
+ * @see {@link McpUiMessageResult `McpUiMessageResult`} for the result type
439
+ */
440
+ private _onmessage?;
441
+ get onmessage(): ((params: McpUiMessageRequest["params"], extra: RequestHandlerExtra) => Promise<McpUiMessageResult>) | undefined;
442
+ set onmessage(callback: ((params: McpUiMessageRequest["params"], extra: RequestHandlerExtra) => Promise<McpUiMessageResult>) | undefined);
443
+ /**
444
+ * Register a handler for external link requests from the view.
445
+ *
446
+ * The view sends `ui/open-link` requests when it wants to open an external
447
+ * URL in the host's default browser. The handler should validate the URL and
448
+ * open it according to the host's security policy and user preferences.
449
+ *
450
+ * The host MAY:
451
+ * - Show a confirmation dialog before opening
452
+ * - Block URLs based on a security policy or allowlist
453
+ * - Log the request for audit purposes
454
+ * - Reject the request entirely
455
+ *
456
+ * @param callback - Handler that receives URL params and returns a result
457
+ * - `params.url` - URL to open in the host's browser
458
+ * - `extra` - Request metadata (abort signal, session info)
459
+ * - Returns: `Promise<McpUiOpenLinkResult>` with optional `isError` flag
460
+ *
461
+ * @example
462
+ * ```ts source="./app-bridge.examples.ts#AppBridge_onopenlink_handleRequest"
463
+ * bridge.onopenlink = async ({ url }, extra) => {
464
+ * if (!isAllowedDomain(url)) {
465
+ * console.warn("Blocked external link:", url);
466
+ * return { isError: true };
467
+ * }
468
+ *
469
+ * const confirmed = await showDialog({
470
+ * message: `Open external link?\n${url}`,
471
+ * buttons: ["Open", "Cancel"],
472
+ * });
473
+ *
474
+ * if (confirmed) {
475
+ * window.open(url, "_blank", "noopener,noreferrer");
476
+ * return {};
477
+ * }
478
+ *
479
+ * return { isError: true };
480
+ * };
481
+ * ```
482
+ *
483
+ * @see {@link McpUiOpenLinkRequest `McpUiOpenLinkRequest`} for the request type
484
+ * @see {@link McpUiOpenLinkResult `McpUiOpenLinkResult`} for the result type
485
+ */
486
+ private _onopenlink?;
487
+ get onopenlink(): ((params: McpUiOpenLinkRequest["params"], extra: RequestHandlerExtra) => Promise<McpUiOpenLinkResult>) | undefined;
488
+ set onopenlink(callback: ((params: McpUiOpenLinkRequest["params"], extra: RequestHandlerExtra) => Promise<McpUiOpenLinkResult>) | undefined);
489
+ /**
490
+ * Register a handler for file download requests from the View.
491
+ *
492
+ * The View sends `ui/download-file` requests when the user wants to
493
+ * download a file. The params contain an array of MCP resource content
494
+ * items — either `EmbeddedResource` (inline data) or `ResourceLink`
495
+ * (URI the host can fetch). The host should show a confirmation dialog
496
+ * and then trigger the download.
497
+ *
498
+ * @param callback - Handler that receives download params and returns a result
499
+ * - `params.contents` - Array of `EmbeddedResource` or `ResourceLink` items
500
+ * - `extra` - Request metadata (abort signal, session info)
501
+ * - Returns: `Promise<McpUiDownloadFileResult>` with optional `isError` flag
502
+ *
503
+ * @example
504
+ * ```ts
505
+ * bridge.ondownloadfile = async ({ contents }, extra) => {
506
+ * for (const item of contents) {
507
+ * if (item.type === "resource") {
508
+ * // EmbeddedResource — inline content
509
+ * const res = item.resource;
510
+ * const blob = res.blob
511
+ * ? new Blob([Uint8Array.from(atob(res.blob), c => c.charCodeAt(0))], { type: res.mimeType })
512
+ * : new Blob([res.text ?? ""], { type: res.mimeType });
513
+ * const url = URL.createObjectURL(blob);
514
+ * const link = document.createElement("a");
515
+ * link.href = url;
516
+ * link.download = res.uri.split("/").pop() ?? "download";
517
+ * link.click();
518
+ * URL.revokeObjectURL(url);
519
+ * } else if (item.type === "resource_link") {
520
+ * // ResourceLink — host fetches or opens directly
521
+ * window.open(item.uri, "_blank");
522
+ * }
523
+ * }
524
+ * return {};
525
+ * };
526
+ * ```
527
+ *
528
+ * @see {@link McpUiDownloadFileRequest `McpUiDownloadFileRequest`} for the request type
529
+ * @see {@link McpUiDownloadFileResult `McpUiDownloadFileResult`} for the result type
530
+ */
531
+ private _ondownloadfile?;
532
+ get ondownloadfile(): ((params: McpUiDownloadFileRequest["params"], extra: RequestHandlerExtra) => Promise<McpUiDownloadFileResult>) | undefined;
533
+ set ondownloadfile(callback: ((params: McpUiDownloadFileRequest["params"], extra: RequestHandlerExtra) => Promise<McpUiDownloadFileResult>) | undefined);
534
+ /**
535
+ * Register a handler for app-initiated teardown request notifications from the view.
536
+ *
537
+ * The view sends `ui/notifications/request-teardown` when it wants the host to tear it down.
538
+ * If the host decides to proceed, it should send
539
+ * `ui/resource-teardown` (via {@link teardownResource `teardownResource`}) to allow
540
+ * the view to perform gracefull termination, then unmount the iframe after the view responds.
541
+ *
542
+ * @example
543
+ * ```typescript
544
+ * bridge.onrequestteardown = async (params) => {
545
+ * console.log("App requested teardown");
546
+ * // Initiate teardown to allow the app to persist unsaved state
547
+ * // Alternatively, the callback can early return to prevent teardown
548
+ * await bridge.teardownResource({});
549
+ * // Now safe to unmount the iframe
550
+ * iframe.remove();
551
+ * };
552
+ * ```
553
+ *
554
+ * @see {@link McpUiRequestTeardownNotification `McpUiRequestTeardownNotification`} for the notification type
555
+ * @see {@link teardownResource `teardownResource`} for initiating teardown
556
+ * @deprecated Use {@link addEventListener `addEventListener("requestteardown", handler)`} instead — it composes with other listeners and supports cleanup via {@link removeEventListener `removeEventListener`}.
557
+ */
558
+ get onrequestteardown(): ((params: McpUiRequestTeardownNotification["params"]) => void) | undefined;
559
+ set onrequestteardown(callback: ((params: McpUiRequestTeardownNotification["params"]) => void) | undefined);
560
+ /**
561
+ * Register a handler for display mode change requests from the view.
562
+ *
563
+ * The view sends `ui/request-display-mode` requests when it wants to change
564
+ * its display mode (e.g., from "inline" to "fullscreen"). The handler should
565
+ * check if the requested mode is in `availableDisplayModes` from the host context,
566
+ * update the display mode if supported, and return the actual mode that was set.
567
+ *
568
+ * If the requested mode is not available, the handler should return the current
569
+ * display mode instead.
570
+ *
571
+ * By default, `AppBridge` returns the current `displayMode` from host context (or "inline").
572
+ * Setting this property replaces that default behavior.
573
+ *
574
+ * @param callback - Handler that receives the requested mode and returns the actual mode set
575
+ * - `params.mode` - The display mode being requested ("inline" | "fullscreen" | "pip")
576
+ * - `extra` - Request metadata (abort signal, session info)
577
+ * - Returns: `Promise<McpUiRequestDisplayModeResult>` with the actual mode set
578
+ *
579
+ * @example
580
+ * ```ts source="./app-bridge.examples.ts#AppBridge_onrequestdisplaymode_handleRequest"
581
+ * bridge.onrequestdisplaymode = async ({ mode }, extra) => {
582
+ * if (availableDisplayModes.includes(mode)) {
583
+ * currentDisplayMode = mode;
584
+ * }
585
+ * return { mode: currentDisplayMode };
586
+ * };
587
+ * ```
588
+ *
589
+ * @see {@link McpUiRequestDisplayModeRequest `McpUiRequestDisplayModeRequest`} for the request type
590
+ * @see {@link McpUiRequestDisplayModeResult `McpUiRequestDisplayModeResult`} for the result type
591
+ */
592
+ private _onrequestdisplaymode?;
593
+ get onrequestdisplaymode(): ((params: McpUiRequestDisplayModeRequest["params"], extra: RequestHandlerExtra) => Promise<McpUiRequestDisplayModeResult>) | undefined;
594
+ set onrequestdisplaymode(callback: ((params: McpUiRequestDisplayModeRequest["params"], extra: RequestHandlerExtra) => Promise<McpUiRequestDisplayModeResult>) | undefined);
595
+ /**
596
+ * Register a handler for logging messages from the view.
597
+ *
598
+ * The view sends standard MCP `notifications/message` (logging) notifications
599
+ * to report debugging information, errors, warnings, and other telemetry to the
600
+ * host. The host can display these in a console, log them to a file, or send
601
+ * them to a monitoring service.
602
+ *
603
+ * This uses the standard MCP logging notification format, not a UI-specific
604
+ * message type.
605
+ *
606
+ * The handler receives `LoggingMessageNotification["params"]`:
607
+ * - `level` — "debug" | "info" | "notice" | "warning" | "error" | "critical" | "alert" | "emergency"
608
+ * - `logger` — optional logger name/identifier
609
+ * - `data` — log message and optional structured data
610
+ *
611
+ * @example
612
+ * ```ts source="./app-bridge.examples.ts#AppBridge_onloggingmessage_handleLog"
613
+ * bridge.onloggingmessage = ({ level, logger, data }) => {
614
+ * console[level === "error" ? "error" : "log"](
615
+ * `[${logger ?? "View"}] ${level.toUpperCase()}:`,
616
+ * data,
617
+ * );
618
+ * };
619
+ * ```
620
+ * @deprecated Use {@link addEventListener `addEventListener("loggingmessage", handler)`} instead — it composes with other listeners and supports cleanup via {@link removeEventListener `removeEventListener`}.
621
+ */
622
+ get onloggingmessage(): ((params: LoggingMessageNotification["params"]) => void) | undefined;
623
+ set onloggingmessage(callback: ((params: LoggingMessageNotification["params"]) => void) | undefined);
624
+ /**
625
+ * Register a handler for model context updates from the view.
626
+ *
627
+ * The view sends `ui/update-model-context` requests to update the Host's
628
+ * model context. Each request overwrites the previous context stored by the view.
629
+ * Unlike logging messages, context updates are intended to be available to
630
+ * the model in future turns. Unlike messages, context updates do not trigger follow-ups.
631
+ *
632
+ * The host will typically defer sending the context to the model until the
633
+ * next user message (including `ui/message`), and will only send the last
634
+ * update received.
635
+ *
636
+ * @example
637
+ * ```ts source="./app-bridge.examples.ts#AppBridge_onupdatemodelcontext_storeContext"
638
+ * bridge.onupdatemodelcontext = async (
639
+ * { content, structuredContent },
640
+ * extra,
641
+ * ) => {
642
+ * // Store the context snapshot for inclusion in the next model request
643
+ * modelContextManager.update({ content, structuredContent });
644
+ * return {};
645
+ * };
646
+ * ```
647
+ *
648
+ * @see {@link McpUiUpdateModelContextRequest `McpUiUpdateModelContextRequest`} for the request type
649
+ */
650
+ private _onupdatemodelcontext?;
651
+ get onupdatemodelcontext(): ((params: McpUiUpdateModelContextRequest["params"], extra: RequestHandlerExtra) => Promise<EmptyResult>) | undefined;
652
+ set onupdatemodelcontext(callback: ((params: McpUiUpdateModelContextRequest["params"], extra: RequestHandlerExtra) => Promise<EmptyResult>) | undefined);
653
+ /**
654
+ * Register a handler for tool call requests from the view.
655
+ *
656
+ * The view sends `tools/call` requests to execute MCP server tools. This
657
+ * handler allows the host to intercept and process these requests, typically
658
+ * by forwarding them to the MCP server.
659
+ *
660
+ * @param callback - Handler that receives tool call params and returns a
661
+ * `CallToolResult`
662
+ * - `params` - Tool call parameters (name and arguments)
663
+ * - `extra` - Request metadata (abort signal, session info)
664
+ *
665
+ * @example
666
+ * ```ts source="./app-bridge.examples.ts#AppBridge_oncalltool_forwardToServer"
667
+ * bridge.oncalltool = async (params, extra) => {
668
+ * return mcpClient.request(
669
+ * { method: "tools/call", params },
670
+ * { signal: extra.mcpReq.signal },
671
+ * );
672
+ * };
673
+ * ```
674
+ *
675
+ * @see `CallToolRequest` from @modelcontextprotocol/client for the request type
676
+ * @see `CallToolResult` from @modelcontextprotocol/client for the result type
677
+ */
678
+ private _oncalltool?;
679
+ get oncalltool(): ((params: CallToolRequest["params"], extra: RequestHandlerExtra) => Promise<CallToolResult>) | undefined;
680
+ set oncalltool(callback: ((params: CallToolRequest["params"], extra: RequestHandlerExtra) => Promise<CallToolResult>) | undefined);
681
+ /**
682
+ * Register a handler for LLM sampling requests from the view.
683
+ *
684
+ * The view sends standard MCP `sampling/createMessage` requests to obtain
685
+ * LLM completions via the host's model connection. The host has full
686
+ * discretion over which model to use and SHOULD apply rate limiting,
687
+ * cost controls, and user approval (human-in-the-loop) before sampling.
688
+ *
689
+ * Hosts that register this handler SHOULD advertise `sampling` (and
690
+ * `sampling.tools` if tool-calling is supported) in
691
+ * {@link McpUiHostCapabilities `McpUiHostCapabilities`}.
692
+ *
693
+ * @param callback - Handler that receives `CreateMessageRequest` params and
694
+ * returns a `CreateMessageResult` (or `CreateMessageResultWithTools` when
695
+ * `params.tools` was provided)
696
+ * - `params` - Standard MCP sampling params (messages, maxTokens, tools, etc.)
697
+ * - `extra` - Request metadata (abort signal, session info)
698
+ *
699
+ * @example Forward to your LLM provider
700
+ * ```ts source="./app-bridge.examples.ts#AppBridge_oncreatesamplingmessage_forwardToLlm"
701
+ * bridge.oncreatesamplingmessage = async (params, extra) => {
702
+ * // Apply rate limiting, user approval, cost controls here
703
+ * return await myLlmProvider.complete(params, {
704
+ * signal: extra.mcpReq.signal,
705
+ * });
706
+ * };
707
+ * ```
708
+ *
709
+ * @see `CreateMessageRequest` from @modelcontextprotocol/client for the request type
710
+ * @see `CreateMessageResult` / `CreateMessageResultWithTools` from @modelcontextprotocol/client for result types
711
+ */
712
+ private _oncreatesamplingmessage?;
713
+ get oncreatesamplingmessage(): ((params: CreateMessageRequest["params"], extra: RequestHandlerExtra) => Promise<CreateMessageResult | CreateMessageResultWithTools>) | undefined;
714
+ set oncreatesamplingmessage(callback: ((params: CreateMessageRequest["params"], extra: RequestHandlerExtra) => Promise<CreateMessageResult | CreateMessageResultWithTools>) | undefined);
715
+ /**
716
+ * Notify the view that the MCP server's tool list has changed.
717
+ *
718
+ * The host sends `notifications/tools/list_changed` to the view when it
719
+ * receives this notification from the MCP server. This allows the view
720
+ * to refresh its tool cache or UI accordingly.
721
+ *
722
+ * @param params - Optional notification params (typically empty)
723
+ *
724
+ * @example
725
+ * ```typescript
726
+ * // In your MCP client notification handler:
727
+ * mcpClient.setNotificationHandler("notifications/tools/list_changed", () => {
728
+ * bridge.sendToolListChanged();
729
+ * });
730
+ * ```
731
+ *
732
+ * @see `ToolListChangedNotification` from @modelcontextprotocol/client for the notification type
733
+ */
734
+ sendToolListChanged(params?: ToolListChangedNotification["params"]): Promise<void>;
735
+ /**
736
+ * Register a handler for list resources requests from the view.
737
+ *
738
+ * The view sends `resources/list` requests to enumerate available MCP
739
+ * resources. This handler allows the host to intercept and process these
740
+ * requests, typically by forwarding them to the MCP server.
741
+ *
742
+ * @param callback - Handler that receives list params and returns a
743
+ * `ListResourcesResult`
744
+ * - `params` - Request params (may include cursor for pagination)
745
+ * - `extra` - Request metadata (abort signal, session info)
746
+ *
747
+ * @example
748
+ * ```ts source="./app-bridge.examples.ts#AppBridge_onlistresources_returnResources"
749
+ * bridge.onlistresources = async (params, extra) => {
750
+ * return mcpClient.request(
751
+ * { method: "resources/list", params },
752
+ * { signal: extra.mcpReq.signal },
753
+ * );
754
+ * };
755
+ * ```
756
+ *
757
+ * @see `ListResourcesRequest` from @modelcontextprotocol/client for the request type
758
+ * @see `ListResourcesResult` from @modelcontextprotocol/client for the result type
759
+ */
760
+ private _onlistresources?;
761
+ get onlistresources(): ((params: ListResourcesRequest["params"], extra: RequestHandlerExtra) => Promise<ListResourcesResult>) | undefined;
762
+ set onlistresources(callback: ((params: ListResourcesRequest["params"], extra: RequestHandlerExtra) => Promise<ListResourcesResult>) | undefined);
763
+ /**
764
+ * Register a handler for list resource templates requests from the view.
765
+ *
766
+ * The view sends `resources/templates/list` requests to enumerate available
767
+ * MCP resource templates. This handler allows the host to intercept and process
768
+ * these requests, typically by forwarding them to the MCP server.
769
+ *
770
+ * @param callback - Handler that receives list params and returns a
771
+ * `ListResourceTemplatesResult`
772
+ * - `params` - Request params (may include cursor for pagination)
773
+ * - `extra` - Request metadata (abort signal, session info)
774
+ *
775
+ * @example
776
+ * ```typescript
777
+ * bridge.onlistresourcetemplates = async (params, extra) => {
778
+ * return mcpClient.request(
779
+ * { method: "resources/templates/list", params },
780
+ * { signal: extra.mcpReq.signal }
781
+ * );
782
+ * };
783
+ * ```
784
+ *
785
+ * @see `ListResourceTemplatesRequest` from @modelcontextprotocol/client for the request type
786
+ * @see `ListResourceTemplatesResult` from @modelcontextprotocol/client for the result type
787
+ */
788
+ private _onlistresourcetemplates?;
789
+ get onlistresourcetemplates(): ((params: ListResourceTemplatesRequest["params"], extra: RequestHandlerExtra) => Promise<ListResourceTemplatesResult>) | undefined;
790
+ set onlistresourcetemplates(callback: ((params: ListResourceTemplatesRequest["params"], extra: RequestHandlerExtra) => Promise<ListResourceTemplatesResult>) | undefined);
791
+ /**
792
+ * Register a handler for read resource requests from the view.
793
+ *
794
+ * The view sends `resources/read` requests to retrieve the contents of an
795
+ * MCP resource. This handler allows the host to intercept and process these
796
+ * requests, typically by forwarding them to the MCP server.
797
+ *
798
+ * @param callback - Handler that receives read params and returns a
799
+ * `ReadResourceResult`
800
+ * - `params` - Read parameters including the resource URI
801
+ * - `extra` - Request metadata (abort signal, session info)
802
+ *
803
+ * @example
804
+ * ```ts source="./app-bridge.examples.ts#AppBridge_onreadresource_returnResource"
805
+ * bridge.onreadresource = async (params, extra) => {
806
+ * return mcpClient.request(
807
+ * { method: "resources/read", params },
808
+ * { signal: extra.mcpReq.signal },
809
+ * );
810
+ * };
811
+ * ```
812
+ *
813
+ * @see `ReadResourceRequest` from @modelcontextprotocol/client for the request type
814
+ * @see `ReadResourceResult` from @modelcontextprotocol/client for the result type
815
+ */
816
+ private _onreadresource?;
817
+ get onreadresource(): ((params: ReadResourceRequest["params"], extra: RequestHandlerExtra) => Promise<ReadResourceResult>) | undefined;
818
+ set onreadresource(callback: ((params: ReadResourceRequest["params"], extra: RequestHandlerExtra) => Promise<ReadResourceResult>) | undefined);
819
+ /**
820
+ * Notify the view that the MCP server's resource list has changed.
821
+ *
822
+ * The host sends `notifications/resources/list_changed` to the view when it
823
+ * receives this notification from the MCP server. This allows the view
824
+ * to refresh its resource cache or UI accordingly.
825
+ *
826
+ * @param params - Optional notification params (typically empty)
827
+ *
828
+ * @example
829
+ * ```typescript
830
+ * // In your MCP client notification handler:
831
+ * mcpClient.setNotificationHandler("notifications/resources/list_changed", () => {
832
+ * bridge.sendResourceListChanged();
833
+ * });
834
+ * ```
835
+ *
836
+ * @see `ResourceListChangedNotification` from @modelcontextprotocol/client for the notification type
837
+ */
838
+ sendResourceListChanged(params?: ResourceListChangedNotification["params"]): Promise<void>;
839
+ /**
840
+ * Register a handler for list prompts requests from the view.
841
+ *
842
+ * The view sends `prompts/list` requests to enumerate available MCP
843
+ * prompts. This handler allows the host to intercept and process these
844
+ * requests, typically by forwarding them to the MCP server.
845
+ *
846
+ * @param callback - Handler that receives list params and returns a
847
+ * `ListPromptsResult`
848
+ * - `params` - Request params (may include cursor for pagination)
849
+ * - `extra` - Request metadata (abort signal, session info)
850
+ *
851
+ * @example
852
+ * ```ts source="./app-bridge.examples.ts#AppBridge_onlistprompts_returnPrompts"
853
+ * bridge.onlistprompts = async (params, extra) => {
854
+ * return mcpClient.request(
855
+ * { method: "prompts/list", params },
856
+ * { signal: extra.mcpReq.signal },
857
+ * );
858
+ * };
859
+ * ```
860
+ *
861
+ * @see `ListPromptsRequest` from @modelcontextprotocol/client for the request type
862
+ * @see `ListPromptsResult` from @modelcontextprotocol/client for the result type
863
+ */
864
+ private _onlistprompts?;
865
+ get onlistprompts(): ((params: ListPromptsRequest["params"], extra: RequestHandlerExtra) => Promise<ListPromptsResult>) | undefined;
866
+ set onlistprompts(callback: ((params: ListPromptsRequest["params"], extra: RequestHandlerExtra) => Promise<ListPromptsResult>) | undefined);
867
+ /**
868
+ * Notify the view that the MCP server's prompt list has changed.
869
+ *
870
+ * The host sends `notifications/prompts/list_changed` to the view when it
871
+ * receives this notification from the MCP server. This allows the view
872
+ * to refresh its prompt cache or UI accordingly.
873
+ *
874
+ * @param params - Optional notification params (typically empty)
875
+ *
876
+ * @example
877
+ * ```typescript
878
+ * // In your MCP client notification handler:
879
+ * mcpClient.setNotificationHandler("notifications/prompts/list_changed", () => {
880
+ * bridge.sendPromptListChanged();
881
+ * });
882
+ * ```
883
+ *
884
+ * @see `PromptListChangedNotification` from @modelcontextprotocol/client for the notification type
885
+ */
886
+ sendPromptListChanged(params?: PromptListChangedNotification["params"]): Promise<void>;
887
+ /**
888
+ * Get the host capabilities passed to the constructor.
889
+ *
890
+ * @returns Host capabilities object
891
+ *
892
+ * @see {@link McpUiHostCapabilities `McpUiHostCapabilities`} for the capabilities structure
893
+ */
894
+ getCapabilities(): McpUiHostCapabilities;
895
+ /**
896
+ * Handle the ui/initialize request from the guest.
897
+ * @internal
898
+ */
899
+ private _onAppsInitialize;
900
+ /**
901
+ * Update the host context and notify the view of changes.
902
+ *
903
+ * Compares fields present in the new context with the current context and sends a
904
+ * `ui/notifications/host-context-changed` notification containing only fields
905
+ * that have been added or modified. If no fields have changed, no notification is sent.
906
+ * The new context fully replaces the internal state.
907
+ *
908
+ * Common use cases include notifying the view when:
909
+ * - Theme changes (light/dark mode toggle)
910
+ * - Viewport size changes (window resize)
911
+ * - Display mode changes (inline/fullscreen)
912
+ * - Locale or timezone changes
913
+ *
914
+ * @param hostContext - The complete new host context state
915
+ *
916
+ * @example Update theme when user toggles dark mode
917
+ * ```ts source="./app-bridge.examples.ts#AppBridge_setHostContext_updateTheme"
918
+ * bridge.setHostContext({ theme: "dark" });
919
+ * ```
920
+ *
921
+ * @example Update multiple context fields
922
+ * ```ts source="./app-bridge.examples.ts#AppBridge_setHostContext_updateMultiple"
923
+ * bridge.setHostContext({
924
+ * theme: "dark",
925
+ * containerDimensions: { maxHeight: 600, width: 800 },
926
+ * });
927
+ * ```
928
+ *
929
+ * @see {@link McpUiHostContext `McpUiHostContext`} for the context structure
930
+ * @see {@link McpUiHostContextChangedNotification `McpUiHostContextChangedNotification`} for the notification type
931
+ */
932
+ setHostContext(hostContext: McpUiHostContext): void;
933
+ /**
934
+ * Low-level method to notify the view of host context changes.
935
+ *
936
+ * Most hosts should use {@link setHostContext `setHostContext`} instead, which automatically
937
+ * detects changes and calls this method with only the modified fields.
938
+ * Use this directly only when you need fine-grained control over change detection.
939
+ *
940
+ * @param params - The context fields that have changed (partial update)
941
+ */
942
+ sendHostContextChange(params: McpUiHostContextChangedNotification["params"]): Promise<void> | void;
943
+ /**
944
+ * Send complete tool arguments to the view.
945
+ *
946
+ * The host MUST send this notification after the View completes initialization
947
+ * (after {@link oninitialized `oninitialized`} callback fires) and complete tool arguments become available.
948
+ * This notification is sent exactly once and is required before {@link sendToolResult `sendToolResult`}.
949
+ *
950
+ * @param params - Complete tool call arguments
951
+ *
952
+ * @example
953
+ * ```ts source="./app-bridge.examples.ts#AppBridge_sendToolInput_afterInit"
954
+ * bridge.oninitialized = () => {
955
+ * bridge.sendToolInput({
956
+ * arguments: { location: "New York", units: "metric" },
957
+ * });
958
+ * };
959
+ * ```
960
+ *
961
+ * @see {@link McpUiToolInputNotification `McpUiToolInputNotification`} for the notification type
962
+ * @see {@link oninitialized `oninitialized`} for the initialization callback
963
+ * @see {@link sendToolResult `sendToolResult`} for sending results after execution
964
+ */
965
+ sendToolInput(params: McpUiToolInputNotification["params"]): Promise<void>;
966
+ /**
967
+ * Send streaming partial tool arguments to the view.
968
+ *
969
+ * The host MAY send this notification zero or more times while tool arguments
970
+ * are being streamed, before {@link sendToolInput `sendToolInput`} is called with complete
971
+ * arguments. This enables progressive rendering of tool arguments in the
972
+ * view.
973
+ *
974
+ * The arguments represent best-effort recovery of incomplete JSON. views
975
+ * SHOULD handle missing or changing fields gracefully between notifications.
976
+ *
977
+ * @param params - Partial tool call arguments (may be incomplete)
978
+ *
979
+ * @example Stream partial arguments as they arrive
980
+ * ```ts source="./app-bridge.examples.ts#AppBridge_sendToolInputPartial_streaming"
981
+ * // As streaming progresses...
982
+ * bridge.sendToolInputPartial({ arguments: { loc: "N" } });
983
+ * bridge.sendToolInputPartial({ arguments: { location: "New" } });
984
+ * bridge.sendToolInputPartial({ arguments: { location: "New York" } });
985
+ *
986
+ * // When complete, send final input
987
+ * bridge.sendToolInput({
988
+ * arguments: { location: "New York", units: "metric" },
989
+ * });
990
+ * ```
991
+ *
992
+ * @see {@link McpUiToolInputPartialNotification `McpUiToolInputPartialNotification`} for the notification type
993
+ * @see {@link sendToolInput `sendToolInput`} for sending complete arguments
994
+ */
995
+ sendToolInputPartial(params: McpUiToolInputPartialNotification["params"]): Promise<void>;
996
+ /**
997
+ * Send tool execution result to the view.
998
+ *
999
+ * The host MUST send this notification when tool execution completes successfully,
1000
+ * provided the view is still displayed. If the view was closed before execution
1001
+ * completes, the host MAY skip this notification. This must be sent after
1002
+ * {@link sendToolInput `sendToolInput`}.
1003
+ *
1004
+ * @param params - Standard MCP tool execution result
1005
+ *
1006
+ * @example
1007
+ * ```ts source="./app-bridge.examples.ts#AppBridge_sendToolResult_afterExecution"
1008
+ * const result = await mcpClient.request({
1009
+ * method: "tools/call",
1010
+ * params: { name: "get_weather", arguments: args },
1011
+ * });
1012
+ * bridge.sendToolResult(result);
1013
+ * ```
1014
+ *
1015
+ * @see {@link McpUiToolResultNotification `McpUiToolResultNotification`} for the notification type
1016
+ * @see {@link sendToolInput `sendToolInput`} for sending tool arguments before results
1017
+ */
1018
+ sendToolResult(params: McpUiToolResultNotification["params"]): Promise<void>;
1019
+ /**
1020
+ * Notify the view that tool execution was cancelled.
1021
+ *
1022
+ * The host MUST send this notification if tool execution was cancelled for any
1023
+ * reason, including user action, sampling error, classifier intervention, or
1024
+ * any other interruption. This allows the view to update its state and
1025
+ * display appropriate feedback to the user.
1026
+ *
1027
+ * @param params - Cancellation details object
1028
+ * - `reason`: Human-readable explanation for why the tool was cancelled
1029
+ *
1030
+ * @example User-initiated cancellation
1031
+ * ```ts source="./app-bridge.examples.ts#AppBridge_sendToolCancelled_userInitiated"
1032
+ * // User clicked "Cancel" button
1033
+ * bridge.sendToolCancelled({ reason: "User cancelled the operation" });
1034
+ * ```
1035
+ *
1036
+ * @example System-level cancellation
1037
+ * ```ts source="./app-bridge.examples.ts#AppBridge_sendToolCancelled_systemLevel"
1038
+ * // Sampling error or timeout
1039
+ * bridge.sendToolCancelled({ reason: "Request timeout after 30 seconds" });
1040
+ *
1041
+ * // Classifier intervention
1042
+ * bridge.sendToolCancelled({ reason: "Content policy violation detected" });
1043
+ * ```
1044
+ *
1045
+ * @see {@link McpUiToolCancelledNotification `McpUiToolCancelledNotification`} for the notification type
1046
+ * @see {@link sendToolResult `sendToolResult`} for sending successful results
1047
+ * @see {@link sendToolInput `sendToolInput`} for sending tool arguments
1048
+ */
1049
+ sendToolCancelled(params: McpUiToolCancelledNotification["params"]): Promise<void>;
1050
+ /**
1051
+ * Send HTML resource to the sandbox proxy for secure loading.
1052
+ *
1053
+ * This is an internal method used by web-based hosts implementing the
1054
+ * double-iframe sandbox architecture. After the sandbox proxy signals readiness
1055
+ * via `ui/notifications/sandbox-proxy-ready`, the host sends this notification
1056
+ * with the HTML content to load.
1057
+ *
1058
+ * @param params - HTML content and sandbox configuration:
1059
+ * - `html`: The HTML content to load into the sandboxed iframe
1060
+ * - `sandbox`: Optional sandbox attribute value (e.g., "allow-scripts")
1061
+ *
1062
+ * @internal
1063
+ * @see {@link onsandboxready `onsandboxready`} for handling the sandbox proxy ready notification
1064
+ */
1065
+ sendSandboxResourceReady(params: McpUiSandboxResourceReadyNotification["params"]): Promise<void>;
1066
+ /**
1067
+ * Request graceful shutdown of the view.
1068
+ *
1069
+ * The host MUST send this request before tearing down the UI resource (before
1070
+ * unmounting the iframe). This gives the view an opportunity to save state,
1071
+ * cancel pending operations, or show confirmation dialogs.
1072
+ *
1073
+ * The host SHOULD wait for the response before unmounting to prevent data loss.
1074
+ *
1075
+ * @param params - Empty params object
1076
+ * @param options - Request options (timeout, etc.)
1077
+ * @returns Promise resolving when view confirms readiness for teardown
1078
+ *
1079
+ * @example
1080
+ * ```ts source="./app-bridge.examples.ts#AppBridge_teardownResource_gracefulShutdown"
1081
+ * try {
1082
+ * await bridge.teardownResource({});
1083
+ * // View is ready, safe to unmount iframe
1084
+ * iframe.remove();
1085
+ * } catch (error) {
1086
+ * console.error("Teardown failed:", error);
1087
+ * }
1088
+ * ```
1089
+ */
1090
+ teardownResource(params: McpUiResourceTeardownRequest["params"], options?: RequestOptions): Promise<Record<string, unknown>>;
1091
+ /** @deprecated Use {@link teardownResource `teardownResource`} instead */
1092
+ sendResourceTeardown: AppBridge["teardownResource"];
1093
+ /**
1094
+ * Call a tool on the view.
1095
+ *
1096
+ * Sends a `tools/call` request to the view and returns the result.
1097
+ *
1098
+ * @param params - Tool call parameters (name and arguments)
1099
+ * @param options - Request options (timeout, abort signal, etc.)
1100
+ * @returns Promise resolving to the tool call result
1101
+ */
1102
+ callTool(params: CallToolRequest["params"], options?: RequestOptions): Promise<{
1103
+ [x: string]: unknown;
1104
+ content: ({
1105
+ type: "text";
1106
+ text: string;
1107
+ annotations?: {
1108
+ audience?: ("user" | "assistant")[] | undefined;
1109
+ priority?: number | undefined;
1110
+ lastModified?: string | undefined;
1111
+ } | undefined;
1112
+ _meta?: {
1113
+ [x: string]: unknown;
1114
+ } | undefined;
1115
+ } | {
1116
+ type: "image";
1117
+ data: string;
1118
+ mimeType: string;
1119
+ annotations?: {
1120
+ audience?: ("user" | "assistant")[] | undefined;
1121
+ priority?: number | undefined;
1122
+ lastModified?: string | undefined;
1123
+ } | undefined;
1124
+ _meta?: {
1125
+ [x: string]: unknown;
1126
+ } | undefined;
1127
+ } | {
1128
+ type: "audio";
1129
+ data: string;
1130
+ mimeType: string;
1131
+ annotations?: {
1132
+ audience?: ("user" | "assistant")[] | undefined;
1133
+ priority?: number | undefined;
1134
+ lastModified?: string | undefined;
1135
+ } | undefined;
1136
+ _meta?: {
1137
+ [x: string]: unknown;
1138
+ } | undefined;
1139
+ } | {
1140
+ uri: string;
1141
+ name: string;
1142
+ type: "resource_link";
1143
+ description?: string | undefined;
1144
+ mimeType?: string | undefined;
1145
+ size?: number | undefined;
1146
+ annotations?: {
1147
+ audience?: ("user" | "assistant")[] | undefined;
1148
+ priority?: number | undefined;
1149
+ lastModified?: string | undefined;
1150
+ } | undefined;
1151
+ _meta?: {
1152
+ [x: string]: unknown;
1153
+ } | undefined;
1154
+ icons?: {
1155
+ src: string;
1156
+ mimeType?: string | undefined;
1157
+ sizes?: string[] | undefined;
1158
+ theme?: "light" | "dark" | undefined;
1159
+ }[] | undefined;
1160
+ title?: string | undefined;
1161
+ } | {
1162
+ type: "resource";
1163
+ resource: {
1164
+ uri: string;
1165
+ text: string;
1166
+ mimeType?: string | undefined;
1167
+ _meta?: {
1168
+ [x: string]: unknown;
1169
+ } | undefined;
1170
+ } | {
1171
+ uri: string;
1172
+ blob: string;
1173
+ mimeType?: string | undefined;
1174
+ _meta?: {
1175
+ [x: string]: unknown;
1176
+ } | undefined;
1177
+ };
1178
+ annotations?: {
1179
+ audience?: ("user" | "assistant")[] | undefined;
1180
+ priority?: number | undefined;
1181
+ lastModified?: string | undefined;
1182
+ } | undefined;
1183
+ _meta?: {
1184
+ [x: string]: unknown;
1185
+ } | undefined;
1186
+ })[];
1187
+ _meta?: {
1188
+ [x: string]: unknown;
1189
+ "io.modelcontextprotocol/serverInfo"?: {
1190
+ version: string;
1191
+ name: string;
1192
+ websiteUrl?: string | undefined;
1193
+ description?: string | undefined;
1194
+ icons?: {
1195
+ src: string;
1196
+ mimeType?: string | undefined;
1197
+ sizes?: string[] | undefined;
1198
+ theme?: "light" | "dark" | undefined;
1199
+ }[] | undefined;
1200
+ title?: string | undefined;
1201
+ } | undefined;
1202
+ } | undefined;
1203
+ structuredContent?: unknown;
1204
+ isError?: boolean | undefined;
1205
+ }>;
1206
+ /**
1207
+ * List tools available on the view.
1208
+ *
1209
+ * Sends a `tools/list` request to the view and returns the result.
1210
+ *
1211
+ * @param params - List tools parameters (may include cursor for pagination)
1212
+ * @param options - Request options (timeout, abort signal, etc.)
1213
+ * @returns Promise resolving to the list of tools
1214
+ */
1215
+ listTools(params: ListToolsRequest["params"], options?: RequestOptions): Promise<{
1216
+ [x: string]: unknown;
1217
+ tools: {
1218
+ inputSchema: {
1219
+ [x: string]: unknown;
1220
+ type: "object";
1221
+ properties?: {
1222
+ [x: string]: string | number | boolean | {
1223
+ [x: string]: string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | /*elided*/ any | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null;
1224
+ } | (string | number | boolean | {
1225
+ [x: string]: string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | /*elided*/ any | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null;
1226
+ } | (string | number | boolean | {
1227
+ [x: string]: string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | /*elided*/ any | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null;
1228
+ } | (string | number | boolean | {
1229
+ [x: string]: string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | /*elided*/ any | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null;
1230
+ } | (string | number | boolean | {
1231
+ [x: string]: string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | /*elided*/ any | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null;
1232
+ } | (string | number | boolean | {
1233
+ [x: string]: string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | /*elided*/ any | null)[] | null)[] | null)[] | null)[] | null)[] | null;
1234
+ } | (string | number | boolean | {
1235
+ [x: string]: string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | /*elided*/ any | null)[] | null)[] | null)[] | null)[] | null;
1236
+ } | (string | number | boolean | {
1237
+ [x: string]: string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | /*elided*/ any | null)[] | null)[] | null)[] | null;
1238
+ } | (string | number | boolean | {
1239
+ [x: string]: string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | /*elided*/ any | null)[] | null)[] | null;
1240
+ } | (string | number | boolean | {
1241
+ [x: string]: string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | /*elided*/ any | null)[] | null;
1242
+ } | (string | number | boolean | {
1243
+ [x: string]: string | number | boolean | /*elided*/ any | /*elided*/ any | null;
1244
+ } | /*elided*/ any | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null;
1245
+ } | undefined;
1246
+ required?: string[] | undefined;
1247
+ };
1248
+ name: string;
1249
+ description?: string | undefined;
1250
+ outputSchema?: {
1251
+ [x: string]: unknown;
1252
+ $schema?: string | undefined;
1253
+ } | undefined;
1254
+ annotations?: {
1255
+ title?: string | undefined;
1256
+ readOnlyHint?: boolean | undefined;
1257
+ destructiveHint?: boolean | undefined;
1258
+ idempotentHint?: boolean | undefined;
1259
+ openWorldHint?: boolean | undefined;
1260
+ } | undefined;
1261
+ execution?: {
1262
+ taskSupport?: "optional" | "required" | "forbidden" | undefined;
1263
+ } | undefined;
1264
+ _meta?: {
1265
+ [x: string]: unknown;
1266
+ } | undefined;
1267
+ icons?: {
1268
+ src: string;
1269
+ mimeType?: string | undefined;
1270
+ sizes?: string[] | undefined;
1271
+ theme?: "light" | "dark" | undefined;
1272
+ }[] | undefined;
1273
+ title?: string | undefined;
1274
+ }[];
1275
+ _meta?: {
1276
+ [x: string]: unknown;
1277
+ "io.modelcontextprotocol/serverInfo"?: {
1278
+ version: string;
1279
+ name: string;
1280
+ websiteUrl?: string | undefined;
1281
+ description?: string | undefined;
1282
+ icons?: {
1283
+ src: string;
1284
+ mimeType?: string | undefined;
1285
+ sizes?: string[] | undefined;
1286
+ theme?: "light" | "dark" | undefined;
1287
+ }[] | undefined;
1288
+ title?: string | undefined;
1289
+ } | undefined;
1290
+ } | undefined;
1291
+ nextCursor?: string | undefined;
1292
+ }>;
1293
+ /**
1294
+ * Connect to the view via transport and optionally set up message forwarding.
1295
+ *
1296
+ * This method establishes the transport connection. If an MCP client was passed
1297
+ * to the constructor, it also automatically sets up request/notification forwarding
1298
+ * based on the MCP server's capabilities, proxying the following to the view:
1299
+ * - Tools (tools/call, notifications/tools/list_changed)
1300
+ * - Resources (resources/list, resources/read, resources/templates/list, notifications/resources/list_changed)
1301
+ * - Prompts (prompts/list, notifications/prompts/list_changed)
1302
+ *
1303
+ * If no client was passed to the constructor, no automatic forwarding is set up
1304
+ * and you must register handlers manually using the {@link oncalltool `oncalltool`}, {@link onlistresources `onlistresources`},
1305
+ * etc. setters.
1306
+ *
1307
+ * After calling connect, wait for the {@link oninitialized `oninitialized`} callback before sending
1308
+ * tool input and other data to the View.
1309
+ *
1310
+ * @param transport - Transport layer (typically {@link PostMessageTransport `PostMessageTransport`})
1311
+ * @returns Promise resolving when connection is established
1312
+ *
1313
+ * @throws {Error} If a client was passed but server capabilities are not available.
1314
+ * This occurs when connect() is called before the MCP client has completed its
1315
+ * initialization with the server. Ensure `await client.connect()` completes
1316
+ * before calling `bridge.connect()`.
1317
+ *
1318
+ * @example With MCP client (automatic forwarding)
1319
+ * ```ts source="./app-bridge.examples.ts#AppBridge_connect_withMcpClient"
1320
+ * const bridge = new AppBridge(mcpClient, hostInfo, capabilities);
1321
+ * const transport = new PostMessageTransport(
1322
+ * iframe.contentWindow!,
1323
+ * iframe.contentWindow!,
1324
+ * );
1325
+ *
1326
+ * bridge.oninitialized = () => {
1327
+ * console.log("View ready");
1328
+ * bridge.sendToolInput({ arguments: toolArgs });
1329
+ * };
1330
+ *
1331
+ * await bridge.connect(transport);
1332
+ * ```
1333
+ *
1334
+ * @example Without MCP client (manual handlers)
1335
+ * ```ts source="./app-bridge.examples.ts#AppBridge_connect_withoutMcpClient"
1336
+ * const bridge = new AppBridge(null, hostInfo, capabilities);
1337
+ *
1338
+ * // Register handlers manually
1339
+ * bridge.oncalltool = async (params, extra) => {
1340
+ * // Custom tool call handling
1341
+ * return { content: [] };
1342
+ * };
1343
+ *
1344
+ * await bridge.connect(transport);
1345
+ * ```
1346
+ */
1347
+ connect(transport: Transport): Promise<void>;
1348
+ }