mcp-use 1.2.2-canary.0 → 1.2.2-canary.1

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 (152) hide show
  1. package/dist/.tsbuildinfo +1 -1
  2. package/dist/{chunk-VPPILX7B.js → chunk-3RJENWH4.js} +15 -6
  3. package/dist/{chunk-UVUM35MV.js → chunk-7UX634PO.js} +307 -112
  4. package/dist/{chunk-CPV4QNHD.js → chunk-KLIBVJ3Z.js} +145 -79
  5. package/dist/{chunk-EYAIJPBH.js → chunk-MZLETWQQ.js} +55 -17
  6. package/dist/{chunk-C3SRZK7H.js → chunk-RSGKBEHH.js} +144 -72
  7. package/dist/index.cjs +719 -300
  8. package/dist/index.d.ts +24 -24
  9. package/dist/index.d.ts.map +1 -1
  10. package/dist/index.js +86 -28
  11. package/dist/{langfuse-MO3AMDBE.js → langfuse-LCJ6VJEP.js} +2 -2
  12. package/dist/src/adapters/base.d.ts +2 -2
  13. package/dist/src/adapters/base.d.ts.map +1 -1
  14. package/dist/src/adapters/index.d.ts +2 -2
  15. package/dist/src/adapters/index.d.ts.map +1 -1
  16. package/dist/src/adapters/langchain_adapter.d.ts +4 -4
  17. package/dist/src/adapters/langchain_adapter.d.ts.map +1 -1
  18. package/dist/src/agents/base.d.ts +1 -1
  19. package/dist/src/agents/base.d.ts.map +1 -1
  20. package/dist/src/agents/index.d.ts +3 -3
  21. package/dist/src/agents/index.d.ts.map +1 -1
  22. package/dist/src/agents/mcp_agent.d.ts +12 -12
  23. package/dist/src/agents/mcp_agent.d.ts.map +1 -1
  24. package/dist/src/agents/prompts/system_prompt_builder.d.ts +2 -2
  25. package/dist/src/agents/prompts/system_prompt_builder.d.ts.map +1 -1
  26. package/dist/src/agents/prompts/templates.d.ts.map +1 -1
  27. package/dist/src/agents/remote.d.ts +2 -2
  28. package/dist/src/agents/remote.d.ts.map +1 -1
  29. package/dist/src/agents/types.d.ts +1 -1
  30. package/dist/src/agents/types.d.ts.map +1 -1
  31. package/dist/src/agents/utils/ai_sdk.d.ts +1 -1
  32. package/dist/src/agents/utils/ai_sdk.d.ts.map +1 -1
  33. package/dist/src/agents/utils/index.d.ts +1 -1
  34. package/dist/src/agents/utils/index.d.ts.map +1 -1
  35. package/dist/src/auth/browser-provider.d.ts +2 -2
  36. package/dist/src/auth/browser-provider.d.ts.map +1 -1
  37. package/dist/src/auth/callback.d.ts.map +1 -1
  38. package/dist/src/auth/index.d.ts +3 -3
  39. package/dist/src/auth/index.d.ts.map +1 -1
  40. package/dist/src/auth/types.d.ts +1 -1
  41. package/dist/src/auth/types.d.ts.map +1 -1
  42. package/dist/src/browser.cjs +508 -201
  43. package/dist/src/browser.d.ts +17 -17
  44. package/dist/src/browser.d.ts.map +1 -1
  45. package/dist/src/browser.js +11 -5
  46. package/dist/src/client/base.d.ts +2 -2
  47. package/dist/src/client/base.d.ts.map +1 -1
  48. package/dist/src/client/browser.d.ts +2 -2
  49. package/dist/src/client/browser.d.ts.map +1 -1
  50. package/dist/src/client.d.ts +2 -2
  51. package/dist/src/client.d.ts.map +1 -1
  52. package/dist/src/config.d.ts +1 -1
  53. package/dist/src/config.d.ts.map +1 -1
  54. package/dist/src/connectors/base.d.ts +5 -5
  55. package/dist/src/connectors/base.d.ts.map +1 -1
  56. package/dist/src/connectors/http.d.ts +3 -3
  57. package/dist/src/connectors/http.d.ts.map +1 -1
  58. package/dist/src/connectors/index.d.ts +4 -4
  59. package/dist/src/connectors/index.d.ts.map +1 -1
  60. package/dist/src/connectors/stdio.d.ts +3 -3
  61. package/dist/src/connectors/stdio.d.ts.map +1 -1
  62. package/dist/src/connectors/websocket.d.ts +3 -3
  63. package/dist/src/connectors/websocket.d.ts.map +1 -1
  64. package/dist/src/logging.d.ts +4 -4
  65. package/dist/src/logging.d.ts.map +1 -1
  66. package/dist/src/managers/index.d.ts +2 -2
  67. package/dist/src/managers/index.d.ts.map +1 -1
  68. package/dist/src/managers/server_manager.d.ts +4 -4
  69. package/dist/src/managers/server_manager.d.ts.map +1 -1
  70. package/dist/src/managers/tools/acquire_active_mcp_server.d.ts +3 -3
  71. package/dist/src/managers/tools/acquire_active_mcp_server.d.ts.map +1 -1
  72. package/dist/src/managers/tools/add_server_from_config.d.ts +3 -3
  73. package/dist/src/managers/tools/add_server_from_config.d.ts.map +1 -1
  74. package/dist/src/managers/tools/base.d.ts +6 -6
  75. package/dist/src/managers/tools/base.d.ts.map +1 -1
  76. package/dist/src/managers/tools/connect_mcp_server.d.ts +4 -4
  77. package/dist/src/managers/tools/connect_mcp_server.d.ts.map +1 -1
  78. package/dist/src/managers/tools/index.d.ts +5 -5
  79. package/dist/src/managers/tools/index.d.ts.map +1 -1
  80. package/dist/src/managers/tools/list_mcp_servers.d.ts +3 -3
  81. package/dist/src/managers/tools/list_mcp_servers.d.ts.map +1 -1
  82. package/dist/src/managers/tools/release_mcp_server_connection.d.ts +3 -3
  83. package/dist/src/managers/tools/release_mcp_server_connection.d.ts.map +1 -1
  84. package/dist/src/managers/types.d.ts +3 -3
  85. package/dist/src/managers/types.d.ts.map +1 -1
  86. package/dist/src/oauth-helper.d.ts.map +1 -1
  87. package/dist/src/observability/index.d.ts +3 -3
  88. package/dist/src/observability/index.d.ts.map +1 -1
  89. package/dist/src/observability/langfuse.d.ts +1 -1
  90. package/dist/src/observability/langfuse.d.ts.map +1 -1
  91. package/dist/src/observability/manager.d.ts +1 -1
  92. package/dist/src/observability/manager.d.ts.map +1 -1
  93. package/dist/src/observability/types.d.ts +1 -1
  94. package/dist/src/observability/types.d.ts.map +1 -1
  95. package/dist/src/react/index.cjs +295 -154
  96. package/dist/src/react/index.d.ts +6 -6
  97. package/dist/src/react/index.d.ts.map +1 -1
  98. package/dist/src/react/index.js +3 -3
  99. package/dist/src/react/types.d.ts +6 -6
  100. package/dist/src/react/types.d.ts.map +1 -1
  101. package/dist/src/react/useMcp.d.ts +1 -1
  102. package/dist/src/react/useMcp.d.ts.map +1 -1
  103. package/dist/src/react/useWidget.d.ts +5 -2
  104. package/dist/src/react/useWidget.d.ts.map +1 -1
  105. package/dist/src/react/widget-types.d.ts +3 -3
  106. package/dist/src/react/widget-types.d.ts.map +1 -1
  107. package/dist/src/server/adapters/mcp-ui-adapter.d.ts +3 -3
  108. package/dist/src/server/adapters/mcp-ui-adapter.d.ts.map +1 -1
  109. package/dist/src/server/index.cjs +170 -50
  110. package/dist/src/server/index.d.ts +4 -4
  111. package/dist/src/server/index.d.ts.map +1 -1
  112. package/dist/src/server/index.js +174 -51
  113. package/dist/src/server/logging.d.ts +1 -1
  114. package/dist/src/server/logging.d.ts.map +1 -1
  115. package/dist/src/server/mcp-server.d.ts +29 -29
  116. package/dist/src/server/mcp-server.d.ts.map +1 -1
  117. package/dist/src/server/types/common.d.ts +2 -2
  118. package/dist/src/server/types/common.d.ts.map +1 -1
  119. package/dist/src/server/types/index.d.ts +4 -4
  120. package/dist/src/server/types/index.d.ts.map +1 -1
  121. package/dist/src/server/types/prompt.d.ts +2 -2
  122. package/dist/src/server/types/prompt.d.ts.map +1 -1
  123. package/dist/src/server/types/resource.d.ts +24 -24
  124. package/dist/src/server/types/resource.d.ts.map +1 -1
  125. package/dist/src/server/types/tool.d.ts +3 -3
  126. package/dist/src/server/types/tool.d.ts.map +1 -1
  127. package/dist/src/server/types/widget.d.ts +1 -1
  128. package/dist/src/server/types.d.ts +1 -1
  129. package/dist/src/server/types.d.ts.map +1 -1
  130. package/dist/src/session.d.ts +1 -1
  131. package/dist/src/session.d.ts.map +1 -1
  132. package/dist/src/task_managers/base.d.ts.map +1 -1
  133. package/dist/src/task_managers/index.d.ts +5 -5
  134. package/dist/src/task_managers/index.d.ts.map +1 -1
  135. package/dist/src/task_managers/sse.d.ts +3 -3
  136. package/dist/src/task_managers/sse.d.ts.map +1 -1
  137. package/dist/src/task_managers/stdio.d.ts +4 -4
  138. package/dist/src/task_managers/stdio.d.ts.map +1 -1
  139. package/dist/src/task_managers/streamable_http.d.ts +3 -3
  140. package/dist/src/task_managers/streamable_http.d.ts.map +1 -1
  141. package/dist/src/task_managers/websocket.d.ts +2 -2
  142. package/dist/src/task_managers/websocket.d.ts.map +1 -1
  143. package/dist/src/telemetry/events.d.ts.map +1 -1
  144. package/dist/src/telemetry/index.d.ts +4 -4
  145. package/dist/src/telemetry/index.d.ts.map +1 -1
  146. package/dist/src/telemetry/telemetry.d.ts +1 -1
  147. package/dist/src/telemetry/telemetry.d.ts.map +1 -1
  148. package/dist/src/telemetry/utils.d.ts +1 -1
  149. package/dist/src/telemetry/utils.d.ts.map +1 -1
  150. package/dist/tsup.config.d.ts.map +1 -1
  151. package/dist/vitest.config.d.ts.map +1 -1
  152. package/package.json +3 -3
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  BrowserMCPClient,
3
3
  BrowserOAuthClientProvider
4
- } from "./chunk-C3SRZK7H.js";
4
+ } from "./chunk-RSGKBEHH.js";
5
5
  import {
6
6
  __name
7
7
  } from "./chunk-SHUYVCID.js";
@@ -28,7 +28,9 @@ function useMcp(options) {
28
28
  enabled = true,
29
29
  clientName,
30
30
  clientUri,
31
- callbackUrl = typeof window !== "undefined" ? sanitizeUrl(new URL("/oauth/callback", window.location.origin).toString()) : "/oauth/callback",
31
+ callbackUrl = typeof window !== "undefined" ? sanitizeUrl(
32
+ new URL("/oauth/callback", window.location.origin).toString()
33
+ ) : "/oauth/callback",
32
34
  storageKeyPrefix = "mcp:auth",
33
35
  clientConfig = {},
34
36
  customHeaders = {},
@@ -69,7 +71,10 @@ function useMcp(options) {
69
71
  const fullMessage = args.length > 0 ? `${message} ${args.map((arg) => JSON.stringify(arg)).join(" ")}` : message;
70
72
  console[level](`[useMcp] ${fullMessage}`);
71
73
  if (isMountedRef.current) {
72
- setLog((prevLog) => [...prevLog.slice(-100), { level, message: fullMessage, timestamp: Date.now() }]);
74
+ setLog((prevLog) => [
75
+ ...prevLog.slice(-100),
76
+ { level, message: fullMessage, timestamp: Date.now() }
77
+ ]);
73
78
  }
74
79
  },
75
80
  []
@@ -110,7 +115,11 @@ function useMcp(options) {
110
115
  const manualUrl = authProviderRef.current?.getLastAttemptedAuthUrl();
111
116
  if (manualUrl) {
112
117
  setAuthUrl(manualUrl);
113
- addLog("info", "Manual authentication URL may be available.", manualUrl);
118
+ addLog(
119
+ "info",
120
+ "Manual authentication URL may be available.",
121
+ manualUrl
122
+ );
114
123
  }
115
124
  }
116
125
  connectingRef.current = false;
@@ -119,7 +128,10 @@ function useMcp(options) {
119
128
  );
120
129
  const connect = useCallback(async () => {
121
130
  if (!enabled || !url) {
122
- addLog("debug", enabled ? "No server URL provided, skipping connection." : "Connection disabled via enabled flag.");
131
+ addLog(
132
+ "debug",
133
+ enabled ? "No server URL provided, skipping connection." : "Connection disabled via enabled flag."
134
+ );
123
135
  return;
124
136
  }
125
137
  if (connectingRef.current) {
@@ -136,7 +148,10 @@ function useMcp(options) {
136
148
  setAuthUrl(void 0);
137
149
  successfulTransportRef.current = null;
138
150
  setState("discovering");
139
- addLog("info", `Connecting attempt #${connectAttemptRef.current} to ${url}...`);
151
+ addLog(
152
+ "info",
153
+ `Connecting attempt #${connectAttemptRef.current} to ${url}...`
154
+ );
140
155
  if (!authProviderRef.current) {
141
156
  authProviderRef.current = new BrowserOAuthClientProvider(url, {
142
157
  storageKeyPrefix,
@@ -153,7 +168,10 @@ function useMcp(options) {
153
168
  addLog("debug", "BrowserMCPClient initialized in connect.");
154
169
  }
155
170
  const tryConnectWithTransport = /* @__PURE__ */ __name(async (transportTypeParam, isAuthRetry = false) => {
156
- addLog("info", `Attempting connection with transport: ${transportTypeParam}`);
171
+ addLog(
172
+ "info",
173
+ `Attempting connection with transport: ${transportTypeParam}`
174
+ );
157
175
  try {
158
176
  const serverName = "inspector-server";
159
177
  const serverConfig = {
@@ -250,7 +268,9 @@ function useMcp(options) {
250
268
  const callTool = useCallback(
251
269
  async (name, args) => {
252
270
  if (stateRef.current !== "ready" || !clientRef.current) {
253
- throw new Error(`MCP client is not ready (current state: ${state}). Cannot call tool "${name}".`);
271
+ throw new Error(
272
+ `MCP client is not ready (current state: ${state}). Cannot call tool "${name}".`
273
+ );
254
274
  }
255
275
  addLog("info", `Calling tool: ${name}`, args);
256
276
  try {
@@ -274,7 +294,10 @@ function useMcp(options) {
274
294
  addLog("info", "Retry requested...");
275
295
  connect();
276
296
  } else {
277
- addLog("warn", `Retry called but state is not 'failed' (state: ${stateRef.current}). Ignoring.`);
297
+ addLog(
298
+ "warn",
299
+ `Retry called but state is not 'failed' (state: ${stateRef.current}). Ignoring.`
300
+ );
278
301
  }
279
302
  }, [addLog, connect]);
280
303
  const authenticate = useCallback(async () => {
@@ -296,9 +319,15 @@ function useMcp(options) {
296
319
  }
297
320
  }, AUTH_TIMEOUT);
298
321
  try {
299
- assert(authProviderRef.current, "Auth Provider not available for manual auth");
322
+ assert(
323
+ authProviderRef.current,
324
+ "Auth Provider not available for manual auth"
325
+ );
300
326
  assert(url, "Server URL is required for authentication");
301
- addLog("info", "Redirecting for manual authentication. Waiting for callback...");
327
+ addLog(
328
+ "info",
329
+ "Redirecting for manual authentication. Waiting for callback..."
330
+ );
302
331
  } catch (authError) {
303
332
  if (!isMountedRef.current) return;
304
333
  if (authTimeoutRef.current) clearTimeout(authTimeoutRef.current);
@@ -308,7 +337,10 @@ function useMcp(options) {
308
337
  );
309
338
  }
310
339
  } else if (currentState === "authenticating") {
311
- addLog("warn", "Already attempting authentication. Check for blocked popups or wait for timeout.");
340
+ addLog(
341
+ "warn",
342
+ "Already attempting authentication. Check for blocked popups or wait for timeout."
343
+ );
312
344
  const manualUrl = authProviderRef.current?.getLastAttemptedAuthUrl();
313
345
  if (manualUrl && !authUrl) {
314
346
  setAuthUrl(manualUrl);
@@ -331,32 +363,33 @@ function useMcp(options) {
331
363
  addLog("warn", "Auth provider not initialized, cannot clear storage.");
332
364
  }
333
365
  }, [url, addLog, disconnect]);
334
- const listResources = useCallback(
335
- async () => {
336
- if (stateRef.current !== "ready" || !clientRef.current) {
337
- throw new Error(`MCP client is not ready (current state: ${state}). Cannot list resources.`);
338
- }
339
- addLog("info", "Listing resources");
340
- try {
341
- const serverName = "inspector-server";
342
- const session = clientRef.current.getSession(serverName);
343
- if (!session) {
344
- throw new Error("No active session found");
345
- }
346
- const resourcesResult = await session.connector.listAllResources();
347
- setResources(resourcesResult.resources || []);
348
- addLog("info", "Resources listed successfully");
349
- } catch (err) {
350
- addLog("error", "List resources failed:", err);
351
- throw err;
366
+ const listResources = useCallback(async () => {
367
+ if (stateRef.current !== "ready" || !clientRef.current) {
368
+ throw new Error(
369
+ `MCP client is not ready (current state: ${state}). Cannot list resources.`
370
+ );
371
+ }
372
+ addLog("info", "Listing resources");
373
+ try {
374
+ const serverName = "inspector-server";
375
+ const session = clientRef.current.getSession(serverName);
376
+ if (!session) {
377
+ throw new Error("No active session found");
352
378
  }
353
- },
354
- [state]
355
- );
379
+ const resourcesResult = await session.connector.listAllResources();
380
+ setResources(resourcesResult.resources || []);
381
+ addLog("info", "Resources listed successfully");
382
+ } catch (err) {
383
+ addLog("error", "List resources failed:", err);
384
+ throw err;
385
+ }
386
+ }, [state]);
356
387
  const readResource = useCallback(
357
388
  async (uri) => {
358
389
  if (stateRef.current !== "ready" || !clientRef.current) {
359
- throw new Error(`MCP client is not ready (current state: ${state}). Cannot read resource.`);
390
+ throw new Error(
391
+ `MCP client is not ready (current state: ${state}). Cannot read resource.`
392
+ );
360
393
  }
361
394
  addLog("info", `Reading resource: ${uri}`);
362
395
  try {
@@ -375,32 +408,33 @@ function useMcp(options) {
375
408
  },
376
409
  [state]
377
410
  );
378
- const listPrompts = useCallback(
379
- async () => {
380
- if (stateRef.current !== "ready" || !clientRef.current) {
381
- throw new Error(`MCP client is not ready (current state: ${state}). Cannot list prompts.`);
382
- }
383
- addLog("info", "Listing prompts");
384
- try {
385
- const serverName = "inspector-server";
386
- const session = clientRef.current.getSession(serverName);
387
- if (!session) {
388
- throw new Error("No active session found");
389
- }
390
- const promptsResult = await session.connector.listPrompts();
391
- setPrompts(promptsResult.prompts || []);
392
- addLog("info", "Prompts listed successfully");
393
- } catch (err) {
394
- addLog("error", "List prompts failed:", err);
395
- throw err;
411
+ const listPrompts = useCallback(async () => {
412
+ if (stateRef.current !== "ready" || !clientRef.current) {
413
+ throw new Error(
414
+ `MCP client is not ready (current state: ${state}). Cannot list prompts.`
415
+ );
416
+ }
417
+ addLog("info", "Listing prompts");
418
+ try {
419
+ const serverName = "inspector-server";
420
+ const session = clientRef.current.getSession(serverName);
421
+ if (!session) {
422
+ throw new Error("No active session found");
396
423
  }
397
- },
398
- [state]
399
- );
424
+ const promptsResult = await session.connector.listPrompts();
425
+ setPrompts(promptsResult.prompts || []);
426
+ addLog("info", "Prompts listed successfully");
427
+ } catch (err) {
428
+ addLog("error", "List prompts failed:", err);
429
+ throw err;
430
+ }
431
+ }, [state]);
400
432
  const getPrompt = useCallback(
401
433
  async (name, args) => {
402
434
  if (stateRef.current !== "ready" || !clientRef.current) {
403
- throw new Error(`MCP client is not ready (current state: ${state}). Cannot get prompt.`);
435
+ throw new Error(
436
+ `MCP client is not ready (current state: ${state}). Cannot get prompt.`
437
+ );
404
438
  }
405
439
  addLog("info", `Getting prompt: ${name}`, args);
406
440
  try {
@@ -433,19 +467,30 @@ function useMcp(options) {
433
467
  if (authTimeoutRef.current) clearTimeout(authTimeoutRef.current);
434
468
  authTimeoutRef.current = null;
435
469
  if (event.data.success) {
436
- addLog("info", "Authentication successful via popup. Reconnecting client...");
470
+ addLog(
471
+ "info",
472
+ "Authentication successful via popup. Reconnecting client..."
473
+ );
437
474
  if (connectingRef.current) {
438
- addLog("debug", "Connection attempt already in progress, resetting flag to allow reconnection.");
475
+ addLog(
476
+ "debug",
477
+ "Connection attempt already in progress, resetting flag to allow reconnection."
478
+ );
439
479
  }
440
480
  connectingRef.current = false;
441
481
  setTimeout(() => {
442
482
  if (isMountedRef.current) {
443
- addLog("debug", "Initiating reconnection after successful auth callback.");
483
+ addLog(
484
+ "debug",
485
+ "Initiating reconnection after successful auth callback."
486
+ );
444
487
  connectRef.current();
445
488
  }
446
489
  }, 100);
447
490
  } else {
448
- failConnectionRef.current(`Authentication failed in callback: ${event.data.error || "Unknown reason."}`);
491
+ failConnectionRef.current(
492
+ `Authentication failed in callback: ${event.data.error || "Unknown reason."}`
493
+ );
449
494
  }
450
495
  }
451
496
  }, "messageHandler");
@@ -460,7 +505,10 @@ function useMcp(options) {
460
505
  useEffect(() => {
461
506
  isMountedRef.current = true;
462
507
  if (!enabled || !url) {
463
- addLog("debug", enabled ? "No server URL provided, skipping connection." : "Connection disabled via enabled flag.");
508
+ addLog(
509
+ "debug",
510
+ enabled ? "No server URL provided, skipping connection." : "Connection disabled via enabled flag."
511
+ );
464
512
  setState("discovering");
465
513
  return () => {
466
514
  isMountedRef.current = false;
@@ -477,7 +525,10 @@ function useMcp(options) {
477
525
  preventAutoAuth,
478
526
  onPopupWindow
479
527
  });
480
- addLog("debug", "BrowserOAuthClientProvider initialized/updated on mount/option change.");
528
+ addLog(
529
+ "debug",
530
+ "BrowserOAuthClientProvider initialized/updated on mount/option change."
531
+ );
481
532
  }
482
533
  connect();
483
534
  return () => {
@@ -485,7 +536,16 @@ function useMcp(options) {
485
536
  addLog("debug", "useMcp unmounting, disconnecting.");
486
537
  disconnect(true);
487
538
  };
488
- }, [url, enabled, storageKeyPrefix, callbackUrl, clientName, clientUri, clientConfig.name, clientConfig.version]);
539
+ }, [
540
+ url,
541
+ enabled,
542
+ storageKeyPrefix,
543
+ callbackUrl,
544
+ clientName,
545
+ clientUri,
546
+ clientConfig.name,
547
+ clientConfig.version
548
+ ]);
489
549
  useEffect(() => {
490
550
  let retryTimeoutId = null;
491
551
  if (state === "failed" && autoRetry && connectAttemptRef.current > 0) {
@@ -525,7 +585,13 @@ function useMcp(options) {
525
585
  __name(useMcp, "useMcp");
526
586
 
527
587
  // src/react/useWidget.ts
528
- import { useCallback as useCallback2, useEffect as useEffect2, useMemo, useState as useState2, useSyncExternalStore } from "react";
588
+ import {
589
+ useCallback as useCallback2,
590
+ useEffect as useEffect2,
591
+ useMemo,
592
+ useState as useState2,
593
+ useSyncExternalStore
594
+ } from "react";
529
595
 
530
596
  // src/react/widget-types.ts
531
597
  var SET_GLOBALS_EVENT_TYPE = "openai:set_globals";
@@ -543,17 +609,11 @@ function useOpenAiGlobal(key) {
543
609
  onChange();
544
610
  }, "handleSetGlobal");
545
611
  if (typeof window !== "undefined") {
546
- window.addEventListener(
547
- SET_GLOBALS_EVENT_TYPE,
548
- handleSetGlobal
549
- );
612
+ window.addEventListener(SET_GLOBALS_EVENT_TYPE, handleSetGlobal);
550
613
  }
551
614
  return () => {
552
615
  if (typeof window !== "undefined") {
553
- window.removeEventListener(
554
- SET_GLOBALS_EVENT_TYPE,
555
- handleSetGlobal
556
- );
616
+ window.removeEventListener(SET_GLOBALS_EVENT_TYPE, handleSetGlobal);
557
617
  }
558
618
  };
559
619
  },
@@ -563,7 +623,10 @@ function useOpenAiGlobal(key) {
563
623
  __name(useOpenAiGlobal, "useOpenAiGlobal");
564
624
  function useWidget(defaultProps) {
565
625
  console.log(window?.location?.search, window.openai);
566
- const isOpenAiAvailable = useMemo(() => typeof window !== "undefined" && !!window.openai, []);
626
+ const isOpenAiAvailable = useMemo(
627
+ () => typeof window !== "undefined" && !!window.openai,
628
+ []
629
+ );
567
630
  const provider = useMemo(() => {
568
631
  return isOpenAiAvailable ? "openai" : "mcp-ui";
569
632
  }, [isOpenAiAvailable]);
@@ -604,12 +667,15 @@ function useWidget(defaultProps) {
604
667
  },
605
668
  []
606
669
  );
607
- const sendFollowUpMessage = useCallback2(async (prompt) => {
608
- if (!window.openai?.sendFollowUpMessage) {
609
- throw new Error("window.openai.sendFollowUpMessage is not available");
610
- }
611
- return window.openai.sendFollowUpMessage({ prompt });
612
- }, []);
670
+ const sendFollowUpMessage = useCallback2(
671
+ async (prompt) => {
672
+ if (!window.openai?.sendFollowUpMessage) {
673
+ throw new Error("window.openai.sendFollowUpMessage is not available");
674
+ }
675
+ return window.openai.sendFollowUpMessage({ prompt });
676
+ },
677
+ []
678
+ );
613
679
  const openExternal = useCallback2((href) => {
614
680
  if (!window.openai?.openExternal) {
615
681
  throw new Error("window.openai.openExternal is not available");
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  logger
3
- } from "./chunk-VPPILX7B.js";
3
+ } from "./chunk-3RJENWH4.js";
4
4
  import {
5
5
  __name
6
6
  } from "./chunk-SHUYVCID.js";
@@ -18,7 +18,9 @@ async function initializeLangfuse(agentId, metadata, metadataProvider, tagsProvi
18
18
  try {
19
19
  const langfuseModule = await import("langfuse-langchain").catch(() => null);
20
20
  if (!langfuseModule) {
21
- logger.debug("Langfuse package not installed - tracing disabled. Install with: npm install @langfuse/langchain");
21
+ logger.debug(
22
+ "Langfuse package not installed - tracing disabled. Install with: npm install @langfuse/langchain"
23
+ );
22
24
  return;
23
25
  }
24
26
  const { CallbackHandler } = langfuseModule;
@@ -47,10 +49,23 @@ async function initializeLangfuse(agentId, metadata, metadataProvider, tagsProvi
47
49
  const enhancedTags = [...tags || [], ...customTags];
48
50
  const enhancedMetadata = { ...metadata2 || {}, ...metadataToAdd };
49
51
  if (this.verbose) {
50
- logger.debug(`Langfuse: Chain start with custom tags: ${JSON.stringify(enhancedTags)}`);
51
- logger.debug(`Langfuse: Chain start with metadata: ${JSON.stringify(enhancedMetadata)}`);
52
+ logger.debug(
53
+ `Langfuse: Chain start with custom tags: ${JSON.stringify(enhancedTags)}`
54
+ );
55
+ logger.debug(
56
+ `Langfuse: Chain start with metadata: ${JSON.stringify(enhancedMetadata)}`
57
+ );
52
58
  }
53
- return super.handleChainStart(chain, inputs, runId, parentRunId, enhancedTags, enhancedMetadata, name, kwargs);
59
+ return super.handleChainStart(
60
+ chain,
61
+ inputs,
62
+ runId,
63
+ parentRunId,
64
+ enhancedTags,
65
+ enhancedMetadata,
66
+ name,
67
+ kwargs
68
+ );
54
69
  }
55
70
  // Get custom tags based on environment and agent configuration
56
71
  getCustomTags() {
@@ -126,7 +141,9 @@ async function initializeLangfuse(agentId, metadata, metadataProvider, tagsProvi
126
141
  async handleRetrieverStart(...args) {
127
142
  logger.debug("Langfuse: Retriever start intercepted");
128
143
  if (this.verbose) {
129
- logger.debug(`Langfuse: Retriever start args: ${JSON.stringify(args)}`);
144
+ logger.debug(
145
+ `Langfuse: Retriever start args: ${JSON.stringify(args)}`
146
+ );
130
147
  }
131
148
  return super.handleRetrieverStart(...args);
132
149
  }
@@ -152,9 +169,13 @@ async function initializeLangfuse(agentId, metadata, metadataProvider, tagsProvi
152
169
  secretKey: process.env.LANGFUSE_SECRET_KEY,
153
170
  baseUrl: process.env.LANGFUSE_HOST || process.env.LANGFUSE_BASEURL || "https://cloud.langfuse.com",
154
171
  flushAt: Number.parseInt(process.env.LANGFUSE_FLUSH_AT || "15"),
155
- flushInterval: Number.parseInt(process.env.LANGFUSE_FLUSH_INTERVAL || "10000"),
172
+ flushInterval: Number.parseInt(
173
+ process.env.LANGFUSE_FLUSH_INTERVAL || "10000"
174
+ ),
156
175
  release: process.env.LANGFUSE_RELEASE,
157
- requestTimeout: Number.parseInt(process.env.LANGFUSE_REQUEST_TIMEOUT || "10000"),
176
+ requestTimeout: Number.parseInt(
177
+ process.env.LANGFUSE_REQUEST_TIMEOUT || "10000"
178
+ ),
158
179
  enabled: process.env.LANGFUSE_ENABLED !== "false",
159
180
  // Set trace name - can be customized via metadata.trace_name or defaults to 'mcp-use-agent'
160
181
  traceName: initialMetadata.trace_name || process.env.LANGFUSE_TRACE_NAME || "mcp-use-agent",
@@ -164,14 +185,29 @@ async function initializeLangfuse(agentId, metadata, metadataProvider, tagsProvi
164
185
  tags: initialTags.length > 0 ? initialTags : void 0,
165
186
  metadata: initialMetadata || void 0
166
187
  };
167
- logger.debug("Langfuse handler config:", JSON.stringify({
168
- traceName: config2.traceName,
169
- sessionId: config2.sessionId,
170
- userId: config2.userId,
171
- tags: config2.tags
172
- }, null, 2));
173
- langfuseState.handler = new LoggingCallbackHandler(config2, agentId, metadata, metadataProvider, tagsProvider);
174
- logger.debug("Langfuse observability initialized successfully with logging enabled");
188
+ logger.debug(
189
+ "Langfuse handler config:",
190
+ JSON.stringify(
191
+ {
192
+ traceName: config2.traceName,
193
+ sessionId: config2.sessionId,
194
+ userId: config2.userId,
195
+ tags: config2.tags
196
+ },
197
+ null,
198
+ 2
199
+ )
200
+ );
201
+ langfuseState.handler = new LoggingCallbackHandler(
202
+ config2,
203
+ agentId,
204
+ metadata,
205
+ metadataProvider,
206
+ tagsProvider
207
+ );
208
+ logger.debug(
209
+ "Langfuse observability initialized successfully with logging enabled"
210
+ );
175
211
  try {
176
212
  const langfuseCore = await import("langfuse").catch(() => null);
177
213
  if (langfuseCore) {
@@ -192,7 +228,9 @@ async function initializeLangfuse(agentId, metadata, metadataProvider, tagsProvi
192
228
  }
193
229
  __name(initializeLangfuse, "initializeLangfuse");
194
230
  if (langfuseDisabled) {
195
- logger.debug("Langfuse tracing disabled via MCP_USE_LANGFUSE environment variable");
231
+ logger.debug(
232
+ "Langfuse tracing disabled via MCP_USE_LANGFUSE environment variable"
233
+ );
196
234
  } else if (!process.env.LANGFUSE_PUBLIC_KEY || !process.env.LANGFUSE_SECRET_KEY) {
197
235
  logger.debug(
198
236
  "Langfuse API keys not found - tracing disabled. Set LANGFUSE_PUBLIC_KEY and LANGFUSE_SECRET_KEY to enable"