mcp-use 1.10.0-canary.5 → 1.10.0-canary.7

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 (108) hide show
  1. package/dist/.tsbuildinfo +1 -1
  2. package/dist/{chunk-LTA4LQTH.js → chunk-3BBYQXEN.js} +15 -1
  3. package/dist/{chunk-YTIDS5CQ.js → chunk-5TGZJKUB.js} +5 -5
  4. package/dist/{chunk-3R5PDYIN.js → chunk-7RUUAWVB.js} +1 -1
  5. package/dist/{chunk-F5MMLHUR.js → chunk-EVWXZWIJ.js} +1 -1
  6. package/dist/{chunk-L6P6GBCW.js → chunk-GPJDNLPU.js} +15 -2
  7. package/dist/{chunk-OTYPVJTH.js → chunk-J77Z4CRV.js} +11 -401
  8. package/dist/chunk-PP653GKW.js +942 -0
  9. package/dist/{chunk-RWH7VLXH.js → chunk-QZCF4NHP.js} +29 -12
  10. package/dist/index.cjs +591 -87
  11. package/dist/index.d.ts +3 -2
  12. package/dist/index.d.ts.map +1 -1
  13. package/dist/index.js +49 -16
  14. package/dist/src/adapters/langchain_adapter.d.ts +1 -1
  15. package/dist/src/adapters/langchain_adapter.d.ts.map +1 -1
  16. package/dist/src/agents/index.cjs +2051 -1604
  17. package/dist/src/agents/index.js +4 -4
  18. package/dist/src/agents/mcp_agent.d.ts +5 -0
  19. package/dist/src/agents/mcp_agent.d.ts.map +1 -1
  20. package/dist/src/auth/browser-provider.d.ts +2 -2
  21. package/dist/src/auth/browser-provider.d.ts.map +1 -1
  22. package/dist/src/auth/index.cjs +1 -1
  23. package/dist/src/auth/index.js +1 -1
  24. package/dist/src/auth/types.d.ts +1 -1
  25. package/dist/src/auth/types.d.ts.map +1 -1
  26. package/dist/src/browser.cjs +3197 -2717
  27. package/dist/src/browser.d.ts +2 -1
  28. package/dist/src/browser.d.ts.map +1 -1
  29. package/dist/src/browser.js +10 -5
  30. package/dist/src/client/browser.d.ts +5 -0
  31. package/dist/src/client/browser.d.ts.map +1 -1
  32. package/dist/src/client/connectors/codeMode.d.ts +1 -1
  33. package/dist/src/client/connectors/codeMode.d.ts.map +1 -1
  34. package/dist/src/client/executors/base.d.ts +1 -1
  35. package/dist/src/client/executors/base.d.ts.map +1 -1
  36. package/dist/src/client/prompts.cjs +13 -4
  37. package/dist/src/client/prompts.js +3 -2
  38. package/dist/src/client.d.ts +7 -1
  39. package/dist/src/client.d.ts.map +1 -1
  40. package/dist/src/connectors/base.d.ts +22 -13
  41. package/dist/src/connectors/base.d.ts.map +1 -1
  42. package/dist/src/connectors/http.d.ts.map +1 -1
  43. package/dist/src/connectors/stdio.d.ts.map +1 -1
  44. package/dist/src/connectors/websocket.d.ts +1 -1
  45. package/dist/src/connectors/websocket.d.ts.map +1 -1
  46. package/dist/src/react/index.cjs +853 -25
  47. package/dist/src/react/index.d.ts +1 -1
  48. package/dist/src/react/index.d.ts.map +1 -1
  49. package/dist/src/react/index.js +5 -5
  50. package/dist/src/react/types.d.ts +1 -1
  51. package/dist/src/react/types.d.ts.map +1 -1
  52. package/dist/src/server/endpoints/mount-mcp.d.ts +1 -1
  53. package/dist/src/server/endpoints/mount-mcp.d.ts.map +1 -1
  54. package/dist/src/server/index.cjs +1357 -83
  55. package/dist/src/server/index.d.ts +1 -0
  56. package/dist/src/server/index.d.ts.map +1 -1
  57. package/dist/src/server/index.js +206 -57
  58. package/dist/src/server/mcp-server.d.ts +32 -7
  59. package/dist/src/server/mcp-server.d.ts.map +1 -1
  60. package/dist/src/server/prompts/conversion.d.ts +1 -1
  61. package/dist/src/server/prompts/conversion.d.ts.map +1 -1
  62. package/dist/src/server/prompts/index.d.ts +1 -1
  63. package/dist/src/server/prompts/index.d.ts.map +1 -1
  64. package/dist/src/server/resources/conversion.d.ts +1 -1
  65. package/dist/src/server/resources/conversion.d.ts.map +1 -1
  66. package/dist/src/server/resources/index.d.ts +2 -2
  67. package/dist/src/server/resources/index.d.ts.map +1 -1
  68. package/dist/src/server/resources/subscriptions.d.ts +1 -1
  69. package/dist/src/server/resources/subscriptions.d.ts.map +1 -1
  70. package/dist/src/server/sessions/session-manager.d.ts +2 -2
  71. package/dist/src/server/sessions/session-manager.d.ts.map +1 -1
  72. package/dist/src/server/tools/tool-execution-helpers.d.ts +1 -1
  73. package/dist/src/server/tools/tool-execution-helpers.d.ts.map +1 -1
  74. package/dist/src/server/tools/tool-registration.d.ts +1 -1
  75. package/dist/src/server/tools/tool-registration.d.ts.map +1 -1
  76. package/dist/src/server/types/prompt.d.ts +1 -1
  77. package/dist/src/server/types/prompt.d.ts.map +1 -1
  78. package/dist/src/server/types/resource.d.ts +1 -1
  79. package/dist/src/server/types/resource.d.ts.map +1 -1
  80. package/dist/src/server/types/tool-context.d.ts +1 -1
  81. package/dist/src/server/types/tool-context.d.ts.map +1 -1
  82. package/dist/src/server/types/tool.d.ts +1 -1
  83. package/dist/src/server/types/tool.d.ts.map +1 -1
  84. package/dist/src/server/utils/response-helpers.d.ts +1 -1
  85. package/dist/src/server/utils/response-helpers.d.ts.map +1 -1
  86. package/dist/src/server/widgets/mount-widgets-dev.d.ts.map +1 -1
  87. package/dist/src/session.d.ts +2 -2
  88. package/dist/src/session.d.ts.map +1 -1
  89. package/dist/src/task_managers/sse.d.ts +2 -2
  90. package/dist/src/task_managers/sse.d.ts.map +1 -1
  91. package/dist/src/task_managers/stdio.d.ts +2 -2
  92. package/dist/src/task_managers/stdio.d.ts.map +1 -1
  93. package/dist/src/task_managers/streamable_http.d.ts +2 -2
  94. package/dist/src/task_managers/streamable_http.d.ts.map +1 -1
  95. package/dist/src/telemetry/events.d.ts +219 -0
  96. package/dist/src/telemetry/events.d.ts.map +1 -1
  97. package/dist/src/telemetry/index.d.ts +2 -2
  98. package/dist/src/telemetry/index.d.ts.map +1 -1
  99. package/dist/src/telemetry/telemetry.d.ts +56 -1
  100. package/dist/src/telemetry/telemetry.d.ts.map +1 -1
  101. package/dist/src/telemetry/utils.d.ts +1 -1
  102. package/dist/src/telemetry/utils.d.ts.map +1 -1
  103. package/dist/src/version.d.ts +8 -0
  104. package/dist/src/version.d.ts.map +1 -0
  105. package/dist/{tool-execution-helpers-2LGVSS7L.js → tool-execution-helpers-PU3NN3NL.js} +3 -2
  106. package/dist/tsup.config.d.ts.map +1 -1
  107. package/package.json +6 -5
  108. package/dist/chunk-MTHLLDCX.js +0 -97
@@ -1,3 +1,6 @@
1
+ import {
2
+ Telemetry
3
+ } from "./chunk-PP653GKW.js";
1
4
  import {
2
5
  logger
3
6
  } from "./chunk-34R6SIER.js";
@@ -10,7 +13,7 @@ import {
10
13
  ListRootsRequestSchema,
11
14
  CreateMessageRequestSchema,
12
15
  ElicitRequestSchema
13
- } from "@modelcontextprotocol/sdk/types.js";
16
+ } from "@mcp-use/modelcontextprotocol-sdk/types.js";
14
17
  var BaseConnector = class {
15
18
  static {
16
19
  __name(this, "BaseConnector");
@@ -30,6 +33,17 @@ var BaseConnector = class {
30
33
  this.rootsCache = [...opts.roots];
31
34
  }
32
35
  }
36
+ /**
37
+ * Track connector initialization event
38
+ * Should be called by subclasses after successful connection
39
+ */
40
+ trackConnectorInit(data) {
41
+ const connectorType = this.constructor.name;
42
+ Telemetry.getInstance().trackConnectorInit({
43
+ connectorType,
44
+ ...data
45
+ }).catch((e) => logger.debug(`Failed to track connector init: ${e}`));
46
+ }
33
47
  /**
34
48
  * Register a handler for server notifications
35
49
  *
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  BrowserMCPClient
3
- } from "./chunk-RWH7VLXH.js";
3
+ } from "./chunk-QZCF4NHP.js";
4
4
  import {
5
5
  BrowserOAuthClientProvider,
6
6
  sanitizeUrl
7
- } from "./chunk-3R5PDYIN.js";
7
+ } from "./chunk-7RUUAWVB.js";
8
8
  import {
9
9
  __name
10
10
  } from "./chunk-3GQAWCBQ.js";
@@ -269,7 +269,7 @@ function useMcp(options) {
269
269
  "Authentication required. OAuth provider available."
270
270
  );
271
271
  try {
272
- const { auth } = await import("@modelcontextprotocol/sdk/client/auth.js");
272
+ const { auth } = await import("@mcp-use/modelcontextprotocol-sdk/client/auth.js");
273
273
  const baseUrl = new URL(url).origin;
274
274
  auth(authProviderRef.current, { serverUrl: baseUrl }).catch(
275
275
  () => {
@@ -437,7 +437,7 @@ function useMcp(options) {
437
437
  });
438
438
  authProviderRef.current = freshAuthProvider;
439
439
  addLog("info", "Triggering fresh OAuth authorization...");
440
- const { auth } = await import("@modelcontextprotocol/sdk/client/auth.js");
440
+ const { auth } = await import("@mcp-use/modelcontextprotocol-sdk/client/auth.js");
441
441
  const baseUrl = new URL(url).origin;
442
442
  auth(freshAuthProvider, {
443
443
  serverUrl: baseUrl
@@ -445,7 +445,7 @@ function useMcp(options) {
445
445
  addLog(
446
446
  "info",
447
447
  "OAuth flow initiated:",
448
- err?.message || "Redirecting..."
448
+ err instanceof Error ? err.message : "Redirecting..."
449
449
  );
450
450
  });
451
451
  } catch (authError) {
@@ -261,7 +261,7 @@ var BrowserOAuthClientProvider = class {
261
261
  };
262
262
 
263
263
  // src/auth/callback.ts
264
- import { auth } from "@modelcontextprotocol/sdk/client/auth.js";
264
+ import { auth } from "@mcp-use/modelcontextprotocol-sdk/client/auth.js";
265
265
  async function onMcpAuthorization() {
266
266
  const queryParams = new URLSearchParams(window.location.search);
267
267
  const code = queryParams.get("code");
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  BaseConnector
3
- } from "./chunk-LTA4LQTH.js";
3
+ } from "./chunk-3BBYQXEN.js";
4
4
  import {
5
5
  __name
6
6
  } from "./chunk-3GQAWCBQ.js";
@@ -2,14 +2,15 @@ import {
2
2
  ElicitationValidationError
3
3
  } from "./chunk-KUEVOU4M.js";
4
4
  import {
5
+ Telemetry,
5
6
  generateUUID
6
- } from "./chunk-MTHLLDCX.js";
7
+ } from "./chunk-PP653GKW.js";
7
8
  import {
8
9
  __name
9
10
  } from "./chunk-3GQAWCBQ.js";
10
11
 
11
12
  // src/server/tools/tool-execution-helpers.ts
12
- import { toJsonSchemaCompat } from "@modelcontextprotocol/sdk/server/zod-json-schema-compat.js";
13
+ import { toJsonSchemaCompat } from "@mcp-use/modelcontextprotocol-sdk/server/zod-json-schema-compat.js";
13
14
  function findSessionContext(sessions, initialRequestContext, extraProgressToken, extraSendNotification) {
14
15
  let requestContext = initialRequestContext;
15
16
  let session;
@@ -196,6 +197,9 @@ function createSampleMethod(createMessage, progressToken, sendNotification) {
196
197
  `Sampling timed out after ${timeout}ms`
197
198
  );
198
199
  console.log("[SAMPLING DEBUG] Got result:", result);
200
+ Telemetry.getInstance().trackServerContext({
201
+ contextType: "sample"
202
+ }).catch((e) => console.debug(`Failed to track sample context: ${e}`));
199
203
  return result;
200
204
  } catch (error) {
201
205
  console.error("[SAMPLING DEBUG] Error during sampling:", error);
@@ -219,6 +223,9 @@ function createElicitMethod(elicitInput) {
219
223
  const { timeout } = options ?? {};
220
224
  const sdkTimeout = timeout && timeout !== Infinity ? timeout : 2147483647;
221
225
  const result = await elicitInput(sdkParams, { timeout: sdkTimeout });
226
+ Telemetry.getInstance().trackServerContext({
227
+ contextType: "elicit"
228
+ }).catch((e) => console.debug(`Failed to track elicit context: ${e}`));
222
229
  if (zodSchema && result.action === "accept" && result.data) {
223
230
  try {
224
231
  const validatedData = zodSchema.parse(result.data);
@@ -303,6 +310,12 @@ function createLogMethod(sendNotification, minLogLevel) {
303
310
  logger: logger || "tool"
304
311
  }
305
312
  });
313
+ Telemetry.getInstance().trackServerContext({
314
+ contextType: "notification",
315
+ notificationType: "message"
316
+ }).catch(
317
+ (e) => console.debug(`Failed to track notification context: ${e}`)
318
+ );
306
319
  };
307
320
  }
308
321
  __name(createLogMethod, "createLogMethod");
@@ -1,6 +1,8 @@
1
1
  import {
2
- generateUUID
3
- } from "./chunk-MTHLLDCX.js";
2
+ Telemetry,
3
+ extractModelInfo,
4
+ getPackageVersion
5
+ } from "./chunk-PP653GKW.js";
4
6
  import {
5
7
  logger
6
8
  } from "./chunk-34R6SIER.js";
@@ -1400,403 +1402,6 @@ var ObservabilityManager = class {
1400
1402
  }
1401
1403
  };
1402
1404
 
1403
- // src/telemetry/telemetry.ts
1404
- import * as fs2 from "fs";
1405
- import * as os from "os";
1406
- import * as path2 from "path";
1407
- import { PostHog } from "posthog-node";
1408
-
1409
- // src/telemetry/events.ts
1410
- var BaseTelemetryEvent = class {
1411
- static {
1412
- __name(this, "BaseTelemetryEvent");
1413
- }
1414
- };
1415
- var MCPAgentExecutionEvent = class extends BaseTelemetryEvent {
1416
- constructor(data) {
1417
- super();
1418
- this.data = data;
1419
- }
1420
- static {
1421
- __name(this, "MCPAgentExecutionEvent");
1422
- }
1423
- get name() {
1424
- return "mcp_agent_execution";
1425
- }
1426
- get properties() {
1427
- return {
1428
- // Core execution info
1429
- execution_method: this.data.executionMethod,
1430
- query: this.data.query,
1431
- query_length: this.data.query.length,
1432
- success: this.data.success,
1433
- // Agent configuration
1434
- model_provider: this.data.modelProvider,
1435
- model_name: this.data.modelName,
1436
- server_count: this.data.serverCount,
1437
- server_identifiers: this.data.serverIdentifiers,
1438
- total_tools_available: this.data.totalToolsAvailable,
1439
- tools_available_names: this.data.toolsAvailableNames,
1440
- max_steps_configured: this.data.maxStepsConfigured,
1441
- memory_enabled: this.data.memoryEnabled,
1442
- use_server_manager: this.data.useServerManager,
1443
- // Execution parameters (always include, even if null)
1444
- max_steps_used: this.data.maxStepsUsed,
1445
- manage_connector: this.data.manageConnector,
1446
- external_history_used: this.data.externalHistoryUsed,
1447
- // Execution results (always include, even if null)
1448
- steps_taken: this.data.stepsTaken ?? null,
1449
- tools_used_count: this.data.toolsUsedCount ?? null,
1450
- tools_used_names: this.data.toolsUsedNames ?? null,
1451
- response: this.data.response ?? null,
1452
- response_length: this.data.response ? this.data.response.length : null,
1453
- execution_time_ms: this.data.executionTimeMs ?? null,
1454
- error_type: this.data.errorType ?? null,
1455
- conversation_history_length: this.data.conversationHistoryLength ?? null
1456
- };
1457
- }
1458
- };
1459
-
1460
- // src/telemetry/utils.ts
1461
- import * as fs from "fs";
1462
- import * as path from "path";
1463
- function getPackageVersion() {
1464
- try {
1465
- if (typeof __dirname === "undefined" || typeof fs === "undefined") {
1466
- return "unknown";
1467
- }
1468
- const packagePath = path.join(__dirname, "../../package.json");
1469
- const packageJson = JSON.parse(fs.readFileSync(packagePath, "utf-8"));
1470
- return packageJson.version || "unknown";
1471
- } catch {
1472
- return "unknown";
1473
- }
1474
- }
1475
- __name(getPackageVersion, "getPackageVersion");
1476
- function getModelProvider(llm) {
1477
- return llm._llm_type || llm.constructor.name.toLowerCase();
1478
- }
1479
- __name(getModelProvider, "getModelProvider");
1480
- function getModelName(llm) {
1481
- if ("_identifyingParams" in llm) {
1482
- const identifyingParams = llm._identifyingParams;
1483
- if (typeof identifyingParams === "object" && identifyingParams !== null) {
1484
- for (const key of [
1485
- "model",
1486
- "modelName",
1487
- "model_name",
1488
- "modelId",
1489
- "model_id",
1490
- "deploymentName",
1491
- "deployment_name"
1492
- ]) {
1493
- if (key in identifyingParams) {
1494
- return String(identifyingParams[key]);
1495
- }
1496
- }
1497
- }
1498
- }
1499
- return llm.model || llm.modelName || llm.constructor.name;
1500
- }
1501
- __name(getModelName, "getModelName");
1502
- function extractModelInfo(llm) {
1503
- return [getModelProvider(llm), getModelName(llm)];
1504
- }
1505
- __name(extractModelInfo, "extractModelInfo");
1506
-
1507
- // src/telemetry/telemetry.ts
1508
- function isNodeJSEnvironment() {
1509
- try {
1510
- if (typeof navigator !== "undefined" && navigator.userAgent?.includes("Cloudflare-Workers")) {
1511
- return false;
1512
- }
1513
- if (typeof globalThis.EdgeRuntime !== "undefined" || typeof globalThis.Deno !== "undefined") {
1514
- return false;
1515
- }
1516
- const hasNodeGlobals = typeof process !== "undefined" && typeof process.platform !== "undefined" && typeof __dirname !== "undefined";
1517
- const hasNodeModules = typeof fs2 !== "undefined" && typeof os !== "undefined" && typeof fs2.existsSync === "function";
1518
- return hasNodeGlobals && hasNodeModules;
1519
- } catch {
1520
- return false;
1521
- }
1522
- }
1523
- __name(isNodeJSEnvironment, "isNodeJSEnvironment");
1524
- var ScarfEventLogger = class {
1525
- static {
1526
- __name(this, "ScarfEventLogger");
1527
- }
1528
- endpoint;
1529
- timeout;
1530
- constructor(endpoint, timeout = 3e3) {
1531
- this.endpoint = endpoint;
1532
- this.timeout = timeout;
1533
- }
1534
- async logEvent(properties) {
1535
- try {
1536
- const controller = new AbortController();
1537
- const timeoutId = setTimeout(() => controller.abort(), this.timeout);
1538
- const response = await fetch(this.endpoint, {
1539
- method: "POST",
1540
- headers: {
1541
- "Content-Type": "application/json"
1542
- },
1543
- body: JSON.stringify(properties),
1544
- signal: controller.signal
1545
- });
1546
- clearTimeout(timeoutId);
1547
- if (!response.ok) {
1548
- throw new Error(`HTTP error! status: ${response.status}`);
1549
- }
1550
- } catch (error) {
1551
- logger.debug(`Failed to send Scarf event: ${error}`);
1552
- }
1553
- }
1554
- };
1555
- function getCacheHome() {
1556
- if (!isNodeJSEnvironment()) {
1557
- return "/tmp/mcp_use_cache";
1558
- }
1559
- const envVar = process.env.XDG_CACHE_HOME;
1560
- if (envVar && path2.isAbsolute(envVar)) {
1561
- return envVar;
1562
- }
1563
- const platform = process.platform;
1564
- const homeDir = os.homedir();
1565
- if (platform === "win32") {
1566
- const appdata = process.env.LOCALAPPDATA || process.env.APPDATA;
1567
- if (appdata) {
1568
- return appdata;
1569
- }
1570
- return path2.join(homeDir, "AppData", "Local");
1571
- } else if (platform === "darwin") {
1572
- return path2.join(homeDir, "Library", "Caches");
1573
- } else {
1574
- return path2.join(homeDir, ".cache");
1575
- }
1576
- }
1577
- __name(getCacheHome, "getCacheHome");
1578
- var Telemetry = class _Telemetry {
1579
- static {
1580
- __name(this, "Telemetry");
1581
- }
1582
- static instance = null;
1583
- USER_ID_PATH = path2.join(
1584
- getCacheHome(),
1585
- "mcp_use_3",
1586
- "telemetry_user_id"
1587
- );
1588
- VERSION_DOWNLOAD_PATH = path2.join(
1589
- getCacheHome(),
1590
- "mcp_use",
1591
- "download_version"
1592
- );
1593
- PROJECT_API_KEY = "phc_lyTtbYwvkdSbrcMQNPiKiiRWrrM1seyKIMjycSvItEI";
1594
- HOST = "https://eu.i.posthog.com";
1595
- SCARF_GATEWAY_URL = "https://mcpuse.gateway.scarf.sh/events-ts";
1596
- UNKNOWN_USER_ID = "UNKNOWN_USER_ID";
1597
- _currUserId = null;
1598
- _posthogClient = null;
1599
- _scarfClient = null;
1600
- _source = "typescript";
1601
- constructor() {
1602
- const isNodeJS = isNodeJSEnvironment();
1603
- const telemetryDisabled = typeof process !== "undefined" && process.env?.MCP_USE_ANONYMIZED_TELEMETRY?.toLowerCase() === "false" || false;
1604
- this._source = typeof process !== "undefined" && process.env?.MCP_USE_TELEMETRY_SOURCE || "typescript";
1605
- if (telemetryDisabled) {
1606
- this._posthogClient = null;
1607
- this._scarfClient = null;
1608
- logger.debug("Telemetry disabled via environment variable");
1609
- } else if (!isNodeJS) {
1610
- this._posthogClient = null;
1611
- this._scarfClient = null;
1612
- logger.debug(
1613
- "Telemetry disabled - non-Node.js environment detected (e.g., Cloudflare Workers)"
1614
- );
1615
- } else {
1616
- logger.info(
1617
- "Anonymized telemetry enabled. Set MCP_USE_ANONYMIZED_TELEMETRY=false to disable."
1618
- );
1619
- try {
1620
- this._posthogClient = new PostHog(this.PROJECT_API_KEY, {
1621
- host: this.HOST,
1622
- disableGeoip: false
1623
- });
1624
- } catch (e) {
1625
- logger.warn(`Failed to initialize PostHog telemetry: ${e}`);
1626
- this._posthogClient = null;
1627
- }
1628
- try {
1629
- this._scarfClient = new ScarfEventLogger(this.SCARF_GATEWAY_URL, 3e3);
1630
- } catch (e) {
1631
- logger.warn(`Failed to initialize Scarf telemetry: ${e}`);
1632
- this._scarfClient = null;
1633
- }
1634
- }
1635
- }
1636
- static getInstance() {
1637
- if (!_Telemetry.instance) {
1638
- _Telemetry.instance = new _Telemetry();
1639
- }
1640
- return _Telemetry.instance;
1641
- }
1642
- /**
1643
- * Set the source identifier for telemetry events.
1644
- * This allows tracking usage from different applications.
1645
- * @param source - The source identifier (e.g., "my-app", "cli", "vs-code-extension")
1646
- */
1647
- setSource(source) {
1648
- this._source = source;
1649
- logger.debug(`Telemetry source set to: ${source}`);
1650
- }
1651
- /**
1652
- * Get the current source identifier.
1653
- */
1654
- getSource() {
1655
- return this._source;
1656
- }
1657
- get userId() {
1658
- if (this._currUserId) {
1659
- return this._currUserId;
1660
- }
1661
- if (!isNodeJSEnvironment()) {
1662
- this._currUserId = this.UNKNOWN_USER_ID;
1663
- return this._currUserId;
1664
- }
1665
- try {
1666
- const isFirstTime = !fs2.existsSync(this.USER_ID_PATH);
1667
- if (isFirstTime) {
1668
- logger.debug(`Creating user ID path: ${this.USER_ID_PATH}`);
1669
- fs2.mkdirSync(path2.dirname(this.USER_ID_PATH), { recursive: true });
1670
- const newUserId = generateUUID();
1671
- fs2.writeFileSync(this.USER_ID_PATH, newUserId);
1672
- this._currUserId = newUserId;
1673
- logger.debug(`User ID path created: ${this.USER_ID_PATH}`);
1674
- } else {
1675
- this._currUserId = fs2.readFileSync(this.USER_ID_PATH, "utf-8").trim();
1676
- }
1677
- this.trackPackageDownload({
1678
- triggered_by: "user_id_property"
1679
- }).catch((e) => logger.debug(`Failed to track package download: ${e}`));
1680
- } catch (e) {
1681
- logger.debug(`Failed to get/create user ID: ${e}`);
1682
- this._currUserId = this.UNKNOWN_USER_ID;
1683
- }
1684
- return this._currUserId;
1685
- }
1686
- async capture(event) {
1687
- if (!this._posthogClient && !this._scarfClient) {
1688
- return;
1689
- }
1690
- if (this._posthogClient) {
1691
- try {
1692
- const properties = { ...event.properties };
1693
- properties.mcp_use_version = getPackageVersion();
1694
- properties.language = "typescript";
1695
- properties.source = this._source;
1696
- this._posthogClient.capture({
1697
- distinctId: this.userId,
1698
- event: event.name,
1699
- properties
1700
- });
1701
- } catch (e) {
1702
- logger.debug(`Failed to track PostHog event ${event.name}: ${e}`);
1703
- }
1704
- }
1705
- if (this._scarfClient) {
1706
- try {
1707
- const properties = {};
1708
- properties.mcp_use_version = getPackageVersion();
1709
- properties.user_id = this.userId;
1710
- properties.event = event.name;
1711
- properties.language = "typescript";
1712
- properties.source = this._source;
1713
- await this._scarfClient.logEvent(properties);
1714
- } catch (e) {
1715
- logger.debug(`Failed to track Scarf event ${event.name}: ${e}`);
1716
- }
1717
- }
1718
- }
1719
- async trackPackageDownload(properties) {
1720
- if (!this._scarfClient) {
1721
- return;
1722
- }
1723
- if (!isNodeJSEnvironment()) {
1724
- return;
1725
- }
1726
- try {
1727
- const currentVersion = getPackageVersion();
1728
- let shouldTrack = false;
1729
- let firstDownload = false;
1730
- if (!fs2.existsSync(this.VERSION_DOWNLOAD_PATH)) {
1731
- shouldTrack = true;
1732
- firstDownload = true;
1733
- fs2.mkdirSync(path2.dirname(this.VERSION_DOWNLOAD_PATH), {
1734
- recursive: true
1735
- });
1736
- fs2.writeFileSync(this.VERSION_DOWNLOAD_PATH, currentVersion);
1737
- } else {
1738
- const savedVersion = fs2.readFileSync(this.VERSION_DOWNLOAD_PATH, "utf-8").trim();
1739
- if (currentVersion > savedVersion) {
1740
- shouldTrack = true;
1741
- firstDownload = false;
1742
- fs2.writeFileSync(this.VERSION_DOWNLOAD_PATH, currentVersion);
1743
- }
1744
- }
1745
- if (shouldTrack) {
1746
- logger.debug(
1747
- `Tracking package download event with properties: ${JSON.stringify(properties)}`
1748
- );
1749
- const eventProperties = { ...properties || {} };
1750
- eventProperties.mcp_use_version = currentVersion;
1751
- eventProperties.user_id = this.userId;
1752
- eventProperties.event = "package_download";
1753
- eventProperties.first_download = firstDownload;
1754
- eventProperties.language = "typescript";
1755
- eventProperties.source = this._source;
1756
- await this._scarfClient.logEvent(eventProperties);
1757
- }
1758
- } catch (e) {
1759
- logger.debug(`Failed to track Scarf package_download event: ${e}`);
1760
- }
1761
- }
1762
- async trackAgentExecution(data) {
1763
- const event = new MCPAgentExecutionEvent(data);
1764
- await this.capture(event);
1765
- }
1766
- flush() {
1767
- if (this._posthogClient) {
1768
- try {
1769
- this._posthogClient.flush();
1770
- logger.debug("PostHog client telemetry queue flushed");
1771
- } catch (e) {
1772
- logger.debug(`Failed to flush PostHog client: ${e}`);
1773
- }
1774
- }
1775
- if (this._scarfClient) {
1776
- logger.debug("Scarf telemetry events sent immediately (no flush needed)");
1777
- }
1778
- }
1779
- shutdown() {
1780
- if (this._posthogClient) {
1781
- try {
1782
- this._posthogClient.shutdown();
1783
- logger.debug("PostHog client shutdown successfully");
1784
- } catch (e) {
1785
- logger.debug(`Error shutting down PostHog client: ${e}`);
1786
- }
1787
- }
1788
- if (this._scarfClient) {
1789
- logger.debug("Scarf telemetry client shutdown (no action needed)");
1790
- }
1791
- }
1792
- };
1793
-
1794
- // src/telemetry/index.ts
1795
- function setTelemetrySource(source) {
1796
- Telemetry.getInstance().setSource(source);
1797
- }
1798
- __name(setTelemetrySource, "setTelemetrySource");
1799
-
1800
1405
  // src/agents/remote.ts
1801
1406
  import { toJSONSchema } from "zod";
1802
1407
  var API_CHATS_ENDPOINT = "/api/v1/chats";
@@ -2134,6 +1739,13 @@ var MCPAgent = class {
2134
1739
  static {
2135
1740
  __name(this, "MCPAgent");
2136
1741
  }
1742
+ /**
1743
+ * Get the mcp-use package version.
1744
+ * Works in all environments (Node.js, browser, Cloudflare Workers, Deno, etc.)
1745
+ */
1746
+ static getPackageVersion() {
1747
+ return getPackageVersion();
1748
+ }
2137
1749
  llm;
2138
1750
  client;
2139
1751
  connectors;
@@ -3547,8 +3159,6 @@ export {
3547
3159
  ReleaseMCPServerConnectionTool,
3548
3160
  ServerManager,
3549
3161
  ObservabilityManager,
3550
- Telemetry,
3551
- setTelemetrySource,
3552
3162
  RemoteAgent,
3553
3163
  MCPAgent
3554
3164
  };