mcp-use 1.11.0-canary.17 → 1.11.0-canary.19

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.
@@ -1651,7 +1651,7 @@ __name(generateUUID, "generateUUID");
1651
1651
  init_logging();
1652
1652
 
1653
1653
  // src/version.ts
1654
- var VERSION = "1.11.0-canary.17";
1654
+ var VERSION = "1.11.0-canary.19";
1655
1655
  function getPackageVersion() {
1656
1656
  return VERSION;
1657
1657
  }
@@ -1821,12 +1821,26 @@ var Telemetry = class _Telemetry {
1821
1821
  "Anonymized telemetry enabled. Set MCP_USE_ANONYMIZED_TELEMETRY=false to disable."
1822
1822
  );
1823
1823
  this._posthogLoading = this._initPostHog();
1824
- try {
1825
- this._scarfClient = new ScarfEventLogger(this.SCARF_GATEWAY_URL, 3e3);
1826
- } catch (e) {
1827
- logger.warn(`Failed to initialize Scarf telemetry: ${e}`);
1824
+ if (this._runtimeEnvironment !== "browser") {
1825
+ try {
1826
+ this._scarfClient = new ScarfEventLogger(
1827
+ this.SCARF_GATEWAY_URL,
1828
+ 3e3
1829
+ );
1830
+ } catch (e) {
1831
+ logger.warn(`Failed to initialize Scarf telemetry: ${e}`);
1832
+ this._scarfClient = null;
1833
+ }
1834
+ } else {
1828
1835
  this._scarfClient = null;
1829
1836
  }
1837
+ if (this._storageCapability === "filesystem" && this._scarfClient) {
1838
+ setTimeout(() => {
1839
+ this.trackPackageDownload({ triggered_by: "initialization" }).catch(
1840
+ (e) => logger.debug(`Failed to track package download: ${e}`)
1841
+ );
1842
+ }, 0);
1843
+ }
1830
1844
  }
1831
1845
  }
1832
1846
  _checkTelemetryDisabled() {
@@ -1951,47 +1965,65 @@ var Telemetry = class _Telemetry {
1951
1965
  break;
1952
1966
  case "session-only":
1953
1967
  default:
1954
- this._currUserId = `session-${generateUUID()}`;
1955
- logger.debug(
1956
- `Using session-based user ID (${this._runtimeEnvironment} environment)`
1957
- );
1968
+ try {
1969
+ this._currUserId = `session-${generateUUID()}`;
1970
+ } catch (uuidError) {
1971
+ this._currUserId = `session-${Date.now()}-${Math.random().toString(36).substring(2, 15)}`;
1972
+ }
1958
1973
  break;
1959
1974
  }
1960
- if (this._storageCapability === "filesystem" && this._currUserId) {
1961
- this._trackPackageDownloadInternal(this._currUserId, {
1962
- triggered_by: "user_id_property"
1963
- }).catch((e) => logger.debug(`Failed to track package download: ${e}`));
1964
- }
1965
1975
  } catch (e) {
1966
- logger.debug(`Failed to get/create user ID: ${e}`);
1967
1976
  this._currUserId = this.UNKNOWN_USER_ID;
1968
1977
  }
1969
1978
  return this._currUserId;
1970
1979
  }
1971
1980
  /**
1972
1981
  * Get or create user ID from filesystem (Node.js/Bun)
1982
+ * Falls back to session ID if filesystem operations fail
1973
1983
  */
1974
1984
  _getUserIdFromFilesystem() {
1975
- const fs2 = require("fs");
1976
- const os = require("os");
1977
- const path2 = require("path");
1978
- if (!this._userIdPath) {
1979
- this._userIdPath = path2.join(
1980
- this._getCacheHome(os, path2),
1981
- "mcp_use_3",
1982
- "telemetry_user_id"
1983
- );
1984
- }
1985
- const isFirstTime = !fs2.existsSync(this._userIdPath);
1986
- if (isFirstTime) {
1987
- logger.debug(`Creating user ID path: ${this._userIdPath}`);
1988
- fs2.mkdirSync(path2.dirname(this._userIdPath), { recursive: true });
1989
- const newUserId = generateUUID();
1990
- fs2.writeFileSync(this._userIdPath, newUserId);
1991
- logger.debug(`User ID path created: ${this._userIdPath}`);
1992
- return newUserId;
1985
+ try {
1986
+ let fs2, os, path2;
1987
+ try {
1988
+ fs2 = require("fs");
1989
+ os = require("os");
1990
+ path2 = require("path");
1991
+ } catch (requireError) {
1992
+ try {
1993
+ const sessionId = `session-${generateUUID()}`;
1994
+ return sessionId;
1995
+ } catch (uuidError) {
1996
+ return `session-${Date.now()}-${Math.random().toString(36).substring(2, 15)}`;
1997
+ }
1998
+ }
1999
+ if (!this._userIdPath) {
2000
+ this._userIdPath = path2.join(
2001
+ this._getCacheHome(os, path2),
2002
+ "mcp_use_3",
2003
+ "telemetry_user_id"
2004
+ );
2005
+ }
2006
+ const isFirstTime = !fs2.existsSync(this._userIdPath);
2007
+ if (isFirstTime) {
2008
+ fs2.mkdirSync(path2.dirname(this._userIdPath), { recursive: true });
2009
+ let newUserId;
2010
+ try {
2011
+ newUserId = generateUUID();
2012
+ } catch (uuidError) {
2013
+ newUserId = `${Date.now()}-${Math.random().toString(36).substring(2, 15)}`;
2014
+ }
2015
+ fs2.writeFileSync(this._userIdPath, newUserId);
2016
+ return newUserId;
2017
+ }
2018
+ const userId = fs2.readFileSync(this._userIdPath, "utf-8").trim();
2019
+ return userId;
2020
+ } catch (e) {
2021
+ try {
2022
+ return `session-${generateUUID()}`;
2023
+ } catch (uuidError) {
2024
+ return `session-${Date.now()}-${Math.random().toString(36).substring(2, 15)}`;
2025
+ }
1993
2026
  }
1994
- return fs2.readFileSync(this._userIdPath, "utf-8").trim();
1995
2027
  }
1996
2028
  /**
1997
2029
  * Get or create user ID from localStorage (Browser)
@@ -2000,14 +2032,22 @@ var Telemetry = class _Telemetry {
2000
2032
  try {
2001
2033
  let userId = localStorage.getItem(USER_ID_STORAGE_KEY);
2002
2034
  if (!userId) {
2003
- userId = generateUUID();
2035
+ try {
2036
+ userId = generateUUID();
2037
+ } catch (uuidError) {
2038
+ userId = `${Date.now()}-${Math.random().toString(36).substring(2, 15)}`;
2039
+ }
2004
2040
  localStorage.setItem(USER_ID_STORAGE_KEY, userId);
2005
- logger.debug(`Created new browser user ID`);
2006
2041
  }
2007
2042
  return userId;
2008
2043
  } catch (e) {
2009
- logger.debug(`localStorage access failed: ${e}`);
2010
- return `session-${generateUUID()}`;
2044
+ let sessionId;
2045
+ try {
2046
+ sessionId = `session-${generateUUID()}`;
2047
+ } catch (uuidError) {
2048
+ sessionId = `session-${Date.now()}-${Math.random().toString(36).substring(2, 15)}`;
2049
+ }
2050
+ return sessionId;
2011
2051
  }
2012
2052
  }
2013
2053
  _getCacheHome(os, path2) {
@@ -2036,6 +2076,7 @@ var Telemetry = class _Telemetry {
2036
2076
  if (!this._posthogNodeClient && !this._posthogBrowserClient && !this._scarfClient) {
2037
2077
  return;
2038
2078
  }
2079
+ const currentUserId = this.userId;
2039
2080
  const properties = { ...event.properties };
2040
2081
  properties.mcp_use_version = getPackageVersion();
2041
2082
  properties.language = "typescript";
@@ -2043,9 +2084,8 @@ var Telemetry = class _Telemetry {
2043
2084
  properties.runtime = this._runtimeEnvironment;
2044
2085
  if (this._posthogNodeClient) {
2045
2086
  try {
2046
- logger.debug(`CAPTURE: PostHog Node Event ${event.name}`);
2047
2087
  this._posthogNodeClient.capture({
2048
- distinctId: this.userId,
2088
+ distinctId: currentUserId,
2049
2089
  event: event.name,
2050
2090
  properties
2051
2091
  });
@@ -2055,10 +2095,9 @@ var Telemetry = class _Telemetry {
2055
2095
  }
2056
2096
  if (this._posthogBrowserClient) {
2057
2097
  try {
2058
- logger.debug(`CAPTURE: PostHog Browser Event ${event.name}`);
2059
2098
  this._posthogBrowserClient.capture(event.name, {
2060
2099
  ...properties,
2061
- distinct_id: this.userId
2100
+ distinct_id: currentUserId
2062
2101
  });
2063
2102
  } catch (e) {
2064
2103
  logger.debug(
@@ -2070,7 +2109,7 @@ var Telemetry = class _Telemetry {
2070
2109
  try {
2071
2110
  const scarfProperties = {
2072
2111
  ...properties,
2073
- user_id: this.userId,
2112
+ user_id: currentUserId,
2074
2113
  event: event.name
2075
2114
  };
2076
2115
  await this._scarfClient.logEvent(scarfProperties);
@@ -12,35 +12,35 @@ import {
12
12
  getSupportedProviders,
13
13
  isValidLLMString,
14
14
  parseLLMString
15
- } from "../chunk-LQJZY6OD.js";
15
+ } from "../chunk-XWY3UCBV.js";
16
16
  import "../chunk-JRGQRPTN.js";
17
- import "../chunk-ETMSIR6K.js";
17
+ import "../chunk-DDBBDHDD.js";
18
18
  import {
19
19
  BaseAdapter
20
20
  } from "../chunk-MFSO5PUW.js";
21
21
  import {
22
22
  BrowserMCPClient
23
- } from "../chunk-NTB5TTZW.js";
23
+ } from "../chunk-7KWUIU7I.js";
24
+ import {
25
+ BrowserOAuthClientProvider,
26
+ onMcpAuthorization
27
+ } from "../chunk-J75I2C26.js";
24
28
  import {
25
29
  BaseConnector,
26
30
  HttpConnector,
27
31
  MCPSession
28
- } from "../chunk-QEEFUZ22.js";
32
+ } from "../chunk-5QAH2BZN.js";
29
33
  import {
30
34
  Tel,
31
35
  Telemetry,
32
36
  VERSION,
33
37
  getPackageVersion,
34
38
  setTelemetrySource
35
- } from "../chunk-JQMHLTXF.js";
39
+ } from "../chunk-2CX2RMGM.js";
36
40
  import {
37
41
  Logger,
38
42
  logger
39
43
  } from "../chunk-FRUZDWXH.js";
40
- import {
41
- BrowserOAuthClientProvider,
42
- onMcpAuthorization
43
- } from "../chunk-J75I2C26.js";
44
44
  import "../chunk-3GQAWCBQ.js";
45
45
  export {
46
46
  BaseAdapter,
@@ -942,7 +942,7 @@ function generateUUID() {
942
942
  __name(generateUUID, "generateUUID");
943
943
 
944
944
  // src/version.ts
945
- var VERSION = "1.11.0-canary.17";
945
+ var VERSION = "1.11.0-canary.19";
946
946
  function getPackageVersion() {
947
947
  return VERSION;
948
948
  }
@@ -1080,12 +1080,26 @@ var Telemetry = class _Telemetry {
1080
1080
  "Anonymized telemetry enabled. Set MCP_USE_ANONYMIZED_TELEMETRY=false to disable."
1081
1081
  );
1082
1082
  this._posthogLoading = this._initPostHog();
1083
- try {
1084
- this._scarfClient = new ScarfEventLogger(this.SCARF_GATEWAY_URL, 3e3);
1085
- } catch (e) {
1086
- logger.warn(`Failed to initialize Scarf telemetry: ${e}`);
1083
+ if (this._runtimeEnvironment !== "browser") {
1084
+ try {
1085
+ this._scarfClient = new ScarfEventLogger(
1086
+ this.SCARF_GATEWAY_URL,
1087
+ 3e3
1088
+ );
1089
+ } catch (e) {
1090
+ logger.warn(`Failed to initialize Scarf telemetry: ${e}`);
1091
+ this._scarfClient = null;
1092
+ }
1093
+ } else {
1087
1094
  this._scarfClient = null;
1088
1095
  }
1096
+ if (this._storageCapability === "filesystem" && this._scarfClient) {
1097
+ setTimeout(() => {
1098
+ this.trackPackageDownload({ triggered_by: "initialization" }).catch(
1099
+ (e) => logger.debug(`Failed to track package download: ${e}`)
1100
+ );
1101
+ }, 0);
1102
+ }
1089
1103
  }
1090
1104
  }
1091
1105
  _checkTelemetryDisabled() {
@@ -1210,47 +1224,65 @@ var Telemetry = class _Telemetry {
1210
1224
  break;
1211
1225
  case "session-only":
1212
1226
  default:
1213
- this._currUserId = `session-${generateUUID()}`;
1214
- logger.debug(
1215
- `Using session-based user ID (${this._runtimeEnvironment} environment)`
1216
- );
1227
+ try {
1228
+ this._currUserId = `session-${generateUUID()}`;
1229
+ } catch (uuidError) {
1230
+ this._currUserId = `session-${Date.now()}-${Math.random().toString(36).substring(2, 15)}`;
1231
+ }
1217
1232
  break;
1218
1233
  }
1219
- if (this._storageCapability === "filesystem" && this._currUserId) {
1220
- this._trackPackageDownloadInternal(this._currUserId, {
1221
- triggered_by: "user_id_property"
1222
- }).catch((e) => logger.debug(`Failed to track package download: ${e}`));
1223
- }
1224
1234
  } catch (e) {
1225
- logger.debug(`Failed to get/create user ID: ${e}`);
1226
1235
  this._currUserId = this.UNKNOWN_USER_ID;
1227
1236
  }
1228
1237
  return this._currUserId;
1229
1238
  }
1230
1239
  /**
1231
1240
  * Get or create user ID from filesystem (Node.js/Bun)
1241
+ * Falls back to session ID if filesystem operations fail
1232
1242
  */
1233
1243
  _getUserIdFromFilesystem() {
1234
- const fs2 = require("fs");
1235
- const os = require("os");
1236
- const path2 = require("path");
1237
- if (!this._userIdPath) {
1238
- this._userIdPath = path2.join(
1239
- this._getCacheHome(os, path2),
1240
- "mcp_use_3",
1241
- "telemetry_user_id"
1242
- );
1243
- }
1244
- const isFirstTime = !fs2.existsSync(this._userIdPath);
1245
- if (isFirstTime) {
1246
- logger.debug(`Creating user ID path: ${this._userIdPath}`);
1247
- fs2.mkdirSync(path2.dirname(this._userIdPath), { recursive: true });
1248
- const newUserId = generateUUID();
1249
- fs2.writeFileSync(this._userIdPath, newUserId);
1250
- logger.debug(`User ID path created: ${this._userIdPath}`);
1251
- return newUserId;
1244
+ try {
1245
+ let fs2, os, path2;
1246
+ try {
1247
+ fs2 = require("fs");
1248
+ os = require("os");
1249
+ path2 = require("path");
1250
+ } catch (requireError) {
1251
+ try {
1252
+ const sessionId = `session-${generateUUID()}`;
1253
+ return sessionId;
1254
+ } catch (uuidError) {
1255
+ return `session-${Date.now()}-${Math.random().toString(36).substring(2, 15)}`;
1256
+ }
1257
+ }
1258
+ if (!this._userIdPath) {
1259
+ this._userIdPath = path2.join(
1260
+ this._getCacheHome(os, path2),
1261
+ "mcp_use_3",
1262
+ "telemetry_user_id"
1263
+ );
1264
+ }
1265
+ const isFirstTime = !fs2.existsSync(this._userIdPath);
1266
+ if (isFirstTime) {
1267
+ fs2.mkdirSync(path2.dirname(this._userIdPath), { recursive: true });
1268
+ let newUserId;
1269
+ try {
1270
+ newUserId = generateUUID();
1271
+ } catch (uuidError) {
1272
+ newUserId = `${Date.now()}-${Math.random().toString(36).substring(2, 15)}`;
1273
+ }
1274
+ fs2.writeFileSync(this._userIdPath, newUserId);
1275
+ return newUserId;
1276
+ }
1277
+ const userId = fs2.readFileSync(this._userIdPath, "utf-8").trim();
1278
+ return userId;
1279
+ } catch (e) {
1280
+ try {
1281
+ return `session-${generateUUID()}`;
1282
+ } catch (uuidError) {
1283
+ return `session-${Date.now()}-${Math.random().toString(36).substring(2, 15)}`;
1284
+ }
1252
1285
  }
1253
- return fs2.readFileSync(this._userIdPath, "utf-8").trim();
1254
1286
  }
1255
1287
  /**
1256
1288
  * Get or create user ID from localStorage (Browser)
@@ -1259,14 +1291,22 @@ var Telemetry = class _Telemetry {
1259
1291
  try {
1260
1292
  let userId = localStorage.getItem(USER_ID_STORAGE_KEY);
1261
1293
  if (!userId) {
1262
- userId = generateUUID();
1294
+ try {
1295
+ userId = generateUUID();
1296
+ } catch (uuidError) {
1297
+ userId = `${Date.now()}-${Math.random().toString(36).substring(2, 15)}`;
1298
+ }
1263
1299
  localStorage.setItem(USER_ID_STORAGE_KEY, userId);
1264
- logger.debug(`Created new browser user ID`);
1265
1300
  }
1266
1301
  return userId;
1267
1302
  } catch (e) {
1268
- logger.debug(`localStorage access failed: ${e}`);
1269
- return `session-${generateUUID()}`;
1303
+ let sessionId;
1304
+ try {
1305
+ sessionId = `session-${generateUUID()}`;
1306
+ } catch (uuidError) {
1307
+ sessionId = `session-${Date.now()}-${Math.random().toString(36).substring(2, 15)}`;
1308
+ }
1309
+ return sessionId;
1270
1310
  }
1271
1311
  }
1272
1312
  _getCacheHome(os, path2) {
@@ -1295,6 +1335,7 @@ var Telemetry = class _Telemetry {
1295
1335
  if (!this._posthogNodeClient && !this._posthogBrowserClient && !this._scarfClient) {
1296
1336
  return;
1297
1337
  }
1338
+ const currentUserId = this.userId;
1298
1339
  const properties = { ...event.properties };
1299
1340
  properties.mcp_use_version = getPackageVersion();
1300
1341
  properties.language = "typescript";
@@ -1302,9 +1343,8 @@ var Telemetry = class _Telemetry {
1302
1343
  properties.runtime = this._runtimeEnvironment;
1303
1344
  if (this._posthogNodeClient) {
1304
1345
  try {
1305
- logger.debug(`CAPTURE: PostHog Node Event ${event.name}`);
1306
1346
  this._posthogNodeClient.capture({
1307
- distinctId: this.userId,
1347
+ distinctId: currentUserId,
1308
1348
  event: event.name,
1309
1349
  properties
1310
1350
  });
@@ -1314,10 +1354,9 @@ var Telemetry = class _Telemetry {
1314
1354
  }
1315
1355
  if (this._posthogBrowserClient) {
1316
1356
  try {
1317
- logger.debug(`CAPTURE: PostHog Browser Event ${event.name}`);
1318
1357
  this._posthogBrowserClient.capture(event.name, {
1319
1358
  ...properties,
1320
- distinct_id: this.userId
1359
+ distinct_id: currentUserId
1321
1360
  });
1322
1361
  } catch (e) {
1323
1362
  logger.debug(
@@ -1329,7 +1368,7 @@ var Telemetry = class _Telemetry {
1329
1368
  try {
1330
1369
  const scarfProperties = {
1331
1370
  ...properties,
1332
- user_id: this.userId,
1371
+ user_id: currentUserId,
1333
1372
  event: event.name
1334
1373
  };
1335
1374
  await this._scarfClient.logEvent(scarfProperties);
@@ -4,11 +4,11 @@ import {
4
4
  MCPClient,
5
5
  VMCodeExecutor,
6
6
  isVMAvailable
7
- } from "../chunk-ETMSIR6K.js";
7
+ } from "../chunk-DDBBDHDD.js";
8
8
  import {
9
9
  MCPSession
10
- } from "../chunk-QEEFUZ22.js";
11
- import "../chunk-JQMHLTXF.js";
10
+ } from "../chunk-5QAH2BZN.js";
11
+ import "../chunk-2CX2RMGM.js";
12
12
  import "../chunk-FRUZDWXH.js";
13
13
  import "../chunk-3GQAWCBQ.js";
14
14
  export {
@@ -918,7 +918,7 @@ function generateUUID() {
918
918
  __name(generateUUID, "generateUUID");
919
919
 
920
920
  // src/version.ts
921
- var VERSION = "1.11.0-canary.17";
921
+ var VERSION = "1.11.0-canary.19";
922
922
  function getPackageVersion() {
923
923
  return VERSION;
924
924
  }
@@ -1056,12 +1056,26 @@ var Telemetry = class _Telemetry {
1056
1056
  "Anonymized telemetry enabled. Set MCP_USE_ANONYMIZED_TELEMETRY=false to disable."
1057
1057
  );
1058
1058
  this._posthogLoading = this._initPostHog();
1059
- try {
1060
- this._scarfClient = new ScarfEventLogger(this.SCARF_GATEWAY_URL, 3e3);
1061
- } catch (e) {
1062
- logger.warn(`Failed to initialize Scarf telemetry: ${e}`);
1059
+ if (this._runtimeEnvironment !== "browser") {
1060
+ try {
1061
+ this._scarfClient = new ScarfEventLogger(
1062
+ this.SCARF_GATEWAY_URL,
1063
+ 3e3
1064
+ );
1065
+ } catch (e) {
1066
+ logger.warn(`Failed to initialize Scarf telemetry: ${e}`);
1067
+ this._scarfClient = null;
1068
+ }
1069
+ } else {
1063
1070
  this._scarfClient = null;
1064
1071
  }
1072
+ if (this._storageCapability === "filesystem" && this._scarfClient) {
1073
+ setTimeout(() => {
1074
+ this.trackPackageDownload({ triggered_by: "initialization" }).catch(
1075
+ (e) => logger.debug(`Failed to track package download: ${e}`)
1076
+ );
1077
+ }, 0);
1078
+ }
1065
1079
  }
1066
1080
  }
1067
1081
  _checkTelemetryDisabled() {
@@ -1186,47 +1200,65 @@ var Telemetry = class _Telemetry {
1186
1200
  break;
1187
1201
  case "session-only":
1188
1202
  default:
1189
- this._currUserId = `session-${generateUUID()}`;
1190
- logger.debug(
1191
- `Using session-based user ID (${this._runtimeEnvironment} environment)`
1192
- );
1203
+ try {
1204
+ this._currUserId = `session-${generateUUID()}`;
1205
+ } catch (uuidError) {
1206
+ this._currUserId = `session-${Date.now()}-${Math.random().toString(36).substring(2, 15)}`;
1207
+ }
1193
1208
  break;
1194
1209
  }
1195
- if (this._storageCapability === "filesystem" && this._currUserId) {
1196
- this._trackPackageDownloadInternal(this._currUserId, {
1197
- triggered_by: "user_id_property"
1198
- }).catch((e) => logger.debug(`Failed to track package download: ${e}`));
1199
- }
1200
1210
  } catch (e) {
1201
- logger.debug(`Failed to get/create user ID: ${e}`);
1202
1211
  this._currUserId = this.UNKNOWN_USER_ID;
1203
1212
  }
1204
1213
  return this._currUserId;
1205
1214
  }
1206
1215
  /**
1207
1216
  * Get or create user ID from filesystem (Node.js/Bun)
1217
+ * Falls back to session ID if filesystem operations fail
1208
1218
  */
1209
1219
  _getUserIdFromFilesystem() {
1210
- const fs = require("fs");
1211
- const os = require("os");
1212
- const path = require("path");
1213
- if (!this._userIdPath) {
1214
- this._userIdPath = path.join(
1215
- this._getCacheHome(os, path),
1216
- "mcp_use_3",
1217
- "telemetry_user_id"
1218
- );
1219
- }
1220
- const isFirstTime = !fs.existsSync(this._userIdPath);
1221
- if (isFirstTime) {
1222
- logger.debug(`Creating user ID path: ${this._userIdPath}`);
1223
- fs.mkdirSync(path.dirname(this._userIdPath), { recursive: true });
1224
- const newUserId = generateUUID();
1225
- fs.writeFileSync(this._userIdPath, newUserId);
1226
- logger.debug(`User ID path created: ${this._userIdPath}`);
1227
- return newUserId;
1220
+ try {
1221
+ let fs, os, path;
1222
+ try {
1223
+ fs = require("fs");
1224
+ os = require("os");
1225
+ path = require("path");
1226
+ } catch (requireError) {
1227
+ try {
1228
+ const sessionId = `session-${generateUUID()}`;
1229
+ return sessionId;
1230
+ } catch (uuidError) {
1231
+ return `session-${Date.now()}-${Math.random().toString(36).substring(2, 15)}`;
1232
+ }
1233
+ }
1234
+ if (!this._userIdPath) {
1235
+ this._userIdPath = path.join(
1236
+ this._getCacheHome(os, path),
1237
+ "mcp_use_3",
1238
+ "telemetry_user_id"
1239
+ );
1240
+ }
1241
+ const isFirstTime = !fs.existsSync(this._userIdPath);
1242
+ if (isFirstTime) {
1243
+ fs.mkdirSync(path.dirname(this._userIdPath), { recursive: true });
1244
+ let newUserId;
1245
+ try {
1246
+ newUserId = generateUUID();
1247
+ } catch (uuidError) {
1248
+ newUserId = `${Date.now()}-${Math.random().toString(36).substring(2, 15)}`;
1249
+ }
1250
+ fs.writeFileSync(this._userIdPath, newUserId);
1251
+ return newUserId;
1252
+ }
1253
+ const userId = fs.readFileSync(this._userIdPath, "utf-8").trim();
1254
+ return userId;
1255
+ } catch (e) {
1256
+ try {
1257
+ return `session-${generateUUID()}`;
1258
+ } catch (uuidError) {
1259
+ return `session-${Date.now()}-${Math.random().toString(36).substring(2, 15)}`;
1260
+ }
1228
1261
  }
1229
- return fs.readFileSync(this._userIdPath, "utf-8").trim();
1230
1262
  }
1231
1263
  /**
1232
1264
  * Get or create user ID from localStorage (Browser)
@@ -1235,14 +1267,22 @@ var Telemetry = class _Telemetry {
1235
1267
  try {
1236
1268
  let userId = localStorage.getItem(USER_ID_STORAGE_KEY);
1237
1269
  if (!userId) {
1238
- userId = generateUUID();
1270
+ try {
1271
+ userId = generateUUID();
1272
+ } catch (uuidError) {
1273
+ userId = `${Date.now()}-${Math.random().toString(36).substring(2, 15)}`;
1274
+ }
1239
1275
  localStorage.setItem(USER_ID_STORAGE_KEY, userId);
1240
- logger.debug(`Created new browser user ID`);
1241
1276
  }
1242
1277
  return userId;
1243
1278
  } catch (e) {
1244
- logger.debug(`localStorage access failed: ${e}`);
1245
- return `session-${generateUUID()}`;
1279
+ let sessionId;
1280
+ try {
1281
+ sessionId = `session-${generateUUID()}`;
1282
+ } catch (uuidError) {
1283
+ sessionId = `session-${Date.now()}-${Math.random().toString(36).substring(2, 15)}`;
1284
+ }
1285
+ return sessionId;
1246
1286
  }
1247
1287
  }
1248
1288
  _getCacheHome(os, path) {
@@ -1271,6 +1311,7 @@ var Telemetry = class _Telemetry {
1271
1311
  if (!this._posthogNodeClient && !this._posthogBrowserClient && !this._scarfClient) {
1272
1312
  return;
1273
1313
  }
1314
+ const currentUserId = this.userId;
1274
1315
  const properties = { ...event.properties };
1275
1316
  properties.mcp_use_version = getPackageVersion();
1276
1317
  properties.language = "typescript";
@@ -1278,9 +1319,8 @@ var Telemetry = class _Telemetry {
1278
1319
  properties.runtime = this._runtimeEnvironment;
1279
1320
  if (this._posthogNodeClient) {
1280
1321
  try {
1281
- logger.debug(`CAPTURE: PostHog Node Event ${event.name}`);
1282
1322
  this._posthogNodeClient.capture({
1283
- distinctId: this.userId,
1323
+ distinctId: currentUserId,
1284
1324
  event: event.name,
1285
1325
  properties
1286
1326
  });
@@ -1290,10 +1330,9 @@ var Telemetry = class _Telemetry {
1290
1330
  }
1291
1331
  if (this._posthogBrowserClient) {
1292
1332
  try {
1293
- logger.debug(`CAPTURE: PostHog Browser Event ${event.name}`);
1294
1333
  this._posthogBrowserClient.capture(event.name, {
1295
1334
  ...properties,
1296
- distinct_id: this.userId
1335
+ distinct_id: currentUserId
1297
1336
  });
1298
1337
  } catch (e) {
1299
1338
  logger.debug(
@@ -1305,7 +1344,7 @@ var Telemetry = class _Telemetry {
1305
1344
  try {
1306
1345
  const scarfProperties = {
1307
1346
  ...properties,
1308
- user_id: this.userId,
1347
+ user_id: currentUserId,
1309
1348
  event: event.name
1310
1349
  };
1311
1350
  await this._scarfClient.logEvent(scarfProperties);