mcp-use 1.10.0-canary.6 → 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.
- package/dist/.tsbuildinfo +1 -1
- package/dist/{chunk-XU3C6BYJ.js → chunk-3BBYQXEN.js} +14 -0
- package/dist/{chunk-464BT6EX.js → chunk-5TGZJKUB.js} +1 -1
- package/dist/{chunk-7AZ4YFTN.js → chunk-EVWXZWIJ.js} +1 -1
- package/dist/{chunk-FWN7BKNM.js → chunk-GPJDNLPU.js} +14 -1
- package/dist/{chunk-YMJL66MY.js → chunk-J77Z4CRV.js} +12 -402
- package/dist/chunk-PP653GKW.js +942 -0
- package/dist/{chunk-T4B7QDPT.js → chunk-QZCF4NHP.js} +20 -4
- package/dist/index.cjs +575 -72
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +46 -13
- package/dist/src/agents/index.cjs +2050 -1603
- package/dist/src/agents/index.js +4 -4
- package/dist/src/agents/mcp_agent.d.ts +5 -0
- package/dist/src/agents/mcp_agent.d.ts.map +1 -1
- package/dist/src/browser.cjs +3189 -2710
- package/dist/src/browser.d.ts +1 -0
- package/dist/src/browser.d.ts.map +1 -1
- package/dist/src/browser.js +9 -4
- package/dist/src/client/browser.d.ts +5 -0
- package/dist/src/client/browser.d.ts.map +1 -1
- package/dist/src/client/prompts.cjs +12 -3
- package/dist/src/client/prompts.js +3 -2
- package/dist/src/client.d.ts +6 -0
- package/dist/src/client.d.ts.map +1 -1
- package/dist/src/connectors/base.d.ts +20 -10
- package/dist/src/connectors/base.d.ts.map +1 -1
- package/dist/src/connectors/http.d.ts.map +1 -1
- package/dist/src/connectors/stdio.d.ts.map +1 -1
- package/dist/src/react/index.cjs +839 -12
- package/dist/src/react/index.js +4 -4
- package/dist/src/server/endpoints/mount-mcp.d.ts.map +1 -1
- package/dist/src/server/index.cjs +1352 -78
- package/dist/src/server/index.d.ts +1 -0
- package/dist/src/server/index.d.ts.map +1 -1
- package/dist/src/server/index.js +199 -53
- package/dist/src/server/mcp-server.d.ts +31 -6
- package/dist/src/server/mcp-server.d.ts.map +1 -1
- package/dist/src/server/tools/tool-execution-helpers.d.ts.map +1 -1
- package/dist/src/server/widgets/mount-widgets-dev.d.ts.map +1 -1
- package/dist/src/telemetry/events.d.ts +219 -0
- package/dist/src/telemetry/events.d.ts.map +1 -1
- package/dist/src/telemetry/index.d.ts +2 -2
- package/dist/src/telemetry/index.d.ts.map +1 -1
- package/dist/src/telemetry/telemetry.d.ts +56 -1
- package/dist/src/telemetry/telemetry.d.ts.map +1 -1
- package/dist/src/telemetry/utils.d.ts +1 -1
- package/dist/src/telemetry/utils.d.ts.map +1 -1
- package/dist/src/version.d.ts +8 -0
- package/dist/src/version.d.ts.map +1 -0
- package/dist/{tool-execution-helpers-M5RO4YO2.js → tool-execution-helpers-PU3NN3NL.js} +3 -2
- package/package.json +5 -4
- 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";
|
|
@@ -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
|
*
|
|
@@ -2,8 +2,9 @@ import {
|
|
|
2
2
|
ElicitationValidationError
|
|
3
3
|
} from "./chunk-KUEVOU4M.js";
|
|
4
4
|
import {
|
|
5
|
+
Telemetry,
|
|
5
6
|
generateUUID
|
|
6
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-PP653GKW.js";
|
|
7
8
|
import {
|
|
8
9
|
__name
|
|
9
10
|
} from "./chunk-3GQAWCBQ.js";
|
|
@@ -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,9 +1,11 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Telemetry,
|
|
3
|
+
extractModelInfo,
|
|
4
|
+
getPackageVersion
|
|
5
|
+
} from "./chunk-PP653GKW.js";
|
|
1
6
|
import {
|
|
2
7
|
logger
|
|
3
8
|
} from "./chunk-34R6SIER.js";
|
|
4
|
-
import {
|
|
5
|
-
generateUUID
|
|
6
|
-
} from "./chunk-MTHLLDCX.js";
|
|
7
9
|
import {
|
|
8
10
|
__name
|
|
9
11
|
} from "./chunk-3GQAWCBQ.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
|
};
|