@mcp-use/client 2.0.0-beta.14 → 2.0.0-beta.16

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.
@@ -128,7 +128,7 @@ var Logger = class {
128
128
  var logger = Logger.get();
129
129
 
130
130
  // src/utils/version.ts
131
- var VERSION = "2.0.0-beta.14";
131
+ var VERSION = "2.0.0-beta.16";
132
132
  function getPackageVersion() {
133
133
  return VERSION;
134
134
  }
package/dist/index.js CHANGED
@@ -1134,7 +1134,7 @@ init_connector_telemetry();
1134
1134
  init_logging();
1135
1135
 
1136
1136
  // src/utils/version.ts
1137
- var VERSION = "2.0.0-beta.14";
1137
+ var VERSION = "2.0.0-beta.16";
1138
1138
  function getPackageVersion() {
1139
1139
  return VERSION;
1140
1140
  }
@@ -30,5 +30,5 @@ export { McpClientProvider, useMcpClient, useMcpServer, } from "./McpClientProvi
30
30
  export type { McpClientContextType, McpClientProviderProps, } from "./McpClientProvider.js";
31
31
  export { LocalStorageProvider, MemoryStorageProvider, type CachedServerMetadata, type StorageProvider, } from "./storage.js";
32
32
  export { getRpcLogs, getAllRpcLogs, subscribeToRpcLogs, clearRpcLogs, type RpcLogEntry, } from "./rpc-logger.js";
33
- export { ViewRenderer, resolveViewResource, getViewResourceUri, isViewResource, isViewTool, isToolVisibleToModel, parseCustomProps, buildViewSandboxBlobUrl, type ViewRendererProps, type ViewConnection, type ViewDisplayMode, type ViewCspMode, type ViewRendererSource, type ResolvedViewResource, type ViewCspViolation, type ViewLifecycleEvent, type ViewLifecycleStatus, type McpUiHostCapabilities, type McpUiHostContext, type McpUiResourceCsp, type McpUiResourcePermissions, type McpUiSupportedContentBlockModalities, } from "./view/ViewRenderer.js";
33
+ export { ViewRenderer, resolveViewResource, getViewResourceUri, isViewResource, isViewTool, isToolVisibleToModel, parseCustomProps, buildSandboxProxyBlobHtml, buildViewSandboxBlobUrl, buildViewSandboxUrl, type ViewRendererProps, type ViewConnection, type ViewDisplayMode, type ViewCspMode, type ViewRendererSource, type ResolvedViewResource, type ViewCspViolation, type ViewLifecycleEvent, type ViewLifecycleStatus, type ViewAppToolConnection, type McpUiDownloadFileRequest, type McpUiDownloadFileResult, type McpUiHostCapabilities, type McpUiHostContext, type McpUiResourceCsp, type McpUiResourcePermissions, type McpUiSupportedContentBlockModalities, } from "./view/ViewRenderer.js";
34
34
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,YAAY,EACV,aAAa,EACb,YAAY,EACZ,mBAAmB,EACnB,SAAS,EACT,eAAe;AACf,sCAAsC;AACtC,gBAAgB,EAChB,wBAAwB,EACxB,eAAe,EACf,sBAAsB,EACtB,yBAAyB,GAC1B,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,yBAAyB,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC;AAChF,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAGpD,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAGzD,OAAO,EACL,GAAG,EACH,SAAS,EACT,kBAAkB,GACnB,MAAM,mCAAmC,CAAC;AAG3C,YAAY,EACV,cAAc,EACd,YAAY,EACZ,uBAAuB,EACvB,sBAAsB,EACtB,YAAY,EACZ,eAAe,EACf,cAAc,EACd,MAAM,EACN,kBAAkB,EAClB,QAAQ,EACR,oBAAoB,EACpB,IAAI,EACJ,SAAS,GACV,MAAM,8BAA8B,CAAC;AACtC,YAAY,EACV,2BAA2B,EAC3B,2BAA2B,GAC5B,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EACV,2BAA2B,EAC3B,2BAA2B,EAC5B,MAAM,mBAAmB,CAAC;AAC3B,sDAAsD;AACtD,MAAM,MAAM,4BAA4B,GAAG;IACzC,MAAM,EAAE,wBAAwB,CAAC;IACjC,MAAM,EAAE,2BAA2B,CAAC;CACrC,CAAC;AACF,4DAA4D;AAC5D,YAAY,EAAE,4BAA4B,IAAI,oBAAoB,EAAE,CAAC;AACrE,2DAA2D;AAC3D,YAAY,EAAE,2BAA2B,IAAI,mBAAmB,EAAE,CAAC;AACnE,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAG/D,OAAO,EACL,iBAAiB,EACjB,YAAY,EACZ,YAAY,GACb,MAAM,wBAAwB,CAAC;AAChC,YAAY,EACV,oBAAoB,EACpB,sBAAsB,GACvB,MAAM,wBAAwB,CAAC;AAGhC,OAAO,EACL,oBAAoB,EACpB,qBAAqB,EACrB,KAAK,oBAAoB,EACzB,KAAK,eAAe,GACrB,MAAM,cAAc,CAAC;AAGtB,OAAO,EACL,UAAU,EACV,aAAa,EACb,kBAAkB,EAClB,YAAY,EACZ,KAAK,WAAW,GACjB,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EACL,YAAY,EACZ,mBAAmB,EACnB,kBAAkB,EAClB,cAAc,EACd,UAAU,EACV,oBAAoB,EACpB,gBAAgB,EAChB,uBAAuB,EACvB,KAAK,iBAAiB,EACtB,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,KAAK,WAAW,EAChB,KAAK,kBAAkB,EACvB,KAAK,oBAAoB,EACzB,KAAK,gBAAgB,EACrB,KAAK,kBAAkB,EACvB,KAAK,mBAAmB,EACxB,KAAK,qBAAqB,EAC1B,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EACrB,KAAK,wBAAwB,EAC7B,KAAK,oCAAoC,GAC1C,MAAM,wBAAwB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,YAAY,EACV,aAAa,EACb,YAAY,EACZ,mBAAmB,EACnB,SAAS,EACT,eAAe;AACf,sCAAsC;AACtC,gBAAgB,EAChB,wBAAwB,EACx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rB,MAAM,cAAc,CAAC;AAGtB,OAAO,EACL,UAAU,EACV,aAAa,EACb,kBAAkB,EAClB,YAAY,EACZ,KAAK,WAAW,GACjB,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EACL,YAAY,EACZ,mBAAmB,EACnB,kBAAkB,EAClB,cAAc,EACd,UAAU,EACV,oBAAoB,EACpB,gBAAgB,EAChB,yBAAyB,EACzB,uBAAuB,EACvB,mBAAmB,EACnB,KAAK,iBAAiB,EACtB,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,KAAK,WAAW,EAChB,KAAK,kBAAkB,EACvB,KAAK,oBAAoB,EACzB,KAAK,gBAAgB,EACrB,KAAK,kBAAkB,EACvB,KAAK,mBAAmB,EACxB,KAAK,qBAAqB,EAC1B,KAAK,wBAAwB,EAC7B,KAAK,uBAAuB,EAC5B,KAAK,qBAAqB,EAC1B,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EACrB,KAAK,wBAAwB,EAC7B,KAAK,oCAAoC,GAC1C,MAAM,wBAAwB,CAAC"}
@@ -1534,7 +1534,7 @@ var HttpConnector = class extends BaseConnector {
1534
1534
  };
1535
1535
 
1536
1536
  // src/utils/version.ts
1537
- var VERSION = "2.0.0-beta.14";
1537
+ var VERSION = "2.0.0-beta.16";
1538
1538
  function getPackageVersion() {
1539
1539
  return VERSION;
1540
1540
  }
@@ -7307,6 +7307,11 @@ function resolveViewResource(options) {
7307
7307
  }
7308
7308
 
7309
7309
  // src/react/view/sandbox-blob-url.ts
7310
+ function buildViewSandboxUrl(sandboxDocumentUrl, options) {
7311
+ const url = new URL(sandboxDocumentUrl.href);
7312
+ applySandboxSearchParams(url, options);
7313
+ return url;
7314
+ }
7310
7315
  function applySandboxSearchParams(url, options) {
7311
7316
  const { cspMode, permissions, widgetCsp } = options;
7312
7317
  url.searchParams.set(
@@ -7679,6 +7684,8 @@ function buildDefaultHostCapabilities({
7679
7684
  hasMessageHandler,
7680
7685
  hasModelContextHandler,
7681
7686
  hasLogHandler,
7687
+ hasSamplingHandler,
7688
+ hasDownloadHandler,
7682
7689
  messageCapabilities,
7683
7690
  modelContextCapabilities
7684
7691
  }) {
@@ -7689,6 +7696,8 @@ function buildDefaultHostCapabilities({
7689
7696
  serverResources: {}
7690
7697
  } : {},
7691
7698
  ...hasLogHandler ? { logging: {} } : {},
7699
+ ...hasSamplingHandler ? { sampling: {} } : {},
7700
+ ...hasDownloadHandler ? { downloadFile: {} } : {},
7692
7701
  ...hasModelContextHandler ? { updateModelContext: modelContextCapabilities ?? { text: {} } } : {},
7693
7702
  ...hasMessageHandler ? { message: messageCapabilities ?? { text: {} } } : {}
7694
7703
  };
@@ -7820,6 +7829,9 @@ function ViewRendererBase({
7820
7829
  inlineMaxWidth = 768,
7821
7830
  chromeless,
7822
7831
  onMessage,
7832
+ onSamplingRequest,
7833
+ onDownloadFile,
7834
+ onAppToolsChanged,
7823
7835
  onModelContextUpdate,
7824
7836
  onLog,
7825
7837
  onReady,
@@ -7857,13 +7869,20 @@ function ViewRendererBase({
7857
7869
  );
7858
7870
  const [internalDisplayMode, setInternalDisplayMode] = useState4("inline");
7859
7871
  const displayMode = displayModeProp ?? internalDisplayMode;
7872
+ const hasMessageHandler = onMessage !== void 0;
7873
+ const hasModelContextHandler = onModelContextUpdate !== void 0;
7874
+ const hasLogHandler = onLog !== void 0;
7875
+ const hasSamplingHandler = onSamplingRequest !== void 0;
7876
+ const hasDownloadHandler = onDownloadFile !== void 0;
7860
7877
  const effectiveHostCapabilities = useMemo3(
7861
7878
  () => ({
7862
7879
  ...buildDefaultHostCapabilities({
7863
7880
  hasConnection: source.kind === "live",
7864
- hasMessageHandler: onMessage !== void 0,
7865
- hasModelContextHandler: onModelContextUpdate !== void 0,
7866
- hasLogHandler: onLog !== void 0,
7881
+ hasMessageHandler,
7882
+ hasModelContextHandler,
7883
+ hasLogHandler,
7884
+ hasSamplingHandler,
7885
+ hasDownloadHandler,
7867
7886
  messageCapabilities,
7868
7887
  modelContextCapabilities
7869
7888
  }),
@@ -7871,11 +7890,13 @@ function ViewRendererBase({
7871
7890
  }),
7872
7891
  [
7873
7892
  hostCapabilities,
7893
+ hasLogHandler,
7894
+ hasSamplingHandler,
7895
+ hasDownloadHandler,
7896
+ hasMessageHandler,
7897
+ hasModelContextHandler,
7874
7898
  messageCapabilities,
7875
7899
  modelContextCapabilities,
7876
- onLog,
7877
- onMessage,
7878
- onModelContextUpdate,
7879
7900
  source.kind
7880
7901
  ]
7881
7902
  );
@@ -7888,6 +7909,12 @@ function ViewRendererBase({
7888
7909
  hostContextRef.current = effectiveHostContext;
7889
7910
  const onMessageRef = useRef4(onMessage);
7890
7911
  onMessageRef.current = onMessage;
7912
+ const onSamplingRequestRef = useRef4(onSamplingRequest);
7913
+ onSamplingRequestRef.current = onSamplingRequest;
7914
+ const onDownloadFileRef = useRef4(onDownloadFile);
7915
+ onDownloadFileRef.current = onDownloadFile;
7916
+ const onAppToolsChangedRef = useRef4(onAppToolsChanged);
7917
+ onAppToolsChangedRef.current = onAppToolsChanged;
7891
7918
  const toolInputRef = useRef4(toolInput);
7892
7919
  toolInputRef.current = toolInput;
7893
7920
  const partialToolInputRef = useRef4(partialToolInput);
@@ -8121,6 +8148,24 @@ function ViewRendererBase({
8121
8148
  return {};
8122
8149
  };
8123
8150
  }
8151
+ if (capabilities.sampling) {
8152
+ bridge.oncreatesamplingmessage = async (params) => {
8153
+ const handler = onSamplingRequestRef.current;
8154
+ if (!handler) {
8155
+ throw new Error("This host surface does not support sampling");
8156
+ }
8157
+ return handler(params);
8158
+ };
8159
+ }
8160
+ if (capabilities.downloadFile) {
8161
+ bridge.ondownloadfile = async (params) => {
8162
+ const handler = onDownloadFileRef.current;
8163
+ if (!handler) {
8164
+ throw new Error("This host surface does not support downloads");
8165
+ }
8166
+ return handler(params);
8167
+ };
8168
+ }
8124
8169
  bridge.onopenlink = async ({ url }) => {
8125
8170
  if (url) window.open(url, "_blank", "noopener,noreferrer");
8126
8171
  return {};
@@ -8208,6 +8253,35 @@ function ViewRendererBase({
8208
8253
  onInlineHeightChangeRef.current?.(height);
8209
8254
  }
8210
8255
  };
8256
+ let publishedAppToolsSignature = null;
8257
+ const publishAppTools = async () => {
8258
+ const handler = onAppToolsChangedRef.current;
8259
+ if (!bridge || !handler) return;
8260
+ const appCapabilities = bridge.getAppCapabilities();
8261
+ if (!appCapabilities?.tools) {
8262
+ handler(null);
8263
+ return;
8264
+ }
8265
+ const result = await bridge.listTools({});
8266
+ if (disposed || !bridge) return;
8267
+ const signature = JSON.stringify(result.tools);
8268
+ if (signature === publishedAppToolsSignature) return;
8269
+ publishedAppToolsSignature = signature;
8270
+ const currentBridge = bridge;
8271
+ handler({
8272
+ tools: result.tools,
8273
+ callTool: (name, args) => currentBridge.callTool({
8274
+ name,
8275
+ arguments: args ?? {}
8276
+ })
8277
+ });
8278
+ };
8279
+ bridge.setNotificationHandler(
8280
+ "notifications/tools/list_changed",
8281
+ async () => {
8282
+ await publishAppTools();
8283
+ }
8284
+ );
8211
8285
  const initPromise = hookInitialized(bridge);
8212
8286
  let transport = new PostMessageTransport(
8213
8287
  iframe.contentWindow,
@@ -8228,9 +8302,11 @@ function ViewRendererBase({
8228
8302
  bridgeRef.current = bridge;
8229
8303
  setInitCount((c) => c + 1);
8230
8304
  onLifecycleChangeRef.current?.({ status: "initialized" });
8305
+ await publishAppTools();
8231
8306
  const currentPartialToolInput = partialToolInputRef.current;
8232
- if (currentPartialToolInput) {
8233
- bridge.sendToolInputPartial({
8307
+ const hasCompletedToolResult = toolOutputRef.current !== void 0 && toolOutputRef.current !== null;
8308
+ if (currentPartialToolInput && !hasCompletedToolResult) {
8309
+ await bridge.sendToolInputPartial({
8234
8310
  arguments: currentPartialToolInput
8235
8311
  });
8236
8312
  } else {
@@ -8238,14 +8314,14 @@ function ViewRendererBase({
8238
8314
  ...toolInputRef.current,
8239
8315
  ...parseCustomProps(customPropsRef.current)
8240
8316
  };
8241
- bridge.sendToolInput({ arguments: mergedArgs });
8317
+ await bridge.sendToolInput({ arguments: mergedArgs });
8242
8318
  }
8243
8319
  const toolResultPayload = buildToolResultPayload(
8244
8320
  toolOutputRef.current,
8245
8321
  customPropsRef.current
8246
8322
  );
8247
8323
  if (toolResultPayload) {
8248
- bridge.sendToolResult(toolResultPayload);
8324
+ await bridge.sendToolResult(toolResultPayload);
8249
8325
  }
8250
8326
  onLifecycleChangeRef.current?.({ status: "ready" });
8251
8327
  } catch (err) {
@@ -8262,6 +8338,7 @@ function ViewRendererBase({
8262
8338
  disposed = true;
8263
8339
  const toClose = bridge;
8264
8340
  bridgeRef.current = null;
8341
+ onAppToolsChangedRef.current?.(null);
8265
8342
  if (!toClose) return;
8266
8343
  onLifecycleChangeRef.current?.({ status: "tearing-down" });
8267
8344
  void (async () => {
@@ -8294,33 +8371,37 @@ function ViewRendererBase({
8294
8371
  useEffect5(() => {
8295
8372
  const bridge = bridgeRef.current;
8296
8373
  if (!bridge || initCount === 0 || !effectiveHostContext) return;
8297
- bridge.setHostContext(effectiveHostContext);
8374
+ void bridge.setHostContext(effectiveHostContext);
8298
8375
  }, [effectiveHostContext, initCount]);
8299
8376
  useEffect5(() => {
8300
8377
  const bridge = bridgeRef.current;
8301
- if (!bridge || initCount === 0 || !partialToolInput) return;
8302
- bridge.sendToolInputPartial({ arguments: partialToolInput });
8303
- }, [initCount, partialToolInput]);
8378
+ if (!bridge || initCount === 0 || !partialToolInput || toolOutput !== void 0 && toolOutput !== null) {
8379
+ return;
8380
+ }
8381
+ void bridge.sendToolInputPartial({ arguments: partialToolInput });
8382
+ }, [initCount, partialToolInput, toolOutput]);
8304
8383
  useEffect5(() => {
8305
8384
  const bridge = bridgeRef.current;
8306
- if (!bridge || initCount === 0 || partialToolInput) return;
8385
+ if (!bridge || initCount === 0 || partialToolInput && (toolOutput === void 0 || toolOutput === null)) {
8386
+ return;
8387
+ }
8307
8388
  const mergedArgs = {
8308
8389
  ...toolInput,
8309
8390
  ...parseCustomProps(customProps)
8310
8391
  };
8311
- bridge.sendToolInput({ arguments: mergedArgs });
8312
- }, [initCount, toolInput, partialToolInput, customProps]);
8392
+ void bridge.sendToolInput({ arguments: mergedArgs });
8393
+ }, [initCount, toolInput, partialToolInput, customProps, toolOutput]);
8313
8394
  useEffect5(() => {
8314
8395
  const bridge = bridgeRef.current;
8315
8396
  if (!bridge || initCount === 0) return;
8316
8397
  const toolResultPayload = buildToolResultPayload(toolOutput, customProps);
8317
8398
  if (!toolResultPayload) return;
8318
- bridge.sendToolResult(toolResultPayload);
8399
+ void bridge.sendToolResult(toolResultPayload);
8319
8400
  }, [initCount, toolOutput, customProps]);
8320
8401
  useEffect5(() => {
8321
8402
  const bridge = bridgeRef.current;
8322
8403
  if (!bridge || initCount === 0 || !cancelled) return;
8323
- bridge.sendToolCancelled({ reason: "Cancelled by user" });
8404
+ void bridge.sendToolCancelled({ reason: "Cancelled by user" });
8324
8405
  }, [cancelled, initCount]);
8325
8406
  const readyFiredRef = useRef4(false);
8326
8407
  useEffect5(() => {
@@ -8454,6 +8535,9 @@ function viewRendererAreEqual(prev, next) {
8454
8535
  if (prev.modelContextCapabilities !== next.modelContextCapabilities)
8455
8536
  return false;
8456
8537
  if (prev.onMessage !== next.onMessage) return false;
8538
+ if (prev.onSamplingRequest !== next.onSamplingRequest) return false;
8539
+ if (prev.onDownloadFile !== next.onDownloadFile) return false;
8540
+ if (prev.onAppToolsChanged !== next.onAppToolsChanged) return false;
8457
8541
  if (prev.onModelContextUpdate !== next.onModelContextUpdate) return false;
8458
8542
  if (prev.cspMode !== next.cspMode) return false;
8459
8543
  if (prev.mockOpenAiFileApis !== next.mockOpenAiFileApis) return false;
@@ -8473,7 +8557,9 @@ export {
8473
8557
  Tel,
8474
8558
  Telemetry,
8475
8559
  ViewRenderer,
8560
+ buildSandboxProxyBlobHtml,
8476
8561
  buildViewSandboxBlobUrl,
8562
+ buildViewSandboxUrl,
8477
8563
  clearRpcLogs,
8478
8564
  detectFavicon,
8479
8565
  getAllRpcLogs,