@mcp-use/client 2.0.0-beta.15 → 2.0.0-beta.17

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 (69) hide show
  1. package/dist/.tsbuildinfo +1 -1
  2. package/dist/auth/browser.d.ts +51 -2
  3. package/dist/auth/browser.d.ts.map +1 -1
  4. package/dist/auth/node.d.ts +99 -4
  5. package/dist/auth/node.d.ts.map +1 -1
  6. package/dist/auth/session-store.d.ts +6 -0
  7. package/dist/auth/session-store.d.ts.map +1 -1
  8. package/dist/core/base.d.ts +4 -8
  9. package/dist/core/base.d.ts.map +1 -1
  10. package/dist/core/browser.d.ts +14 -2
  11. package/dist/core/browser.d.ts.map +1 -1
  12. package/dist/core/config.d.ts +82 -20
  13. package/dist/core/config.d.ts.map +1 -1
  14. package/dist/core/node.d.ts +7 -10
  15. package/dist/core/node.d.ts.map +1 -1
  16. package/dist/core/session.d.ts +18 -4
  17. package/dist/core/session.d.ts.map +1 -1
  18. package/dist/index-browser.d.ts +1 -0
  19. package/dist/index-browser.d.ts.map +1 -1
  20. package/dist/index-browser.js +142 -21
  21. package/dist/index-browser.js.map +1 -1
  22. package/dist/index.d.ts +1 -1
  23. package/dist/index.js +218 -31
  24. package/dist/index.js.map +1 -1
  25. package/dist/react/McpClientProvider.d.ts +22 -10
  26. package/dist/react/McpClientProvider.d.ts.map +1 -1
  27. package/dist/react/index.d.ts +2 -0
  28. package/dist/react/index.d.ts.map +1 -1
  29. package/dist/react/index.js +164 -21
  30. package/dist/react/index.js.map +1 -1
  31. package/dist/react/rpc-logger.d.ts +5 -0
  32. package/dist/react/rpc-logger.d.ts.map +1 -1
  33. package/dist/react/storage.d.ts +47 -0
  34. package/dist/react/storage.d.ts.map +1 -1
  35. package/dist/react/types.d.ts +107 -16
  36. package/dist/react/types.d.ts.map +1 -1
  37. package/dist/react/useMcp-operations.d.ts.map +1 -1
  38. package/dist/react/view/ViewRenderer.d.ts +7 -0
  39. package/dist/react/view/ViewRenderer.d.ts.map +1 -1
  40. package/dist/react/view/parse-custom-props.d.ts +8 -0
  41. package/dist/react/view/parse-custom-props.d.ts.map +1 -1
  42. package/dist/react/view/resolve-view-resource.d.ts +10 -0
  43. package/dist/react/view/resolve-view-resource.d.ts.map +1 -1
  44. package/dist/react/view/types.d.ts +89 -0
  45. package/dist/react/view/types.d.ts.map +1 -1
  46. package/dist/react/view/view-detection.d.ts +18 -0
  47. package/dist/react/view/view-detection.d.ts.map +1 -1
  48. package/dist/react/view/view-host-policy.d.ts +35 -0
  49. package/dist/react/view/view-host-policy.d.ts.map +1 -1
  50. package/dist/sandbox.d.ts +2 -0
  51. package/dist/sandbox.d.ts.map +1 -0
  52. package/dist/sandbox.js +283 -0
  53. package/dist/sandbox.js.map +1 -0
  54. package/dist/telemetry/telemetry.d.ts +5 -1
  55. package/dist/telemetry/telemetry.d.ts.map +1 -1
  56. package/dist/transport/base.d.ts +85 -13
  57. package/dist/transport/base.d.ts.map +1 -1
  58. package/dist/transport/connection-manager.d.ts +1 -1
  59. package/dist/transport/http.d.ts +51 -2
  60. package/dist/transport/http.d.ts.map +1 -1
  61. package/dist/transport/stdio.d.ts +29 -1
  62. package/dist/transport/stdio.d.ts.map +1 -1
  63. package/dist/utils/elicitation.d.ts +4 -2
  64. package/dist/utils/elicitation.d.ts.map +1 -1
  65. package/dist/utils/logging.d.ts +1 -0
  66. package/dist/utils/logging.d.ts.map +1 -1
  67. package/dist/utils/version.d.ts +6 -0
  68. package/dist/utils/version.d.ts.map +1 -1
  69. package/package.json +8 -4
@@ -3,110 +3,193 @@ import type { CreateMessageRequest, CreateMessageResult, CreateMessageResultWith
3
3
  export type { McpUiDownloadFileRequest, McpUiDownloadFileResult, McpUiHostCapabilities, McpUiHostContext, McpUiResourceCsp, McpUiResourcePermissions, McpUiSupportedContentBlockModalities, };
4
4
  import type { Transport } from "@modelcontextprotocol/client";
5
5
  import type { ReactNode } from "react";
6
+ /** Display mode requested by an MCP App. */
6
7
  export type ViewDisplayMode = "inline" | "pip" | "fullscreen";
8
+ /** Policy used to enforce an MCP App's declared content security policy. */
7
9
  export type ViewCspMode = "permissive" | "widget-declared";
10
+ /** Host operations and server metadata available to a live MCP App. */
8
11
  export interface ViewConnection {
12
+ /** Calls an MCP server tool. */
9
13
  callTool: (name: string, args?: Record<string, unknown>, options?: {
10
14
  timeout?: number;
11
15
  resetTimeoutOnProgress?: boolean;
12
16
  }) => Promise<unknown>;
17
+ /** Reads an MCP resource by URI. */
13
18
  readResource: (uri: string) => Promise<unknown>;
19
+ /** Tools available to the host, including app visibility metadata. */
14
20
  tools?: readonly {
21
+ /** Tool name. */
15
22
  name: string;
23
+ /** Optional tool metadata. */
16
24
  _meta?: {
25
+ /** MCP App-specific tool metadata. */
17
26
  ui?: {
27
+ /** Surfaces allowed to invoke or receive the tool. */
18
28
  visibility?: readonly ("model" | "app")[];
19
29
  };
20
30
  };
21
31
  }[];
32
+ /** Resources available to the host. */
22
33
  resources?: readonly {
34
+ /** Resource URI. */
23
35
  uri: string;
36
+ /** Optional resource metadata. */
24
37
  _meta?: {
38
+ /** MCP App-specific resource metadata. */
25
39
  ui?: unknown;
26
40
  };
27
41
  }[];
28
42
  }
43
+ /** Live or preloaded content used to initialize a {@link ViewRenderer}. */
29
44
  export type ViewRendererSource = {
45
+ /** Selects live resource resolution. */
30
46
  kind: "live";
47
+ /** MCP connection used to read the resource and call tools. */
31
48
  connection: ViewConnection;
49
+ /** URI of the MCP App resource to load. */
32
50
  resourceUri: string;
33
51
  } | {
52
+ /** Selects preloaded HTML rendering. */
34
53
  kind: "preloaded";
54
+ /** Complete HTML document to render. */
35
55
  html: string;
56
+ /** CSP declared for the preloaded document. */
36
57
  csp?: McpUiResourceCsp;
58
+ /** Browser permissions requested by the preloaded document. */
37
59
  permissions?: McpUiResourcePermissions;
60
+ /** Whether the preloaded app prefers visible host borders. */
38
61
  prefersBorder?: boolean;
39
62
  };
63
+ /** Normalized HTML, CSP, permissions, and MIME metadata for a rendered view. */
40
64
  export type ResolvedViewResource = {
65
+ /** HTML document rendered in the sandbox. */
41
66
  html: string;
67
+ /** CSP declared by the resource before host policy is applied. */
42
68
  declaredCsp: McpUiResourceCsp | undefined;
69
+ /** CSP enforced by the host, if any. */
43
70
  csp: McpUiResourceCsp | undefined;
71
+ /** Browser permissions requested by the resource. */
44
72
  permissions: McpUiResourcePermissions | undefined;
73
+ /** Whether the app prefers a visible host border. */
45
74
  prefersBorder: boolean;
75
+ /** MIME type reported by the resource. */
46
76
  mimeType: string | undefined;
77
+ /** Whether the MIME type is the MCP App resource media type. */
47
78
  mimeTypeValid: boolean;
79
+ /** MIME validation warning, or `null` for a valid resource. */
48
80
  mimeTypeWarning: string | null;
49
81
  };
82
+ /** Browser CSP violation observed while an MCP App is running. */
50
83
  export type ViewCspViolation = {
84
+ /** CSP directive reported by the browser. */
51
85
  directive: string;
86
+ /** Effective CSP directive reported by the browser. */
52
87
  effectiveDirective?: string;
88
+ /** URI blocked by the policy. */
53
89
  blockedUri: string;
90
+ /** Source file associated with the violation. */
54
91
  sourceFile?: string | null;
92
+ /** Source line associated with the violation. */
55
93
  lineNumber?: number | null;
94
+ /** Source column associated with the violation. */
56
95
  columnNumber?: number | null;
96
+ /** Original policy text reported by the browser. */
57
97
  originalPolicy?: string;
98
+ /** Unix timestamp in milliseconds when the violation occurred. */
58
99
  timestamp: number;
59
100
  };
101
+ /** App-visible tools and the function used to call them. */
60
102
  export type ViewAppToolConnection = {
103
+ /** Tools available to the app. */
61
104
  tools: Tool[];
105
+ /** Calls an app-visible tool. */
62
106
  callTool: (name: string, args?: Record<string, unknown>) => Promise<unknown>;
63
107
  };
108
+ /** Lifecycle stage reported by a rendered MCP App. */
64
109
  export type ViewLifecycleStatus = "resolving" | "sandbox-loading" | "connecting" | "initialized" | "ready" | "tearing-down" | "closed" | "error";
110
+ /** Lifecycle update emitted by {@link ViewRenderer}. */
65
111
  export type ViewLifecycleEvent = {
112
+ /** Current lifecycle stage. */
66
113
  status: ViewLifecycleStatus;
114
+ /** Error message when `status` is `"error"`. */
67
115
  error?: string;
68
116
  };
117
+ /** Props accepted by {@link ViewRenderer}. */
69
118
  export interface ViewRendererProps {
119
+ /** Stable identifier for the view instance. */
70
120
  viewId: string;
121
+ /** Live resource or preloaded HTML to render. */
71
122
  source: ViewRendererSource;
123
+ /** Sandbox page URL or function that derives one from the resolved resource. */
72
124
  sandboxUrl?: URL | ((resolved: ResolvedViewResource) => URL);
125
+ /** Tool associated with the view. */
73
126
  toolName?: string;
127
+ /** Complete tool input forwarded to the app. */
74
128
  toolInput?: Record<string, unknown>;
129
+ /** Tool result forwarded to the app. */
75
130
  toolOutput?: unknown;
131
+ /** Partial streaming tool input forwarded to the app. */
76
132
  partialToolInput?: Record<string, unknown>;
133
+ /** String-valued custom properties forwarded to the app. */
77
134
  customProps?: Record<string, string>;
135
+ /** Whether the associated tool call was cancelled. */
78
136
  cancelled?: boolean;
137
+ /** Host identity advertised to the app. */
79
138
  hostInfo?: {
139
+ /** Stable host name. */
80
140
  name: string;
141
+ /** Host version. */
81
142
  version: string;
82
143
  };
144
+ /** Initial host context sent to the app. */
83
145
  hostContext?: McpUiHostContext;
146
+ /** Explicit host capability overrides. */
84
147
  hostCapabilities?: Partial<McpUiHostCapabilities>;
148
+ /** Content modalities accepted by the host's message handler. */
85
149
  messageCapabilities?: McpUiSupportedContentBlockModalities;
150
+ /** Content modalities accepted by the model-context handler. */
86
151
  modelContextCapabilities?: McpUiSupportedContentBlockModalities;
152
+ /** CSP enforcement mode. Defaults to `"permissive"`. */
87
153
  cspMode?: ViewCspMode;
154
+ /** Initial display mode. Defaults to `"inline"`. */
88
155
  displayMode?: ViewDisplayMode;
156
+ /** Called when the app requests a supported display mode. */
89
157
  onDisplayModeChange?: (mode: ViewDisplayMode) => void;
158
+ /** Maximum inline view width in pixels. */
90
159
  inlineMaxWidth?: number;
160
+ /** Whether to hide the built-in view chrome. */
91
161
  chromeless?: boolean;
162
+ /** Handles content the app sends to the conversation. */
92
163
  onMessage?: (content: unknown[]) => void | Promise<void>;
164
+ /** Handles sampling requests from the app. */
93
165
  onSamplingRequest?: (params: CreateMessageRequest["params"]) => Promise<CreateMessageResult | CreateMessageResultWithTools>;
166
+ /** Handles file-download requests from the app. */
94
167
  onDownloadFile?: (params: McpUiDownloadFileRequest["params"]) => Promise<McpUiDownloadFileResult>;
168
+ /** Receives the current app-visible tool connection. */
95
169
  onAppToolsChanged?: (connection: ViewAppToolConnection | null) => void;
170
+ /** Handles model-context updates from the app. */
96
171
  onModelContextUpdate?: (ctx: {
97
172
  content?: unknown;
98
173
  structuredContent?: unknown;
99
174
  }) => void | Promise<void>;
175
+ /** Handles structured log entries from the app. */
100
176
  onLog?: (entry: {
101
177
  level: string;
102
178
  data: unknown;
103
179
  }) => void;
180
+ /** Called when the app signals that it is ready. */
104
181
  onReady?: () => void;
182
+ /** Called for each view lifecycle transition. */
105
183
  onLifecycleChange?: (event: ViewLifecycleEvent) => void;
184
+ /** Called when view initialization or runtime handling fails. */
106
185
  onError?: (message: string) => void;
186
+ /** Called when the browser reports a CSP violation. */
107
187
  onCspViolation?: (violation: ViewCspViolation) => void;
188
+ /** Called after a live or preloaded resource is normalized. */
108
189
  onResourceResolved?: (resolved: ResolvedViewResource) => void;
190
+ /** Wraps the host transport before it is connected to the app bridge. */
109
191
  wrapTransport?: (transport: Transport, viewId: string) => Transport;
192
+ /** Timeout in milliseconds for app-initiated tool calls. Defaults to `600000`. */
110
193
  toolCallTimeout?: number;
111
194
  /** Dev mock of ChatGPT file APIs for local hosts (inspector). Default false. */
112
195
  mockOpenAiFileApis?: boolean;
@@ -114,7 +197,9 @@ export interface ViewRendererProps {
114
197
  onInlineHeightChange?: (height: number) => void;
115
198
  /** Inspector-only chrome shown above the iframe in fullscreen display mode. */
116
199
  fullscreenHeader?: {
200
+ /** Header title. */
117
201
  title: string;
202
+ /** Optional header icon URL. */
118
203
  iconUrl?: string | null;
119
204
  };
120
205
  /** Optional host close control for fullscreen (e.g. shared Button + icon). */
@@ -123,9 +208,13 @@ export interface ViewRendererProps {
123
208
  "data-testid": string;
124
209
  "aria-label": string;
125
210
  }) => ReactNode;
211
+ /** Additional class name applied to the view container. */
126
212
  className?: string;
213
+ /** Test identifier applied to the view container. */
127
214
  testId?: string;
215
+ /** Status text shown while the associated tool is running. */
128
216
  invoking?: string;
217
+ /** Status text shown after the associated tool completes. */
129
218
  invoked?: string;
130
219
  }
131
220
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/react/view/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,uBAAuB,EACvB,qBAAqB,EACrB,gBAAgB,EAChB,gBAAgB,EAChB,wBAAwB,EACxB,oCAAoC,EACrC,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EACV,oBAAoB,EACpB,mBAAmB,EACnB,4BAA4B,EAC5B,IAAI,EACL,MAAM,8BAA8B,CAAC;AAEtC,YAAY,EACV,wBAAwB,EACxB,uBAAuB,EACvB,qBAAqB,EACrB,gBAAgB,EAChB,gBAAgB,EAChB,wBAAwB,EACxB,oCAAoC,GACrC,CAAC;AACF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAEvC,MAAM,MAAM,eAAe,GAAG,QAAQ,GAAG,KAAK,GAAG,YAAY,CAAC;AAE9D,MAAM,MAAM,WAAW,GAAG,YAAY,GAAG,iBAAiB,CAAC;AAE3D,MAAM,WAAW,cAAc;IAC7B,QAAQ,EAAE,CACR,IAAI,EAAE,MAAM,EACZ,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC9B,OAAO,CAAC,EAAE;QAAE,OAAO,CAAC,EAAE,MAAM,CAAC;QAAC,sBAAsB,CAAC,EAAE,OAAO,CAAA;KAAE,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AoF;IACpF,oBAAoB,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;IAChD,+EAA+E;IAC/E,gBAAgB,CAAC,EAAE;QACjB,oBAAoB;QACpB,KAAK,EAAE,MAAM,CAAC;QACd,gCAAgC;QAChC,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;KACzB,CAAC;IACF,8EAA8E;IAC9E,qBAAqB,CAAC,EAAE,CAAC,KAAK,EAAE;QAC9B,OAAO,EAAE,MAAM,IAAI,CAAC;QACpB,aAAa,EAAE,MAAM,CAAC;QACtB,YAAY,EAAE,MAAM,CAAC;KACtB,KAAK,SAAS,CAAC;IAChB,2DAA2D;IAC3D,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,qDAAqD;IACrD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,8DAA8D;IAC9D,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,6DAA6D;IAC7D,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB"}
@@ -1,4 +1,22 @@
1
+ /**
2
+ * Reads the MCP App resource URI from tool metadata.
3
+ *
4
+ * @param toolMeta - Tool `_meta` object.
5
+ * @returns The declared view resource URI, or `null` when none is declared.
6
+ */
1
7
  export declare function getViewResourceUri(toolMeta?: Record<string, unknown>): string | null;
8
+ /**
9
+ * Tests whether tool metadata declares an MCP App resource.
10
+ *
11
+ * @param toolMeta - Tool `_meta` object.
12
+ * @returns `true` when the tool declares a view resource URI.
13
+ */
2
14
  export declare function isViewTool(toolMeta?: Record<string, unknown>): boolean;
15
+ /**
16
+ * Tests whether a resource uses the MCP App HTML media type.
17
+ *
18
+ * @param mimeType - Resource MIME type.
19
+ * @returns `true` for the MCP App resource media type.
20
+ */
3
21
  export declare function isViewResource(mimeType?: string): boolean;
4
22
  //# sourceMappingURL=view-detection.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"view-detection.d.ts","sourceRoot":"","sources":["../../../src/react/view/view-detection.ts"],"names":[],"mappings":"AAEA,wBAAgB,kBAAkB,CAChC,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GACjC,MAAM,GAAG,IAAI,CAWf;AAED,wBAAgB,UAAU,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAEtE;AAED,wBAAgB,cAAc,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAEzD"}
1
+ {"version":3,"file":"view-detection.d.ts","sourceRoot":"","sources":["../../../src/react/view/view-detection.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAChC,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GACjC,MAAM,GAAG,IAAI,CAWf;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAEtE;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAEzD"}
@@ -1,5 +1,6 @@
1
1
  import type { McpUiHostCapabilities, McpUiSupportedContentBlockModalities } from "./ext-apps-bridge.js";
2
2
  import type { ViewConnection, ViewDisplayMode } from "./types.js";
3
+ /** Inputs used to derive the capabilities advertised by an MCP App host. */
3
4
  type CapabilityInputs = {
4
5
  hasConnection: boolean;
5
6
  hasMessageHandler: boolean;
@@ -10,17 +11,51 @@ type CapabilityInputs = {
10
11
  messageCapabilities?: McpUiSupportedContentBlockModalities;
11
12
  modelContextCapabilities?: McpUiSupportedContentBlockModalities;
12
13
  };
14
+ /**
15
+ * Builds host capabilities from the callbacks and connections the host exposes.
16
+ *
17
+ * @param inputs - Available host features and supported content modalities.
18
+ * @returns Capabilities suitable for MCP App bridge initialization.
19
+ */
13
20
  export declare function buildDefaultHostCapabilities({ hasConnection, hasMessageHandler, hasModelContextHandler, hasLogHandler, hasSamplingHandler, hasDownloadHandler, messageCapabilities, modelContextCapabilities, }: CapabilityInputs): McpUiHostCapabilities;
21
+ /**
22
+ * Tests whether a tool is visible to the model.
23
+ *
24
+ * Tools without explicit visibility metadata remain model-visible.
25
+ *
26
+ * @param tool - Tool metadata to inspect.
27
+ * @returns `true` when the tool may be presented to the model.
28
+ */
14
29
  export declare function isToolVisibleToModel(tool: {
15
30
  _meta?: unknown;
16
31
  }): boolean;
32
+ /**
33
+ * Validates and dispatches an MCP App `ui/message` payload.
34
+ *
35
+ * @param handler - Host callback that accepts message content.
36
+ * @param content - Content blocks supplied by the app.
37
+ * @throws When the host has no message handler or `content` is empty.
38
+ */
17
39
  export declare function dispatchUiMessage(handler: ((content: unknown[]) => void | Promise<void>) | undefined, content: unknown[]): Promise<void>;
40
+ /**
41
+ * Resolves a display-mode request against host and app availability.
42
+ *
43
+ * @param options - Requested and current modes plus each side's supported modes.
44
+ * @returns The requested mode when both sides support it; otherwise `current`.
45
+ */
18
46
  export declare function resolveRequestedDisplayMode({ requested, current, hostAvailable, appAvailable, }: {
19
47
  requested: ViewDisplayMode;
20
48
  current: ViewDisplayMode;
21
49
  hostAvailable?: readonly ViewDisplayMode[];
22
50
  appAvailable?: readonly ViewDisplayMode[];
23
51
  }): ViewDisplayMode;
52
+ /**
53
+ * Asserts that an MCP App may call a named server tool.
54
+ *
55
+ * @param tools - Tools available through the live view connection.
56
+ * @param name - Tool name requested by the app.
57
+ * @throws When the tool is unavailable or not visible to apps.
58
+ */
24
59
  export declare function assertAppCanCallTool(tools: ViewConnection["tools"], name: string): void;
25
60
  export {};
26
61
  //# sourceMappingURL=view-host-policy.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"view-host-policy.d.ts","sourceRoot":"","sources":["../../../src/react/view/view-host-policy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,qBAAqB,EACrB,oCAAoC,EACrC,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE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1
+ {"version":3,"file":"view-host-policy.d.ts","sourceRoot":"","sources":["../../../src/react/view/view-host-policy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,qBAAqB,EACrB,oCAAoC,EACrC,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAElE,4EAA4E;AAC5E,KAAK,gBAAgB,GAAG;IACtB,aAAa,EAAE,OAAO,CAAC;IACvB,iBAAiB,EAAE,OAAO,CAAC;IAC3B,sBAAsB,EAAE,OAAO,CAAC;IAChC,aAAa,EAAE,OAAO,CAAC;IACvB,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,mBAAmB,CAAC,EAAE,oCAAoC,CAAC;IAC3D,wBAAwB,CAAC,EAAE,oCAAoC,CAAC;CACjE,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,4BAA4B,CAAC,EAC3C,aAAa,EACb,iBAAiB,EACjB,sBAAsB,EACtB,aAAa,EACb,kBAAkB,EAClB,kBAAkB,EAClB,mBAAmB,EACnB,wBAAwB,GACzB,EAAE,gBAAgB,GAAG,qBAAqB,CAmB1C;AAED;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE;IAAE,KAAK,CAAC,EAAE,OAAO,CAAA;CAAE,GAAG,OAAO,CAQvE;AAED;;;;;;GAMG;AACH,wBAAsB,iBAAiB,CACrC,OAAO,EAAE,CAAC,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,GAAG,SAAS,EACnE,OAAO,EAAE,OAAO,EAAE,GACjB,OAAO,CAAC,IAAI,CAAC,CAQf;AAED;;;;;GAKG;AACH,wBAAgB,2BAA2B,CAAC,EAC1C,SAAS,EACT,OAAO,EACP,aAAa,EACb,YAAY,GACb,EAAE;IACD,SAAS,EAAE,eAAe,CAAC;IAC3B,OAAO,EAAE,eAAe,CAAC;IACzB,aAAa,CAAC,EAAE,SAAS,eAAe,EAAE,CAAC;IAC3C,YAAY,CAAC,EAAE,SAAS,eAAe,EAAE,CAAC;CAC3C,GAAG,eAAe,CAMlB;AAED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,cAAc,CAAC,OAAO,CAAC,EAC9B,IAAI,EAAE,MAAM,GACX,IAAI,CAUN"}
@@ -0,0 +1,2 @@
1
+ export { buildSandboxProxyBlobHtml } from "./react/view/sandbox-blob-url.js";
2
+ //# sourceMappingURL=sandbox.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sandbox.d.ts","sourceRoot":"","sources":["../src/sandbox.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,kCAAkC,CAAC"}
@@ -0,0 +1,283 @@
1
+ // src/react/view/sandbox-blob-url.ts
2
+ var SANDBOX_PROXY_HTML = `<!doctype html>
3
+ <html>
4
+ <head>
5
+ <meta charset="utf-8" />
6
+ <meta
7
+ http-equiv="Content-Security-Policy"
8
+ content="default-src 'self'; img-src * data: blob: 'unsafe-inline'; media-src * blob: data:; font-src * blob: data:; script-src * 'wasm-unsafe-eval' 'unsafe-inline' 'unsafe-eval' blob: data:; style-src * blob: data: 'unsafe-inline'; connect-src * data: blob: about:; frame-src * blob: data: http://localhost:* https://localhost:* http://127.0.0.1:* https://127.0.0.1:*;"
9
+ />
10
+ <title>MCP Apps Sandbox Proxy</title>
11
+ <style>
12
+ html, body { margin: 0; padding: 0; height: 100%; width: 100%; overflow: hidden; }
13
+ * { box-sizing: border-box; }
14
+ iframe { display: block; background-color: transparent; border: 0px none transparent; padding: 0px; width: 100%; height: 100%; }
15
+ </style>
16
+ </head>
17
+ <body>
18
+ <script>
19
+ function sanitizeDomain(domain) {
20
+ if (typeof domain !== "string") return "";
21
+ return domain.replace(/['"<>;]/g, "").trim();
22
+ }
23
+
24
+ function buildAllowAttribute(permissions) {
25
+ if (!permissions) return "";
26
+ const allowList = [];
27
+ if (permissions.camera) allowList.push("camera *");
28
+ if (permissions.microphone) allowList.push("microphone *");
29
+ if (permissions.geolocation) allowList.push("geolocation *");
30
+ if (permissions.clipboardWrite) allowList.push("clipboard-write *");
31
+ return allowList.join("; ");
32
+ }
33
+
34
+ function buildCSP(csp) {
35
+ if (!csp) {
36
+ return [
37
+ "default-src 'none'",
38
+ "script-src 'unsafe-inline'",
39
+ "style-src 'unsafe-inline'",
40
+ "img-src data:",
41
+ "font-src data:",
42
+ "media-src data:",
43
+ "connect-src 'none'",
44
+ "frame-src 'none'",
45
+ "object-src 'none'",
46
+ "base-uri 'none'",
47
+ ].join("; ");
48
+ }
49
+
50
+ const connectDomains = (csp.connectDomains || []).map(sanitizeDomain).filter(Boolean);
51
+ const resourceDomains = (csp.resourceDomains || []).map(sanitizeDomain).filter(Boolean);
52
+ const frameDomains = (csp.frameDomains || []).map(sanitizeDomain).filter(Boolean);
53
+ const baseUriDomains = (csp.baseUriDomains || []).map(sanitizeDomain).filter(Boolean);
54
+ const scriptDirectives = (csp.scriptDirectives || []).filter(function(d) { return typeof d === "string" && d.length > 0; });
55
+
56
+ const connectSrc = connectDomains.length > 0 ? connectDomains.join(" ") : "'none'";
57
+ const resourceSrc = resourceDomains.length > 0 ? ["data:", "blob:", ...resourceDomains].join(" ") : "data: blob:";
58
+ const frameSrc = frameDomains.length > 0 ? frameDomains.join(" ") : "'none'";
59
+ const baseUri = baseUriDomains.length > 0 ? baseUriDomains.join(" ") : "'none'";
60
+ const scriptSrcParts = ["'unsafe-inline'", resourceSrc];
61
+ if (scriptDirectives.length > 0) scriptSrcParts.push(scriptDirectives.join(" "));
62
+
63
+ return [
64
+ "default-src 'none'",
65
+ "script-src " + scriptSrcParts.join(" "),
66
+ "style-src 'unsafe-inline' " + resourceSrc,
67
+ "img-src " + resourceSrc,
68
+ "font-src " + resourceSrc,
69
+ "media-src " + resourceSrc,
70
+ "connect-src " + connectSrc,
71
+ "frame-src " + frameSrc,
72
+ "object-src 'none'",
73
+ "base-uri " + baseUri,
74
+ ].join("; ");
75
+ }
76
+
77
+ function buildViolationListenerScript() {
78
+ return \`<script>
79
+ document.addEventListener('securitypolicyviolation', function(e) {
80
+ var violation = {
81
+ type: 'mcp-apps:csp-violation',
82
+ directive: e.violatedDirective,
83
+ blockedUri: e.blockedURI,
84
+ sourceFile: e.sourceFile || null,
85
+ lineNumber: e.lineNumber || null,
86
+ columnNumber: e.columnNumber || null,
87
+ effectiveDirective: e.effectiveDirective,
88
+ originalPolicy: e.originalPolicy,
89
+ disposition: e.disposition,
90
+ timestamp: Date.now()
91
+ };
92
+ console.warn('[MCP Apps CSP Violation]', violation.directive, ':', violation.blockedUri);
93
+ window.parent.postMessage(violation, '*');
94
+ });
95
+
96
+ function serializeConsoleArgs(args) {
97
+ try {
98
+ return Array.from(args || []).map(function(arg) {
99
+ if (arg instanceof Error) {
100
+ return {
101
+ type: 'Error',
102
+ message: arg.message,
103
+ stack: arg.stack,
104
+ name: arg.name,
105
+ };
106
+ }
107
+ if (typeof arg === 'object' && arg !== null) {
108
+ try {
109
+ return JSON.parse(JSON.stringify(arg));
110
+ } catch (e) {
111
+ return String(arg);
112
+ }
113
+ }
114
+ return arg;
115
+ });
116
+ } catch (e) {
117
+ return [String(args)];
118
+ }
119
+ }
120
+
121
+ function sendConsoleToParent(level, args) {
122
+ try {
123
+ window.parent.postMessage({
124
+ type: 'iframe-console-log',
125
+ level: level,
126
+ args: serializeConsoleArgs(args),
127
+ timestamp: new Date().toISOString(),
128
+ url: window.location.href,
129
+ }, '*');
130
+ } catch (e) {}
131
+ }
132
+
133
+ var originalConsoleError = console.error.bind(console);
134
+ console.error = function() {
135
+ var args = Array.from(arguments);
136
+ originalConsoleError.apply(console, args);
137
+ sendConsoleToParent('error', args);
138
+ };
139
+
140
+ window.addEventListener('error', function(event) {
141
+ sendConsoleToParent('error', [{
142
+ message: event.message,
143
+ filename: event.filename,
144
+ lineno: event.lineno,
145
+ colno: event.colno,
146
+ error: event.error ? {
147
+ message: event.error.message,
148
+ stack: event.error.stack,
149
+ name: event.error.name,
150
+ } : null,
151
+ }]);
152
+ });
153
+
154
+ window.addEventListener('unhandledrejection', function(event) {
155
+ sendConsoleToParent('error', [{
156
+ message: 'Unhandled Promise Rejection',
157
+ reason: event.reason ? String(event.reason) : 'Unknown',
158
+ error: event.reason instanceof Error ? {
159
+ message: event.reason.message,
160
+ stack: event.reason.stack,
161
+ name: event.reason.name,
162
+ } : null,
163
+ }]);
164
+ });
165
+ </\` + \`script>\`;
166
+ }
167
+
168
+ function injectCSP(html, cspValue) {
169
+ const cspMeta = '<meta http-equiv="Content-Security-Policy" content="' + cspValue + '">';
170
+ const violationListener = buildViolationListenerScript();
171
+ const injection = cspMeta + violationListener;
172
+
173
+ if (html.includes("<head>")) {
174
+ return html.replace("<head>", "<head>" + injection);
175
+ } else if (html.includes("<HEAD>")) {
176
+ return html.replace("<HEAD>", "<HEAD>" + injection);
177
+ } else if (html.includes("<html>")) {
178
+ return html.replace("<html>", "<html><head>" + injection + "</head>");
179
+ } else if (html.includes("<HTML>")) {
180
+ return html.replace("<HTML>", "<HTML><head>" + injection + "</head>");
181
+ } else if (html.includes("<!DOCTYPE") || html.includes("<!doctype")) {
182
+ return html.replace(/(<!DOCTYPE[^>]*>|<!doctype[^>]*>)/i, "$1<head>" + injection + "</head>");
183
+ } else {
184
+ return injection + html;
185
+ }
186
+ }
187
+
188
+ // Query params from host (csp_mode, permissions, widget_csp). AppFrame only
189
+ // sends { html, csp } in sandbox-resource-ready; we carry the rest on the URL.
190
+ // Blob URLs cannot reliably carry search params, so the CDN shell injects
191
+ // window.__SANDBOX_SEARCH__ via buildSandboxProxyBlobHtml.
192
+ const query = new URLSearchParams(
193
+ typeof window.__SANDBOX_SEARCH__ === "string"
194
+ ? window.__SANDBOX_SEARCH__
195
+ : location.search
196
+ );
197
+ const queryCspMode = query.get("csp_mode") || "permissive";
198
+ let queryPermissions = null;
199
+ let queryWidgetCsp = null;
200
+ try {
201
+ const rawPerm = query.get("permissions");
202
+ if (rawPerm) queryPermissions = JSON.parse(rawPerm);
203
+ } catch (e) {}
204
+ try {
205
+ const rawCsp = query.get("widget_csp");
206
+ if (rawCsp) queryWidgetCsp = JSON.parse(rawCsp);
207
+ } catch (e) {}
208
+
209
+ const inner = document.createElement("iframe");
210
+ inner.style = "width:100%; height:100%; border:none;";
211
+ inner.setAttribute("sandbox", "allow-scripts allow-same-origin allow-forms");
212
+ document.body.appendChild(inner);
213
+
214
+ window.addEventListener("message", async (event) => {
215
+ if (event.source === window.parent) {
216
+ if (event.data && event.data.method === "ui/notifications/sandbox-resource-ready") {
217
+ const params = event.data.params || {};
218
+ const html = params.html;
219
+ const sandbox = params.sandbox;
220
+ // Prefer message csp when present; fall back to URL widget_csp
221
+ const csp = params.csp != null ? params.csp : queryWidgetCsp;
222
+ const permissions = params.permissions != null ? params.permissions : queryPermissions;
223
+ const permissive =
224
+ typeof params.permissive === "boolean"
225
+ ? params.permissive
226
+ : queryCspMode === "permissive";
227
+ if (typeof sandbox === "string") {
228
+ inner.setAttribute("sandbox", sandbox);
229
+ }
230
+ const allowAttribute = buildAllowAttribute(permissions);
231
+ if (allowAttribute) {
232
+ inner.setAttribute("allow", allowAttribute);
233
+ }
234
+ if (typeof html === "string") {
235
+ if (permissive) {
236
+ const permissiveCsp = [
237
+ "default-src * 'unsafe-inline' 'unsafe-eval' data: blob: filesystem: about:",
238
+ "script-src * 'unsafe-inline' 'unsafe-eval' data: blob:",
239
+ "style-src * 'unsafe-inline' data: blob:",
240
+ "img-src * data: blob: https: http:",
241
+ "media-src * data: blob: https: http:",
242
+ "font-src * data: blob: https: http:",
243
+ "connect-src * data: blob: https: http: ws: wss: about:",
244
+ "frame-src * data: blob: https: http: about:",
245
+ "object-src * data: blob:",
246
+ "base-uri *",
247
+ "form-action *",
248
+ ].join("; ");
249
+ const processedHtml = injectCSP(html, permissiveCsp);
250
+ inner.srcdoc = processedHtml;
251
+ } else {
252
+ const cspValue = buildCSP(csp);
253
+ const processedHtml = injectCSP(html, cspValue);
254
+ inner.srcdoc = processedHtml;
255
+ }
256
+ }
257
+ } else {
258
+ if (inner && inner.contentWindow) {
259
+ inner.contentWindow.postMessage(event.data, "*");
260
+ }
261
+ }
262
+ } else if (event.source === inner.contentWindow) {
263
+ window.parent.postMessage(event.data, "*");
264
+ }
265
+ });
266
+
267
+ window.parent.postMessage({
268
+ jsonrpc: "2.0",
269
+ method: "ui/notifications/sandbox-proxy-ready",
270
+ params: {},
271
+ }, "*");
272
+ </script>
273
+ </body>
274
+ </html>`;
275
+ function buildSandboxProxyBlobHtml(search) {
276
+ const escaped = JSON.stringify(search).replace(/</g, "\\u003c");
277
+ const inject = "<script>window.__SANDBOX_SEARCH__ = " + escaped + ";</script>";
278
+ return SANDBOX_PROXY_HTML.replace("<body>", "<body>" + inject);
279
+ }
280
+ export {
281
+ buildSandboxProxyBlobHtml
282
+ };
283
+ //# sourceMappingURL=sandbox.js.map