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

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.
@@ -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.17";
1420
+ var VERSION = "1.11.0-canary.18";
1421
1421
  function getPackageVersion() {
1422
1422
  return VERSION;
1423
1423
  }
@@ -1587,12 +1587,26 @@ var Telemetry = class _Telemetry {
1587
1587
  "Anonymized telemetry enabled. Set MCP_USE_ANONYMIZED_TELEMETRY=false to disable."
1588
1588
  );
1589
1589
  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}`);
1590
+ if (this._runtimeEnvironment !== "browser") {
1591
+ try {
1592
+ this._scarfClient = new ScarfEventLogger(
1593
+ this.SCARF_GATEWAY_URL,
1594
+ 3e3
1595
+ );
1596
+ } catch (e) {
1597
+ logger.warn(`Failed to initialize Scarf telemetry: ${e}`);
1598
+ this._scarfClient = null;
1599
+ }
1600
+ } else {
1594
1601
  this._scarfClient = null;
1595
1602
  }
1603
+ if (this._storageCapability === "filesystem" && this._scarfClient) {
1604
+ setTimeout(() => {
1605
+ this.trackPackageDownload({ triggered_by: "initialization" }).catch(
1606
+ (e) => logger.debug(`Failed to track package download: ${e}`)
1607
+ );
1608
+ }, 0);
1609
+ }
1596
1610
  }
1597
1611
  }
1598
1612
  _checkTelemetryDisabled() {
@@ -1717,47 +1731,65 @@ var Telemetry = class _Telemetry {
1717
1731
  break;
1718
1732
  case "session-only":
1719
1733
  default:
1720
- this._currUserId = `session-${generateUUID()}`;
1721
- logger.debug(
1722
- `Using session-based user ID (${this._runtimeEnvironment} environment)`
1723
- );
1734
+ try {
1735
+ this._currUserId = `session-${generateUUID()}`;
1736
+ } catch (uuidError) {
1737
+ this._currUserId = `session-${Date.now()}-${Math.random().toString(36).substring(2, 15)}`;
1738
+ }
1724
1739
  break;
1725
1740
  }
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
1741
  } catch (e) {
1732
- logger.debug(`Failed to get/create user ID: ${e}`);
1733
1742
  this._currUserId = this.UNKNOWN_USER_ID;
1734
1743
  }
1735
1744
  return this._currUserId;
1736
1745
  }
1737
1746
  /**
1738
1747
  * Get or create user ID from filesystem (Node.js/Bun)
1748
+ * Falls back to session ID if filesystem operations fail
1739
1749
  */
1740
1750
  _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;
1751
+ try {
1752
+ let fs2, os, path2;
1753
+ try {
1754
+ fs2 = require("fs");
1755
+ os = require("os");
1756
+ path2 = require("path");
1757
+ } catch (requireError) {
1758
+ try {
1759
+ const sessionId = `session-${generateUUID()}`;
1760
+ return sessionId;
1761
+ } catch (uuidError) {
1762
+ return `session-${Date.now()}-${Math.random().toString(36).substring(2, 15)}`;
1763
+ }
1764
+ }
1765
+ if (!this._userIdPath) {
1766
+ this._userIdPath = path2.join(
1767
+ this._getCacheHome(os, path2),
1768
+ "mcp_use_3",
1769
+ "telemetry_user_id"
1770
+ );
1771
+ }
1772
+ const isFirstTime = !fs2.existsSync(this._userIdPath);
1773
+ if (isFirstTime) {
1774
+ fs2.mkdirSync(path2.dirname(this._userIdPath), { recursive: true });
1775
+ let newUserId;
1776
+ try {
1777
+ newUserId = generateUUID();
1778
+ } catch (uuidError) {
1779
+ newUserId = `${Date.now()}-${Math.random().toString(36).substring(2, 15)}`;
1780
+ }
1781
+ fs2.writeFileSync(this._userIdPath, newUserId);
1782
+ return newUserId;
1783
+ }
1784
+ const userId = fs2.readFileSync(this._userIdPath, "utf-8").trim();
1785
+ return userId;
1786
+ } catch (e) {
1787
+ try {
1788
+ return `session-${generateUUID()}`;
1789
+ } catch (uuidError) {
1790
+ return `session-${Date.now()}-${Math.random().toString(36).substring(2, 15)}`;
1791
+ }
1759
1792
  }
1760
- return fs2.readFileSync(this._userIdPath, "utf-8").trim();
1761
1793
  }
1762
1794
  /**
1763
1795
  * Get or create user ID from localStorage (Browser)
@@ -1766,14 +1798,22 @@ var Telemetry = class _Telemetry {
1766
1798
  try {
1767
1799
  let userId = localStorage.getItem(USER_ID_STORAGE_KEY);
1768
1800
  if (!userId) {
1769
- userId = generateUUID();
1801
+ try {
1802
+ userId = generateUUID();
1803
+ } catch (uuidError) {
1804
+ userId = `${Date.now()}-${Math.random().toString(36).substring(2, 15)}`;
1805
+ }
1770
1806
  localStorage.setItem(USER_ID_STORAGE_KEY, userId);
1771
- logger.debug(`Created new browser user ID`);
1772
1807
  }
1773
1808
  return userId;
1774
1809
  } catch (e) {
1775
- logger.debug(`localStorage access failed: ${e}`);
1776
- return `session-${generateUUID()}`;
1810
+ let sessionId;
1811
+ try {
1812
+ sessionId = `session-${generateUUID()}`;
1813
+ } catch (uuidError) {
1814
+ sessionId = `session-${Date.now()}-${Math.random().toString(36).substring(2, 15)}`;
1815
+ }
1816
+ return sessionId;
1777
1817
  }
1778
1818
  }
1779
1819
  _getCacheHome(os, path2) {
@@ -1802,6 +1842,7 @@ var Telemetry = class _Telemetry {
1802
1842
  if (!this._posthogNodeClient && !this._posthogBrowserClient && !this._scarfClient) {
1803
1843
  return;
1804
1844
  }
1845
+ const currentUserId = this.userId;
1805
1846
  const properties = { ...event.properties };
1806
1847
  properties.mcp_use_version = getPackageVersion();
1807
1848
  properties.language = "typescript";
@@ -1809,9 +1850,8 @@ var Telemetry = class _Telemetry {
1809
1850
  properties.runtime = this._runtimeEnvironment;
1810
1851
  if (this._posthogNodeClient) {
1811
1852
  try {
1812
- logger.debug(`CAPTURE: PostHog Node Event ${event.name}`);
1813
1853
  this._posthogNodeClient.capture({
1814
- distinctId: this.userId,
1854
+ distinctId: currentUserId,
1815
1855
  event: event.name,
1816
1856
  properties
1817
1857
  });
@@ -1821,10 +1861,9 @@ var Telemetry = class _Telemetry {
1821
1861
  }
1822
1862
  if (this._posthogBrowserClient) {
1823
1863
  try {
1824
- logger.debug(`CAPTURE: PostHog Browser Event ${event.name}`);
1825
1864
  this._posthogBrowserClient.capture(event.name, {
1826
1865
  ...properties,
1827
- distinct_id: this.userId
1866
+ distinct_id: currentUserId
1828
1867
  });
1829
1868
  } catch (e) {
1830
1869
  logger.debug(
@@ -1836,7 +1875,7 @@ var Telemetry = class _Telemetry {
1836
1875
  try {
1837
1876
  const scarfProperties = {
1838
1877
  ...properties,
1839
- user_id: this.userId,
1878
+ user_id: currentUserId,
1840
1879
  event: event.name
1841
1880
  };
1842
1881
  await this._scarfClient.logEvent(scarfProperties);
@@ -1,16 +1,16 @@
1
1
  import {
2
2
  BaseAgent,
3
3
  PROMPTS
4
- } from "../../chunk-XZM65NMN.js";
4
+ } from "../../chunk-DKK3OEIY.js";
5
5
  import {
6
6
  MCPAgent,
7
7
  RemoteAgent
8
- } from "../../chunk-LQJZY6OD.js";
8
+ } from "../../chunk-6TCXBLDE.js";
9
9
  import "../../chunk-JRGQRPTN.js";
10
- import "../../chunk-ETMSIR6K.js";
10
+ import "../../chunk-I3NZCYBR.js";
11
11
  import "../../chunk-MFSO5PUW.js";
12
- import "../../chunk-QEEFUZ22.js";
13
- import "../../chunk-JQMHLTXF.js";
12
+ import "../../chunk-M6HG2X4Q.js";
13
+ import "../../chunk-MIY5EBAT.js";
14
14
  import "../../chunk-FRUZDWXH.js";
15
15
  import "../../chunk-3GQAWCBQ.js";
16
16
  export {
@@ -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.18";
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,27 +12,27 @@ import {
12
12
  getSupportedProviders,
13
13
  isValidLLMString,
14
14
  parseLLMString
15
- } from "../chunk-LQJZY6OD.js";
15
+ } from "../chunk-6TCXBLDE.js";
16
16
  import "../chunk-JRGQRPTN.js";
17
- import "../chunk-ETMSIR6K.js";
17
+ import "../chunk-I3NZCYBR.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-OD724W55.js";
24
24
  import {
25
25
  BaseConnector,
26
26
  HttpConnector,
27
27
  MCPSession
28
- } from "../chunk-QEEFUZ22.js";
28
+ } from "../chunk-M6HG2X4Q.js";
29
29
  import {
30
30
  Tel,
31
31
  Telemetry,
32
32
  VERSION,
33
33
  getPackageVersion,
34
34
  setTelemetrySource
35
- } from "../chunk-JQMHLTXF.js";
35
+ } from "../chunk-MIY5EBAT.js";
36
36
  import {
37
37
  Logger,
38
38
  logger
@@ -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.18";
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-I3NZCYBR.js";
8
8
  import {
9
9
  MCPSession
10
- } from "../chunk-QEEFUZ22.js";
11
- import "../chunk-JQMHLTXF.js";
10
+ } from "../chunk-M6HG2X4Q.js";
11
+ import "../chunk-MIY5EBAT.js";
12
12
  import "../chunk-FRUZDWXH.js";
13
13
  import "../chunk-3GQAWCBQ.js";
14
14
  export {