mcp-use 1.11.0-canary.9 → 1.11.0

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 (51) hide show
  1. package/dist/.tsbuildinfo +1 -1
  2. package/dist/{chunk-N3DO4P2L.js → chunk-A4QJRN7Z.js} +2 -2
  3. package/dist/{chunk-UCPSHMNO.js → chunk-B7AGEK7F.js} +1 -1
  4. package/dist/{chunk-HU2DGJ5J.js → chunk-GN5HOAV3.js} +491 -5
  5. package/dist/{chunk-D3CNYAYE.js → chunk-QPIDKGV4.js} +199 -8
  6. package/dist/{chunk-ZFZPZ4GE.js → chunk-V77WS6CS.js} +9 -0
  7. package/dist/{chunk-5QFJZ7H3.js → chunk-VRHAF2WT.js} +10 -4
  8. package/dist/{chunk-F3BZFJCD.js → chunk-Y2HHHJQB.js} +10 -5
  9. package/dist/{chunk-Q5LZL6BH.js → chunk-ZLZOOXMJ.js} +96 -43
  10. package/dist/index.cjs +122 -47
  11. package/dist/index.js +15 -19
  12. package/dist/src/agents/index.cjs +108 -44
  13. package/dist/src/agents/index.d.ts +1 -1
  14. package/dist/src/agents/index.d.ts.map +1 -1
  15. package/dist/src/agents/index.js +7 -11
  16. package/dist/src/agents/mcp_agent.d.ts.map +1 -1
  17. package/dist/src/{client/prompts.d.ts → agents/prompts/index.d.ts} +3 -3
  18. package/dist/src/agents/prompts/index.d.ts.map +1 -0
  19. package/dist/src/browser.cjs +115 -45
  20. package/dist/src/browser.js +10 -13
  21. package/dist/src/client/browser.d.ts.map +1 -1
  22. package/dist/src/client.cjs +108 -43
  23. package/dist/src/client.d.ts +2 -0
  24. package/dist/src/client.d.ts.map +1 -1
  25. package/dist/src/client.js +6 -5
  26. package/dist/src/config.d.ts.map +1 -1
  27. package/dist/src/connectors/http.d.ts +2 -0
  28. package/dist/src/connectors/http.d.ts.map +1 -1
  29. package/dist/src/react/index.cjs +119 -46
  30. package/dist/src/react/index.js +7 -8
  31. package/dist/src/react/useMcp.d.ts.map +1 -1
  32. package/dist/src/server/index.cjs +178 -113
  33. package/dist/src/server/index.js +92 -80
  34. package/dist/src/server/types/widget.d.ts +2 -2
  35. package/dist/src/server/types/widget.d.ts.map +1 -1
  36. package/dist/src/server/widgets/mount-widgets-dev.d.ts.map +1 -1
  37. package/dist/src/server/widgets/ui-resource-registration.d.ts.map +1 -1
  38. package/dist/src/telemetry/telemetry.d.ts +1 -0
  39. package/dist/src/telemetry/telemetry.d.ts.map +1 -1
  40. package/dist/src/version.d.ts +1 -1
  41. package/dist/src/version.d.ts.map +1 -1
  42. package/dist/{tool-execution-helpers-MXVN6YNU.js → tool-execution-helpers-ZUA5D5IO.js} +2 -2
  43. package/package.json +49 -52
  44. package/dist/chunk-ESMOFYJ6.js +0 -2638
  45. package/dist/chunk-M7WATKYM.js +0 -204
  46. package/dist/chunk-OWPXM4QQ.js +0 -12
  47. package/dist/chunk-WW3A2EKQ.js +0 -1055
  48. package/dist/chunk-XEFWIBQF.js +0 -491
  49. package/dist/src/client/prompts.cjs +0 -407
  50. package/dist/src/client/prompts.d.ts.map +0 -1
  51. package/dist/src/client/prompts.js +0 -11
package/dist/index.cjs CHANGED
@@ -2790,7 +2790,7 @@ __name(generateUUID, "generateUUID");
2790
2790
  init_logging();
2791
2791
 
2792
2792
  // src/version.ts
2793
- var VERSION = "1.11.0-canary.9";
2793
+ var VERSION = "1.11.0";
2794
2794
  function getPackageVersion() {
2795
2795
  return VERSION;
2796
2796
  }
@@ -2829,6 +2829,20 @@ function extractModelInfo(llm) {
2829
2829
  __name(extractModelInfo, "extractModelInfo");
2830
2830
 
2831
2831
  // src/telemetry/telemetry.ts
2832
+ function secureRandomString() {
2833
+ if (typeof window !== "undefined" && window.crypto && typeof window.crypto.getRandomValues === "function") {
2834
+ const array = new Uint8Array(8);
2835
+ window.crypto.getRandomValues(array);
2836
+ return Array.from(array, (v) => v.toString(16).padStart(2, "0")).join("");
2837
+ }
2838
+ try {
2839
+ const crypto = require("crypto");
2840
+ return crypto.randomBytes(8).toString("hex");
2841
+ } catch (e) {
2842
+ return Math.random().toString(36).substring(2, 15);
2843
+ }
2844
+ }
2845
+ __name(secureRandomString, "secureRandomString");
2832
2846
  var USER_ID_STORAGE_KEY = "mcp_use_user_id";
2833
2847
  function detectRuntimeEnvironment() {
2834
2848
  try {
@@ -2960,12 +2974,26 @@ var Telemetry = class _Telemetry {
2960
2974
  "Anonymized telemetry enabled. Set MCP_USE_ANONYMIZED_TELEMETRY=false to disable."
2961
2975
  );
2962
2976
  this._posthogLoading = this._initPostHog();
2963
- try {
2964
- this._scarfClient = new ScarfEventLogger(this.SCARF_GATEWAY_URL, 3e3);
2965
- } catch (e) {
2966
- logger.warn(`Failed to initialize Scarf telemetry: ${e}`);
2977
+ if (this._runtimeEnvironment !== "browser") {
2978
+ try {
2979
+ this._scarfClient = new ScarfEventLogger(
2980
+ this.SCARF_GATEWAY_URL,
2981
+ 3e3
2982
+ );
2983
+ } catch (e) {
2984
+ logger.warn(`Failed to initialize Scarf telemetry: ${e}`);
2985
+ this._scarfClient = null;
2986
+ }
2987
+ } else {
2967
2988
  this._scarfClient = null;
2968
2989
  }
2990
+ if (this._storageCapability === "filesystem" && this._scarfClient) {
2991
+ setTimeout(() => {
2992
+ this.trackPackageDownload({ triggered_by: "initialization" }).catch(
2993
+ (e) => logger.debug(`Failed to track package download: ${e}`)
2994
+ );
2995
+ }, 0);
2996
+ }
2969
2997
  }
2970
2998
  }
2971
2999
  _checkTelemetryDisabled() {
@@ -3090,47 +3118,65 @@ var Telemetry = class _Telemetry {
3090
3118
  break;
3091
3119
  case "session-only":
3092
3120
  default:
3093
- this._currUserId = `session-${generateUUID()}`;
3094
- logger.debug(
3095
- `Using session-based user ID (${this._runtimeEnvironment} environment)`
3096
- );
3121
+ try {
3122
+ this._currUserId = `session-${generateUUID()}`;
3123
+ } catch (uuidError) {
3124
+ this._currUserId = `session-${Date.now()}-${Math.random().toString(36).substring(2, 15)}`;
3125
+ }
3097
3126
  break;
3098
3127
  }
3099
- if (this._storageCapability === "filesystem" && this._currUserId) {
3100
- this._trackPackageDownloadInternal(this._currUserId, {
3101
- triggered_by: "user_id_property"
3102
- }).catch((e) => logger.debug(`Failed to track package download: ${e}`));
3103
- }
3104
3128
  } catch (e) {
3105
- logger.debug(`Failed to get/create user ID: ${e}`);
3106
3129
  this._currUserId = this.UNKNOWN_USER_ID;
3107
3130
  }
3108
3131
  return this._currUserId;
3109
3132
  }
3110
3133
  /**
3111
3134
  * Get or create user ID from filesystem (Node.js/Bun)
3135
+ * Falls back to session ID if filesystem operations fail
3112
3136
  */
3113
3137
  _getUserIdFromFilesystem() {
3114
- const fs2 = require("fs");
3115
- const os = require("os");
3116
- const path2 = require("path");
3117
- if (!this._userIdPath) {
3118
- this._userIdPath = path2.join(
3119
- this._getCacheHome(os, path2),
3120
- "mcp_use_3",
3121
- "telemetry_user_id"
3122
- );
3123
- }
3124
- const isFirstTime = !fs2.existsSync(this._userIdPath);
3125
- if (isFirstTime) {
3126
- logger.debug(`Creating user ID path: ${this._userIdPath}`);
3127
- fs2.mkdirSync(path2.dirname(this._userIdPath), { recursive: true });
3128
- const newUserId = generateUUID();
3129
- fs2.writeFileSync(this._userIdPath, newUserId);
3130
- logger.debug(`User ID path created: ${this._userIdPath}`);
3131
- return newUserId;
3138
+ try {
3139
+ let fs2, os, path2;
3140
+ try {
3141
+ fs2 = require("fs");
3142
+ os = require("os");
3143
+ path2 = require("path");
3144
+ } catch (requireError) {
3145
+ try {
3146
+ const sessionId = `session-${generateUUID()}`;
3147
+ return sessionId;
3148
+ } catch (uuidError) {
3149
+ return `session-${Date.now()}-${Math.random().toString(36).substring(2, 15)}`;
3150
+ }
3151
+ }
3152
+ if (!this._userIdPath) {
3153
+ this._userIdPath = path2.join(
3154
+ this._getCacheHome(os, path2),
3155
+ "mcp_use_3",
3156
+ "telemetry_user_id"
3157
+ );
3158
+ }
3159
+ const isFirstTime = !fs2.existsSync(this._userIdPath);
3160
+ if (isFirstTime) {
3161
+ fs2.mkdirSync(path2.dirname(this._userIdPath), { recursive: true });
3162
+ let newUserId;
3163
+ try {
3164
+ newUserId = generateUUID();
3165
+ } catch (uuidError) {
3166
+ newUserId = `${Date.now()}-${Math.random().toString(36).substring(2, 15)}`;
3167
+ }
3168
+ fs2.writeFileSync(this._userIdPath, newUserId);
3169
+ return newUserId;
3170
+ }
3171
+ const userId = fs2.readFileSync(this._userIdPath, "utf-8").trim();
3172
+ return userId;
3173
+ } catch (e) {
3174
+ try {
3175
+ return `session-${generateUUID()}`;
3176
+ } catch (uuidError) {
3177
+ return `session-${Date.now()}-${secureRandomString()}`;
3178
+ }
3132
3179
  }
3133
- return fs2.readFileSync(this._userIdPath, "utf-8").trim();
3134
3180
  }
3135
3181
  /**
3136
3182
  * Get or create user ID from localStorage (Browser)
@@ -3139,14 +3185,22 @@ var Telemetry = class _Telemetry {
3139
3185
  try {
3140
3186
  let userId = localStorage.getItem(USER_ID_STORAGE_KEY);
3141
3187
  if (!userId) {
3142
- userId = generateUUID();
3188
+ try {
3189
+ userId = generateUUID();
3190
+ } catch (uuidError) {
3191
+ userId = `${Date.now()}-${secureRandomString()}`;
3192
+ }
3143
3193
  localStorage.setItem(USER_ID_STORAGE_KEY, userId);
3144
- logger.debug(`Created new browser user ID`);
3145
3194
  }
3146
3195
  return userId;
3147
3196
  } catch (e) {
3148
- logger.debug(`localStorage access failed: ${e}`);
3149
- return `session-${generateUUID()}`;
3197
+ let sessionId;
3198
+ try {
3199
+ sessionId = `session-${generateUUID()}`;
3200
+ } catch (uuidError) {
3201
+ sessionId = `session-${Date.now()}-${secureRandomString()}`;
3202
+ }
3203
+ return sessionId;
3150
3204
  }
3151
3205
  }
3152
3206
  _getCacheHome(os, path2) {
@@ -3175,6 +3229,7 @@ var Telemetry = class _Telemetry {
3175
3229
  if (!this._posthogNodeClient && !this._posthogBrowserClient && !this._scarfClient) {
3176
3230
  return;
3177
3231
  }
3232
+ const currentUserId = this.userId;
3178
3233
  const properties = { ...event.properties };
3179
3234
  properties.mcp_use_version = getPackageVersion();
3180
3235
  properties.language = "typescript";
@@ -3182,9 +3237,8 @@ var Telemetry = class _Telemetry {
3182
3237
  properties.runtime = this._runtimeEnvironment;
3183
3238
  if (this._posthogNodeClient) {
3184
3239
  try {
3185
- logger.debug(`CAPTURE: PostHog Node Event ${event.name}`);
3186
3240
  this._posthogNodeClient.capture({
3187
- distinctId: this.userId,
3241
+ distinctId: currentUserId,
3188
3242
  event: event.name,
3189
3243
  properties
3190
3244
  });
@@ -3194,10 +3248,9 @@ var Telemetry = class _Telemetry {
3194
3248
  }
3195
3249
  if (this._posthogBrowserClient) {
3196
3250
  try {
3197
- logger.debug(`CAPTURE: PostHog Browser Event ${event.name}`);
3198
3251
  this._posthogBrowserClient.capture(event.name, {
3199
3252
  ...properties,
3200
- distinct_id: this.userId
3253
+ distinct_id: currentUserId
3201
3254
  });
3202
3255
  } catch (e) {
3203
3256
  logger.debug(
@@ -3209,7 +3262,7 @@ var Telemetry = class _Telemetry {
3209
3262
  try {
3210
3263
  const scarfProperties = {
3211
3264
  ...properties,
3212
- user_id: this.userId,
3265
+ user_id: currentUserId,
3213
3266
  event: event.name
3214
3267
  };
3215
3268
  await this._scarfClient.logEvent(scarfProperties);
@@ -5121,6 +5174,7 @@ var HttpConnector = class extends BaseConnector {
5121
5174
  sseReadTimeout;
5122
5175
  clientInfo;
5123
5176
  preferSse;
5177
+ disableSseFallback;
5124
5178
  transportType = null;
5125
5179
  streamableTransport = null;
5126
5180
  constructor(baseUrl, opts = {}) {
@@ -5137,6 +5191,7 @@ var HttpConnector = class extends BaseConnector {
5137
5191
  version: "1.0.0"
5138
5192
  };
5139
5193
  this.preferSse = opts.preferSse ?? false;
5194
+ this.disableSseFallback = opts.disableSseFallback ?? false;
5140
5195
  }
5141
5196
  /** Establish connection to the MCP implementation via HTTP (streamable or SSE). */
5142
5197
  async connect() {
@@ -5193,6 +5248,13 @@ var HttpConnector = class extends BaseConnector {
5193
5248
  authError.code = 401;
5194
5249
  throw authError;
5195
5250
  }
5251
+ if (this.disableSseFallback) {
5252
+ logger.info("SSE fallback disabled - failing connection");
5253
+ await this.cleanupResources();
5254
+ throw new Error(
5255
+ `Streamable HTTP connection failed: ${fallbackReason}. SSE fallback is disabled.`
5256
+ );
5257
+ }
5196
5258
  logger.info("\u{1F504} Falling back to SSE transport...");
5197
5259
  try {
5198
5260
  await this.connectWithSse(baseUrl);
@@ -5559,6 +5621,8 @@ function createConnectorFromConfig(serverConfig, connectorOptions) {
5559
5621
  authToken: serverConfig.auth_token || serverConfig.authToken,
5560
5622
  // Only force SSE if explicitly requested
5561
5623
  preferSse: serverConfig.preferSse || transport === "sse",
5624
+ // Disable SSE fallback if explicitly disabled in config
5625
+ disableSseFallback: serverConfig.disableSseFallback,
5562
5626
  ...connectorOptions
5563
5627
  });
5564
5628
  }
@@ -9318,7 +9382,9 @@ var BrowserMCPClient = class _BrowserMCPClient extends BaseMCPClient {
9318
9382
  wrapTransport,
9319
9383
  clientOptions,
9320
9384
  samplingCallback,
9321
- elicitationCallback
9385
+ elicitationCallback,
9386
+ disableSseFallback,
9387
+ preferSse
9322
9388
  } = serverConfig;
9323
9389
  if (!url) {
9324
9390
  throw new Error("Server URL is required");
@@ -9334,8 +9400,12 @@ var BrowserMCPClient = class _BrowserMCPClient extends BaseMCPClient {
9334
9400
  // ← Pass client options (capabilities, etc.) to connector
9335
9401
  samplingCallback,
9336
9402
  // ← Pass sampling callback to connector
9337
- elicitationCallback
9403
+ elicitationCallback,
9338
9404
  // ← Pass elicitation callback to connector
9405
+ disableSseFallback,
9406
+ // ← Disable automatic SSE fallback
9407
+ preferSse
9408
+ // ← Use SSE transport directly
9339
9409
  };
9340
9410
  if (clientOptions) {
9341
9411
  console.log(
@@ -9543,7 +9613,12 @@ function useMcp(options) {
9543
9613
  const serverName = "inspector-server";
9544
9614
  const serverConfig = {
9545
9615
  url,
9546
- transport: transportTypeParam === "sse" ? "http" : transportTypeParam
9616
+ transport: transportTypeParam === "sse" ? "http" : transportTypeParam,
9617
+ // Disable SSE fallback when using explicit HTTP transport (not SSE)
9618
+ // This prevents automatic HTTP → SSE fallback at the connector level
9619
+ disableSseFallback: transportTypeParam === "http",
9620
+ // Use SSE transport when explicitly requested
9621
+ preferSse: transportTypeParam === "sse"
9547
9622
  };
9548
9623
  if (customHeaders && Object.keys(customHeaders).length > 0) {
9549
9624
  serverConfig.headers = customHeaders;
@@ -11183,7 +11258,7 @@ function McpUseProvider({
11183
11258
  }
11184
11259
  __name(McpUseProvider, "McpUseProvider");
11185
11260
 
11186
- // src/client/prompts.ts
11261
+ // src/agents/prompts/index.ts
11187
11262
  var PROMPTS = {
11188
11263
  CODE_MODE: CODE_MODE_AGENT_PROMPT
11189
11264
  };
package/dist/index.js CHANGED
@@ -1,4 +1,3 @@
1
- import "./chunk-JQKKMUCT.js";
2
1
  import {
3
2
  ElicitationDeclinedError,
4
3
  ElicitationTimeoutError,
@@ -10,7 +9,9 @@ import {
10
9
  streamEventsToAISDKWithTools
11
10
  } from "./chunk-LGDFGYRL.js";
12
11
  import "./chunk-GXNAXUDI.js";
13
- import "./chunk-ZFZPZ4GE.js";
12
+ import {
13
+ PROMPTS
14
+ } from "./chunk-V77WS6CS.js";
14
15
  import {
15
16
  AcquireActiveMCPServerTool,
16
17
  AddMCPServerFromConfigTool,
@@ -25,7 +26,7 @@ import {
25
26
  getSupportedProviders,
26
27
  isValidLLMString,
27
28
  parseLLMString
28
- } from "./chunk-N3DO4P2L.js";
29
+ } from "./chunk-A4QJRN7Z.js";
29
30
  import "./chunk-JRGQRPTN.js";
30
31
  import {
31
32
  BaseCodeExecutor,
@@ -35,14 +36,11 @@ import {
35
36
  VMCodeExecutor,
36
37
  isVMAvailable,
37
38
  loadConfigFile
38
- } from "./chunk-WW3A2EKQ.js";
39
+ } from "./chunk-QPIDKGV4.js";
39
40
  import {
40
41
  BaseAdapter
41
42
  } from "./chunk-MFSO5PUW.js";
42
- import {
43
- PROMPTS
44
- } from "./chunk-OWPXM4QQ.js";
45
- import "./chunk-M7WATKYM.js";
43
+ import "./chunk-JQKKMUCT.js";
46
44
  import {
47
45
  ErrorBoundary,
48
46
  Image,
@@ -54,30 +52,28 @@ import {
54
52
  useWidgetProps,
55
53
  useWidgetState,
56
54
  useWidgetTheme
57
- } from "./chunk-F3BZFJCD.js";
58
- import "./chunk-5QFJZ7H3.js";
59
- import {
60
- BrowserOAuthClientProvider,
61
- onMcpAuthorization
62
- } from "./chunk-J75I2C26.js";
55
+ } from "./chunk-Y2HHHJQB.js";
56
+ import "./chunk-VRHAF2WT.js";
63
57
  import {
58
+ BaseConnector,
64
59
  HttpConnector,
65
60
  MCPSession
66
- } from "./chunk-HU2DGJ5J.js";
67
- import {
68
- BaseConnector
69
- } from "./chunk-XEFWIBQF.js";
61
+ } from "./chunk-GN5HOAV3.js";
70
62
  import {
71
63
  Tel,
72
64
  Telemetry,
73
65
  VERSION,
74
66
  getPackageVersion,
75
67
  setTelemetrySource
76
- } from "./chunk-Q5LZL6BH.js";
68
+ } from "./chunk-ZLZOOXMJ.js";
77
69
  import {
78
70
  Logger,
79
71
  logger
80
72
  } from "./chunk-FRUZDWXH.js";
73
+ import {
74
+ BrowserOAuthClientProvider,
75
+ onMcpAuthorization
76
+ } from "./chunk-J75I2C26.js";
81
77
  import {
82
78
  __name
83
79
  } from "./chunk-3GQAWCBQ.js";
@@ -1417,7 +1417,7 @@ __name(generateUUID, "generateUUID");
1417
1417
  init_logging();
1418
1418
 
1419
1419
  // src/version.ts
1420
- var VERSION = "1.11.0-canary.9";
1420
+ var VERSION = "1.11.0";
1421
1421
  function getPackageVersion() {
1422
1422
  return VERSION;
1423
1423
  }
@@ -1456,6 +1456,20 @@ function extractModelInfo(llm) {
1456
1456
  __name(extractModelInfo, "extractModelInfo");
1457
1457
 
1458
1458
  // src/telemetry/telemetry.ts
1459
+ function secureRandomString() {
1460
+ if (typeof window !== "undefined" && window.crypto && typeof window.crypto.getRandomValues === "function") {
1461
+ const array = new Uint8Array(8);
1462
+ window.crypto.getRandomValues(array);
1463
+ return Array.from(array, (v) => v.toString(16).padStart(2, "0")).join("");
1464
+ }
1465
+ try {
1466
+ const crypto = require("crypto");
1467
+ return crypto.randomBytes(8).toString("hex");
1468
+ } catch (e) {
1469
+ return Math.random().toString(36).substring(2, 15);
1470
+ }
1471
+ }
1472
+ __name(secureRandomString, "secureRandomString");
1459
1473
  var USER_ID_STORAGE_KEY = "mcp_use_user_id";
1460
1474
  function detectRuntimeEnvironment() {
1461
1475
  try {
@@ -1587,12 +1601,26 @@ var Telemetry = class _Telemetry {
1587
1601
  "Anonymized telemetry enabled. Set MCP_USE_ANONYMIZED_TELEMETRY=false to disable."
1588
1602
  );
1589
1603
  this._posthogLoading = this._initPostHog();
1590
- try {
1591
- this._scarfClient = new ScarfEventLogger(this.SCARF_GATEWAY_URL, 3e3);
1592
- } catch (e) {
1593
- logger.warn(`Failed to initialize Scarf telemetry: ${e}`);
1604
+ if (this._runtimeEnvironment !== "browser") {
1605
+ try {
1606
+ this._scarfClient = new ScarfEventLogger(
1607
+ this.SCARF_GATEWAY_URL,
1608
+ 3e3
1609
+ );
1610
+ } catch (e) {
1611
+ logger.warn(`Failed to initialize Scarf telemetry: ${e}`);
1612
+ this._scarfClient = null;
1613
+ }
1614
+ } else {
1594
1615
  this._scarfClient = null;
1595
1616
  }
1617
+ if (this._storageCapability === "filesystem" && this._scarfClient) {
1618
+ setTimeout(() => {
1619
+ this.trackPackageDownload({ triggered_by: "initialization" }).catch(
1620
+ (e) => logger.debug(`Failed to track package download: ${e}`)
1621
+ );
1622
+ }, 0);
1623
+ }
1596
1624
  }
1597
1625
  }
1598
1626
  _checkTelemetryDisabled() {
@@ -1717,47 +1745,65 @@ var Telemetry = class _Telemetry {
1717
1745
  break;
1718
1746
  case "session-only":
1719
1747
  default:
1720
- this._currUserId = `session-${generateUUID()}`;
1721
- logger.debug(
1722
- `Using session-based user ID (${this._runtimeEnvironment} environment)`
1723
- );
1748
+ try {
1749
+ this._currUserId = `session-${generateUUID()}`;
1750
+ } catch (uuidError) {
1751
+ this._currUserId = `session-${Date.now()}-${Math.random().toString(36).substring(2, 15)}`;
1752
+ }
1724
1753
  break;
1725
1754
  }
1726
- if (this._storageCapability === "filesystem" && this._currUserId) {
1727
- this._trackPackageDownloadInternal(this._currUserId, {
1728
- triggered_by: "user_id_property"
1729
- }).catch((e) => logger.debug(`Failed to track package download: ${e}`));
1730
- }
1731
1755
  } catch (e) {
1732
- logger.debug(`Failed to get/create user ID: ${e}`);
1733
1756
  this._currUserId = this.UNKNOWN_USER_ID;
1734
1757
  }
1735
1758
  return this._currUserId;
1736
1759
  }
1737
1760
  /**
1738
1761
  * Get or create user ID from filesystem (Node.js/Bun)
1762
+ * Falls back to session ID if filesystem operations fail
1739
1763
  */
1740
1764
  _getUserIdFromFilesystem() {
1741
- const fs2 = require("fs");
1742
- const os = require("os");
1743
- const path2 = require("path");
1744
- if (!this._userIdPath) {
1745
- this._userIdPath = path2.join(
1746
- this._getCacheHome(os, path2),
1747
- "mcp_use_3",
1748
- "telemetry_user_id"
1749
- );
1750
- }
1751
- const isFirstTime = !fs2.existsSync(this._userIdPath);
1752
- if (isFirstTime) {
1753
- logger.debug(`Creating user ID path: ${this._userIdPath}`);
1754
- fs2.mkdirSync(path2.dirname(this._userIdPath), { recursive: true });
1755
- const newUserId = generateUUID();
1756
- fs2.writeFileSync(this._userIdPath, newUserId);
1757
- logger.debug(`User ID path created: ${this._userIdPath}`);
1758
- return newUserId;
1765
+ try {
1766
+ let fs2, os, path2;
1767
+ try {
1768
+ fs2 = require("fs");
1769
+ os = require("os");
1770
+ path2 = require("path");
1771
+ } catch (requireError) {
1772
+ try {
1773
+ const sessionId = `session-${generateUUID()}`;
1774
+ return sessionId;
1775
+ } catch (uuidError) {
1776
+ return `session-${Date.now()}-${Math.random().toString(36).substring(2, 15)}`;
1777
+ }
1778
+ }
1779
+ if (!this._userIdPath) {
1780
+ this._userIdPath = path2.join(
1781
+ this._getCacheHome(os, path2),
1782
+ "mcp_use_3",
1783
+ "telemetry_user_id"
1784
+ );
1785
+ }
1786
+ const isFirstTime = !fs2.existsSync(this._userIdPath);
1787
+ if (isFirstTime) {
1788
+ fs2.mkdirSync(path2.dirname(this._userIdPath), { recursive: true });
1789
+ let newUserId;
1790
+ try {
1791
+ newUserId = generateUUID();
1792
+ } catch (uuidError) {
1793
+ newUserId = `${Date.now()}-${Math.random().toString(36).substring(2, 15)}`;
1794
+ }
1795
+ fs2.writeFileSync(this._userIdPath, newUserId);
1796
+ return newUserId;
1797
+ }
1798
+ const userId = fs2.readFileSync(this._userIdPath, "utf-8").trim();
1799
+ return userId;
1800
+ } catch (e) {
1801
+ try {
1802
+ return `session-${generateUUID()}`;
1803
+ } catch (uuidError) {
1804
+ return `session-${Date.now()}-${secureRandomString()}`;
1805
+ }
1759
1806
  }
1760
- return fs2.readFileSync(this._userIdPath, "utf-8").trim();
1761
1807
  }
1762
1808
  /**
1763
1809
  * Get or create user ID from localStorage (Browser)
@@ -1766,14 +1812,22 @@ var Telemetry = class _Telemetry {
1766
1812
  try {
1767
1813
  let userId = localStorage.getItem(USER_ID_STORAGE_KEY);
1768
1814
  if (!userId) {
1769
- userId = generateUUID();
1815
+ try {
1816
+ userId = generateUUID();
1817
+ } catch (uuidError) {
1818
+ userId = `${Date.now()}-${secureRandomString()}`;
1819
+ }
1770
1820
  localStorage.setItem(USER_ID_STORAGE_KEY, userId);
1771
- logger.debug(`Created new browser user ID`);
1772
1821
  }
1773
1822
  return userId;
1774
1823
  } catch (e) {
1775
- logger.debug(`localStorage access failed: ${e}`);
1776
- return `session-${generateUUID()}`;
1824
+ let sessionId;
1825
+ try {
1826
+ sessionId = `session-${generateUUID()}`;
1827
+ } catch (uuidError) {
1828
+ sessionId = `session-${Date.now()}-${secureRandomString()}`;
1829
+ }
1830
+ return sessionId;
1777
1831
  }
1778
1832
  }
1779
1833
  _getCacheHome(os, path2) {
@@ -1802,6 +1856,7 @@ var Telemetry = class _Telemetry {
1802
1856
  if (!this._posthogNodeClient && !this._posthogBrowserClient && !this._scarfClient) {
1803
1857
  return;
1804
1858
  }
1859
+ const currentUserId = this.userId;
1805
1860
  const properties = { ...event.properties };
1806
1861
  properties.mcp_use_version = getPackageVersion();
1807
1862
  properties.language = "typescript";
@@ -1809,9 +1864,8 @@ var Telemetry = class _Telemetry {
1809
1864
  properties.runtime = this._runtimeEnvironment;
1810
1865
  if (this._posthogNodeClient) {
1811
1866
  try {
1812
- logger.debug(`CAPTURE: PostHog Node Event ${event.name}`);
1813
1867
  this._posthogNodeClient.capture({
1814
- distinctId: this.userId,
1868
+ distinctId: currentUserId,
1815
1869
  event: event.name,
1816
1870
  properties
1817
1871
  });
@@ -1821,10 +1875,9 @@ var Telemetry = class _Telemetry {
1821
1875
  }
1822
1876
  if (this._posthogBrowserClient) {
1823
1877
  try {
1824
- logger.debug(`CAPTURE: PostHog Browser Event ${event.name}`);
1825
1878
  this._posthogBrowserClient.capture(event.name, {
1826
1879
  ...properties,
1827
- distinct_id: this.userId
1880
+ distinct_id: currentUserId
1828
1881
  });
1829
1882
  } catch (e) {
1830
1883
  logger.debug(
@@ -1836,7 +1889,7 @@ var Telemetry = class _Telemetry {
1836
1889
  try {
1837
1890
  const scarfProperties = {
1838
1891
  ...properties,
1839
- user_id: this.userId,
1892
+ user_id: currentUserId,
1840
1893
  event: event.name
1841
1894
  };
1842
1895
  await this._scarfClient.logEvent(scarfProperties);
@@ -2752,7 +2805,7 @@ var CodeModeConnector = class extends BaseConnector {
2752
2805
  }
2753
2806
  };
2754
2807
 
2755
- // src/client/prompts.ts
2808
+ // src/agents/prompts/index.ts
2756
2809
  var PROMPTS = {
2757
2810
  CODE_MODE: CODE_MODE_AGENT_PROMPT
2758
2811
  };
@@ -5082,6 +5135,7 @@ var HttpConnector = class extends BaseConnector {
5082
5135
  sseReadTimeout;
5083
5136
  clientInfo;
5084
5137
  preferSse;
5138
+ disableSseFallback;
5085
5139
  transportType = null;
5086
5140
  streamableTransport = null;
5087
5141
  constructor(baseUrl, opts = {}) {
@@ -5098,6 +5152,7 @@ var HttpConnector = class extends BaseConnector {
5098
5152
  version: "1.0.0"
5099
5153
  };
5100
5154
  this.preferSse = opts.preferSse ?? false;
5155
+ this.disableSseFallback = opts.disableSseFallback ?? false;
5101
5156
  }
5102
5157
  /** Establish connection to the MCP implementation via HTTP (streamable or SSE). */
5103
5158
  async connect() {
@@ -5154,6 +5209,13 @@ var HttpConnector = class extends BaseConnector {
5154
5209
  authError.code = 401;
5155
5210
  throw authError;
5156
5211
  }
5212
+ if (this.disableSseFallback) {
5213
+ logger.info("SSE fallback disabled - failing connection");
5214
+ await this.cleanupResources();
5215
+ throw new Error(
5216
+ `Streamable HTTP connection failed: ${fallbackReason}. SSE fallback is disabled.`
5217
+ );
5218
+ }
5157
5219
  logger.info("\u{1F504} Falling back to SSE transport...");
5158
5220
  try {
5159
5221
  await this.connectWithSse(baseUrl);
@@ -5520,6 +5582,8 @@ function createConnectorFromConfig(serverConfig, connectorOptions) {
5520
5582
  authToken: serverConfig.auth_token || serverConfig.authToken,
5521
5583
  // Only force SSE if explicitly requested
5522
5584
  preferSse: serverConfig.preferSse || transport === "sse",
5585
+ // Disable SSE fallback if explicitly disabled in config
5586
+ disableSseFallback: serverConfig.disableSseFallback,
5523
5587
  ...connectorOptions
5524
5588
  });
5525
5589
  }
@@ -1,4 +1,4 @@
1
- export { PROMPTS } from "../client/prompts.js";
1
+ export { PROMPTS } from "./prompts/index.js";
2
2
  export { BaseAgent } from "./base.js";
3
3
  export { MCPAgent } from "./mcp_agent.js";
4
4
  export { RemoteAgent } from "./remote.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/agents/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,YAAY,EACV,WAAW,EACX,mBAAmB,EACnB,aAAa,EACb,eAAe,EACf,eAAe,EACf,qBAAqB,GACtB,MAAM,YAAY,CAAC;AACpB,YAAY,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/agents/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,YAAY,EACV,WAAW,EACX,mBAAmB,EACnB,aAAa,EACb,eAAe,EACf,eAAe,EACf,qBAAqB,GACtB,MAAM,YAAY,CAAC;AACpB,YAAY,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC"}