@blade-hq/agent-react 2612.0.0-beta.8 → 2612.0.0-beta.81
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.
- package/README.md +47 -0
- package/dist/SessionPluginConfigForm-7LJ5SUNY.js +9 -0
- package/dist/SessionPluginConfigForm-7LJ5SUNY.js.map +1 -0
- package/dist/chat/AgentLoopBlock.d.ts +0 -2
- package/dist/chat/AskUserQuestionBlock.d.ts +3 -20
- package/dist/chat/AssistantTurnBlock.d.ts +1 -9
- package/dist/chat/AttachmentPreviewDialog.d.ts +0 -1
- package/dist/chat/ChatLoadingIndicator.d.ts +7 -0
- package/dist/chat/ContextAttachmentPills.d.ts +4 -0
- package/dist/chat/CurrentPlanPanel.d.ts +0 -3
- package/dist/chat/FileDeliveryCards.d.ts +0 -4
- package/dist/chat/FinalArtifactCards.d.ts +0 -1
- package/dist/chat/ImageLightbox.d.ts +1 -1
- package/dist/chat/LiteMessageList.d.ts +5 -3
- package/dist/chat/MessageFileAttachmentList.d.ts +0 -5
- package/dist/chat/QuestionnaireQuestionBlock.d.ts +11 -0
- package/dist/chat/SessionReplayBar.d.ts +0 -1
- package/dist/chat/TextAttachmentPills.d.ts +0 -3
- package/dist/chat/TurnNavRail.d.ts +1 -7
- package/dist/chat/WorkflowRunBlock.d.ts +21 -4
- package/dist/chat/ai-elements/shimmer.d.ts +0 -4
- package/dist/chat/customization.d.ts +1 -1
- package/dist/chat/index.d.ts +3 -2
- package/dist/chat/markdown/ExternalAnchor.d.ts +2 -2
- package/dist/chat/markdown/MarkdownContent.d.ts +3 -0
- package/dist/chat/message-list-blocks.d.ts +0 -1
- package/dist/chat/runtime/actions.d.ts +2 -2
- package/dist/chat/runtime/background-task-dismissals.d.ts +0 -1
- package/dist/chat/runtime/composer-channels.d.ts +0 -3
- package/dist/chat/runtime/input-cache-reset.d.ts +0 -5
- package/dist/chat/runtime/input-services.d.ts +10 -0
- package/dist/chat/runtime/session-source.d.ts +0 -5
- package/dist/chat/runtime/use-chat-actions.d.ts +0 -4
- package/dist/chat/turn-locate-channel.d.ts +53 -0
- package/dist/{chat-OCLOVB3H.css → chat-IHPRU35X.css} +5 -18
- package/dist/chat.css +5 -18
- package/dist/chunk-66JXSDLB.js +13770 -0
- package/dist/chunk-66JXSDLB.js.map +1 -0
- package/dist/chunk-C3LBNHVM.js +9482 -0
- package/dist/chunk-C3LBNHVM.js.map +1 -0
- package/dist/chunk-F4MWGSKX.js +1308 -0
- package/dist/chunk-F4MWGSKX.js.map +1 -0
- package/dist/chunk-FBGCDXRK.js +607 -0
- package/dist/chunk-FBGCDXRK.js.map +1 -0
- package/dist/{chunk-67GHJQK5.js → chunk-FDB3J5QF.js} +3889 -26106
- package/dist/chunk-FDB3J5QF.js.map +1 -0
- package/dist/chunk-FH5HA3GW.js +2416 -0
- package/dist/chunk-FH5HA3GW.js.map +1 -0
- package/dist/chunk-KHJEIHMJ.js +973 -0
- package/dist/chunk-KHJEIHMJ.js.map +1 -0
- package/dist/chunk-MWILWSPG.js +9629 -0
- package/dist/chunk-MWILWSPG.js.map +1 -0
- package/dist/chunk-NRYLAO3X.js +3978 -0
- package/dist/chunk-NRYLAO3X.js.map +1 -0
- package/dist/{chunk-MERN5XEM.js → chunk-SK43YNRX.js} +4181 -16594
- package/dist/chunk-SK43YNRX.js.map +1 -0
- package/dist/components/AccountConnectorRules.d.ts +7 -0
- package/dist/components/AccountConnectors.d.ts +13 -0
- package/dist/components/BrowserConnectionDialog.d.ts +8 -0
- package/dist/components/ChatInput.d.ts +1 -15
- package/dist/components/ConfigConnection.d.ts +16 -0
- package/dist/components/ConnectorAuthorizationProgress.d.ts +6 -0
- package/dist/components/ConnectorConnection.d.ts +4 -0
- package/dist/components/ConnectorDetail.d.ts +46 -0
- package/dist/components/ConnectorPanel.d.ts +3 -1
- package/dist/components/ConnectorRulesPanel.d.ts +10 -0
- package/dist/components/ConnectorRuntimeDiagnostics.d.ts +5 -0
- package/dist/components/DeviceConnection.d.ts +17 -0
- package/dist/components/FeishuCapabilitySelection.d.ts +14 -0
- package/dist/components/FeishuPermissionStatus.d.ts +7 -0
- package/dist/components/LlmAdvancedSettings.d.ts +0 -1
- package/dist/components/ManagedConnection.d.ts +12 -0
- package/dist/components/McpAppFrame.d.ts +17 -0
- package/dist/components/PackEventNotice.d.ts +3 -0
- package/dist/components/PlanUpdateBlock.d.ts +0 -1
- package/dist/components/SessionPluginConfigForm.d.ts +4 -1
- package/dist/components/SessionPluginIcon.d.ts +1 -0
- package/dist/components/plugin-connector.d.ts +1 -0
- package/dist/connectors.d.ts +6 -0
- package/dist/connectors.js +19 -0
- package/dist/connectors.js.map +1 -0
- package/dist/embed/blade-chat-element.d.ts +0 -8
- package/dist/embed/entry.d.ts +13 -19
- package/dist/hooks/use-message-pin.d.ts +1 -1
- package/dist/hooks/use-turn-navigation.d.ts +19 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +23 -3
- package/dist/internal.d.ts +7 -3
- package/dist/internal.js +59 -71
- package/dist/internal.js.map +1 -1
- package/dist/lib/message-shortcuts.d.ts +5 -0
- package/dist/questions.d.ts +7 -0
- package/dist/questions.js +910 -0
- package/dist/questions.js.map +1 -0
- package/dist/rich-input/ConnectButton.d.ts +7 -5
- package/dist/rich-input/FileCompletionMenu.d.ts +1 -2
- package/dist/rich-input/InputActionSubmenu.d.ts +10 -0
- package/dist/rich-input/SkillActionMenu.d.ts +10 -0
- package/dist/rich-input/SkillStatusBar.d.ts +0 -6
- package/dist/rich-input/extensions/skill-mention.d.ts +3 -20
- package/dist/rich-input/index.d.ts +3 -2
- package/dist/rich-input/lib/composer-content.d.ts +5 -1
- package/dist/rich-input/lib/plugin-suggestions.d.ts +5 -5
- package/dist/rich-input/lib/reference-candidates.d.ts +0 -1
- package/dist/rich-input/lib/skill-suggestions.d.ts +1 -1
- package/dist/rich-input/lib/user-home.d.ts +0 -17
- package/dist/rich-input/services.d.ts +1 -1
- package/dist/rich-input/voice/VoiceWaveform.d.ts +0 -3
- package/dist/rich-input.js +793 -1068
- package/dist/rich-input.js.map +1 -1
- package/dist/style.css +16 -55
- package/dist/style.full.css +23 -77
- package/dist/tool-details.d.ts +8 -0
- package/dist/tool-details.js +25 -0
- package/dist/tool-details.js.map +1 -0
- package/node_modules/@modelcontextprotocol/ext-apps/LICENSE +216 -0
- package/node_modules/@modelcontextprotocol/ext-apps/README.md +284 -0
- package/node_modules/@modelcontextprotocol/ext-apps/dist/docs/patterns.d.ts +9 -0
- package/node_modules/@modelcontextprotocol/ext-apps/dist/src/app-bridge.d.ts +1348 -0
- package/node_modules/@modelcontextprotocol/ext-apps/dist/src/app-bridge.examples.d.ts +9 -0
- package/node_modules/@modelcontextprotocol/ext-apps/dist/src/app-bridge.js +39 -0
- package/node_modules/@modelcontextprotocol/ext-apps/dist/src/app-bridge.test.d.ts +1 -0
- package/node_modules/@modelcontextprotocol/ext-apps/dist/src/app-with-deps.js +82 -0
- package/node_modules/@modelcontextprotocol/ext-apps/dist/src/app.d.ts +1214 -0
- package/node_modules/@modelcontextprotocol/ext-apps/dist/src/app.examples.d.ts +9 -0
- package/node_modules/@modelcontextprotocol/ext-apps/dist/src/app.js +39 -0
- package/node_modules/@modelcontextprotocol/ext-apps/dist/src/app.test.d.ts +1 -0
- package/node_modules/@modelcontextprotocol/ext-apps/dist/src/constants.d.ts +65 -0
- package/node_modules/@modelcontextprotocol/ext-apps/dist/src/events.d.ts +47 -0
- package/node_modules/@modelcontextprotocol/ext-apps/dist/src/events.test.d.ts +1 -0
- package/node_modules/@modelcontextprotocol/ext-apps/dist/src/generated/schema.d.ts +1047 -0
- package/node_modules/@modelcontextprotocol/ext-apps/dist/src/generated/schema.json +6170 -0
- package/node_modules/@modelcontextprotocol/ext-apps/dist/src/generated/schema.test.d.ts +41 -0
- package/node_modules/@modelcontextprotocol/ext-apps/dist/src/interop-v1.test.d.ts +1 -0
- package/node_modules/@modelcontextprotocol/ext-apps/dist/src/legacy-handlers.d.ts +66 -0
- package/node_modules/@modelcontextprotocol/ext-apps/dist/src/legacy-handlers.test.d.ts +1 -0
- package/node_modules/@modelcontextprotocol/ext-apps/dist/src/message-transport.d.ts +126 -0
- package/node_modules/@modelcontextprotocol/ext-apps/dist/src/message-transport.examples.d.ts +9 -0
- package/node_modules/@modelcontextprotocol/ext-apps/dist/src/message-transport.test.d.ts +1 -0
- package/node_modules/@modelcontextprotocol/ext-apps/dist/src/react/index.d.ts +37 -0
- package/node_modules/@modelcontextprotocol/ext-apps/dist/src/react/index.examples.d.ts +6 -0
- package/node_modules/@modelcontextprotocol/ext-apps/dist/src/react/index.js +39 -0
- package/node_modules/@modelcontextprotocol/ext-apps/dist/src/react/react-with-deps.js +82 -0
- package/node_modules/@modelcontextprotocol/ext-apps/dist/src/react/useApp.d.ts +115 -0
- package/node_modules/@modelcontextprotocol/ext-apps/dist/src/react/useApp.examples.d.ts +6 -0
- package/node_modules/@modelcontextprotocol/ext-apps/dist/src/react/useAutoResize.d.ts +54 -0
- package/node_modules/@modelcontextprotocol/ext-apps/dist/src/react/useAutoResize.examples.d.ts +6 -0
- package/node_modules/@modelcontextprotocol/ext-apps/dist/src/react/useDocumentTheme.d.ts +44 -0
- package/node_modules/@modelcontextprotocol/ext-apps/dist/src/react/useDocumentTheme.examples.d.ts +6 -0
- package/node_modules/@modelcontextprotocol/ext-apps/dist/src/react/useHostStyles.d.ts +113 -0
- package/node_modules/@modelcontextprotocol/ext-apps/dist/src/react/useHostStyles.examples.d.ts +6 -0
- package/node_modules/@modelcontextprotocol/ext-apps/dist/src/server/index.d.ts +381 -0
- package/node_modules/@modelcontextprotocol/ext-apps/dist/src/server/index.examples.d.ts +9 -0
- package/node_modules/@modelcontextprotocol/ext-apps/dist/src/server/index.js +1 -0
- package/node_modules/@modelcontextprotocol/ext-apps/dist/src/server/index.test.d.ts +1 -0
- package/node_modules/@modelcontextprotocol/ext-apps/dist/src/spec.types.d.ts +698 -0
- package/node_modules/@modelcontextprotocol/ext-apps/dist/src/standard-schema.d.ts +23 -0
- package/node_modules/@modelcontextprotocol/ext-apps/dist/src/styles.d.ts +184 -0
- package/node_modules/@modelcontextprotocol/ext-apps/dist/src/styles.examples.d.ts +9 -0
- package/node_modules/@modelcontextprotocol/ext-apps/dist/src/types.d.ts +33 -0
- package/node_modules/@modelcontextprotocol/ext-apps/dist/src/wire-compat.test.d.ts +1 -0
- package/node_modules/@modelcontextprotocol/ext-apps/package.json +144 -0
- package/node_modules/@standard-schema/spec/LICENSE +21 -0
- package/node_modules/@standard-schema/spec/README.md +198 -0
- package/node_modules/@standard-schema/spec/dist/index.cjs +18 -0
- package/node_modules/@standard-schema/spec/dist/index.d.cts +119 -0
- package/node_modules/@standard-schema/spec/dist/index.d.ts +119 -0
- package/node_modules/@standard-schema/spec/dist/index.js +0 -0
- package/node_modules/@standard-schema/spec/package.json +52 -0
- package/package.json +19 -3
- package/public-api.md +60 -4
- package/dist/chunk-67GHJQK5.js.map +0 -1
- package/dist/chunk-DPDXGYGM.js +0 -258
- package/dist/chunk-DPDXGYGM.js.map +0 -1
- package/dist/chunk-MERN5XEM.js.map +0 -1
- package/dist/lib/agent-computer-command.d.ts +0 -32
- package/dist/rich-input/extensions/workflow-mention.d.ts +0 -10
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { z } from "zod/v4";
|
|
2
|
+
import * as generated from "./schema.js";
|
|
3
|
+
export type McpUiThemeSchemaInferredType = z.infer<typeof generated.McpUiThemeSchema>;
|
|
4
|
+
export type McpUiDisplayModeSchemaInferredType = z.infer<typeof generated.McpUiDisplayModeSchema>;
|
|
5
|
+
export type McpUiStyleVariableKeySchemaInferredType = z.infer<typeof generated.McpUiStyleVariableKeySchema>;
|
|
6
|
+
export type McpUiStylesSchemaInferredType = z.infer<typeof generated.McpUiStylesSchema>;
|
|
7
|
+
export type McpUiOpenLinkRequestSchemaInferredType = z.infer<typeof generated.McpUiOpenLinkRequestSchema>;
|
|
8
|
+
export type McpUiOpenLinkResultSchemaInferredType = z.infer<typeof generated.McpUiOpenLinkResultSchema>;
|
|
9
|
+
export type McpUiDownloadFileResultSchemaInferredType = z.infer<typeof generated.McpUiDownloadFileResultSchema>;
|
|
10
|
+
export type McpUiMessageResultSchemaInferredType = z.infer<typeof generated.McpUiMessageResultSchema>;
|
|
11
|
+
export type McpUiSandboxProxyReadyNotificationSchemaInferredType = z.infer<typeof generated.McpUiSandboxProxyReadyNotificationSchema>;
|
|
12
|
+
export type McpUiResourceCspSchemaInferredType = z.infer<typeof generated.McpUiResourceCspSchema>;
|
|
13
|
+
export type McpUiResourcePermissionsSchemaInferredType = z.infer<typeof generated.McpUiResourcePermissionsSchema>;
|
|
14
|
+
export type McpUiSizeChangedNotificationSchemaInferredType = z.infer<typeof generated.McpUiSizeChangedNotificationSchema>;
|
|
15
|
+
export type McpUiToolInputNotificationSchemaInferredType = z.infer<typeof generated.McpUiToolInputNotificationSchema>;
|
|
16
|
+
export type McpUiToolInputPartialNotificationSchemaInferredType = z.infer<typeof generated.McpUiToolInputPartialNotificationSchema>;
|
|
17
|
+
export type McpUiToolCancelledNotificationSchemaInferredType = z.infer<typeof generated.McpUiToolCancelledNotificationSchema>;
|
|
18
|
+
export type McpUiHostCssSchemaInferredType = z.infer<typeof generated.McpUiHostCssSchema>;
|
|
19
|
+
export type McpUiHostStylesSchemaInferredType = z.infer<typeof generated.McpUiHostStylesSchema>;
|
|
20
|
+
export type McpUiResourceTeardownRequestSchemaInferredType = z.infer<typeof generated.McpUiResourceTeardownRequestSchema>;
|
|
21
|
+
export type McpUiResourceTeardownResultSchemaInferredType = z.infer<typeof generated.McpUiResourceTeardownResultSchema>;
|
|
22
|
+
export type McpUiSupportedContentBlockModalitiesSchemaInferredType = z.infer<typeof generated.McpUiSupportedContentBlockModalitiesSchema>;
|
|
23
|
+
export type McpUiRequestTeardownNotificationSchemaInferredType = z.infer<typeof generated.McpUiRequestTeardownNotificationSchema>;
|
|
24
|
+
export type McpUiHostCapabilitiesSchemaInferredType = z.infer<typeof generated.McpUiHostCapabilitiesSchema>;
|
|
25
|
+
export type McpUiAppCapabilitiesSchemaInferredType = z.infer<typeof generated.McpUiAppCapabilitiesSchema>;
|
|
26
|
+
export type McpUiInitializedNotificationSchemaInferredType = z.infer<typeof generated.McpUiInitializedNotificationSchema>;
|
|
27
|
+
export type McpUiResourceMetaSchemaInferredType = z.infer<typeof generated.McpUiResourceMetaSchema>;
|
|
28
|
+
export type McpUiRequestDisplayModeRequestSchemaInferredType = z.infer<typeof generated.McpUiRequestDisplayModeRequestSchema>;
|
|
29
|
+
export type McpUiRequestDisplayModeResultSchemaInferredType = z.infer<typeof generated.McpUiRequestDisplayModeResultSchema>;
|
|
30
|
+
export type McpUiToolVisibilitySchemaInferredType = z.infer<typeof generated.McpUiToolVisibilitySchema>;
|
|
31
|
+
export type McpUiToolMetaSchemaInferredType = z.infer<typeof generated.McpUiToolMetaSchema>;
|
|
32
|
+
export type McpUiClientCapabilitiesSchemaInferredType = z.infer<typeof generated.McpUiClientCapabilitiesSchema>;
|
|
33
|
+
export type McpUiDownloadFileRequestSchemaInferredType = z.infer<typeof generated.McpUiDownloadFileRequestSchema>;
|
|
34
|
+
export type McpUiMessageRequestSchemaInferredType = z.infer<typeof generated.McpUiMessageRequestSchema>;
|
|
35
|
+
export type McpUiSandboxResourceReadyNotificationSchemaInferredType = z.infer<typeof generated.McpUiSandboxResourceReadyNotificationSchema>;
|
|
36
|
+
export type McpUiToolResultNotificationSchemaInferredType = z.infer<typeof generated.McpUiToolResultNotificationSchema>;
|
|
37
|
+
export type McpUiHostContextSchemaInferredType = z.infer<typeof generated.McpUiHostContextSchema>;
|
|
38
|
+
export type McpUiHostContextChangedNotificationSchemaInferredType = z.infer<typeof generated.McpUiHostContextChangedNotificationSchema>;
|
|
39
|
+
export type McpUiUpdateModelContextRequestSchemaInferredType = z.infer<typeof generated.McpUiUpdateModelContextRequestSchema>;
|
|
40
|
+
export type McpUiInitializeRequestSchemaInferredType = z.infer<typeof generated.McpUiInitializeRequestSchema>;
|
|
41
|
+
export type McpUiInitializeResultSchemaInferredType = z.infer<typeof generated.McpUiInitializeResultSchema>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type { BaseContext, RequestId } from "@modelcontextprotocol/client";
|
|
2
|
+
import type { ZodLiteral, ZodObject, ZodType } from "zod/v4";
|
|
3
|
+
/**
|
|
4
|
+
* A whole-message Zod schema (`method` literal plus `params`), as accepted by
|
|
5
|
+
* the 1.x `setRequestHandler(Schema, handler)` forms.
|
|
6
|
+
*/
|
|
7
|
+
export type LegacyMethodSchema = ZodObject<{
|
|
8
|
+
method: ZodLiteral<string>;
|
|
9
|
+
params: ZodType;
|
|
10
|
+
}>;
|
|
11
|
+
/**
|
|
12
|
+
* The `extra` argument 1.x request handlers received.
|
|
13
|
+
*
|
|
14
|
+
* @deprecated Use the 2.x `BaseContext` (`extra.mcpReq.signal`, `extra.mcpReq.id`).
|
|
15
|
+
*/
|
|
16
|
+
export type LegacyRequestHandlerExtra = {
|
|
17
|
+
signal: AbortSignal;
|
|
18
|
+
requestId: RequestId;
|
|
19
|
+
sessionId?: string;
|
|
20
|
+
_meta?: BaseContext["mcpReq"]["_meta"];
|
|
21
|
+
sendRequest: BaseContext["mcpReq"]["send"];
|
|
22
|
+
sendNotification: BaseContext["mcpReq"]["notify"];
|
|
23
|
+
authInfo?: NonNullable<BaseContext["http"]>["authInfo"];
|
|
24
|
+
};
|
|
25
|
+
/** @deprecated Use `setRequestHandler("method", { params, result }, (params, ctx) => …)`. */
|
|
26
|
+
export type LegacyRequestHandler<S extends LegacyMethodSchema> = (request: S["_output"], extra: LegacyRequestHandlerExtra) => unknown;
|
|
27
|
+
/** @deprecated Use `setNotificationHandler("method", { params }, (params) => …)`. */
|
|
28
|
+
export type LegacyNotificationHandler<S extends LegacyMethodSchema> = (notification: S["_output"]) => void | Promise<void>;
|
|
29
|
+
/**
|
|
30
|
+
* `setRequestHandler` with the 1.x `(Schema, handler)` form kept as a
|
|
31
|
+
* deprecated overload next to the 2.x forms in `Modern`.
|
|
32
|
+
*/
|
|
33
|
+
export type LegacyRequestHandlerSetter<Modern> = Modern & {
|
|
34
|
+
/**
|
|
35
|
+
* @deprecated 1.x form. Pass the method name and `{ params }` instead;
|
|
36
|
+
* removed in 3.0.
|
|
37
|
+
*/
|
|
38
|
+
<S extends LegacyMethodSchema>(schema: S, handler: LegacyRequestHandler<S>): void;
|
|
39
|
+
};
|
|
40
|
+
/** `setNotificationHandler` counterpart of {@link LegacyRequestHandlerSetter}. */
|
|
41
|
+
export type LegacyNotificationHandlerSetter<Modern> = Modern & {
|
|
42
|
+
/**
|
|
43
|
+
* @deprecated 1.x form. Pass the method name and `{ params }` instead;
|
|
44
|
+
* removed in 3.0.
|
|
45
|
+
*/
|
|
46
|
+
<S extends LegacyMethodSchema>(schema: S, handler: LegacyNotificationHandler<S>): void;
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Arguments for the 2.x three-argument `setRequestHandler` /
|
|
50
|
+
* `setNotificationHandler` form.
|
|
51
|
+
*/
|
|
52
|
+
type ModernArgs = [
|
|
53
|
+
method: string,
|
|
54
|
+
schemas: {
|
|
55
|
+
params: ZodType;
|
|
56
|
+
},
|
|
57
|
+
handler: (params: unknown, ctx: BaseContext) => unknown
|
|
58
|
+
];
|
|
59
|
+
/**
|
|
60
|
+
* Translate a 1.x `(Schema, handler)` registration into the 2.x
|
|
61
|
+
* `(method, { params }, handler)` form, or return `undefined` when the call
|
|
62
|
+
* is already in the 2.x form. The 1.x handler receives the reassembled
|
|
63
|
+
* `{ method, params }` message and, for requests, a 1.x-shaped `extra`.
|
|
64
|
+
*/
|
|
65
|
+
export declare function toModernArgs(kind: "request" | "notification", args: unknown[]): ModernArgs | undefined;
|
|
66
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import type { JSONRPCMessage, MessageExtraInfo, Transport, TransportSendOptions } from "@modelcontextprotocol/client";
|
|
2
|
+
/**
|
|
3
|
+
* JSON-RPC transport using `window.postMessage` for iframe↔parent communication.
|
|
4
|
+
*
|
|
5
|
+
* This transport enables bidirectional communication between MCP Apps running in
|
|
6
|
+
* iframes and their host applications using the browser's `postMessage` API. It
|
|
7
|
+
* implements the MCP SDK's `Transport` interface.
|
|
8
|
+
*
|
|
9
|
+
* ## Security
|
|
10
|
+
*
|
|
11
|
+
* The `eventSource` parameter is required and validates the message source window
|
|
12
|
+
* by checking `event.source`. For views, pass `window.parent`.
|
|
13
|
+
* For hosts, pass `iframe.contentWindow` to validate the iframe source.
|
|
14
|
+
*
|
|
15
|
+
* ## Usage
|
|
16
|
+
*
|
|
17
|
+
* **View**:
|
|
18
|
+
* ```ts source="./message-transport.examples.ts#PostMessageTransport_view"
|
|
19
|
+
* const transport = new PostMessageTransport(window.parent, window.parent);
|
|
20
|
+
* await app.connect(transport);
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* **Host**:
|
|
24
|
+
* ```ts source="./message-transport.examples.ts#PostMessageTransport_host"
|
|
25
|
+
* const iframe = document.getElementById("app-iframe") as HTMLIFrameElement;
|
|
26
|
+
* const transport = new PostMessageTransport(
|
|
27
|
+
* iframe.contentWindow!,
|
|
28
|
+
* iframe.contentWindow!,
|
|
29
|
+
* );
|
|
30
|
+
* await bridge.connect(transport);
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* @see {@link app!App.connect `App.connect`} for View usage
|
|
34
|
+
* @see {@link app-bridge!AppBridge.connect `AppBridge.connect`} for Host usage
|
|
35
|
+
*/
|
|
36
|
+
export declare class PostMessageTransport implements Transport {
|
|
37
|
+
private eventTarget;
|
|
38
|
+
private eventSource;
|
|
39
|
+
private messageListener;
|
|
40
|
+
/**
|
|
41
|
+
* Create a new PostMessageTransport.
|
|
42
|
+
*
|
|
43
|
+
* @param eventTarget - Target window to send messages to (default: `window.parent`)
|
|
44
|
+
* @param eventSource - Source window for message validation. For views, pass
|
|
45
|
+
* `window.parent`. For hosts, pass `iframe.contentWindow`.
|
|
46
|
+
*
|
|
47
|
+
* @example View connecting to parent
|
|
48
|
+
* ```ts source="./message-transport.examples.ts#PostMessageTransport_constructor_view"
|
|
49
|
+
* const transport = new PostMessageTransport(window.parent, window.parent);
|
|
50
|
+
* ```
|
|
51
|
+
*
|
|
52
|
+
* @example Host connecting to iframe
|
|
53
|
+
* ```ts source="./message-transport.examples.ts#PostMessageTransport_constructor_host"
|
|
54
|
+
* const iframe = document.getElementById("app-iframe") as HTMLIFrameElement;
|
|
55
|
+
* const transport = new PostMessageTransport(
|
|
56
|
+
* iframe.contentWindow!,
|
|
57
|
+
* iframe.contentWindow!,
|
|
58
|
+
* );
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
constructor(eventTarget: Window | undefined, eventSource: MessageEventSource);
|
|
62
|
+
/**
|
|
63
|
+
* Begin listening for messages from the event source.
|
|
64
|
+
*
|
|
65
|
+
* Registers a message event listener on the window. Must be called before
|
|
66
|
+
* messages can be received.
|
|
67
|
+
*/
|
|
68
|
+
start(): Promise<void>;
|
|
69
|
+
/**
|
|
70
|
+
* Send a JSON-RPC message to the target window.
|
|
71
|
+
*
|
|
72
|
+
* Messages are sent using `postMessage` with `"*"` origin, meaning they are visible
|
|
73
|
+
* to all frames. The receiver should validate the message source for security.
|
|
74
|
+
*
|
|
75
|
+
* @param message - JSON-RPC message to send
|
|
76
|
+
* @param options - Optional send options (currently unused)
|
|
77
|
+
*/
|
|
78
|
+
send(message: JSONRPCMessage, options?: TransportSendOptions): Promise<void>;
|
|
79
|
+
/**
|
|
80
|
+
* Stop listening for messages and cleanup.
|
|
81
|
+
*
|
|
82
|
+
* Removes the message event listener and calls the {@link onclose `onclose`} callback if set.
|
|
83
|
+
*/
|
|
84
|
+
close(): Promise<void>;
|
|
85
|
+
/**
|
|
86
|
+
* Called when the transport is closed.
|
|
87
|
+
*
|
|
88
|
+
* Set this handler to be notified when {@link close `close`} is called.
|
|
89
|
+
*/
|
|
90
|
+
onclose?: () => void;
|
|
91
|
+
/**
|
|
92
|
+
* Called when a message parsing error occurs.
|
|
93
|
+
*
|
|
94
|
+
* This handler is invoked when a received message fails JSON-RPC schema
|
|
95
|
+
* validation. The error parameter contains details about the validation failure.
|
|
96
|
+
*
|
|
97
|
+
* @param error - Error describing the validation failure
|
|
98
|
+
*/
|
|
99
|
+
onerror?: (error: Error) => void;
|
|
100
|
+
/**
|
|
101
|
+
* Called when a valid JSON-RPC message is received.
|
|
102
|
+
*
|
|
103
|
+
* This handler is invoked after message validation succeeds. The {@link start `start`}
|
|
104
|
+
* method must be called before messages will be received.
|
|
105
|
+
*
|
|
106
|
+
* @param message - The validated JSON-RPC message
|
|
107
|
+
* @param extra - Optional metadata about the message (unused in this transport)
|
|
108
|
+
*/
|
|
109
|
+
onmessage?: (message: JSONRPCMessage, extra?: MessageExtraInfo) => void;
|
|
110
|
+
/**
|
|
111
|
+
* Optional session identifier for this transport connection.
|
|
112
|
+
*
|
|
113
|
+
* Set by the MCP SDK to track the connection session. Not required for
|
|
114
|
+
* `PostMessageTransport` functionality.
|
|
115
|
+
*/
|
|
116
|
+
sessionId?: string;
|
|
117
|
+
/**
|
|
118
|
+
* Callback to set the negotiated protocol version.
|
|
119
|
+
*
|
|
120
|
+
* The MCP SDK calls this during initialization to communicate the protocol
|
|
121
|
+
* version negotiated with the peer.
|
|
122
|
+
*
|
|
123
|
+
* @param version - The negotiated protocol version string
|
|
124
|
+
*/
|
|
125
|
+
setProtocolVersion?: (version: string) => void;
|
|
126
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type-checked examples for {@link PostMessageTransport `PostMessageTransport`}.
|
|
3
|
+
*
|
|
4
|
+
* These examples are included in the API documentation via `@includeCode` tags.
|
|
5
|
+
* Each function's region markers define the code snippet that appears in the docs.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* React utilities for building MCP Apps.
|
|
3
|
+
*
|
|
4
|
+
* This module provides React hooks and utilities for easily building
|
|
5
|
+
* interactive MCP Apps using React. This is optional - the core SDK
|
|
6
|
+
* ({@link App `App`}, {@link PostMessageTransport `PostMessageTransport`}) is framework-agnostic and can be
|
|
7
|
+
* used with any UI framework or vanilla JavaScript.
|
|
8
|
+
*
|
|
9
|
+
* ## Main Exports
|
|
10
|
+
*
|
|
11
|
+
* - {@link useApp `useApp`} - React hook to create and connect an MCP App
|
|
12
|
+
* - {@link useHostStyleVariables `useHostStyleVariables`} - React hook to apply host style variables and theme
|
|
13
|
+
* - {@link useHostFonts `useHostFonts`} - React hook to apply host fonts
|
|
14
|
+
* - {@link useDocumentTheme `useDocumentTheme`} - React hook for reactive document theme
|
|
15
|
+
* - {@link useAutoResize `useAutoResize`} - React hook for manual auto-resize control (rarely needed)
|
|
16
|
+
*
|
|
17
|
+
* @module @modelcontextprotocol/ext-apps/react
|
|
18
|
+
*
|
|
19
|
+
* @example Basic React App
|
|
20
|
+
* ```tsx source="./index.examples.tsx#index_basicReactApp"
|
|
21
|
+
* function MyApp() {
|
|
22
|
+
* const { app, isConnected, error } = useApp({
|
|
23
|
+
* appInfo: { name: "MyApp", version: "1.0.0" },
|
|
24
|
+
* capabilities: {},
|
|
25
|
+
* });
|
|
26
|
+
*
|
|
27
|
+
* if (error) return <div>Error: {error.message}</div>;
|
|
28
|
+
* if (!isConnected) return <div>Connecting...</div>;
|
|
29
|
+
*
|
|
30
|
+
* return <div>Connected!</div>;
|
|
31
|
+
* }
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export * from "./useApp.js";
|
|
35
|
+
export * from "./useAutoResize.js";
|
|
36
|
+
export * from "./useDocumentTheme.js";
|
|
37
|
+
export * from "./useHostStyles.js";
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import{useEffect as nQ,useState as r}from"react";import{Protocol as lQ}from"@modelcontextprotocol/client";import{EmptyResultSchema as pQ}from"@modelcontextprotocol/core";var $Q="ui/resourceUri",KQ="text/html;profile=mcp-app";class j{_eventSlots=new Map;setHandler(X,Y){let Z=this._ensureEventSlot(X);if(Z.onHandler&&Y)console.warn(`[MCP Apps] on${String(X)} handler replaced. Use addEventListener("${String(X)}", …) to add multiple listeners without replacing.`);Z.onHandler=Y}getHandler(X){return this._eventSlots.get(X)?.onHandler}addEventListener(X,Y){this._ensureEventSlot(X).listeners.push(Y)}removeEventListener(X,Y){let Z=this._eventSlots.get(X);if(!Z)return;let $=Z.listeners.indexOf(Y);if($!==-1)Z.listeners.splice($,1)}dispatch(X,Y){let Z=this._eventSlots.get(X);if(!Z)return;Z.onHandler?.(Y);for(let $ of[...Z.listeners])$(Y)}_ensureEventSlot(X){let Y=this._eventSlots.get(X);if(!Y)Y={listeners:[]},this._eventSlots.set(X,Y);return Y}}class M{_methods=new Set;claim(X,Y){if(this._methods.has(X))throw Error(`Handler for "${X}" already registered (via ${Y}). Use addEventListener() to attach multiple listeners, or the on* setter for replace semantics.`);this._methods.add(X)}replace(X){this._methods.add(X)}release(X){this._methods.delete(X)}has(X){return this._methods.has(X)}}var i=new Set;function H(X,Y){let[Z,$]=Y,K=Z?.shape;if(typeof K?.method?.value!=="string")return;let J=K.method.value,G=X==="request"?"setRequestHandler":"setNotificationHandler";if(!i.has(G))i.add(G),console.warn(`[ext-apps] ${G}(Schema, handler) is deprecated; use ${G}("${J}", { params: Schema.shape.params }, handler).`);let W=$;return[J,{params:K.params},X==="request"?(L,N)=>W({method:J,params:L},JQ(N)):(L)=>W({method:J,params:L})]}function JQ(X){return{signal:X.mcpReq.signal,requestId:X.mcpReq.id,sessionId:X.sessionId,_meta:X.mcpReq._meta,sendRequest:X.mcpReq.send,sendNotification:X.mcpReq.notify,authInfo:X.http?.authInfo}}import{JSONRPCMessageSchema as zQ}from"@modelcontextprotocol/core";var T="2026-01-26",GQ="ui/open-link",WQ="ui/download-file",LQ="ui/message",NQ="ui/notifications/sandbox-proxy-ready",BQ="ui/notifications/sandbox-resource-ready",VQ="ui/notifications/size-changed",_Q="ui/notifications/tool-input",A="ui/notifications/tool-input-partial",qQ="ui/notifications/tool-result",OQ="ui/notifications/tool-cancelled",PQ="ui/notifications/host-context-changed",jQ="ui/notifications/request-teardown",DQ="ui/resource-teardown",FQ="ui/initialize",EQ="ui/notifications/initialized",RQ="ui/request-display-mode";class V{eventTarget;eventSource;messageListener;constructor(X=window.parent,Y){this.eventTarget=X;this.eventSource=Y;this.messageListener=(Z)=>{if(Y&&Z.source!==this.eventSource){console.debug("Ignoring message from unknown source",Z);return}let $=zQ.safeParse(Z.data);if($.success)console.debug("Parsed message",$.data),this.onmessage?.($.data);else if(Z.data?.jsonrpc!=="2.0")console.debug("Ignoring non-JSON-RPC message",$.error.message,Z);else console.error("Failed to parse message",$.error.message,Z),this.onerror?.(Error("Invalid JSON-RPC message received: "+$.error.message))}}async start(){window.addEventListener("message",this.messageListener)}async send(X,Y){if(X.method!==A)console.debug("Sending message",X);this.eventTarget.postMessage(X,"*")}async close(){window.removeEventListener("message",this.messageListener),this.onclose?.()}onclose;onerror;onmessage;sessionId;setProtocolVersion}import{z as Q}from"zod/v4";import{ContentBlockSchema as n,CallToolResultSchema as IQ,EmbeddedResourceSchema as UQ,ImplementationSchema as o,RequestIdSchema as wQ,ResourceLinkSchema as MQ,ToolSchema as HQ}from"@modelcontextprotocol/core";var s=Q.union([Q.literal("light"),Q.literal("dark")]).describe("Color theme preference for the host environment."),_=Q.union([Q.literal("inline"),Q.literal("fullscreen"),Q.literal("pip")]).describe("Display mode for UI presentation."),TQ=Q.union([Q.literal("--color-background-primary"),Q.literal("--color-background-secondary"),Q.literal("--color-background-tertiary"),Q.literal("--color-background-inverse"),Q.literal("--color-background-ghost"),Q.literal("--color-background-info"),Q.literal("--color-background-danger"),Q.literal("--color-background-success"),Q.literal("--color-background-warning"),Q.literal("--color-background-disabled"),Q.literal("--color-text-primary"),Q.literal("--color-text-secondary"),Q.literal("--color-text-tertiary"),Q.literal("--color-text-inverse"),Q.literal("--color-text-ghost"),Q.literal("--color-text-info"),Q.literal("--color-text-danger"),Q.literal("--color-text-success"),Q.literal("--color-text-warning"),Q.literal("--color-text-disabled"),Q.literal("--color-border-primary"),Q.literal("--color-border-secondary"),Q.literal("--color-border-tertiary"),Q.literal("--color-border-inverse"),Q.literal("--color-border-ghost"),Q.literal("--color-border-info"),Q.literal("--color-border-danger"),Q.literal("--color-border-success"),Q.literal("--color-border-warning"),Q.literal("--color-border-disabled"),Q.literal("--color-ring-primary"),Q.literal("--color-ring-secondary"),Q.literal("--color-ring-inverse"),Q.literal("--color-ring-info"),Q.literal("--color-ring-danger"),Q.literal("--color-ring-success"),Q.literal("--color-ring-warning"),Q.literal("--font-sans"),Q.literal("--font-mono"),Q.literal("--font-weight-normal"),Q.literal("--font-weight-medium"),Q.literal("--font-weight-semibold"),Q.literal("--font-weight-bold"),Q.literal("--font-text-xs-size"),Q.literal("--font-text-sm-size"),Q.literal("--font-text-md-size"),Q.literal("--font-text-lg-size"),Q.literal("--font-heading-xs-size"),Q.literal("--font-heading-sm-size"),Q.literal("--font-heading-md-size"),Q.literal("--font-heading-lg-size"),Q.literal("--font-heading-xl-size"),Q.literal("--font-heading-2xl-size"),Q.literal("--font-heading-3xl-size"),Q.literal("--font-text-xs-line-height"),Q.literal("--font-text-sm-line-height"),Q.literal("--font-text-md-line-height"),Q.literal("--font-text-lg-line-height"),Q.literal("--font-heading-xs-line-height"),Q.literal("--font-heading-sm-line-height"),Q.literal("--font-heading-md-line-height"),Q.literal("--font-heading-lg-line-height"),Q.literal("--font-heading-xl-line-height"),Q.literal("--font-heading-2xl-line-height"),Q.literal("--font-heading-3xl-line-height"),Q.literal("--border-radius-xs"),Q.literal("--border-radius-sm"),Q.literal("--border-radius-md"),Q.literal("--border-radius-lg"),Q.literal("--border-radius-xl"),Q.literal("--border-radius-full"),Q.literal("--border-width-regular"),Q.literal("--shadow-hairline"),Q.literal("--shadow-sm"),Q.literal("--shadow-md"),Q.literal("--shadow-lg")]).describe("CSS variable keys available to MCP apps for theming."),AQ=Q.record(TQ.describe(`Style variables for theming MCP apps.
|
|
2
|
+
|
|
3
|
+
Individual style keys are optional - hosts may provide any subset of these values.
|
|
4
|
+
Values are strings containing CSS values (colors, sizes, font stacks, etc.).
|
|
5
|
+
|
|
6
|
+
Note: This type uses \`Record<K, string | undefined>\` rather than \`Partial<Record<K, string>>\`
|
|
7
|
+
for compatibility with Zod schema generation. Both are functionally equivalent for validation.`),Q.union([Q.string(),Q.undefined()]).describe(`Style variables for theming MCP apps.
|
|
8
|
+
|
|
9
|
+
Individual style keys are optional - hosts may provide any subset of these values.
|
|
10
|
+
Values are strings containing CSS values (colors, sizes, font stacks, etc.).
|
|
11
|
+
|
|
12
|
+
Note: This type uses \`Record<K, string | undefined>\` rather than \`Partial<Record<K, string>>\`
|
|
13
|
+
for compatibility with Zod schema generation. Both are functionally equivalent for validation.`)).describe(`Style variables for theming MCP apps.
|
|
14
|
+
|
|
15
|
+
Individual style keys are optional - hosts may provide any subset of these values.
|
|
16
|
+
Values are strings containing CSS values (colors, sizes, font stacks, etc.).
|
|
17
|
+
|
|
18
|
+
Note: This type uses \`Record<K, string | undefined>\` rather than \`Partial<Record<K, string>>\`
|
|
19
|
+
for compatibility with Zod schema generation. Both are functionally equivalent for validation.`),kQ=Q.object({method:Q.literal("ui/open-link"),params:Q.object({url:Q.string().describe("URL to open in the host's browser")})}),S=Q.object({isError:Q.boolean().optional().describe("True if the host failed to open the URL (e.g., due to security policy).")}).passthrough(),C=Q.object({isError:Q.boolean().optional().describe("True if the download failed (e.g., user cancelled or host denied).")}).passthrough(),b=Q.object({isError:Q.boolean().optional().describe("True if the host rejected or failed to deliver the message.")}).passthrough(),SQ=Q.object({method:Q.literal("ui/notifications/sandbox-proxy-ready"),params:Q.object({})}),D=Q.object({connectDomains:Q.array(Q.string()).optional().describe(`Origins for network requests (fetch/XHR/WebSocket).
|
|
20
|
+
|
|
21
|
+
- Maps to CSP \`connect-src\` directive
|
|
22
|
+
- Empty or omitted → no network connections (secure default)`),resourceDomains:Q.array(Q.string()).optional().describe("Origins for static resources (images, scripts, stylesheets, fonts, media).\n\n- Maps to CSP `img-src`, `script-src`, `style-src`, `font-src`, `media-src` directives\n- Wildcard subdomains supported: `https://*.example.com`\n- Empty or omitted → no network resources (secure default)"),frameDomains:Q.array(Q.string()).optional().describe("Origins for nested iframes.\n\n- Maps to CSP `frame-src` directive\n- Empty or omitted → no nested iframes allowed (`frame-src 'none'`)"),baseUriDomains:Q.array(Q.string()).optional().describe("Allowed base URIs for the document.\n\n- Maps to CSP `base-uri` directive\n- Empty or omitted → only same origin allowed (`base-uri 'self'`)")}),F=Q.object({camera:Q.object({}).optional().describe("Request camera access.\n\nMaps to Permission Policy `camera` feature."),microphone:Q.object({}).optional().describe("Request microphone access.\n\nMaps to Permission Policy `microphone` feature."),geolocation:Q.object({}).optional().describe("Request geolocation access.\n\nMaps to Permission Policy `geolocation` feature."),clipboardWrite:Q.object({}).optional().describe("Request clipboard write access.\n\nMaps to Permission Policy `clipboard-write` feature.")}),CQ=Q.object({method:Q.literal("ui/notifications/size-changed"),params:Q.object({width:Q.number().optional().describe("New width in pixels."),height:Q.number().optional().describe("New height in pixels.")})}),x=Q.object({method:Q.literal("ui/notifications/tool-input"),params:Q.object({arguments:Q.record(Q.string(),Q.unknown().describe("Complete tool call arguments as key-value pairs.")).optional().describe("Complete tool call arguments as key-value pairs.")})}),v=Q.object({method:Q.literal("ui/notifications/tool-input-partial"),params:Q.object({arguments:Q.record(Q.string(),Q.unknown().describe("Partial tool call arguments (incomplete, may change).")).optional().describe("Partial tool call arguments (incomplete, may change).")})}),g=Q.object({method:Q.literal("ui/notifications/tool-cancelled"),params:Q.object({reason:Q.string().optional().describe('Optional reason for the cancellation (e.g., "user action", "timeout").')})}),a=Q.object({fonts:Q.string().optional()}),t=Q.object({variables:AQ.optional().describe("CSS variables for theming the app."),css:a.optional().describe("CSS blocks that apps can inject.")}),y=Q.object({method:Q.literal("ui/resource-teardown"),params:Q.object({})}),f=Q.record(Q.string(),Q.unknown()),k=Q.object({text:Q.object({}).optional().describe("Host supports text content blocks."),image:Q.object({}).optional().describe("Host supports image content blocks."),audio:Q.object({}).optional().describe("Host supports audio content blocks."),resource:Q.object({}).optional().describe("Host supports resource content blocks."),resourceLink:Q.object({}).optional().describe("Host supports resource link content blocks."),structuredContent:Q.object({}).optional().describe("Host supports structured content.")}),bQ=Q.object({method:Q.literal("ui/notifications/request-teardown"),params:Q.object({}).optional()}),e=Q.object({experimental:Q.record(Q.string(),Q.record(Q.string(),Q.any()).describe("Experimental features keyed by identifier.")).optional().describe("Experimental features keyed by identifier."),openLinks:Q.object({}).optional().describe("Host supports opening external URLs."),downloadFile:Q.object({}).optional().describe("Host supports file downloads via ui/download-file."),serverTools:Q.object({listChanged:Q.boolean().optional().describe("Host supports tools/list_changed notifications.")}).optional().describe("Host can proxy tool calls to the MCP server."),serverResources:Q.object({listChanged:Q.boolean().optional().describe("Host supports resources/list_changed notifications.")}).optional().describe("Host can proxy resource reads to the MCP server."),logging:Q.object({}).optional().describe("Host accepts log messages."),sandbox:Q.object({permissions:F.optional().describe("Permissions granted by the host (camera, microphone, geolocation)."),csp:D.optional().describe("CSP domains approved by the host.")}).optional().describe("Sandbox configuration applied by the host."),updateModelContext:k.optional().describe("Host accepts context updates (ui/update-model-context) to be included in the model's context for future turns."),message:k.optional().describe("Host supports receiving content messages (ui/message) from the view."),sampling:Q.object({tools:Q.object({}).optional().describe("Host supports tool use via `tools` and `toolChoice` parameters.")}).optional().describe("Host supports LLM sampling (sampling/createMessage) from the view.\nMirrors the MCP `ClientCapabilities.sampling` shape so hosts can pass it through.")}),QQ=Q.object({experimental:Q.record(Q.string(),Q.record(Q.string(),Q.any()).describe("Experimental features keyed by identifier.")).optional().describe("Experimental features keyed by identifier."),tools:Q.object({listChanged:Q.boolean().optional().describe("App supports tools/list_changed notifications.")}).optional().describe("App exposes MCP-style tools that the host can call."),availableDisplayModes:Q.array(_).optional().describe("Display modes the app supports.")}),xQ=Q.object({method:Q.literal("ui/notifications/initialized"),params:Q.object({}).optional()}),vQ=Q.object({csp:D.optional().describe("Content Security Policy configuration for UI resources."),permissions:F.optional().describe("Sandbox permissions requested by the UI resource."),domain:Q.string().optional().describe(`Dedicated origin for view sandbox.
|
|
23
|
+
|
|
24
|
+
Useful when views need stable, dedicated origins for OAuth callbacks, CORS policies, or API key allowlists.
|
|
25
|
+
|
|
26
|
+
**Host-dependent:** The format and validation rules for this field are determined by each host. Servers MUST consult host-specific documentation for the expected domain format. Common patterns include:
|
|
27
|
+
- Hash-based subdomains (e.g., \`{hash}.claudemcpcontent.com\`)
|
|
28
|
+
- URL-derived subdomains (e.g., \`www-example-com.oaiusercontent.com\`)
|
|
29
|
+
|
|
30
|
+
If omitted, host uses default sandbox origin (typically per-conversation).`),prefersBorder:Q.boolean().optional().describe(`Visual boundary preference - true if view prefers a visible border.
|
|
31
|
+
|
|
32
|
+
Boolean requesting whether a visible border and background is provided by the host. Specifying an explicit value for this is recommended because hosts' defaults may vary.
|
|
33
|
+
|
|
34
|
+
- \`true\`: request visible border + background
|
|
35
|
+
- \`false\`: request no visible border + background
|
|
36
|
+
- omitted: host decides border`)}),gQ=Q.object({method:Q.literal("ui/request-display-mode"),params:Q.object({mode:_.describe("The display mode being requested.")})}),u=Q.object({mode:_.describe("The display mode that was actually set. May differ from requested if not supported.")}).passthrough(),XQ=Q.union([Q.literal("model"),Q.literal("app")]).describe("Tool visibility scope - who can access the tool."),yQ=Q.object({resourceUri:Q.string().optional(),visibility:Q.array(XQ).optional().describe(`Who can access this tool. Default: ["model", "app"]
|
|
37
|
+
- "model": Tool visible to and callable by the agent
|
|
38
|
+
- "app": Tool callable by the app from this server only`),csp:Q.never().optional(),permissions:Q.never().optional()}),LX=Q.object({mimeTypes:Q.array(Q.string()).optional().describe('Array of supported MIME types for UI resources.\nMust include `"text/html;profile=mcp-app"` for MCP Apps support.')}),fQ=Q.object({method:Q.literal("ui/download-file"),params:Q.object({contents:Q.array(Q.union([UQ,MQ])).describe("Resource contents to download — embedded (inline data) or linked (host fetches). Uses standard MCP resource types.")})}),uQ=Q.object({method:Q.literal("ui/message"),params:Q.object({role:Q.literal("user").describe('Message role, currently only "user" is supported.'),content:Q.array(n).describe("Message content blocks (text, image, etc.).")})}),dQ=Q.object({method:Q.literal("ui/notifications/sandbox-resource-ready"),params:Q.object({html:Q.string().describe("HTML content to load into the inner iframe."),sandbox:Q.string().optional().describe("Optional override for the inner iframe's sandbox attribute."),csp:D.optional().describe("CSP configuration from resource metadata."),permissions:F.optional().describe("Sandbox permissions from resource metadata.")})}),d=Q.object({method:Q.literal("ui/notifications/tool-result"),params:IQ.describe("Standard MCP tool execution result.")}),h=Q.object({toolInfo:Q.object({id:wQ.optional().describe("JSON-RPC id of the tools/call request."),tool:HQ.describe("Tool definition including name, inputSchema, etc.")}).optional().describe("Metadata of the tool call that instantiated this App."),theme:s.optional().describe("Current color theme preference."),styles:t.optional().describe("Style configuration for theming the app."),displayMode:_.optional().describe("How the UI is currently displayed."),availableDisplayModes:Q.array(_).optional().describe("Display modes the host supports."),containerDimensions:Q.union([Q.object({height:Q.number().describe("Fixed container height in pixels.")}),Q.object({maxHeight:Q.union([Q.number(),Q.undefined()]).optional().describe("Maximum container height in pixels.")})]).and(Q.union([Q.object({width:Q.number().describe("Fixed container width in pixels.")}),Q.object({maxWidth:Q.union([Q.number(),Q.undefined()]).optional().describe("Maximum container width in pixels.")})])).optional().describe(`Container dimensions. Represents the dimensions of the iframe or other
|
|
39
|
+
container holding the app. Specify either width or maxWidth, and either height or maxHeight.`),locale:Q.string().optional().describe("User's language and region preference in BCP 47 format."),timeZone:Q.string().optional().describe("User's timezone in IANA format."),userAgent:Q.string().optional().describe("Host application identifier."),platform:Q.union([Q.literal("web"),Q.literal("desktop"),Q.literal("mobile")]).optional().describe("Platform type for responsive design decisions."),deviceCapabilities:Q.object({touch:Q.boolean().optional().describe("Whether the device supports touch input."),hover:Q.boolean().optional().describe("Whether the device supports hover interactions.")}).optional().describe("Device input capabilities."),safeAreaInsets:Q.object({top:Q.number().describe("Top safe area inset in pixels."),right:Q.number().describe("Right safe area inset in pixels."),bottom:Q.number().describe("Bottom safe area inset in pixels."),left:Q.number().describe("Left safe area inset in pixels.")}).optional().describe("Mobile safe area boundaries in pixels.")}).passthrough(),m=Q.object({method:Q.literal("ui/notifications/host-context-changed"),params:h.describe("Partial context update containing only changed fields.")}),hQ=Q.object({method:Q.literal("ui/update-model-context"),params:Q.object({content:Q.array(n).optional().describe("Context content blocks (text, image, etc.)."),structuredContent:Q.record(Q.string(),Q.unknown().describe("Structured content for machine-readable context data.")).optional().describe("Structured content for machine-readable context data.")})}),mQ=Q.object({method:Q.literal("ui/initialize"),params:Q.object({appInfo:o.describe("App identification (name and version)."),appCapabilities:QQ.describe("Features and capabilities this app provides."),protocolVersion:Q.string().describe("Protocol version this app supports.")})}),c=Q.object({protocolVersion:Q.string().describe('Negotiated protocol version string (e.g., "2025-11-21").'),hostInfo:o.describe("Host application identification and version."),hostCapabilities:e.describe("Features and capabilities provided by the host."),hostContext:h.describe("Rich context about the host environment.")}).passthrough();var cQ={target:"draft-2020-12"};async function l(X,Y){let Z=X["~standard"];if(Z.jsonSchema)return Z.jsonSchema[Y](cQ);throw Error(`Schema (vendor: ${Z.vendor}) does not implement Standard JSON Schema (~standard.jsonSchema). Use a library that does (zod v4, ArkType, Valibot) or wrap your schema accordingly.`)}async function p(X,Y,Z=""){let $=await X["~standard"].validate(Y);if($.issues){let K=$.issues.map((J)=>{let G=J.path?.map((W)=>typeof W==="object"?W.key:W).join(".");return G?`${G}: ${J.message}`:J.message}).join("; ");throw Error(Z+K)}return $.value}import{z as rQ}from"zod/v4";function E(){let X=document.documentElement.getAttribute("data-theme");if(X==="dark"||X==="light")return X;return document.documentElement.classList.contains("dark")?"dark":"light"}function R(X){let Y=document.documentElement;Y.setAttribute("data-theme",X),Y.style.colorScheme=X}function z(X,Y=document.documentElement){for(let[Z,$]of Object.entries(X))if($!==void 0)Y.style.setProperty(Z,$)}function I(X){if(document.getElementById("__mcp-host-fonts"))return;let Z=document.createElement("style");Z.id="__mcp-host-fonts",Z.textContent=X,document.head.appendChild(Z)}function iQ(X,Y){let Z={...X,...Y};if(Y.experimental!==void 0)Z.experimental={...X.experimental,...Y.experimental};if(Y.tools!==void 0)Z.tools={...X.tools,...Y.tools};return Z}class U extends lQ{_appInfo;_appCapabilities;options;_hostCapabilities;_hostInfo;_hostContext;_registeredTools={};_initializedSent=!1;_registeredEvents=new Set;_events=new j;_methods=new M;setRequestHandler=(...X)=>{let[Y,...Z]=H("request",X)??X;this._methods.claim(Y,"setRequestHandler"),super.setRequestHandler.call(this,Y,...Z)};setNotificationHandler=(...X)=>{let[Y,...Z]=H("notification",X)??X;this._methods.claim(Y,"setNotificationHandler"),super.setNotificationHandler.call(this,Y,...Z)};removeRequestHandler=(X)=>{this._methods.release(X),super.removeRequestHandler(X)};removeNotificationHandler=(X)=>{this._methods.release(X),super.removeNotificationHandler(X)};replaceRequestHandler=(X,...Y)=>{this._methods.replace(X),super.setRequestHandler.call(this,X,...Y)};_assertInitialized(X){if(this._initializedSent)return;let Y=`[ext-apps] App.${X}() called before connect() completed the ui/initialize handshake. Await app.connect() before calling this method, or move data loading to an ontoolresult handler.`;if(this.options?.strict)throw Error(Y);console.warn(`${Y}. This will throw in a future release.`)}eventSchemas={toolinput:x,toolinputpartial:v,toolresult:d,toolcancelled:g,hostcontextchanged:m};static ONE_SHOT_EVENTS=new Set(["toolinput","toolinputpartial","toolresult","toolcancelled"]);_everHadListener=new Set;_assertHandlerTiming(X){if(!U.ONE_SHOT_EVENTS.has(X)||this._everHadListener.has(X))return;if(this._everHadListener.add(X),!this._initializedSent)return;let Y=`[ext-apps] "${String(X)}" handler registered after connect() completed the ui/initialize handshake. The host may have already sent this notification. Register handlers before calling app.connect().`;if(this.options?.strict)throw Error(Y);console.warn(Y)}setEventHandler(X,Y){if(Y)this._assertHandlerTiming(X);this._ensureEventSlot(X),this._events.setHandler(X,Y)}addEventListener(X,Y){this._assertHandlerTiming(X),this._ensureEventSlot(X),this._events.addEventListener(X,Y)}removeEventListener(X,Y){this._events.removeEventListener(X,Y)}_ensureEventSlot(X){if(this._registeredEvents.has(X))return;let Y=this.eventSchemas[X];if(!Y)throw Error(`Unknown event: ${String(X)}`);this.setNotificationHandler(Y.shape.method.value,{params:Y.shape.params},(Z)=>{let $=Z;if(X==="hostcontextchanged")this._hostContext={...this._hostContext,...$};this._events.dispatch(X,$)}),this._registeredEvents.add(X)}getEventHandler(X){return this._events.getHandler(X)}warnIfRequestHandlerReplaced(X,Y,Z){if(Y&&Z)console.warn(`[MCP Apps] ${X} handler replaced. Previous handler will no longer be called.`)}constructor(X,Y={},Z={autoResize:!0}){super(Z);this._appInfo=X;this._appCapabilities=Y;this.options=Z;if(this._methods.replace("notifications/cancelled"),this._methods.replace("notifications/progress"),!Z.allowUnsafeEval)rQ.config({jitless:!0});this.replaceRequestHandler("ping",($)=>{return console.log("Received ping:",$.params),{}}),this.setEventHandler("hostcontextchanged",void 0)}buildContext(X){return X}registerAppCapabilities(X){if(this.transport)throw Error("Cannot register capabilities after transport is established");this._appCapabilities=iQ(this._appCapabilities,X)}registerTool(X,Y,Z){if(this._registeredTools[X])throw Error(`Tool ${X} is already registered`);let $=this,K=()=>{if($._initializedSent&&$._appCapabilities.tools?.listChanged)$.sendToolListChanged()},J=Y.inputSchema!==void 0,G={title:Y.title,description:Y.description,inputSchema:Y.inputSchema,outputSchema:Y.outputSchema,annotations:Y.annotations,_meta:Y._meta,enabled:!0,enable(){this.enabled=!0,K()},disable(){this.enabled=!1,K()},update(W){Object.assign(this,W),K()},remove(){if($._registeredTools[X]!==G)return;delete $._registeredTools[X],K()},handler:async(W,L)=>{if(!G.enabled)throw Error(`Tool ${X} is disabled`);let N;if(J){let q=G.inputSchema,O=q?await p(q,W??{},`Invalid input for tool ${X}: `):W??{};N=await Z(O,L)}else N=await Z(L);if(G.outputSchema&&!N.isError)N.structuredContent=await p(G.outputSchema,N.structuredContent,`Invalid output for tool ${X}: `);return N}};if(this._registeredTools[X]=G,!this._appCapabilities.tools&&!this.transport)this.registerAppCapabilities({tools:{listChanged:!0}});return this.ensureToolHandlersInitialized(),K(),G}_toolHandlersInitialized=!1;ensureToolHandlersInitialized(){if(this._toolHandlersInitialized)return;this._toolHandlersInitialized=!0,this.oncalltool=async(X,Y)=>{let Z=this._registeredTools[X.name];if(!Z)throw Error(`Tool ${X.name} not found`);return Z.handler(X.arguments,Y)},this.onlisttools=async(X,Y)=>{return{tools:await Promise.all(Object.entries(this._registeredTools).filter(([$,K])=>K.enabled).map(async([$,K])=>{let J={name:$,title:K.title,description:K.description,inputSchema:K.inputSchema?await l(K.inputSchema,"input"):{type:"object",properties:{}}};if(K.outputSchema)J.outputSchema=await l(K.outputSchema,"output");if(K.annotations)J.annotations=K.annotations;if(K._meta)J._meta=K._meta;return J}))}}}async sendToolListChanged(X={}){this._assertInitialized("sendToolListChanged"),await this.notification({method:"notifications/tools/list_changed",params:X})}getHostCapabilities(){return this._hostCapabilities}getHostVersion(){return this._hostInfo}getHostContext(){return this._hostContext}get ontoolinput(){return this.getEventHandler("toolinput")}set ontoolinput(X){this.setEventHandler("toolinput",X)}get ontoolinputpartial(){return this.getEventHandler("toolinputpartial")}set ontoolinputpartial(X){this.setEventHandler("toolinputpartial",X)}get ontoolresult(){return this.getEventHandler("toolresult")}set ontoolresult(X){this.setEventHandler("toolresult",X)}get ontoolcancelled(){return this.getEventHandler("toolcancelled")}set ontoolcancelled(X){this.setEventHandler("toolcancelled",X)}get onhostcontextchanged(){return this.getEventHandler("hostcontextchanged")}set onhostcontextchanged(X){this.setEventHandler("hostcontextchanged",X)}_onteardown;get onteardown(){return this._onteardown}set onteardown(X){this.warnIfRequestHandlerReplaced("onteardown",this._onteardown,X),this._onteardown=X,this.replaceRequestHandler("ui/resource-teardown",{params:y.shape.params,result:f},(Y,Z)=>{if(!this._onteardown)throw Error("No onteardown handler set");return this._onteardown(Y,Z)})}_oncalltool;get oncalltool(){return this._oncalltool}set oncalltool(X){this.warnIfRequestHandlerReplaced("oncalltool",this._oncalltool,X),this._oncalltool=X,this.replaceRequestHandler("tools/call",(Y,Z)=>{if(!this._oncalltool)throw Error("No oncalltool handler set");return this._oncalltool(Y.params,Z)})}_onlisttools;get onlisttools(){return this._onlisttools}set onlisttools(X){this.warnIfRequestHandlerReplaced("onlisttools",this._onlisttools,X),this._onlisttools=X,this.replaceRequestHandler("tools/list",(Y,Z)=>{if(!this._onlisttools)throw Error("No onlisttools handler set");return this._onlisttools(Y.params,Z)})}assertCapabilityForMethod(X){switch(X){case"sampling/createMessage":if(!this._hostCapabilities?.sampling)throw Error(`Host does not support sampling (required for ${X})`);break}}assertRequestHandlerCapability(X){switch(X){case"tools/call":case"tools/list":if(!this._appCapabilities.tools)throw Error(`Client does not support tool capability (required for ${X})`);return;default:return}}assertNotificationCapability(X){}async callServerTool(X,Y){if(this._assertInitialized("callServerTool"),typeof X==="string")throw Error(`callServerTool() expects an object as its first argument, but received a string ("${X}"). Did you mean: callServerTool({ name: "${X}", arguments: { ... } })?`);return await this.request({method:"tools/call",params:X},{onprogress:()=>{},resetTimeoutOnProgress:!0,...Y})}async readServerResource(X,Y){return this._assertInitialized("readServerResource"),await this.request({method:"resources/read",params:X},Y)}async listServerResources(X,Y){return this._assertInitialized("listServerResources"),await this.request({method:"resources/list",params:X},Y)}async createSamplingMessage(X,Y){return this._assertInitialized("createSamplingMessage"),await this.request({method:"sampling/createMessage",params:X},Y)}sendMessage(X,Y){return this._assertInitialized("sendMessage"),this.request({method:"ui/message",params:X},b,Y)}sendLog(X){return this.notification({method:"notifications/message",params:X})}updateModelContext(X,Y){return this._assertInitialized("updateModelContext"),this.request({method:"ui/update-model-context",params:X},pQ,Y)}openLink(X,Y){return this._assertInitialized("openLink"),this.request({method:"ui/open-link",params:X},S,Y)}sendOpenLink=this.openLink;downloadFile(X,Y){return this._assertInitialized("downloadFile"),this.request({method:"ui/download-file",params:X},C,Y)}requestTeardown(X={}){return this.notification({method:"ui/notifications/request-teardown",params:X})}requestDisplayMode(X,Y){return this._assertInitialized("requestDisplayMode"),this.request({method:"ui/request-display-mode",params:X},u,Y)}sendSizeChanged(X){return this.notification({method:"ui/notifications/size-changed",params:X})}setupSizeChangedNotifications(){let X=!1,Y=0,Z=0,$=()=>{if(X)return;X=!0,requestAnimationFrame(()=>{X=!1;let J=document.documentElement,G=J.style.height;J.style.height="max-content";let W=Math.ceil(J.getBoundingClientRect().height);J.style.height=G;let L=Math.ceil(window.innerWidth);if(L!==Y||W!==Z)Y=L,Z=W,this.sendSizeChanged({width:L,height:W})})};$();let K=new ResizeObserver($);return K.observe(document.documentElement),K.observe(document.body),()=>K.disconnect()}async connect(X=new V(window.parent,window.parent),Y){if(this.transport)throw Error("App is already connected. Call close() before connecting again.");this._initializedSent=!1;try{await super.connect(X);let Z=await this.request({method:"ui/initialize",params:{appCapabilities:this._appCapabilities,appInfo:this._appInfo,protocolVersion:T}},c,Y);if(Z===void 0)throw Error(`Server sent invalid initialize result: ${Z}`);if(this._hostCapabilities=Z.hostCapabilities,this._hostInfo=Z.hostInfo,this._hostContext=Z.hostContext,await this.notification({method:"ui/notifications/initialized"}),this._initializedSent=!0,this.options?.autoResize)this.setupSizeChangedNotifications()}catch(Z){throw this.close(),Z}}}function QY({appInfo:X,capabilities:Y,onAppCreated:Z,autoResize:$=!0,strict:K}){let[J,G]=r(null),[W,L]=r(!1),[N,q]=r(null);return nQ(()=>{let O=!0,B;async function ZQ(){try{let P=new V(window.parent,window.parent);if(B=new U(X,Y,{autoResize:$,strict:K}),Z?.(B),await B.connect(P),!O){B.close();return}G(B),L(!0),q(null)}catch(P){if(O)G(null),L(!1),q(P instanceof Error?P:Error("Failed to connect"))}}return ZQ(),()=>{O=!1,B?.close()}},[]),{app:J,isConnected:W,error:N}}import{useEffect as oQ}from"react";function KY(X,Y){oQ(()=>{if(!X)return;return X.setupSizeChangedNotifications()},[X,Y])}import{useEffect as sQ,useState as aQ}from"react";function LY(){let[X,Y]=aQ(E);return sQ(()=>{let Z=new MutationObserver(()=>{Y(E())});return Z.observe(document.documentElement,{attributes:!0,attributeFilter:["data-theme","class"],characterData:!1,childList:!1,subtree:!1}),()=>Z.disconnect()},[]),X}import{useEffect as w,useRef as YQ}from"react";function tQ(X,Y){let Z=YQ(!1);w(()=>{if(Z.current)return;if(Y?.theme)R(Y.theme);if(Y?.styles?.variables)z(Y.styles.variables);if(Y?.theme||Y?.styles?.variables)Z.current=!0},[Y]),w(()=>{if(!X)return;let $=(K)=>{if(K.theme)R(K.theme);if(K.styles?.variables)z(K.styles.variables)};return X.addEventListener("hostcontextchanged",$),()=>X.removeEventListener("hostcontextchanged",$)},[X])}function eQ(X,Y){let Z=YQ(!1);w(()=>{if(Z.current)return;if(Y?.styles?.css?.fonts)I(Y.styles.css.fonts),Z.current=!0},[Y]),w(()=>{if(!X)return;let $=(K)=>{if(K.styles?.css?.fonts)I(K.styles.css.fonts)};return X.addEventListener("hostcontextchanged",$),()=>X.removeEventListener("hostcontextchanged",$)},[X])}function _Y(X,Y){tQ(X,Y),eQ(X,Y)}export{_Y as useHostStyles,tQ as useHostStyleVariables,eQ as useHostFonts,LY as useDocumentTheme,KY as useAutoResize,QY as useApp,E as getDocumentTheme,z as applyHostStyleVariables,I as applyHostFonts,R as applyDocumentTheme,qQ as TOOL_RESULT_METHOD,A as TOOL_INPUT_PARTIAL_METHOD,_Q as TOOL_INPUT_METHOD,OQ as TOOL_CANCELLED_METHOD,VQ as SIZE_CHANGED_METHOD,BQ as SANDBOX_RESOURCE_READY_METHOD,NQ as SANDBOX_PROXY_READY_METHOD,$Q as RESOURCE_URI_META_KEY,DQ as RESOURCE_TEARDOWN_METHOD,KQ as RESOURCE_MIME_TYPE,jQ as REQUEST_TEARDOWN_METHOD,RQ as REQUEST_DISPLAY_MODE_METHOD,V as PostMessageTransport,GQ as OPEN_LINK_METHOD,hQ as McpUiUpdateModelContextRequestSchema,XQ as McpUiToolVisibilitySchema,d as McpUiToolResultNotificationSchema,yQ as McpUiToolMetaSchema,v as McpUiToolInputPartialNotificationSchema,x as McpUiToolInputNotificationSchema,g as McpUiToolCancelledNotificationSchema,s as McpUiThemeSchema,k as McpUiSupportedContentBlockModalitiesSchema,CQ as McpUiSizeChangedNotificationSchema,dQ as McpUiSandboxResourceReadyNotificationSchema,SQ as McpUiSandboxProxyReadyNotificationSchema,f as McpUiResourceTeardownResultSchema,y as McpUiResourceTeardownRequestSchema,F as McpUiResourcePermissionsSchema,vQ as McpUiResourceMetaSchema,D as McpUiResourceCspSchema,bQ as McpUiRequestTeardownNotificationSchema,u as McpUiRequestDisplayModeResultSchema,gQ as McpUiRequestDisplayModeRequestSchema,S as McpUiOpenLinkResultSchema,kQ as McpUiOpenLinkRequestSchema,b as McpUiMessageResultSchema,uQ as McpUiMessageRequestSchema,xQ as McpUiInitializedNotificationSchema,c as McpUiInitializeResultSchema,mQ as McpUiInitializeRequestSchema,t as McpUiHostStylesSchema,a as McpUiHostCssSchema,h as McpUiHostContextSchema,m as McpUiHostContextChangedNotificationSchema,e as McpUiHostCapabilitiesSchema,C as McpUiDownloadFileResultSchema,fQ as McpUiDownloadFileRequestSchema,_ as McpUiDisplayModeSchema,QQ as McpUiAppCapabilitiesSchema,LQ as MESSAGE_METHOD,T as LATEST_PROTOCOL_VERSION,FQ as INITIALIZE_METHOD,EQ as INITIALIZED_METHOD,PQ as HOST_CONTEXT_CHANGED_METHOD,j as EventDispatcher,WQ as DOWNLOAD_FILE_METHOD,U as App};
|