mcp-use 1.10.0-canary.9 → 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.
- package/dist/.tsbuildinfo +1 -1
- package/dist/{chunk-ZNO3O2HO.js → chunk-BLIJYL2F.js} +1 -1
- package/dist/{chunk-PH2WQV56.js → chunk-D3GIGCHA.js} +1 -1
- package/dist/{chunk-Y6BFGMPU.js → chunk-EKIKWKIM.js} +1 -1
- package/dist/{chunk-ILW5LBQD.js → chunk-J76TXLP2.js} +24 -2
- package/dist/{chunk-BZQ3E73M.js → chunk-TWQ72HSN.js} +51 -2
- package/dist/{chunk-DBIXD6FA.js → chunk-UZJK3IKC.js} +1 -1
- package/dist/{chunk-467MICF6.js → chunk-X5EWD2UY.js} +344 -157
- package/dist/index.cjs +424 -166
- package/dist/index.js +24 -18
- package/dist/src/agents/index.cjs +337 -151
- package/dist/src/agents/index.js +4 -4
- package/dist/src/browser.cjs +371 -151
- package/dist/src/browser.d.ts +3 -0
- package/dist/src/browser.d.ts.map +1 -1
- package/dist/src/browser.js +13 -5
- package/dist/src/client/base.d.ts.map +1 -1
- package/dist/src/client/browser.d.ts +1 -0
- package/dist/src/client/browser.d.ts.map +1 -1
- package/dist/src/client/prompts.cjs +3 -9
- package/dist/src/client/prompts.js +3 -3
- package/dist/src/client.d.ts.map +1 -1
- package/dist/src/react/index.cjs +414 -151
- package/dist/src/react/index.d.ts +3 -0
- package/dist/src/react/index.d.ts.map +1 -1
- package/dist/src/react/index.js +13 -4
- package/dist/src/react/useMcp.d.ts.map +1 -1
- package/dist/src/server/index.cjs +756 -569
- package/dist/src/server/index.js +5 -5
- package/dist/src/telemetry/events.d.ts +28 -0
- package/dist/src/telemetry/events.d.ts.map +1 -1
- package/dist/src/telemetry/index.d.ts +4 -4
- package/dist/src/telemetry/index.d.ts.map +1 -1
- package/dist/src/telemetry/telemetry.d.ts +74 -11
- package/dist/src/telemetry/telemetry.d.ts.map +1 -1
- package/dist/src/version.d.ts +1 -1
- package/dist/src/version.d.ts.map +1 -1
- package/dist/{tool-execution-helpers-WS2PRGDY.js → tool-execution-helpers-IMWBWRMK.js} +2 -2
- package/package.json +4 -3
package/dist/src/browser.cjs
CHANGED
|
@@ -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
|
|
39
|
-
const
|
|
40
|
-
return { fs:
|
|
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
|
}
|
|
@@ -1050,6 +1050,7 @@ __export(browser_exports, {
|
|
|
1050
1050
|
BaseAdapter: () => BaseAdapter,
|
|
1051
1051
|
BaseConnector: () => BaseConnector,
|
|
1052
1052
|
BrowserOAuthClientProvider: () => BrowserOAuthClientProvider,
|
|
1053
|
+
BrowserTelemetry: () => Tel,
|
|
1053
1054
|
HttpConnector: () => HttpConnector,
|
|
1054
1055
|
LangChainAdapter: () => LangChainAdapter,
|
|
1055
1056
|
Logger: () => Logger,
|
|
@@ -1058,12 +1059,16 @@ __export(browser_exports, {
|
|
|
1058
1059
|
MCPSession: () => MCPSession,
|
|
1059
1060
|
ObservabilityManager: () => ObservabilityManager,
|
|
1060
1061
|
RemoteAgent: () => RemoteAgent,
|
|
1062
|
+
Tel: () => Tel,
|
|
1063
|
+
Telemetry: () => Telemetry,
|
|
1061
1064
|
VERSION: () => VERSION,
|
|
1062
1065
|
WebSocketConnector: () => WebSocketConnector,
|
|
1063
1066
|
createReadableStreamFromGenerator: () => createReadableStreamFromGenerator,
|
|
1064
1067
|
getPackageVersion: () => getPackageVersion,
|
|
1065
1068
|
logger: () => logger,
|
|
1066
1069
|
onMcpAuthorization: () => onMcpAuthorization,
|
|
1070
|
+
setBrowserTelemetrySource: () => setTelemetrySource,
|
|
1071
|
+
setTelemetrySource: () => setTelemetrySource,
|
|
1067
1072
|
streamEventsToAISDK: () => streamEventsToAISDK,
|
|
1068
1073
|
streamEventsToAISDKWithTools: () => streamEventsToAISDKWithTools
|
|
1069
1074
|
});
|
|
@@ -1243,22 +1248,6 @@ var SseConnectionManager = class extends ConnectionManager {
|
|
|
1243
1248
|
var import_types = require("@mcp-use/modelcontextprotocol-sdk/types.js");
|
|
1244
1249
|
init_logging();
|
|
1245
1250
|
|
|
1246
|
-
// src/telemetry/telemetry.ts
|
|
1247
|
-
var fs = __toESM(require("fs"), 1);
|
|
1248
|
-
var os = __toESM(require("os"), 1);
|
|
1249
|
-
var path = __toESM(require("path"), 1);
|
|
1250
|
-
var import_posthog_node = require("posthog-node");
|
|
1251
|
-
|
|
1252
|
-
// src/server/utils/runtime.ts
|
|
1253
|
-
var isDeno = typeof globalThis.Deno !== "undefined";
|
|
1254
|
-
function generateUUID() {
|
|
1255
|
-
return globalThis.crypto.randomUUID();
|
|
1256
|
-
}
|
|
1257
|
-
__name(generateUUID, "generateUUID");
|
|
1258
|
-
|
|
1259
|
-
// src/telemetry/telemetry.ts
|
|
1260
|
-
init_logging();
|
|
1261
|
-
|
|
1262
1251
|
// src/telemetry/events.ts
|
|
1263
1252
|
var BaseTelemetryEvent = class {
|
|
1264
1253
|
static {
|
|
@@ -1534,7 +1523,8 @@ var MCPClientInitEvent = class extends BaseTelemetryEvent {
|
|
|
1534
1523
|
all_callbacks: this.data.allCallbacks,
|
|
1535
1524
|
verify: this.data.verify,
|
|
1536
1525
|
servers: this.data.servers,
|
|
1537
|
-
num_servers: this.data.numServers
|
|
1526
|
+
num_servers: this.data.numServers,
|
|
1527
|
+
is_browser: this.data.isBrowser
|
|
1538
1528
|
};
|
|
1539
1529
|
}
|
|
1540
1530
|
};
|
|
@@ -1559,9 +1549,65 @@ var ConnectorInitEvent = class extends BaseTelemetryEvent {
|
|
|
1559
1549
|
};
|
|
1560
1550
|
}
|
|
1561
1551
|
};
|
|
1552
|
+
var ClientAddServerEvent = class extends BaseTelemetryEvent {
|
|
1553
|
+
constructor(data) {
|
|
1554
|
+
super();
|
|
1555
|
+
this.data = data;
|
|
1556
|
+
}
|
|
1557
|
+
static {
|
|
1558
|
+
__name(this, "ClientAddServerEvent");
|
|
1559
|
+
}
|
|
1560
|
+
get name() {
|
|
1561
|
+
return "client_add_server";
|
|
1562
|
+
}
|
|
1563
|
+
get properties() {
|
|
1564
|
+
const { serverName, serverConfig } = this.data;
|
|
1565
|
+
const url = serverConfig.url;
|
|
1566
|
+
return {
|
|
1567
|
+
server_name: serverName,
|
|
1568
|
+
server_url_domain: url ? this._extractHostname(url) : null,
|
|
1569
|
+
transport: serverConfig.transport ?? null,
|
|
1570
|
+
has_auth: !!(serverConfig.authToken || serverConfig.authProvider)
|
|
1571
|
+
};
|
|
1572
|
+
}
|
|
1573
|
+
_extractHostname(url) {
|
|
1574
|
+
try {
|
|
1575
|
+
return new URL(url).hostname;
|
|
1576
|
+
} catch {
|
|
1577
|
+
return null;
|
|
1578
|
+
}
|
|
1579
|
+
}
|
|
1580
|
+
};
|
|
1581
|
+
var ClientRemoveServerEvent = class extends BaseTelemetryEvent {
|
|
1582
|
+
constructor(data) {
|
|
1583
|
+
super();
|
|
1584
|
+
this.data = data;
|
|
1585
|
+
}
|
|
1586
|
+
static {
|
|
1587
|
+
__name(this, "ClientRemoveServerEvent");
|
|
1588
|
+
}
|
|
1589
|
+
get name() {
|
|
1590
|
+
return "client_remove_server";
|
|
1591
|
+
}
|
|
1592
|
+
get properties() {
|
|
1593
|
+
return {
|
|
1594
|
+
server_name: this.data.serverName
|
|
1595
|
+
};
|
|
1596
|
+
}
|
|
1597
|
+
};
|
|
1598
|
+
|
|
1599
|
+
// src/server/utils/runtime.ts
|
|
1600
|
+
var isDeno = typeof globalThis.Deno !== "undefined";
|
|
1601
|
+
function generateUUID() {
|
|
1602
|
+
return globalThis.crypto.randomUUID();
|
|
1603
|
+
}
|
|
1604
|
+
__name(generateUUID, "generateUUID");
|
|
1605
|
+
|
|
1606
|
+
// src/telemetry/telemetry.ts
|
|
1607
|
+
init_logging();
|
|
1562
1608
|
|
|
1563
1609
|
// src/version.ts
|
|
1564
|
-
var VERSION = "1.10.0
|
|
1610
|
+
var VERSION = "1.10.0";
|
|
1565
1611
|
function getPackageVersion() {
|
|
1566
1612
|
return VERSION;
|
|
1567
1613
|
}
|
|
@@ -1615,12 +1661,12 @@ function detectRuntimeEnvironment() {
|
|
|
1615
1661
|
if (typeof globalThis.EdgeRuntime !== "undefined") {
|
|
1616
1662
|
return "edge";
|
|
1617
1663
|
}
|
|
1618
|
-
if (typeof process !== "undefined" && typeof process.versions?.node !== "undefined" && typeof fs !== "undefined" && typeof fs.existsSync === "function") {
|
|
1619
|
-
return "node";
|
|
1620
|
-
}
|
|
1621
1664
|
if (typeof window !== "undefined" && typeof document !== "undefined") {
|
|
1622
1665
|
return "browser";
|
|
1623
1666
|
}
|
|
1667
|
+
if (typeof process !== "undefined" && typeof process.versions?.node !== "undefined") {
|
|
1668
|
+
return "node";
|
|
1669
|
+
}
|
|
1624
1670
|
return "unknown";
|
|
1625
1671
|
} catch {
|
|
1626
1672
|
return "unknown";
|
|
@@ -1657,11 +1703,6 @@ function getRuntimeEnvironment() {
|
|
|
1657
1703
|
return cachedEnvironment;
|
|
1658
1704
|
}
|
|
1659
1705
|
__name(getRuntimeEnvironment, "getRuntimeEnvironment");
|
|
1660
|
-
function isNodeJSEnvironment2() {
|
|
1661
|
-
const env = getRuntimeEnvironment();
|
|
1662
|
-
return env === "node" || env === "bun";
|
|
1663
|
-
}
|
|
1664
|
-
__name(isNodeJSEnvironment2, "isNodeJSEnvironment");
|
|
1665
1706
|
var ScarfEventLogger = class {
|
|
1666
1707
|
static {
|
|
1667
1708
|
__name(this, "ScarfEventLogger");
|
|
@@ -1693,71 +1734,40 @@ var ScarfEventLogger = class {
|
|
|
1693
1734
|
}
|
|
1694
1735
|
}
|
|
1695
1736
|
};
|
|
1696
|
-
function getCacheHome() {
|
|
1697
|
-
if (!isNodeJSEnvironment2()) {
|
|
1698
|
-
return "/tmp/mcp_use_cache";
|
|
1699
|
-
}
|
|
1700
|
-
const envVar = process.env.XDG_CACHE_HOME;
|
|
1701
|
-
if (envVar && path.isAbsolute(envVar)) {
|
|
1702
|
-
return envVar;
|
|
1703
|
-
}
|
|
1704
|
-
const platform = process.platform;
|
|
1705
|
-
const homeDir = os.homedir();
|
|
1706
|
-
if (platform === "win32") {
|
|
1707
|
-
const appdata = process.env.LOCALAPPDATA || process.env.APPDATA;
|
|
1708
|
-
if (appdata) {
|
|
1709
|
-
return appdata;
|
|
1710
|
-
}
|
|
1711
|
-
return path.join(homeDir, "AppData", "Local");
|
|
1712
|
-
} else if (platform === "darwin") {
|
|
1713
|
-
return path.join(homeDir, "Library", "Caches");
|
|
1714
|
-
} else {
|
|
1715
|
-
return path.join(homeDir, ".cache");
|
|
1716
|
-
}
|
|
1717
|
-
}
|
|
1718
|
-
__name(getCacheHome, "getCacheHome");
|
|
1719
1737
|
var Telemetry = class _Telemetry {
|
|
1720
1738
|
static {
|
|
1721
1739
|
__name(this, "Telemetry");
|
|
1722
1740
|
}
|
|
1723
1741
|
static instance = null;
|
|
1724
|
-
USER_ID_PATH = path.join(
|
|
1725
|
-
getCacheHome(),
|
|
1726
|
-
"mcp_use_3",
|
|
1727
|
-
"telemetry_user_id"
|
|
1728
|
-
);
|
|
1729
|
-
VERSION_DOWNLOAD_PATH = path.join(
|
|
1730
|
-
getCacheHome(),
|
|
1731
|
-
"mcp_use",
|
|
1732
|
-
"download_version"
|
|
1733
|
-
);
|
|
1734
1742
|
PROJECT_API_KEY = "phc_lyTtbYwvkdSbrcMQNPiKiiRWrrM1seyKIMjycSvItEI";
|
|
1735
1743
|
HOST = "https://eu.i.posthog.com";
|
|
1736
1744
|
SCARF_GATEWAY_URL = "https://mcpuse.gateway.scarf.sh/events-ts";
|
|
1737
1745
|
UNKNOWN_USER_ID = "UNKNOWN_USER_ID";
|
|
1738
1746
|
_currUserId = null;
|
|
1739
|
-
|
|
1747
|
+
_posthogNodeClient = null;
|
|
1748
|
+
_posthogBrowserClient = null;
|
|
1749
|
+
_posthogLoading = null;
|
|
1740
1750
|
_scarfClient = null;
|
|
1741
1751
|
_runtimeEnvironment;
|
|
1742
1752
|
_storageCapability;
|
|
1743
1753
|
_source;
|
|
1754
|
+
// Node.js specific paths (lazily computed)
|
|
1755
|
+
_userIdPath = null;
|
|
1756
|
+
_versionDownloadPath = null;
|
|
1744
1757
|
constructor() {
|
|
1745
1758
|
this._runtimeEnvironment = getRuntimeEnvironment();
|
|
1746
1759
|
this._storageCapability = getStorageCapability(this._runtimeEnvironment);
|
|
1747
1760
|
this._source = typeof process !== "undefined" && process.env?.MCP_USE_TELEMETRY_SOURCE || this._runtimeEnvironment;
|
|
1748
|
-
const telemetryDisabled =
|
|
1761
|
+
const telemetryDisabled = this._checkTelemetryDisabled();
|
|
1749
1762
|
const canSupportTelemetry = this._runtimeEnvironment !== "unknown";
|
|
1750
|
-
const isServerlessEnvironment = [
|
|
1751
|
-
"cloudflare-workers",
|
|
1752
|
-
"edge",
|
|
1753
|
-
"deno"
|
|
1754
|
-
].includes(this._runtimeEnvironment);
|
|
1755
1763
|
if (telemetryDisabled) {
|
|
1756
|
-
this.
|
|
1764
|
+
this._posthogNodeClient = null;
|
|
1765
|
+
this._posthogBrowserClient = null;
|
|
1757
1766
|
this._scarfClient = null;
|
|
1758
|
-
logger.debug("Telemetry disabled via environment
|
|
1767
|
+
logger.debug("Telemetry disabled via environment/localStorage");
|
|
1759
1768
|
} else if (!canSupportTelemetry) {
|
|
1760
|
-
this.
|
|
1769
|
+
this._posthogNodeClient = null;
|
|
1770
|
+
this._posthogBrowserClient = null;
|
|
1761
1771
|
this._scarfClient = null;
|
|
1762
1772
|
logger.debug(
|
|
1763
1773
|
`Telemetry disabled - unknown environment: ${this._runtimeEnvironment}`
|
|
@@ -1766,27 +1776,7 @@ var Telemetry = class _Telemetry {
|
|
|
1766
1776
|
logger.info(
|
|
1767
1777
|
"Anonymized telemetry enabled. Set MCP_USE_ANONYMIZED_TELEMETRY=false to disable."
|
|
1768
1778
|
);
|
|
1769
|
-
|
|
1770
|
-
try {
|
|
1771
|
-
const posthogOptions = {
|
|
1772
|
-
host: this.HOST,
|
|
1773
|
-
disableGeoip: false
|
|
1774
|
-
};
|
|
1775
|
-
if (isServerlessEnvironment) {
|
|
1776
|
-
posthogOptions.flushAt = 1;
|
|
1777
|
-
posthogOptions.flushInterval = 0;
|
|
1778
|
-
}
|
|
1779
|
-
this._posthogClient = new import_posthog_node.PostHog(
|
|
1780
|
-
this.PROJECT_API_KEY,
|
|
1781
|
-
posthogOptions
|
|
1782
|
-
);
|
|
1783
|
-
} catch (e) {
|
|
1784
|
-
logger.warn(`Failed to initialize PostHog telemetry: ${e}`);
|
|
1785
|
-
this._posthogClient = null;
|
|
1786
|
-
}
|
|
1787
|
-
} else {
|
|
1788
|
-
this._posthogClient = null;
|
|
1789
|
-
}
|
|
1779
|
+
this._posthogLoading = this._initPostHog();
|
|
1790
1780
|
try {
|
|
1791
1781
|
this._scarfClient = new ScarfEventLogger(this.SCARF_GATEWAY_URL, 3e3);
|
|
1792
1782
|
} catch (e) {
|
|
@@ -1795,6 +1785,75 @@ var Telemetry = class _Telemetry {
|
|
|
1795
1785
|
}
|
|
1796
1786
|
}
|
|
1797
1787
|
}
|
|
1788
|
+
_checkTelemetryDisabled() {
|
|
1789
|
+
if (typeof process !== "undefined" && process.env?.MCP_USE_ANONYMIZED_TELEMETRY?.toLowerCase() === "false") {
|
|
1790
|
+
return true;
|
|
1791
|
+
}
|
|
1792
|
+
if (typeof localStorage !== "undefined" && localStorage.getItem("MCP_USE_ANONYMIZED_TELEMETRY") === "false") {
|
|
1793
|
+
return true;
|
|
1794
|
+
}
|
|
1795
|
+
return false;
|
|
1796
|
+
}
|
|
1797
|
+
async _initPostHog() {
|
|
1798
|
+
const isBrowser = this._runtimeEnvironment === "browser";
|
|
1799
|
+
if (isBrowser) {
|
|
1800
|
+
await this._initPostHogBrowser();
|
|
1801
|
+
} else {
|
|
1802
|
+
await this._initPostHogNode();
|
|
1803
|
+
}
|
|
1804
|
+
}
|
|
1805
|
+
async _initPostHogBrowser() {
|
|
1806
|
+
try {
|
|
1807
|
+
const posthogModule = await import("posthog-js");
|
|
1808
|
+
const posthog = posthogModule.default || posthogModule.posthog;
|
|
1809
|
+
if (!posthog || typeof posthog.init !== "function") {
|
|
1810
|
+
throw new Error("posthog-js module did not export expected interface");
|
|
1811
|
+
}
|
|
1812
|
+
posthog.init(this.PROJECT_API_KEY, {
|
|
1813
|
+
api_host: this.HOST,
|
|
1814
|
+
persistence: "localStorage",
|
|
1815
|
+
autocapture: false,
|
|
1816
|
+
// We only want explicit captures
|
|
1817
|
+
capture_pageview: false,
|
|
1818
|
+
// We don't want automatic pageview tracking
|
|
1819
|
+
disable_session_recording: true,
|
|
1820
|
+
// No session recording
|
|
1821
|
+
loaded: /* @__PURE__ */ __name(() => {
|
|
1822
|
+
logger.debug("PostHog browser client initialized");
|
|
1823
|
+
}, "loaded")
|
|
1824
|
+
});
|
|
1825
|
+
this._posthogBrowserClient = posthog;
|
|
1826
|
+
} catch (e) {
|
|
1827
|
+
logger.warn(`Failed to initialize PostHog browser telemetry: ${e}`);
|
|
1828
|
+
this._posthogBrowserClient = null;
|
|
1829
|
+
}
|
|
1830
|
+
}
|
|
1831
|
+
async _initPostHogNode() {
|
|
1832
|
+
try {
|
|
1833
|
+
const { PostHog } = await import("posthog-node");
|
|
1834
|
+
const isServerlessEnvironment = [
|
|
1835
|
+
"cloudflare-workers",
|
|
1836
|
+
"edge",
|
|
1837
|
+
"deno"
|
|
1838
|
+
].includes(this._runtimeEnvironment);
|
|
1839
|
+
const posthogOptions = {
|
|
1840
|
+
host: this.HOST,
|
|
1841
|
+
disableGeoip: false
|
|
1842
|
+
};
|
|
1843
|
+
if (isServerlessEnvironment) {
|
|
1844
|
+
posthogOptions.flushAt = 1;
|
|
1845
|
+
posthogOptions.flushInterval = 0;
|
|
1846
|
+
}
|
|
1847
|
+
this._posthogNodeClient = new PostHog(
|
|
1848
|
+
this.PROJECT_API_KEY,
|
|
1849
|
+
posthogOptions
|
|
1850
|
+
);
|
|
1851
|
+
logger.debug("PostHog Node.js client initialized");
|
|
1852
|
+
} catch (e) {
|
|
1853
|
+
logger.warn(`Failed to initialize PostHog Node.js telemetry: ${e}`);
|
|
1854
|
+
this._posthogNodeClient = null;
|
|
1855
|
+
}
|
|
1856
|
+
}
|
|
1798
1857
|
/**
|
|
1799
1858
|
* Get the detected runtime environment
|
|
1800
1859
|
*/
|
|
@@ -1830,10 +1889,9 @@ var Telemetry = class _Telemetry {
|
|
|
1830
1889
|
}
|
|
1831
1890
|
/**
|
|
1832
1891
|
* Check if telemetry is enabled.
|
|
1833
|
-
* Returns false if telemetry was disabled via environment variable or if not in Node.js environment.
|
|
1834
1892
|
*/
|
|
1835
1893
|
get isEnabled() {
|
|
1836
|
-
return this.
|
|
1894
|
+
return this._posthogNodeClient !== null || this._posthogBrowserClient !== null || this._scarfClient !== null;
|
|
1837
1895
|
}
|
|
1838
1896
|
get userId() {
|
|
1839
1897
|
if (this._currUserId) {
|
|
@@ -1842,10 +1900,10 @@ var Telemetry = class _Telemetry {
|
|
|
1842
1900
|
try {
|
|
1843
1901
|
switch (this._storageCapability) {
|
|
1844
1902
|
case "filesystem":
|
|
1845
|
-
this._currUserId = this.
|
|
1903
|
+
this._currUserId = this._getUserIdFromFilesystem();
|
|
1846
1904
|
break;
|
|
1847
1905
|
case "localStorage":
|
|
1848
|
-
this._currUserId = this.
|
|
1906
|
+
this._currUserId = this._getUserIdFromLocalStorage();
|
|
1849
1907
|
break;
|
|
1850
1908
|
case "session-only":
|
|
1851
1909
|
default:
|
|
@@ -1856,7 +1914,7 @@ var Telemetry = class _Telemetry {
|
|
|
1856
1914
|
break;
|
|
1857
1915
|
}
|
|
1858
1916
|
if (this._storageCapability === "filesystem" && this._currUserId) {
|
|
1859
|
-
this.
|
|
1917
|
+
this._trackPackageDownloadInternal(this._currUserId, {
|
|
1860
1918
|
triggered_by: "user_id_property"
|
|
1861
1919
|
}).catch((e) => logger.debug(`Failed to track package download: ${e}`));
|
|
1862
1920
|
}
|
|
@@ -1869,22 +1927,32 @@ var Telemetry = class _Telemetry {
|
|
|
1869
1927
|
/**
|
|
1870
1928
|
* Get or create user ID from filesystem (Node.js/Bun)
|
|
1871
1929
|
*/
|
|
1872
|
-
|
|
1873
|
-
const
|
|
1930
|
+
_getUserIdFromFilesystem() {
|
|
1931
|
+
const fs = require("fs");
|
|
1932
|
+
const os = require("os");
|
|
1933
|
+
const path = require("path");
|
|
1934
|
+
if (!this._userIdPath) {
|
|
1935
|
+
this._userIdPath = path.join(
|
|
1936
|
+
this._getCacheHome(os, path),
|
|
1937
|
+
"mcp_use_3",
|
|
1938
|
+
"telemetry_user_id"
|
|
1939
|
+
);
|
|
1940
|
+
}
|
|
1941
|
+
const isFirstTime = !fs.existsSync(this._userIdPath);
|
|
1874
1942
|
if (isFirstTime) {
|
|
1875
|
-
logger.debug(`Creating user ID path: ${this.
|
|
1876
|
-
fs.mkdirSync(path.dirname(this.
|
|
1943
|
+
logger.debug(`Creating user ID path: ${this._userIdPath}`);
|
|
1944
|
+
fs.mkdirSync(path.dirname(this._userIdPath), { recursive: true });
|
|
1877
1945
|
const newUserId = generateUUID();
|
|
1878
|
-
fs.writeFileSync(this.
|
|
1879
|
-
logger.debug(`User ID path created: ${this.
|
|
1946
|
+
fs.writeFileSync(this._userIdPath, newUserId);
|
|
1947
|
+
logger.debug(`User ID path created: ${this._userIdPath}`);
|
|
1880
1948
|
return newUserId;
|
|
1881
1949
|
}
|
|
1882
|
-
return fs.readFileSync(this.
|
|
1950
|
+
return fs.readFileSync(this._userIdPath, "utf-8").trim();
|
|
1883
1951
|
}
|
|
1884
1952
|
/**
|
|
1885
1953
|
* Get or create user ID from localStorage (Browser)
|
|
1886
1954
|
*/
|
|
1887
|
-
|
|
1955
|
+
_getUserIdFromLocalStorage() {
|
|
1888
1956
|
try {
|
|
1889
1957
|
let userId = localStorage.getItem(USER_ID_STORAGE_KEY);
|
|
1890
1958
|
if (!userId) {
|
|
@@ -1898,60 +1966,89 @@ var Telemetry = class _Telemetry {
|
|
|
1898
1966
|
return `session-${generateUUID()}`;
|
|
1899
1967
|
}
|
|
1900
1968
|
}
|
|
1969
|
+
_getCacheHome(os, path) {
|
|
1970
|
+
const envVar = process.env.XDG_CACHE_HOME;
|
|
1971
|
+
if (envVar && path.isAbsolute(envVar)) {
|
|
1972
|
+
return envVar;
|
|
1973
|
+
}
|
|
1974
|
+
const platform = process.platform;
|
|
1975
|
+
const homeDir = os.homedir();
|
|
1976
|
+
if (platform === "win32") {
|
|
1977
|
+
const appdata = process.env.LOCALAPPDATA || process.env.APPDATA;
|
|
1978
|
+
if (appdata) {
|
|
1979
|
+
return appdata;
|
|
1980
|
+
}
|
|
1981
|
+
return path.join(homeDir, "AppData", "Local");
|
|
1982
|
+
} else if (platform === "darwin") {
|
|
1983
|
+
return path.join(homeDir, "Library", "Caches");
|
|
1984
|
+
} else {
|
|
1985
|
+
return path.join(homeDir, ".cache");
|
|
1986
|
+
}
|
|
1987
|
+
}
|
|
1901
1988
|
async capture(event) {
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
if (!this.
|
|
1989
|
+
if (this._posthogLoading) {
|
|
1990
|
+
await this._posthogLoading;
|
|
1991
|
+
}
|
|
1992
|
+
if (!this._posthogNodeClient && !this._posthogBrowserClient && !this._scarfClient) {
|
|
1906
1993
|
return;
|
|
1907
1994
|
}
|
|
1908
|
-
|
|
1995
|
+
const properties = { ...event.properties };
|
|
1996
|
+
properties.mcp_use_version = getPackageVersion();
|
|
1997
|
+
properties.language = "typescript";
|
|
1998
|
+
properties.source = this._source;
|
|
1999
|
+
properties.runtime = this._runtimeEnvironment;
|
|
2000
|
+
if (this._posthogNodeClient) {
|
|
1909
2001
|
try {
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
properties.language = "typescript";
|
|
1913
|
-
properties.source = this._source;
|
|
1914
|
-
properties.runtime = this._runtimeEnvironment;
|
|
1915
|
-
logger.debug(`CAPTURE: PostHog Event ${event.name}`);
|
|
1916
|
-
logger.debug(
|
|
1917
|
-
`CAPTURE: PostHog Properties ${JSON.stringify(properties)}`
|
|
1918
|
-
);
|
|
1919
|
-
this._posthogClient.capture({
|
|
2002
|
+
logger.debug(`CAPTURE: PostHog Node Event ${event.name}`);
|
|
2003
|
+
this._posthogNodeClient.capture({
|
|
1920
2004
|
distinctId: this.userId,
|
|
1921
2005
|
event: event.name,
|
|
1922
2006
|
properties
|
|
1923
2007
|
});
|
|
1924
2008
|
} catch (e) {
|
|
1925
|
-
logger.debug(`Failed to track PostHog event ${event.name}: ${e}`);
|
|
2009
|
+
logger.debug(`Failed to track PostHog Node event ${event.name}: ${e}`);
|
|
2010
|
+
}
|
|
2011
|
+
}
|
|
2012
|
+
if (this._posthogBrowserClient) {
|
|
2013
|
+
try {
|
|
2014
|
+
logger.debug(`CAPTURE: PostHog Browser Event ${event.name}`);
|
|
2015
|
+
this._posthogBrowserClient.capture(event.name, {
|
|
2016
|
+
...properties,
|
|
2017
|
+
distinct_id: this.userId
|
|
2018
|
+
});
|
|
2019
|
+
} catch (e) {
|
|
2020
|
+
logger.debug(
|
|
2021
|
+
`Failed to track PostHog Browser event ${event.name}: ${e}`
|
|
2022
|
+
);
|
|
1926
2023
|
}
|
|
1927
2024
|
}
|
|
1928
2025
|
if (this._scarfClient) {
|
|
1929
2026
|
try {
|
|
1930
|
-
const
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
properties.runtime = this._runtimeEnvironment;
|
|
1937
|
-
await this._scarfClient.logEvent(properties);
|
|
2027
|
+
const scarfProperties = {
|
|
2028
|
+
...properties,
|
|
2029
|
+
user_id: this.userId,
|
|
2030
|
+
event: event.name
|
|
2031
|
+
};
|
|
2032
|
+
await this._scarfClient.logEvent(scarfProperties);
|
|
1938
2033
|
} catch (e) {
|
|
1939
2034
|
logger.debug(`Failed to track Scarf event ${event.name}: ${e}`);
|
|
1940
2035
|
}
|
|
1941
2036
|
}
|
|
1942
2037
|
}
|
|
2038
|
+
// ============================================================================
|
|
2039
|
+
// Package Download Tracking (Node.js only)
|
|
2040
|
+
// ============================================================================
|
|
1943
2041
|
/**
|
|
1944
2042
|
* Track package download event.
|
|
1945
2043
|
* This is a public wrapper that safely accesses userId.
|
|
1946
2044
|
*/
|
|
1947
2045
|
async trackPackageDownload(properties) {
|
|
1948
|
-
return this.
|
|
2046
|
+
return this._trackPackageDownloadInternal(this.userId, properties);
|
|
1949
2047
|
}
|
|
1950
2048
|
/**
|
|
1951
2049
|
* Internal method to track package download with explicit userId.
|
|
1952
|
-
* This avoids circular dependency when called from the userId getter.
|
|
1953
2050
|
*/
|
|
1954
|
-
async
|
|
2051
|
+
async _trackPackageDownloadInternal(userId, properties) {
|
|
1955
2052
|
if (!this._scarfClient) {
|
|
1956
2053
|
return;
|
|
1957
2054
|
}
|
|
@@ -1959,22 +2056,32 @@ var Telemetry = class _Telemetry {
|
|
|
1959
2056
|
return;
|
|
1960
2057
|
}
|
|
1961
2058
|
try {
|
|
2059
|
+
const fs = require("fs");
|
|
2060
|
+
const path = require("path");
|
|
2061
|
+
const os = require("os");
|
|
2062
|
+
if (!this._versionDownloadPath) {
|
|
2063
|
+
this._versionDownloadPath = path.join(
|
|
2064
|
+
this._getCacheHome(os, path),
|
|
2065
|
+
"mcp_use",
|
|
2066
|
+
"download_version"
|
|
2067
|
+
);
|
|
2068
|
+
}
|
|
1962
2069
|
const currentVersion = getPackageVersion();
|
|
1963
2070
|
let shouldTrack = false;
|
|
1964
2071
|
let firstDownload = false;
|
|
1965
|
-
if (!fs.existsSync(this.
|
|
2072
|
+
if (!fs.existsSync(this._versionDownloadPath)) {
|
|
1966
2073
|
shouldTrack = true;
|
|
1967
2074
|
firstDownload = true;
|
|
1968
|
-
fs.mkdirSync(path.dirname(this.
|
|
2075
|
+
fs.mkdirSync(path.dirname(this._versionDownloadPath), {
|
|
1969
2076
|
recursive: true
|
|
1970
2077
|
});
|
|
1971
|
-
fs.writeFileSync(this.
|
|
2078
|
+
fs.writeFileSync(this._versionDownloadPath, currentVersion);
|
|
1972
2079
|
} else {
|
|
1973
|
-
const savedVersion = fs.readFileSync(this.
|
|
2080
|
+
const savedVersion = fs.readFileSync(this._versionDownloadPath, "utf-8").trim();
|
|
1974
2081
|
if (currentVersion > savedVersion) {
|
|
1975
2082
|
shouldTrack = true;
|
|
1976
2083
|
firstDownload = false;
|
|
1977
|
-
fs.writeFileSync(this.
|
|
2084
|
+
fs.writeFileSync(this._versionDownloadPath, currentVersion);
|
|
1978
2085
|
}
|
|
1979
2086
|
}
|
|
1980
2087
|
if (shouldTrack) {
|
|
@@ -2008,9 +2115,6 @@ var Telemetry = class _Telemetry {
|
|
|
2008
2115
|
// ============================================================================
|
|
2009
2116
|
/**
|
|
2010
2117
|
* Track server run event directly from an MCPServer instance.
|
|
2011
|
-
* This extracts the necessary data from the server and creates the event.
|
|
2012
|
-
* @param server - The MCPServer instance (or any object conforming to MCPServerTelemetryInfo)
|
|
2013
|
-
* @param transport - The transport type (e.g., "http", "stdio", "supabase")
|
|
2014
2118
|
*/
|
|
2015
2119
|
async trackServerRunFromServer(server, transport) {
|
|
2016
2120
|
if (!this.isEnabled) return;
|
|
@@ -2056,33 +2160,125 @@ var Telemetry = class _Telemetry {
|
|
|
2056
2160
|
const event = new ConnectorInitEvent(data);
|
|
2057
2161
|
await this.capture(event);
|
|
2058
2162
|
}
|
|
2163
|
+
async trackClientAddServer(serverName, serverConfig) {
|
|
2164
|
+
if (!this.isEnabled) return;
|
|
2165
|
+
const event = new ClientAddServerEvent({ serverName, serverConfig });
|
|
2166
|
+
await this.capture(event);
|
|
2167
|
+
}
|
|
2168
|
+
async trackClientRemoveServer(serverName) {
|
|
2169
|
+
if (!this.isEnabled) return;
|
|
2170
|
+
const event = new ClientRemoveServerEvent({ serverName });
|
|
2171
|
+
await this.capture(event);
|
|
2172
|
+
}
|
|
2173
|
+
// ============================================================================
|
|
2174
|
+
// React Hook / Browser specific events
|
|
2175
|
+
// ============================================================================
|
|
2176
|
+
async trackUseMcpConnection(data) {
|
|
2177
|
+
if (!this.isEnabled) return;
|
|
2178
|
+
await this.capture({
|
|
2179
|
+
name: "usemcp_connection",
|
|
2180
|
+
properties: {
|
|
2181
|
+
url_domain: new URL(data.url).hostname,
|
|
2182
|
+
// Only domain for privacy
|
|
2183
|
+
transport_type: data.transportType,
|
|
2184
|
+
success: data.success,
|
|
2185
|
+
error_type: data.errorType ?? null,
|
|
2186
|
+
connection_time_ms: data.connectionTimeMs ?? null,
|
|
2187
|
+
has_oauth: data.hasOAuth,
|
|
2188
|
+
has_sampling: data.hasSampling,
|
|
2189
|
+
has_elicitation: data.hasElicitation
|
|
2190
|
+
}
|
|
2191
|
+
});
|
|
2192
|
+
}
|
|
2193
|
+
async trackUseMcpToolCall(data) {
|
|
2194
|
+
if (!this.isEnabled) return;
|
|
2195
|
+
await this.capture({
|
|
2196
|
+
name: "usemcp_tool_call",
|
|
2197
|
+
properties: {
|
|
2198
|
+
tool_name: data.toolName,
|
|
2199
|
+
success: data.success,
|
|
2200
|
+
error_type: data.errorType ?? null,
|
|
2201
|
+
execution_time_ms: data.executionTimeMs ?? null
|
|
2202
|
+
}
|
|
2203
|
+
});
|
|
2204
|
+
}
|
|
2205
|
+
async trackUseMcpResourceRead(data) {
|
|
2206
|
+
if (!this.isEnabled) return;
|
|
2207
|
+
await this.capture({
|
|
2208
|
+
name: "usemcp_resource_read",
|
|
2209
|
+
properties: {
|
|
2210
|
+
resource_uri_scheme: data.resourceUri.split(":")[0],
|
|
2211
|
+
// Only scheme for privacy
|
|
2212
|
+
success: data.success,
|
|
2213
|
+
error_type: data.errorType ?? null
|
|
2214
|
+
}
|
|
2215
|
+
});
|
|
2216
|
+
}
|
|
2217
|
+
// ============================================================================
|
|
2218
|
+
// Browser-specific Methods
|
|
2219
|
+
// ============================================================================
|
|
2220
|
+
/**
|
|
2221
|
+
* Identify the current user (useful for linking sessions)
|
|
2222
|
+
* Browser only - no-op in Node.js
|
|
2223
|
+
*/
|
|
2224
|
+
identify(userId, properties) {
|
|
2225
|
+
if (this._posthogBrowserClient) {
|
|
2226
|
+
try {
|
|
2227
|
+
this._posthogBrowserClient.identify(userId, properties);
|
|
2228
|
+
} catch (e) {
|
|
2229
|
+
logger.debug(`Failed to identify user: ${e}`);
|
|
2230
|
+
}
|
|
2231
|
+
}
|
|
2232
|
+
}
|
|
2233
|
+
/**
|
|
2234
|
+
* Reset the user identity (useful for logout)
|
|
2235
|
+
* Browser only - no-op in Node.js
|
|
2236
|
+
*/
|
|
2237
|
+
reset() {
|
|
2238
|
+
if (this._posthogBrowserClient) {
|
|
2239
|
+
try {
|
|
2240
|
+
this._posthogBrowserClient.reset();
|
|
2241
|
+
} catch (e) {
|
|
2242
|
+
logger.debug(`Failed to reset user: ${e}`);
|
|
2243
|
+
}
|
|
2244
|
+
}
|
|
2245
|
+
this._currUserId = null;
|
|
2246
|
+
}
|
|
2247
|
+
// ============================================================================
|
|
2248
|
+
// Node.js-specific Methods
|
|
2249
|
+
// ============================================================================
|
|
2250
|
+
/**
|
|
2251
|
+
* Flush the telemetry queue (Node.js only)
|
|
2252
|
+
*/
|
|
2059
2253
|
flush() {
|
|
2060
|
-
if (this.
|
|
2254
|
+
if (this._posthogNodeClient) {
|
|
2061
2255
|
try {
|
|
2062
|
-
this.
|
|
2256
|
+
this._posthogNodeClient.flush();
|
|
2063
2257
|
logger.debug("PostHog client telemetry queue flushed");
|
|
2064
2258
|
} catch (e) {
|
|
2065
2259
|
logger.debug(`Failed to flush PostHog client: ${e}`);
|
|
2066
2260
|
}
|
|
2067
2261
|
}
|
|
2068
|
-
if (this._scarfClient) {
|
|
2069
|
-
logger.debug("Scarf telemetry events sent immediately (no flush needed)");
|
|
2070
|
-
}
|
|
2071
2262
|
}
|
|
2263
|
+
/**
|
|
2264
|
+
* Shutdown the telemetry client (Node.js only)
|
|
2265
|
+
*/
|
|
2072
2266
|
shutdown() {
|
|
2073
|
-
if (this.
|
|
2267
|
+
if (this._posthogNodeClient) {
|
|
2074
2268
|
try {
|
|
2075
|
-
this.
|
|
2269
|
+
this._posthogNodeClient.shutdown();
|
|
2076
2270
|
logger.debug("PostHog client shutdown successfully");
|
|
2077
2271
|
} catch (e) {
|
|
2078
2272
|
logger.debug(`Error shutting down PostHog client: ${e}`);
|
|
2079
2273
|
}
|
|
2080
2274
|
}
|
|
2081
|
-
if (this._scarfClient) {
|
|
2082
|
-
logger.debug("Scarf telemetry client shutdown (no action needed)");
|
|
2083
|
-
}
|
|
2084
2275
|
}
|
|
2085
2276
|
};
|
|
2277
|
+
var Tel = Telemetry;
|
|
2278
|
+
function setTelemetrySource(source) {
|
|
2279
|
+
Tel.getInstance().setSource(source);
|
|
2280
|
+
}
|
|
2281
|
+
__name(setTelemetrySource, "setTelemetrySource");
|
|
2086
2282
|
|
|
2087
2283
|
// src/connectors/base.ts
|
|
2088
2284
|
var BaseConnector = class {
|
|
@@ -3093,6 +3289,9 @@ var WebSocketConnector = class extends BaseConnector {
|
|
|
3093
3289
|
}
|
|
3094
3290
|
};
|
|
3095
3291
|
|
|
3292
|
+
// src/client/browser.ts
|
|
3293
|
+
init_logging();
|
|
3294
|
+
|
|
3096
3295
|
// src/client/base.ts
|
|
3097
3296
|
init_logging();
|
|
3098
3297
|
|
|
@@ -3372,11 +3571,13 @@ var BaseMCPClient = class {
|
|
|
3372
3571
|
addServer(name, serverConfig) {
|
|
3373
3572
|
this.config.mcpServers = this.config.mcpServers || {};
|
|
3374
3573
|
this.config.mcpServers[name] = serverConfig;
|
|
3574
|
+
Tel.getInstance().trackClientAddServer(name, serverConfig);
|
|
3375
3575
|
}
|
|
3376
3576
|
removeServer(name) {
|
|
3377
3577
|
if (this.config.mcpServers?.[name]) {
|
|
3378
3578
|
delete this.config.mcpServers[name];
|
|
3379
3579
|
this.activeSessions = this.activeSessions.filter((n) => n !== name);
|
|
3580
|
+
Tel.getInstance().trackClientRemoveServer(name);
|
|
3380
3581
|
}
|
|
3381
3582
|
}
|
|
3382
3583
|
getServerNames() {
|
|
@@ -3484,6 +3685,25 @@ var BrowserMCPClient = class _BrowserMCPClient extends BaseMCPClient {
|
|
|
3484
3685
|
}
|
|
3485
3686
|
constructor(config) {
|
|
3486
3687
|
super(config);
|
|
3688
|
+
this._trackClientInit();
|
|
3689
|
+
}
|
|
3690
|
+
_trackClientInit() {
|
|
3691
|
+
const servers = Object.keys(this.config.mcpServers ?? {});
|
|
3692
|
+
Tel.getInstance().trackMCPClientInit({
|
|
3693
|
+
codeMode: false,
|
|
3694
|
+
// Browser client doesn't support code mode
|
|
3695
|
+
sandbox: false,
|
|
3696
|
+
// Sandbox not supported in browser
|
|
3697
|
+
allCallbacks: false,
|
|
3698
|
+
// Will be set per-server
|
|
3699
|
+
verify: false,
|
|
3700
|
+
servers,
|
|
3701
|
+
numServers: servers.length,
|
|
3702
|
+
isBrowser: true
|
|
3703
|
+
// Browser MCPClient
|
|
3704
|
+
}).catch(
|
|
3705
|
+
(e) => logger.debug(`Failed to track BrowserMCPClient init: ${e}`)
|
|
3706
|
+
);
|
|
3487
3707
|
}
|
|
3488
3708
|
static fromDict(cfg) {
|
|
3489
3709
|
return new _BrowserMCPClient(cfg);
|