mcp-use 1.10.0-canary.8 → 1.10.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 (39) hide show
  1. package/dist/.tsbuildinfo +1 -1
  2. package/dist/{chunk-CAIRNNL6.js → chunk-BLIJYL2F.js} +1 -1
  3. package/dist/{chunk-BBOYAKT6.js → chunk-D3GIGCHA.js} +1 -1
  4. package/dist/{chunk-X5QAXENQ.js → chunk-EKIKWKIM.js} +1 -1
  5. package/dist/{chunk-QBKQ6JN2.js → chunk-J76TXLP2.js} +24 -2
  6. package/dist/{chunk-6W6MURTQ.js → chunk-TWQ72HSN.js} +51 -2
  7. package/dist/{chunk-MSA3YBQE.js → chunk-UZJK3IKC.js} +1 -1
  8. package/dist/{chunk-ITRC7CNB.js → chunk-X5EWD2UY.js} +344 -157
  9. package/dist/index.cjs +424 -166
  10. package/dist/index.js +24 -18
  11. package/dist/src/agents/index.cjs +337 -151
  12. package/dist/src/agents/index.js +4 -4
  13. package/dist/src/browser.cjs +371 -151
  14. package/dist/src/browser.d.ts +3 -0
  15. package/dist/src/browser.d.ts.map +1 -1
  16. package/dist/src/browser.js +13 -5
  17. package/dist/src/client/base.d.ts.map +1 -1
  18. package/dist/src/client/browser.d.ts +1 -0
  19. package/dist/src/client/browser.d.ts.map +1 -1
  20. package/dist/src/client/prompts.cjs +3 -9
  21. package/dist/src/client/prompts.js +3 -3
  22. package/dist/src/client.d.ts.map +1 -1
  23. package/dist/src/react/index.cjs +414 -151
  24. package/dist/src/react/index.d.ts +3 -0
  25. package/dist/src/react/index.d.ts.map +1 -1
  26. package/dist/src/react/index.js +13 -4
  27. package/dist/src/react/useMcp.d.ts.map +1 -1
  28. package/dist/src/server/index.cjs +756 -569
  29. package/dist/src/server/index.js +5 -5
  30. package/dist/src/telemetry/events.d.ts +28 -0
  31. package/dist/src/telemetry/events.d.ts.map +1 -1
  32. package/dist/src/telemetry/index.d.ts +4 -4
  33. package/dist/src/telemetry/index.d.ts.map +1 -1
  34. package/dist/src/telemetry/telemetry.d.ts +74 -11
  35. package/dist/src/telemetry/telemetry.d.ts.map +1 -1
  36. package/dist/src/version.d.ts +1 -1
  37. package/dist/src/version.d.ts.map +1 -1
  38. package/dist/{tool-execution-helpers-BMGQQKS2.js → tool-execution-helpers-IMWBWRMK.js} +2 -2
  39. package/package.json +4 -3
@@ -35,9 +35,9 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
35
35
  async function getNodeModules() {
36
36
  if (typeof process !== "undefined" && process.platform) {
37
37
  try {
38
- const fs2 = await import("fs");
39
- const path2 = await import("path");
40
- return { fs: fs2.default, path: path2.default };
38
+ const fs = await import("fs");
39
+ const path = await import("path");
40
+ return { fs: fs.default, path: path.default };
41
41
  } catch {
42
42
  return { fs: null, path: null };
43
43
  }
@@ -1058,22 +1058,6 @@ module.exports = __toCommonJS(agents_exports);
1058
1058
  var import_types = require("@mcp-use/modelcontextprotocol-sdk/types.js");
1059
1059
  init_logging();
1060
1060
 
1061
- // src/telemetry/telemetry.ts
1062
- var fs = __toESM(require("fs"), 1);
1063
- var os = __toESM(require("os"), 1);
1064
- var path = __toESM(require("path"), 1);
1065
- var import_posthog_node = require("posthog-node");
1066
-
1067
- // src/server/utils/runtime.ts
1068
- var isDeno = typeof globalThis.Deno !== "undefined";
1069
- function generateUUID() {
1070
- return globalThis.crypto.randomUUID();
1071
- }
1072
- __name(generateUUID, "generateUUID");
1073
-
1074
- // src/telemetry/telemetry.ts
1075
- init_logging();
1076
-
1077
1061
  // src/telemetry/events.ts
1078
1062
  var BaseTelemetryEvent = class {
1079
1063
  static {
@@ -1349,7 +1333,8 @@ var MCPClientInitEvent = class extends BaseTelemetryEvent {
1349
1333
  all_callbacks: this.data.allCallbacks,
1350
1334
  verify: this.data.verify,
1351
1335
  servers: this.data.servers,
1352
- num_servers: this.data.numServers
1336
+ num_servers: this.data.numServers,
1337
+ is_browser: this.data.isBrowser
1353
1338
  };
1354
1339
  }
1355
1340
  };
@@ -1374,9 +1359,65 @@ var ConnectorInitEvent = class extends BaseTelemetryEvent {
1374
1359
  };
1375
1360
  }
1376
1361
  };
1362
+ var ClientAddServerEvent = class extends BaseTelemetryEvent {
1363
+ constructor(data) {
1364
+ super();
1365
+ this.data = data;
1366
+ }
1367
+ static {
1368
+ __name(this, "ClientAddServerEvent");
1369
+ }
1370
+ get name() {
1371
+ return "client_add_server";
1372
+ }
1373
+ get properties() {
1374
+ const { serverName, serverConfig } = this.data;
1375
+ const url = serverConfig.url;
1376
+ return {
1377
+ server_name: serverName,
1378
+ server_url_domain: url ? this._extractHostname(url) : null,
1379
+ transport: serverConfig.transport ?? null,
1380
+ has_auth: !!(serverConfig.authToken || serverConfig.authProvider)
1381
+ };
1382
+ }
1383
+ _extractHostname(url) {
1384
+ try {
1385
+ return new URL(url).hostname;
1386
+ } catch {
1387
+ return null;
1388
+ }
1389
+ }
1390
+ };
1391
+ var ClientRemoveServerEvent = class extends BaseTelemetryEvent {
1392
+ constructor(data) {
1393
+ super();
1394
+ this.data = data;
1395
+ }
1396
+ static {
1397
+ __name(this, "ClientRemoveServerEvent");
1398
+ }
1399
+ get name() {
1400
+ return "client_remove_server";
1401
+ }
1402
+ get properties() {
1403
+ return {
1404
+ server_name: this.data.serverName
1405
+ };
1406
+ }
1407
+ };
1408
+
1409
+ // src/server/utils/runtime.ts
1410
+ var isDeno = typeof globalThis.Deno !== "undefined";
1411
+ function generateUUID() {
1412
+ return globalThis.crypto.randomUUID();
1413
+ }
1414
+ __name(generateUUID, "generateUUID");
1415
+
1416
+ // src/telemetry/telemetry.ts
1417
+ init_logging();
1377
1418
 
1378
1419
  // src/version.ts
1379
- var VERSION = "1.10.0-canary.8";
1420
+ var VERSION = "1.10.0";
1380
1421
  function getPackageVersion() {
1381
1422
  return VERSION;
1382
1423
  }
@@ -1430,12 +1471,12 @@ function detectRuntimeEnvironment() {
1430
1471
  if (typeof globalThis.EdgeRuntime !== "undefined") {
1431
1472
  return "edge";
1432
1473
  }
1433
- if (typeof process !== "undefined" && typeof process.versions?.node !== "undefined" && typeof fs !== "undefined" && typeof fs.existsSync === "function") {
1434
- return "node";
1435
- }
1436
1474
  if (typeof window !== "undefined" && typeof document !== "undefined") {
1437
1475
  return "browser";
1438
1476
  }
1477
+ if (typeof process !== "undefined" && typeof process.versions?.node !== "undefined") {
1478
+ return "node";
1479
+ }
1439
1480
  return "unknown";
1440
1481
  } catch {
1441
1482
  return "unknown";
@@ -1472,11 +1513,6 @@ function getRuntimeEnvironment() {
1472
1513
  return cachedEnvironment;
1473
1514
  }
1474
1515
  __name(getRuntimeEnvironment, "getRuntimeEnvironment");
1475
- function isNodeJSEnvironment2() {
1476
- const env = getRuntimeEnvironment();
1477
- return env === "node" || env === "bun";
1478
- }
1479
- __name(isNodeJSEnvironment2, "isNodeJSEnvironment");
1480
1516
  var ScarfEventLogger = class {
1481
1517
  static {
1482
1518
  __name(this, "ScarfEventLogger");
@@ -1508,71 +1544,40 @@ var ScarfEventLogger = class {
1508
1544
  }
1509
1545
  }
1510
1546
  };
1511
- function getCacheHome() {
1512
- if (!isNodeJSEnvironment2()) {
1513
- return "/tmp/mcp_use_cache";
1514
- }
1515
- const envVar = process.env.XDG_CACHE_HOME;
1516
- if (envVar && path.isAbsolute(envVar)) {
1517
- return envVar;
1518
- }
1519
- const platform = process.platform;
1520
- const homeDir = os.homedir();
1521
- if (platform === "win32") {
1522
- const appdata = process.env.LOCALAPPDATA || process.env.APPDATA;
1523
- if (appdata) {
1524
- return appdata;
1525
- }
1526
- return path.join(homeDir, "AppData", "Local");
1527
- } else if (platform === "darwin") {
1528
- return path.join(homeDir, "Library", "Caches");
1529
- } else {
1530
- return path.join(homeDir, ".cache");
1531
- }
1532
- }
1533
- __name(getCacheHome, "getCacheHome");
1534
1547
  var Telemetry = class _Telemetry {
1535
1548
  static {
1536
1549
  __name(this, "Telemetry");
1537
1550
  }
1538
1551
  static instance = null;
1539
- USER_ID_PATH = path.join(
1540
- getCacheHome(),
1541
- "mcp_use_3",
1542
- "telemetry_user_id"
1543
- );
1544
- VERSION_DOWNLOAD_PATH = path.join(
1545
- getCacheHome(),
1546
- "mcp_use",
1547
- "download_version"
1548
- );
1549
1552
  PROJECT_API_KEY = "phc_lyTtbYwvkdSbrcMQNPiKiiRWrrM1seyKIMjycSvItEI";
1550
1553
  HOST = "https://eu.i.posthog.com";
1551
1554
  SCARF_GATEWAY_URL = "https://mcpuse.gateway.scarf.sh/events-ts";
1552
1555
  UNKNOWN_USER_ID = "UNKNOWN_USER_ID";
1553
1556
  _currUserId = null;
1554
- _posthogClient = null;
1557
+ _posthogNodeClient = null;
1558
+ _posthogBrowserClient = null;
1559
+ _posthogLoading = null;
1555
1560
  _scarfClient = null;
1556
1561
  _runtimeEnvironment;
1557
1562
  _storageCapability;
1558
1563
  _source;
1564
+ // Node.js specific paths (lazily computed)
1565
+ _userIdPath = null;
1566
+ _versionDownloadPath = null;
1559
1567
  constructor() {
1560
1568
  this._runtimeEnvironment = getRuntimeEnvironment();
1561
1569
  this._storageCapability = getStorageCapability(this._runtimeEnvironment);
1562
1570
  this._source = typeof process !== "undefined" && process.env?.MCP_USE_TELEMETRY_SOURCE || this._runtimeEnvironment;
1563
- const telemetryDisabled = typeof process !== "undefined" && process.env?.MCP_USE_ANONYMIZED_TELEMETRY?.toLowerCase() === "false" || false;
1571
+ const telemetryDisabled = this._checkTelemetryDisabled();
1564
1572
  const canSupportTelemetry = this._runtimeEnvironment !== "unknown";
1565
- const isServerlessEnvironment = [
1566
- "cloudflare-workers",
1567
- "edge",
1568
- "deno"
1569
- ].includes(this._runtimeEnvironment);
1570
1573
  if (telemetryDisabled) {
1571
- this._posthogClient = null;
1574
+ this._posthogNodeClient = null;
1575
+ this._posthogBrowserClient = null;
1572
1576
  this._scarfClient = null;
1573
- logger.debug("Telemetry disabled via environment variable");
1577
+ logger.debug("Telemetry disabled via environment/localStorage");
1574
1578
  } else if (!canSupportTelemetry) {
1575
- this._posthogClient = null;
1579
+ this._posthogNodeClient = null;
1580
+ this._posthogBrowserClient = null;
1576
1581
  this._scarfClient = null;
1577
1582
  logger.debug(
1578
1583
  `Telemetry disabled - unknown environment: ${this._runtimeEnvironment}`
@@ -1581,27 +1586,7 @@ var Telemetry = class _Telemetry {
1581
1586
  logger.info(
1582
1587
  "Anonymized telemetry enabled. Set MCP_USE_ANONYMIZED_TELEMETRY=false to disable."
1583
1588
  );
1584
- if (this._runtimeEnvironment !== "browser") {
1585
- try {
1586
- const posthogOptions = {
1587
- host: this.HOST,
1588
- disableGeoip: false
1589
- };
1590
- if (isServerlessEnvironment) {
1591
- posthogOptions.flushAt = 1;
1592
- posthogOptions.flushInterval = 0;
1593
- }
1594
- this._posthogClient = new import_posthog_node.PostHog(
1595
- this.PROJECT_API_KEY,
1596
- posthogOptions
1597
- );
1598
- } catch (e) {
1599
- logger.warn(`Failed to initialize PostHog telemetry: ${e}`);
1600
- this._posthogClient = null;
1601
- }
1602
- } else {
1603
- this._posthogClient = null;
1604
- }
1589
+ this._posthogLoading = this._initPostHog();
1605
1590
  try {
1606
1591
  this._scarfClient = new ScarfEventLogger(this.SCARF_GATEWAY_URL, 3e3);
1607
1592
  } catch (e) {
@@ -1610,6 +1595,75 @@ var Telemetry = class _Telemetry {
1610
1595
  }
1611
1596
  }
1612
1597
  }
1598
+ _checkTelemetryDisabled() {
1599
+ if (typeof process !== "undefined" && process.env?.MCP_USE_ANONYMIZED_TELEMETRY?.toLowerCase() === "false") {
1600
+ return true;
1601
+ }
1602
+ if (typeof localStorage !== "undefined" && localStorage.getItem("MCP_USE_ANONYMIZED_TELEMETRY") === "false") {
1603
+ return true;
1604
+ }
1605
+ return false;
1606
+ }
1607
+ async _initPostHog() {
1608
+ const isBrowser = this._runtimeEnvironment === "browser";
1609
+ if (isBrowser) {
1610
+ await this._initPostHogBrowser();
1611
+ } else {
1612
+ await this._initPostHogNode();
1613
+ }
1614
+ }
1615
+ async _initPostHogBrowser() {
1616
+ try {
1617
+ const posthogModule = await import("posthog-js");
1618
+ const posthog = posthogModule.default || posthogModule.posthog;
1619
+ if (!posthog || typeof posthog.init !== "function") {
1620
+ throw new Error("posthog-js module did not export expected interface");
1621
+ }
1622
+ posthog.init(this.PROJECT_API_KEY, {
1623
+ api_host: this.HOST,
1624
+ persistence: "localStorage",
1625
+ autocapture: false,
1626
+ // We only want explicit captures
1627
+ capture_pageview: false,
1628
+ // We don't want automatic pageview tracking
1629
+ disable_session_recording: true,
1630
+ // No session recording
1631
+ loaded: /* @__PURE__ */ __name(() => {
1632
+ logger.debug("PostHog browser client initialized");
1633
+ }, "loaded")
1634
+ });
1635
+ this._posthogBrowserClient = posthog;
1636
+ } catch (e) {
1637
+ logger.warn(`Failed to initialize PostHog browser telemetry: ${e}`);
1638
+ this._posthogBrowserClient = null;
1639
+ }
1640
+ }
1641
+ async _initPostHogNode() {
1642
+ try {
1643
+ const { PostHog } = await import("posthog-node");
1644
+ const isServerlessEnvironment = [
1645
+ "cloudflare-workers",
1646
+ "edge",
1647
+ "deno"
1648
+ ].includes(this._runtimeEnvironment);
1649
+ const posthogOptions = {
1650
+ host: this.HOST,
1651
+ disableGeoip: false
1652
+ };
1653
+ if (isServerlessEnvironment) {
1654
+ posthogOptions.flushAt = 1;
1655
+ posthogOptions.flushInterval = 0;
1656
+ }
1657
+ this._posthogNodeClient = new PostHog(
1658
+ this.PROJECT_API_KEY,
1659
+ posthogOptions
1660
+ );
1661
+ logger.debug("PostHog Node.js client initialized");
1662
+ } catch (e) {
1663
+ logger.warn(`Failed to initialize PostHog Node.js telemetry: ${e}`);
1664
+ this._posthogNodeClient = null;
1665
+ }
1666
+ }
1613
1667
  /**
1614
1668
  * Get the detected runtime environment
1615
1669
  */
@@ -1645,10 +1699,9 @@ var Telemetry = class _Telemetry {
1645
1699
  }
1646
1700
  /**
1647
1701
  * Check if telemetry is enabled.
1648
- * Returns false if telemetry was disabled via environment variable or if not in Node.js environment.
1649
1702
  */
1650
1703
  get isEnabled() {
1651
- return this._posthogClient !== null || this._scarfClient !== null;
1704
+ return this._posthogNodeClient !== null || this._posthogBrowserClient !== null || this._scarfClient !== null;
1652
1705
  }
1653
1706
  get userId() {
1654
1707
  if (this._currUserId) {
@@ -1657,10 +1710,10 @@ var Telemetry = class _Telemetry {
1657
1710
  try {
1658
1711
  switch (this._storageCapability) {
1659
1712
  case "filesystem":
1660
- this._currUserId = this.getUserIdFromFilesystem();
1713
+ this._currUserId = this._getUserIdFromFilesystem();
1661
1714
  break;
1662
1715
  case "localStorage":
1663
- this._currUserId = this.getUserIdFromLocalStorage();
1716
+ this._currUserId = this._getUserIdFromLocalStorage();
1664
1717
  break;
1665
1718
  case "session-only":
1666
1719
  default:
@@ -1671,7 +1724,7 @@ var Telemetry = class _Telemetry {
1671
1724
  break;
1672
1725
  }
1673
1726
  if (this._storageCapability === "filesystem" && this._currUserId) {
1674
- this.trackPackageDownloadInternal(this._currUserId, {
1727
+ this._trackPackageDownloadInternal(this._currUserId, {
1675
1728
  triggered_by: "user_id_property"
1676
1729
  }).catch((e) => logger.debug(`Failed to track package download: ${e}`));
1677
1730
  }
@@ -1684,22 +1737,32 @@ var Telemetry = class _Telemetry {
1684
1737
  /**
1685
1738
  * Get or create user ID from filesystem (Node.js/Bun)
1686
1739
  */
1687
- getUserIdFromFilesystem() {
1688
- const isFirstTime = !fs.existsSync(this.USER_ID_PATH);
1740
+ _getUserIdFromFilesystem() {
1741
+ const fs = require("fs");
1742
+ const os = require("os");
1743
+ const path = require("path");
1744
+ if (!this._userIdPath) {
1745
+ this._userIdPath = path.join(
1746
+ this._getCacheHome(os, path),
1747
+ "mcp_use_3",
1748
+ "telemetry_user_id"
1749
+ );
1750
+ }
1751
+ const isFirstTime = !fs.existsSync(this._userIdPath);
1689
1752
  if (isFirstTime) {
1690
- logger.debug(`Creating user ID path: ${this.USER_ID_PATH}`);
1691
- fs.mkdirSync(path.dirname(this.USER_ID_PATH), { recursive: true });
1753
+ logger.debug(`Creating user ID path: ${this._userIdPath}`);
1754
+ fs.mkdirSync(path.dirname(this._userIdPath), { recursive: true });
1692
1755
  const newUserId = generateUUID();
1693
- fs.writeFileSync(this.USER_ID_PATH, newUserId);
1694
- logger.debug(`User ID path created: ${this.USER_ID_PATH}`);
1756
+ fs.writeFileSync(this._userIdPath, newUserId);
1757
+ logger.debug(`User ID path created: ${this._userIdPath}`);
1695
1758
  return newUserId;
1696
1759
  }
1697
- return fs.readFileSync(this.USER_ID_PATH, "utf-8").trim();
1760
+ return fs.readFileSync(this._userIdPath, "utf-8").trim();
1698
1761
  }
1699
1762
  /**
1700
1763
  * Get or create user ID from localStorage (Browser)
1701
1764
  */
1702
- getUserIdFromLocalStorage() {
1765
+ _getUserIdFromLocalStorage() {
1703
1766
  try {
1704
1767
  let userId = localStorage.getItem(USER_ID_STORAGE_KEY);
1705
1768
  if (!userId) {
@@ -1713,60 +1776,89 @@ var Telemetry = class _Telemetry {
1713
1776
  return `session-${generateUUID()}`;
1714
1777
  }
1715
1778
  }
1779
+ _getCacheHome(os, path) {
1780
+ const envVar = process.env.XDG_CACHE_HOME;
1781
+ if (envVar && path.isAbsolute(envVar)) {
1782
+ return envVar;
1783
+ }
1784
+ const platform = process.platform;
1785
+ const homeDir = os.homedir();
1786
+ if (platform === "win32") {
1787
+ const appdata = process.env.LOCALAPPDATA || process.env.APPDATA;
1788
+ if (appdata) {
1789
+ return appdata;
1790
+ }
1791
+ return path.join(homeDir, "AppData", "Local");
1792
+ } else if (platform === "darwin") {
1793
+ return path.join(homeDir, "Library", "Caches");
1794
+ } else {
1795
+ return path.join(homeDir, ".cache");
1796
+ }
1797
+ }
1716
1798
  async capture(event) {
1717
- logger.debug(
1718
- `CAPTURE: posthog: ${this._posthogClient !== null}, scarf: ${this._scarfClient !== null}`
1719
- );
1720
- if (!this._posthogClient && !this._scarfClient) {
1799
+ if (this._posthogLoading) {
1800
+ await this._posthogLoading;
1801
+ }
1802
+ if (!this._posthogNodeClient && !this._posthogBrowserClient && !this._scarfClient) {
1721
1803
  return;
1722
1804
  }
1723
- if (this._posthogClient) {
1805
+ const properties = { ...event.properties };
1806
+ properties.mcp_use_version = getPackageVersion();
1807
+ properties.language = "typescript";
1808
+ properties.source = this._source;
1809
+ properties.runtime = this._runtimeEnvironment;
1810
+ if (this._posthogNodeClient) {
1724
1811
  try {
1725
- const properties = { ...event.properties };
1726
- properties.mcp_use_version = getPackageVersion();
1727
- properties.language = "typescript";
1728
- properties.source = this._source;
1729
- properties.runtime = this._runtimeEnvironment;
1730
- logger.debug(`CAPTURE: PostHog Event ${event.name}`);
1731
- logger.debug(
1732
- `CAPTURE: PostHog Properties ${JSON.stringify(properties)}`
1733
- );
1734
- this._posthogClient.capture({
1812
+ logger.debug(`CAPTURE: PostHog Node Event ${event.name}`);
1813
+ this._posthogNodeClient.capture({
1735
1814
  distinctId: this.userId,
1736
1815
  event: event.name,
1737
1816
  properties
1738
1817
  });
1739
1818
  } catch (e) {
1740
- logger.debug(`Failed to track PostHog event ${event.name}: ${e}`);
1819
+ logger.debug(`Failed to track PostHog Node event ${event.name}: ${e}`);
1820
+ }
1821
+ }
1822
+ if (this._posthogBrowserClient) {
1823
+ try {
1824
+ logger.debug(`CAPTURE: PostHog Browser Event ${event.name}`);
1825
+ this._posthogBrowserClient.capture(event.name, {
1826
+ ...properties,
1827
+ distinct_id: this.userId
1828
+ });
1829
+ } catch (e) {
1830
+ logger.debug(
1831
+ `Failed to track PostHog Browser event ${event.name}: ${e}`
1832
+ );
1741
1833
  }
1742
1834
  }
1743
1835
  if (this._scarfClient) {
1744
1836
  try {
1745
- const properties = {};
1746
- properties.mcp_use_version = getPackageVersion();
1747
- properties.user_id = this.userId;
1748
- properties.event = event.name;
1749
- properties.language = "typescript";
1750
- properties.source = this._source;
1751
- properties.runtime = this._runtimeEnvironment;
1752
- await this._scarfClient.logEvent(properties);
1837
+ const scarfProperties = {
1838
+ ...properties,
1839
+ user_id: this.userId,
1840
+ event: event.name
1841
+ };
1842
+ await this._scarfClient.logEvent(scarfProperties);
1753
1843
  } catch (e) {
1754
1844
  logger.debug(`Failed to track Scarf event ${event.name}: ${e}`);
1755
1845
  }
1756
1846
  }
1757
1847
  }
1848
+ // ============================================================================
1849
+ // Package Download Tracking (Node.js only)
1850
+ // ============================================================================
1758
1851
  /**
1759
1852
  * Track package download event.
1760
1853
  * This is a public wrapper that safely accesses userId.
1761
1854
  */
1762
1855
  async trackPackageDownload(properties) {
1763
- return this.trackPackageDownloadInternal(this.userId, properties);
1856
+ return this._trackPackageDownloadInternal(this.userId, properties);
1764
1857
  }
1765
1858
  /**
1766
1859
  * Internal method to track package download with explicit userId.
1767
- * This avoids circular dependency when called from the userId getter.
1768
1860
  */
1769
- async trackPackageDownloadInternal(userId, properties) {
1861
+ async _trackPackageDownloadInternal(userId, properties) {
1770
1862
  if (!this._scarfClient) {
1771
1863
  return;
1772
1864
  }
@@ -1774,22 +1866,32 @@ var Telemetry = class _Telemetry {
1774
1866
  return;
1775
1867
  }
1776
1868
  try {
1869
+ const fs = require("fs");
1870
+ const path = require("path");
1871
+ const os = require("os");
1872
+ if (!this._versionDownloadPath) {
1873
+ this._versionDownloadPath = path.join(
1874
+ this._getCacheHome(os, path),
1875
+ "mcp_use",
1876
+ "download_version"
1877
+ );
1878
+ }
1777
1879
  const currentVersion = getPackageVersion();
1778
1880
  let shouldTrack = false;
1779
1881
  let firstDownload = false;
1780
- if (!fs.existsSync(this.VERSION_DOWNLOAD_PATH)) {
1882
+ if (!fs.existsSync(this._versionDownloadPath)) {
1781
1883
  shouldTrack = true;
1782
1884
  firstDownload = true;
1783
- fs.mkdirSync(path.dirname(this.VERSION_DOWNLOAD_PATH), {
1885
+ fs.mkdirSync(path.dirname(this._versionDownloadPath), {
1784
1886
  recursive: true
1785
1887
  });
1786
- fs.writeFileSync(this.VERSION_DOWNLOAD_PATH, currentVersion);
1888
+ fs.writeFileSync(this._versionDownloadPath, currentVersion);
1787
1889
  } else {
1788
- const savedVersion = fs.readFileSync(this.VERSION_DOWNLOAD_PATH, "utf-8").trim();
1890
+ const savedVersion = fs.readFileSync(this._versionDownloadPath, "utf-8").trim();
1789
1891
  if (currentVersion > savedVersion) {
1790
1892
  shouldTrack = true;
1791
1893
  firstDownload = false;
1792
- fs.writeFileSync(this.VERSION_DOWNLOAD_PATH, currentVersion);
1894
+ fs.writeFileSync(this._versionDownloadPath, currentVersion);
1793
1895
  }
1794
1896
  }
1795
1897
  if (shouldTrack) {
@@ -1823,9 +1925,6 @@ var Telemetry = class _Telemetry {
1823
1925
  // ============================================================================
1824
1926
  /**
1825
1927
  * Track server run event directly from an MCPServer instance.
1826
- * This extracts the necessary data from the server and creates the event.
1827
- * @param server - The MCPServer instance (or any object conforming to MCPServerTelemetryInfo)
1828
- * @param transport - The transport type (e.g., "http", "stdio", "supabase")
1829
1928
  */
1830
1929
  async trackServerRunFromServer(server, transport) {
1831
1930
  if (!this.isEnabled) return;
@@ -1871,31 +1970,118 @@ var Telemetry = class _Telemetry {
1871
1970
  const event = new ConnectorInitEvent(data);
1872
1971
  await this.capture(event);
1873
1972
  }
1973
+ async trackClientAddServer(serverName, serverConfig) {
1974
+ if (!this.isEnabled) return;
1975
+ const event = new ClientAddServerEvent({ serverName, serverConfig });
1976
+ await this.capture(event);
1977
+ }
1978
+ async trackClientRemoveServer(serverName) {
1979
+ if (!this.isEnabled) return;
1980
+ const event = new ClientRemoveServerEvent({ serverName });
1981
+ await this.capture(event);
1982
+ }
1983
+ // ============================================================================
1984
+ // React Hook / Browser specific events
1985
+ // ============================================================================
1986
+ async trackUseMcpConnection(data) {
1987
+ if (!this.isEnabled) return;
1988
+ await this.capture({
1989
+ name: "usemcp_connection",
1990
+ properties: {
1991
+ url_domain: new URL(data.url).hostname,
1992
+ // Only domain for privacy
1993
+ transport_type: data.transportType,
1994
+ success: data.success,
1995
+ error_type: data.errorType ?? null,
1996
+ connection_time_ms: data.connectionTimeMs ?? null,
1997
+ has_oauth: data.hasOAuth,
1998
+ has_sampling: data.hasSampling,
1999
+ has_elicitation: data.hasElicitation
2000
+ }
2001
+ });
2002
+ }
2003
+ async trackUseMcpToolCall(data) {
2004
+ if (!this.isEnabled) return;
2005
+ await this.capture({
2006
+ name: "usemcp_tool_call",
2007
+ properties: {
2008
+ tool_name: data.toolName,
2009
+ success: data.success,
2010
+ error_type: data.errorType ?? null,
2011
+ execution_time_ms: data.executionTimeMs ?? null
2012
+ }
2013
+ });
2014
+ }
2015
+ async trackUseMcpResourceRead(data) {
2016
+ if (!this.isEnabled) return;
2017
+ await this.capture({
2018
+ name: "usemcp_resource_read",
2019
+ properties: {
2020
+ resource_uri_scheme: data.resourceUri.split(":")[0],
2021
+ // Only scheme for privacy
2022
+ success: data.success,
2023
+ error_type: data.errorType ?? null
2024
+ }
2025
+ });
2026
+ }
2027
+ // ============================================================================
2028
+ // Browser-specific Methods
2029
+ // ============================================================================
2030
+ /**
2031
+ * Identify the current user (useful for linking sessions)
2032
+ * Browser only - no-op in Node.js
2033
+ */
2034
+ identify(userId, properties) {
2035
+ if (this._posthogBrowserClient) {
2036
+ try {
2037
+ this._posthogBrowserClient.identify(userId, properties);
2038
+ } catch (e) {
2039
+ logger.debug(`Failed to identify user: ${e}`);
2040
+ }
2041
+ }
2042
+ }
2043
+ /**
2044
+ * Reset the user identity (useful for logout)
2045
+ * Browser only - no-op in Node.js
2046
+ */
2047
+ reset() {
2048
+ if (this._posthogBrowserClient) {
2049
+ try {
2050
+ this._posthogBrowserClient.reset();
2051
+ } catch (e) {
2052
+ logger.debug(`Failed to reset user: ${e}`);
2053
+ }
2054
+ }
2055
+ this._currUserId = null;
2056
+ }
2057
+ // ============================================================================
2058
+ // Node.js-specific Methods
2059
+ // ============================================================================
2060
+ /**
2061
+ * Flush the telemetry queue (Node.js only)
2062
+ */
1874
2063
  flush() {
1875
- if (this._posthogClient) {
2064
+ if (this._posthogNodeClient) {
1876
2065
  try {
1877
- this._posthogClient.flush();
2066
+ this._posthogNodeClient.flush();
1878
2067
  logger.debug("PostHog client telemetry queue flushed");
1879
2068
  } catch (e) {
1880
2069
  logger.debug(`Failed to flush PostHog client: ${e}`);
1881
2070
  }
1882
2071
  }
1883
- if (this._scarfClient) {
1884
- logger.debug("Scarf telemetry events sent immediately (no flush needed)");
1885
- }
1886
2072
  }
2073
+ /**
2074
+ * Shutdown the telemetry client (Node.js only)
2075
+ */
1887
2076
  shutdown() {
1888
- if (this._posthogClient) {
2077
+ if (this._posthogNodeClient) {
1889
2078
  try {
1890
- this._posthogClient.shutdown();
2079
+ this._posthogNodeClient.shutdown();
1891
2080
  logger.debug("PostHog client shutdown successfully");
1892
2081
  } catch (e) {
1893
2082
  logger.debug(`Error shutting down PostHog client: ${e}`);
1894
2083
  }
1895
2084
  }
1896
- if (this._scarfClient) {
1897
- logger.debug("Scarf telemetry client shutdown (no action needed)");
1898
- }
1899
2085
  }
1900
2086
  };
1901
2087