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
|
@@ -2,7 +2,8 @@ import {
|
|
|
2
2
|
logger
|
|
3
3
|
} from "./chunk-34R6SIER.js";
|
|
4
4
|
import {
|
|
5
|
-
__name
|
|
5
|
+
__name,
|
|
6
|
+
__require
|
|
6
7
|
} from "./chunk-3GQAWCBQ.js";
|
|
7
8
|
|
|
8
9
|
// src/server/utils/runtime.ts
|
|
@@ -22,48 +23,48 @@ function getCwd() {
|
|
|
22
23
|
}
|
|
23
24
|
__name(getCwd, "getCwd");
|
|
24
25
|
var fsHelpers = {
|
|
25
|
-
async readFileSync(
|
|
26
|
+
async readFileSync(path, encoding = "utf8") {
|
|
26
27
|
if (isDeno) {
|
|
27
|
-
return await globalThis.Deno.readTextFile(
|
|
28
|
+
return await globalThis.Deno.readTextFile(path);
|
|
28
29
|
}
|
|
29
|
-
const { readFileSync
|
|
30
|
-
const result =
|
|
30
|
+
const { readFileSync } = await import("fs");
|
|
31
|
+
const result = readFileSync(path, encoding);
|
|
31
32
|
return typeof result === "string" ? result : result.toString(encoding);
|
|
32
33
|
},
|
|
33
|
-
async readFile(
|
|
34
|
+
async readFile(path) {
|
|
34
35
|
if (isDeno) {
|
|
35
|
-
const data = await globalThis.Deno.readFile(
|
|
36
|
+
const data = await globalThis.Deno.readFile(path);
|
|
36
37
|
return data.buffer;
|
|
37
38
|
}
|
|
38
|
-
const { readFileSync
|
|
39
|
-
const buffer =
|
|
39
|
+
const { readFileSync } = await import("fs");
|
|
40
|
+
const buffer = readFileSync(path);
|
|
40
41
|
return buffer.buffer.slice(
|
|
41
42
|
buffer.byteOffset,
|
|
42
43
|
buffer.byteOffset + buffer.byteLength
|
|
43
44
|
);
|
|
44
45
|
},
|
|
45
|
-
async existsSync(
|
|
46
|
+
async existsSync(path) {
|
|
46
47
|
if (isDeno) {
|
|
47
48
|
try {
|
|
48
|
-
await globalThis.Deno.stat(
|
|
49
|
+
await globalThis.Deno.stat(path);
|
|
49
50
|
return true;
|
|
50
51
|
} catch {
|
|
51
52
|
return false;
|
|
52
53
|
}
|
|
53
54
|
}
|
|
54
|
-
const { existsSync
|
|
55
|
-
return
|
|
55
|
+
const { existsSync } = await import("fs");
|
|
56
|
+
return existsSync(path);
|
|
56
57
|
},
|
|
57
|
-
async readdirSync(
|
|
58
|
+
async readdirSync(path) {
|
|
58
59
|
if (isDeno) {
|
|
59
60
|
const entries = [];
|
|
60
|
-
for await (const entry of globalThis.Deno.readDir(
|
|
61
|
+
for await (const entry of globalThis.Deno.readDir(path)) {
|
|
61
62
|
entries.push(entry.name);
|
|
62
63
|
}
|
|
63
64
|
return entries;
|
|
64
65
|
}
|
|
65
66
|
const { readdirSync } = await import("fs");
|
|
66
|
-
return readdirSync(
|
|
67
|
+
return readdirSync(path);
|
|
67
68
|
}
|
|
68
69
|
};
|
|
69
70
|
var pathHelpers = {
|
|
@@ -91,18 +92,12 @@ function generateUUID() {
|
|
|
91
92
|
__name(generateUUID, "generateUUID");
|
|
92
93
|
|
|
93
94
|
// src/version.ts
|
|
94
|
-
var VERSION = "1.10.0
|
|
95
|
+
var VERSION = "1.10.0";
|
|
95
96
|
function getPackageVersion() {
|
|
96
97
|
return VERSION;
|
|
97
98
|
}
|
|
98
99
|
__name(getPackageVersion, "getPackageVersion");
|
|
99
100
|
|
|
100
|
-
// src/telemetry/telemetry.ts
|
|
101
|
-
import * as fs from "fs";
|
|
102
|
-
import * as os from "os";
|
|
103
|
-
import * as path from "path";
|
|
104
|
-
import { PostHog } from "posthog-node";
|
|
105
|
-
|
|
106
101
|
// src/telemetry/events.ts
|
|
107
102
|
var BaseTelemetryEvent = class {
|
|
108
103
|
static {
|
|
@@ -378,7 +373,8 @@ var MCPClientInitEvent = class extends BaseTelemetryEvent {
|
|
|
378
373
|
all_callbacks: this.data.allCallbacks,
|
|
379
374
|
verify: this.data.verify,
|
|
380
375
|
servers: this.data.servers,
|
|
381
|
-
num_servers: this.data.numServers
|
|
376
|
+
num_servers: this.data.numServers,
|
|
377
|
+
is_browser: this.data.isBrowser
|
|
382
378
|
};
|
|
383
379
|
}
|
|
384
380
|
};
|
|
@@ -403,6 +399,52 @@ var ConnectorInitEvent = class extends BaseTelemetryEvent {
|
|
|
403
399
|
};
|
|
404
400
|
}
|
|
405
401
|
};
|
|
402
|
+
var ClientAddServerEvent = class extends BaseTelemetryEvent {
|
|
403
|
+
constructor(data) {
|
|
404
|
+
super();
|
|
405
|
+
this.data = data;
|
|
406
|
+
}
|
|
407
|
+
static {
|
|
408
|
+
__name(this, "ClientAddServerEvent");
|
|
409
|
+
}
|
|
410
|
+
get name() {
|
|
411
|
+
return "client_add_server";
|
|
412
|
+
}
|
|
413
|
+
get properties() {
|
|
414
|
+
const { serverName, serverConfig } = this.data;
|
|
415
|
+
const url = serverConfig.url;
|
|
416
|
+
return {
|
|
417
|
+
server_name: serverName,
|
|
418
|
+
server_url_domain: url ? this._extractHostname(url) : null,
|
|
419
|
+
transport: serverConfig.transport ?? null,
|
|
420
|
+
has_auth: !!(serverConfig.authToken || serverConfig.authProvider)
|
|
421
|
+
};
|
|
422
|
+
}
|
|
423
|
+
_extractHostname(url) {
|
|
424
|
+
try {
|
|
425
|
+
return new URL(url).hostname;
|
|
426
|
+
} catch {
|
|
427
|
+
return null;
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
};
|
|
431
|
+
var ClientRemoveServerEvent = class extends BaseTelemetryEvent {
|
|
432
|
+
constructor(data) {
|
|
433
|
+
super();
|
|
434
|
+
this.data = data;
|
|
435
|
+
}
|
|
436
|
+
static {
|
|
437
|
+
__name(this, "ClientRemoveServerEvent");
|
|
438
|
+
}
|
|
439
|
+
get name() {
|
|
440
|
+
return "client_remove_server";
|
|
441
|
+
}
|
|
442
|
+
get properties() {
|
|
443
|
+
return {
|
|
444
|
+
server_name: this.data.serverName
|
|
445
|
+
};
|
|
446
|
+
}
|
|
447
|
+
};
|
|
406
448
|
|
|
407
449
|
// src/telemetry/utils.ts
|
|
408
450
|
function getModelProvider(llm) {
|
|
@@ -452,12 +494,12 @@ function detectRuntimeEnvironment() {
|
|
|
452
494
|
if (typeof globalThis.EdgeRuntime !== "undefined") {
|
|
453
495
|
return "edge";
|
|
454
496
|
}
|
|
455
|
-
if (typeof process !== "undefined" && typeof process.versions?.node !== "undefined" && typeof fs !== "undefined" && typeof fs.existsSync === "function") {
|
|
456
|
-
return "node";
|
|
457
|
-
}
|
|
458
497
|
if (typeof window !== "undefined" && typeof document !== "undefined") {
|
|
459
498
|
return "browser";
|
|
460
499
|
}
|
|
500
|
+
if (typeof process !== "undefined" && typeof process.versions?.node !== "undefined") {
|
|
501
|
+
return "node";
|
|
502
|
+
}
|
|
461
503
|
return "unknown";
|
|
462
504
|
} catch {
|
|
463
505
|
return "unknown";
|
|
@@ -494,11 +536,6 @@ function getRuntimeEnvironment() {
|
|
|
494
536
|
return cachedEnvironment;
|
|
495
537
|
}
|
|
496
538
|
__name(getRuntimeEnvironment, "getRuntimeEnvironment");
|
|
497
|
-
function isNodeJSEnvironment() {
|
|
498
|
-
const env = getRuntimeEnvironment();
|
|
499
|
-
return env === "node" || env === "bun";
|
|
500
|
-
}
|
|
501
|
-
__name(isNodeJSEnvironment, "isNodeJSEnvironment");
|
|
502
539
|
var ScarfEventLogger = class {
|
|
503
540
|
static {
|
|
504
541
|
__name(this, "ScarfEventLogger");
|
|
@@ -530,71 +567,40 @@ var ScarfEventLogger = class {
|
|
|
530
567
|
}
|
|
531
568
|
}
|
|
532
569
|
};
|
|
533
|
-
function getCacheHome() {
|
|
534
|
-
if (!isNodeJSEnvironment()) {
|
|
535
|
-
return "/tmp/mcp_use_cache";
|
|
536
|
-
}
|
|
537
|
-
const envVar = process.env.XDG_CACHE_HOME;
|
|
538
|
-
if (envVar && path.isAbsolute(envVar)) {
|
|
539
|
-
return envVar;
|
|
540
|
-
}
|
|
541
|
-
const platform = process.platform;
|
|
542
|
-
const homeDir = os.homedir();
|
|
543
|
-
if (platform === "win32") {
|
|
544
|
-
const appdata = process.env.LOCALAPPDATA || process.env.APPDATA;
|
|
545
|
-
if (appdata) {
|
|
546
|
-
return appdata;
|
|
547
|
-
}
|
|
548
|
-
return path.join(homeDir, "AppData", "Local");
|
|
549
|
-
} else if (platform === "darwin") {
|
|
550
|
-
return path.join(homeDir, "Library", "Caches");
|
|
551
|
-
} else {
|
|
552
|
-
return path.join(homeDir, ".cache");
|
|
553
|
-
}
|
|
554
|
-
}
|
|
555
|
-
__name(getCacheHome, "getCacheHome");
|
|
556
570
|
var Telemetry = class _Telemetry {
|
|
557
571
|
static {
|
|
558
572
|
__name(this, "Telemetry");
|
|
559
573
|
}
|
|
560
574
|
static instance = null;
|
|
561
|
-
USER_ID_PATH = path.join(
|
|
562
|
-
getCacheHome(),
|
|
563
|
-
"mcp_use_3",
|
|
564
|
-
"telemetry_user_id"
|
|
565
|
-
);
|
|
566
|
-
VERSION_DOWNLOAD_PATH = path.join(
|
|
567
|
-
getCacheHome(),
|
|
568
|
-
"mcp_use",
|
|
569
|
-
"download_version"
|
|
570
|
-
);
|
|
571
575
|
PROJECT_API_KEY = "phc_lyTtbYwvkdSbrcMQNPiKiiRWrrM1seyKIMjycSvItEI";
|
|
572
576
|
HOST = "https://eu.i.posthog.com";
|
|
573
577
|
SCARF_GATEWAY_URL = "https://mcpuse.gateway.scarf.sh/events-ts";
|
|
574
578
|
UNKNOWN_USER_ID = "UNKNOWN_USER_ID";
|
|
575
579
|
_currUserId = null;
|
|
576
|
-
|
|
580
|
+
_posthogNodeClient = null;
|
|
581
|
+
_posthogBrowserClient = null;
|
|
582
|
+
_posthogLoading = null;
|
|
577
583
|
_scarfClient = null;
|
|
578
584
|
_runtimeEnvironment;
|
|
579
585
|
_storageCapability;
|
|
580
586
|
_source;
|
|
587
|
+
// Node.js specific paths (lazily computed)
|
|
588
|
+
_userIdPath = null;
|
|
589
|
+
_versionDownloadPath = null;
|
|
581
590
|
constructor() {
|
|
582
591
|
this._runtimeEnvironment = getRuntimeEnvironment();
|
|
583
592
|
this._storageCapability = getStorageCapability(this._runtimeEnvironment);
|
|
584
593
|
this._source = typeof process !== "undefined" && process.env?.MCP_USE_TELEMETRY_SOURCE || this._runtimeEnvironment;
|
|
585
|
-
const telemetryDisabled =
|
|
594
|
+
const telemetryDisabled = this._checkTelemetryDisabled();
|
|
586
595
|
const canSupportTelemetry = this._runtimeEnvironment !== "unknown";
|
|
587
|
-
const isServerlessEnvironment = [
|
|
588
|
-
"cloudflare-workers",
|
|
589
|
-
"edge",
|
|
590
|
-
"deno"
|
|
591
|
-
].includes(this._runtimeEnvironment);
|
|
592
596
|
if (telemetryDisabled) {
|
|
593
|
-
this.
|
|
597
|
+
this._posthogNodeClient = null;
|
|
598
|
+
this._posthogBrowserClient = null;
|
|
594
599
|
this._scarfClient = null;
|
|
595
|
-
logger.debug("Telemetry disabled via environment
|
|
600
|
+
logger.debug("Telemetry disabled via environment/localStorage");
|
|
596
601
|
} else if (!canSupportTelemetry) {
|
|
597
|
-
this.
|
|
602
|
+
this._posthogNodeClient = null;
|
|
603
|
+
this._posthogBrowserClient = null;
|
|
598
604
|
this._scarfClient = null;
|
|
599
605
|
logger.debug(
|
|
600
606
|
`Telemetry disabled - unknown environment: ${this._runtimeEnvironment}`
|
|
@@ -603,27 +609,7 @@ var Telemetry = class _Telemetry {
|
|
|
603
609
|
logger.info(
|
|
604
610
|
"Anonymized telemetry enabled. Set MCP_USE_ANONYMIZED_TELEMETRY=false to disable."
|
|
605
611
|
);
|
|
606
|
-
|
|
607
|
-
try {
|
|
608
|
-
const posthogOptions = {
|
|
609
|
-
host: this.HOST,
|
|
610
|
-
disableGeoip: false
|
|
611
|
-
};
|
|
612
|
-
if (isServerlessEnvironment) {
|
|
613
|
-
posthogOptions.flushAt = 1;
|
|
614
|
-
posthogOptions.flushInterval = 0;
|
|
615
|
-
}
|
|
616
|
-
this._posthogClient = new PostHog(
|
|
617
|
-
this.PROJECT_API_KEY,
|
|
618
|
-
posthogOptions
|
|
619
|
-
);
|
|
620
|
-
} catch (e) {
|
|
621
|
-
logger.warn(`Failed to initialize PostHog telemetry: ${e}`);
|
|
622
|
-
this._posthogClient = null;
|
|
623
|
-
}
|
|
624
|
-
} else {
|
|
625
|
-
this._posthogClient = null;
|
|
626
|
-
}
|
|
612
|
+
this._posthogLoading = this._initPostHog();
|
|
627
613
|
try {
|
|
628
614
|
this._scarfClient = new ScarfEventLogger(this.SCARF_GATEWAY_URL, 3e3);
|
|
629
615
|
} catch (e) {
|
|
@@ -632,6 +618,75 @@ var Telemetry = class _Telemetry {
|
|
|
632
618
|
}
|
|
633
619
|
}
|
|
634
620
|
}
|
|
621
|
+
_checkTelemetryDisabled() {
|
|
622
|
+
if (typeof process !== "undefined" && process.env?.MCP_USE_ANONYMIZED_TELEMETRY?.toLowerCase() === "false") {
|
|
623
|
+
return true;
|
|
624
|
+
}
|
|
625
|
+
if (typeof localStorage !== "undefined" && localStorage.getItem("MCP_USE_ANONYMIZED_TELEMETRY") === "false") {
|
|
626
|
+
return true;
|
|
627
|
+
}
|
|
628
|
+
return false;
|
|
629
|
+
}
|
|
630
|
+
async _initPostHog() {
|
|
631
|
+
const isBrowser = this._runtimeEnvironment === "browser";
|
|
632
|
+
if (isBrowser) {
|
|
633
|
+
await this._initPostHogBrowser();
|
|
634
|
+
} else {
|
|
635
|
+
await this._initPostHogNode();
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
async _initPostHogBrowser() {
|
|
639
|
+
try {
|
|
640
|
+
const posthogModule = await import("posthog-js");
|
|
641
|
+
const posthog = posthogModule.default || posthogModule.posthog;
|
|
642
|
+
if (!posthog || typeof posthog.init !== "function") {
|
|
643
|
+
throw new Error("posthog-js module did not export expected interface");
|
|
644
|
+
}
|
|
645
|
+
posthog.init(this.PROJECT_API_KEY, {
|
|
646
|
+
api_host: this.HOST,
|
|
647
|
+
persistence: "localStorage",
|
|
648
|
+
autocapture: false,
|
|
649
|
+
// We only want explicit captures
|
|
650
|
+
capture_pageview: false,
|
|
651
|
+
// We don't want automatic pageview tracking
|
|
652
|
+
disable_session_recording: true,
|
|
653
|
+
// No session recording
|
|
654
|
+
loaded: /* @__PURE__ */ __name(() => {
|
|
655
|
+
logger.debug("PostHog browser client initialized");
|
|
656
|
+
}, "loaded")
|
|
657
|
+
});
|
|
658
|
+
this._posthogBrowserClient = posthog;
|
|
659
|
+
} catch (e) {
|
|
660
|
+
logger.warn(`Failed to initialize PostHog browser telemetry: ${e}`);
|
|
661
|
+
this._posthogBrowserClient = null;
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
async _initPostHogNode() {
|
|
665
|
+
try {
|
|
666
|
+
const { PostHog } = await import("posthog-node");
|
|
667
|
+
const isServerlessEnvironment = [
|
|
668
|
+
"cloudflare-workers",
|
|
669
|
+
"edge",
|
|
670
|
+
"deno"
|
|
671
|
+
].includes(this._runtimeEnvironment);
|
|
672
|
+
const posthogOptions = {
|
|
673
|
+
host: this.HOST,
|
|
674
|
+
disableGeoip: false
|
|
675
|
+
};
|
|
676
|
+
if (isServerlessEnvironment) {
|
|
677
|
+
posthogOptions.flushAt = 1;
|
|
678
|
+
posthogOptions.flushInterval = 0;
|
|
679
|
+
}
|
|
680
|
+
this._posthogNodeClient = new PostHog(
|
|
681
|
+
this.PROJECT_API_KEY,
|
|
682
|
+
posthogOptions
|
|
683
|
+
);
|
|
684
|
+
logger.debug("PostHog Node.js client initialized");
|
|
685
|
+
} catch (e) {
|
|
686
|
+
logger.warn(`Failed to initialize PostHog Node.js telemetry: ${e}`);
|
|
687
|
+
this._posthogNodeClient = null;
|
|
688
|
+
}
|
|
689
|
+
}
|
|
635
690
|
/**
|
|
636
691
|
* Get the detected runtime environment
|
|
637
692
|
*/
|
|
@@ -667,10 +722,9 @@ var Telemetry = class _Telemetry {
|
|
|
667
722
|
}
|
|
668
723
|
/**
|
|
669
724
|
* Check if telemetry is enabled.
|
|
670
|
-
* Returns false if telemetry was disabled via environment variable or if not in Node.js environment.
|
|
671
725
|
*/
|
|
672
726
|
get isEnabled() {
|
|
673
|
-
return this.
|
|
727
|
+
return this._posthogNodeClient !== null || this._posthogBrowserClient !== null || this._scarfClient !== null;
|
|
674
728
|
}
|
|
675
729
|
get userId() {
|
|
676
730
|
if (this._currUserId) {
|
|
@@ -679,10 +733,10 @@ var Telemetry = class _Telemetry {
|
|
|
679
733
|
try {
|
|
680
734
|
switch (this._storageCapability) {
|
|
681
735
|
case "filesystem":
|
|
682
|
-
this._currUserId = this.
|
|
736
|
+
this._currUserId = this._getUserIdFromFilesystem();
|
|
683
737
|
break;
|
|
684
738
|
case "localStorage":
|
|
685
|
-
this._currUserId = this.
|
|
739
|
+
this._currUserId = this._getUserIdFromLocalStorage();
|
|
686
740
|
break;
|
|
687
741
|
case "session-only":
|
|
688
742
|
default:
|
|
@@ -693,7 +747,7 @@ var Telemetry = class _Telemetry {
|
|
|
693
747
|
break;
|
|
694
748
|
}
|
|
695
749
|
if (this._storageCapability === "filesystem" && this._currUserId) {
|
|
696
|
-
this.
|
|
750
|
+
this._trackPackageDownloadInternal(this._currUserId, {
|
|
697
751
|
triggered_by: "user_id_property"
|
|
698
752
|
}).catch((e) => logger.debug(`Failed to track package download: ${e}`));
|
|
699
753
|
}
|
|
@@ -706,22 +760,32 @@ var Telemetry = class _Telemetry {
|
|
|
706
760
|
/**
|
|
707
761
|
* Get or create user ID from filesystem (Node.js/Bun)
|
|
708
762
|
*/
|
|
709
|
-
|
|
710
|
-
const
|
|
763
|
+
_getUserIdFromFilesystem() {
|
|
764
|
+
const fs = __require("fs");
|
|
765
|
+
const os = __require("os");
|
|
766
|
+
const path = __require("path");
|
|
767
|
+
if (!this._userIdPath) {
|
|
768
|
+
this._userIdPath = path.join(
|
|
769
|
+
this._getCacheHome(os, path),
|
|
770
|
+
"mcp_use_3",
|
|
771
|
+
"telemetry_user_id"
|
|
772
|
+
);
|
|
773
|
+
}
|
|
774
|
+
const isFirstTime = !fs.existsSync(this._userIdPath);
|
|
711
775
|
if (isFirstTime) {
|
|
712
|
-
logger.debug(`Creating user ID path: ${this.
|
|
713
|
-
fs.mkdirSync(path.dirname(this.
|
|
776
|
+
logger.debug(`Creating user ID path: ${this._userIdPath}`);
|
|
777
|
+
fs.mkdirSync(path.dirname(this._userIdPath), { recursive: true });
|
|
714
778
|
const newUserId = generateUUID();
|
|
715
|
-
fs.writeFileSync(this.
|
|
716
|
-
logger.debug(`User ID path created: ${this.
|
|
779
|
+
fs.writeFileSync(this._userIdPath, newUserId);
|
|
780
|
+
logger.debug(`User ID path created: ${this._userIdPath}`);
|
|
717
781
|
return newUserId;
|
|
718
782
|
}
|
|
719
|
-
return fs.readFileSync(this.
|
|
783
|
+
return fs.readFileSync(this._userIdPath, "utf-8").trim();
|
|
720
784
|
}
|
|
721
785
|
/**
|
|
722
786
|
* Get or create user ID from localStorage (Browser)
|
|
723
787
|
*/
|
|
724
|
-
|
|
788
|
+
_getUserIdFromLocalStorage() {
|
|
725
789
|
try {
|
|
726
790
|
let userId = localStorage.getItem(USER_ID_STORAGE_KEY);
|
|
727
791
|
if (!userId) {
|
|
@@ -735,60 +799,89 @@ var Telemetry = class _Telemetry {
|
|
|
735
799
|
return `session-${generateUUID()}`;
|
|
736
800
|
}
|
|
737
801
|
}
|
|
802
|
+
_getCacheHome(os, path) {
|
|
803
|
+
const envVar = process.env.XDG_CACHE_HOME;
|
|
804
|
+
if (envVar && path.isAbsolute(envVar)) {
|
|
805
|
+
return envVar;
|
|
806
|
+
}
|
|
807
|
+
const platform = process.platform;
|
|
808
|
+
const homeDir = os.homedir();
|
|
809
|
+
if (platform === "win32") {
|
|
810
|
+
const appdata = process.env.LOCALAPPDATA || process.env.APPDATA;
|
|
811
|
+
if (appdata) {
|
|
812
|
+
return appdata;
|
|
813
|
+
}
|
|
814
|
+
return path.join(homeDir, "AppData", "Local");
|
|
815
|
+
} else if (platform === "darwin") {
|
|
816
|
+
return path.join(homeDir, "Library", "Caches");
|
|
817
|
+
} else {
|
|
818
|
+
return path.join(homeDir, ".cache");
|
|
819
|
+
}
|
|
820
|
+
}
|
|
738
821
|
async capture(event) {
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
if (!this.
|
|
822
|
+
if (this._posthogLoading) {
|
|
823
|
+
await this._posthogLoading;
|
|
824
|
+
}
|
|
825
|
+
if (!this._posthogNodeClient && !this._posthogBrowserClient && !this._scarfClient) {
|
|
743
826
|
return;
|
|
744
827
|
}
|
|
745
|
-
|
|
828
|
+
const properties = { ...event.properties };
|
|
829
|
+
properties.mcp_use_version = getPackageVersion();
|
|
830
|
+
properties.language = "typescript";
|
|
831
|
+
properties.source = this._source;
|
|
832
|
+
properties.runtime = this._runtimeEnvironment;
|
|
833
|
+
if (this._posthogNodeClient) {
|
|
746
834
|
try {
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
properties.language = "typescript";
|
|
750
|
-
properties.source = this._source;
|
|
751
|
-
properties.runtime = this._runtimeEnvironment;
|
|
752
|
-
logger.debug(`CAPTURE: PostHog Event ${event.name}`);
|
|
753
|
-
logger.debug(
|
|
754
|
-
`CAPTURE: PostHog Properties ${JSON.stringify(properties)}`
|
|
755
|
-
);
|
|
756
|
-
this._posthogClient.capture({
|
|
835
|
+
logger.debug(`CAPTURE: PostHog Node Event ${event.name}`);
|
|
836
|
+
this._posthogNodeClient.capture({
|
|
757
837
|
distinctId: this.userId,
|
|
758
838
|
event: event.name,
|
|
759
839
|
properties
|
|
760
840
|
});
|
|
761
841
|
} catch (e) {
|
|
762
|
-
logger.debug(`Failed to track PostHog event ${event.name}: ${e}`);
|
|
842
|
+
logger.debug(`Failed to track PostHog Node event ${event.name}: ${e}`);
|
|
843
|
+
}
|
|
844
|
+
}
|
|
845
|
+
if (this._posthogBrowserClient) {
|
|
846
|
+
try {
|
|
847
|
+
logger.debug(`CAPTURE: PostHog Browser Event ${event.name}`);
|
|
848
|
+
this._posthogBrowserClient.capture(event.name, {
|
|
849
|
+
...properties,
|
|
850
|
+
distinct_id: this.userId
|
|
851
|
+
});
|
|
852
|
+
} catch (e) {
|
|
853
|
+
logger.debug(
|
|
854
|
+
`Failed to track PostHog Browser event ${event.name}: ${e}`
|
|
855
|
+
);
|
|
763
856
|
}
|
|
764
857
|
}
|
|
765
858
|
if (this._scarfClient) {
|
|
766
859
|
try {
|
|
767
|
-
const
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
properties.runtime = this._runtimeEnvironment;
|
|
774
|
-
await this._scarfClient.logEvent(properties);
|
|
860
|
+
const scarfProperties = {
|
|
861
|
+
...properties,
|
|
862
|
+
user_id: this.userId,
|
|
863
|
+
event: event.name
|
|
864
|
+
};
|
|
865
|
+
await this._scarfClient.logEvent(scarfProperties);
|
|
775
866
|
} catch (e) {
|
|
776
867
|
logger.debug(`Failed to track Scarf event ${event.name}: ${e}`);
|
|
777
868
|
}
|
|
778
869
|
}
|
|
779
870
|
}
|
|
871
|
+
// ============================================================================
|
|
872
|
+
// Package Download Tracking (Node.js only)
|
|
873
|
+
// ============================================================================
|
|
780
874
|
/**
|
|
781
875
|
* Track package download event.
|
|
782
876
|
* This is a public wrapper that safely accesses userId.
|
|
783
877
|
*/
|
|
784
878
|
async trackPackageDownload(properties) {
|
|
785
|
-
return this.
|
|
879
|
+
return this._trackPackageDownloadInternal(this.userId, properties);
|
|
786
880
|
}
|
|
787
881
|
/**
|
|
788
882
|
* Internal method to track package download with explicit userId.
|
|
789
|
-
* This avoids circular dependency when called from the userId getter.
|
|
790
883
|
*/
|
|
791
|
-
async
|
|
884
|
+
async _trackPackageDownloadInternal(userId, properties) {
|
|
792
885
|
if (!this._scarfClient) {
|
|
793
886
|
return;
|
|
794
887
|
}
|
|
@@ -796,22 +889,32 @@ var Telemetry = class _Telemetry {
|
|
|
796
889
|
return;
|
|
797
890
|
}
|
|
798
891
|
try {
|
|
892
|
+
const fs = __require("fs");
|
|
893
|
+
const path = __require("path");
|
|
894
|
+
const os = __require("os");
|
|
895
|
+
if (!this._versionDownloadPath) {
|
|
896
|
+
this._versionDownloadPath = path.join(
|
|
897
|
+
this._getCacheHome(os, path),
|
|
898
|
+
"mcp_use",
|
|
899
|
+
"download_version"
|
|
900
|
+
);
|
|
901
|
+
}
|
|
799
902
|
const currentVersion = getPackageVersion();
|
|
800
903
|
let shouldTrack = false;
|
|
801
904
|
let firstDownload = false;
|
|
802
|
-
if (!fs.existsSync(this.
|
|
905
|
+
if (!fs.existsSync(this._versionDownloadPath)) {
|
|
803
906
|
shouldTrack = true;
|
|
804
907
|
firstDownload = true;
|
|
805
|
-
fs.mkdirSync(path.dirname(this.
|
|
908
|
+
fs.mkdirSync(path.dirname(this._versionDownloadPath), {
|
|
806
909
|
recursive: true
|
|
807
910
|
});
|
|
808
|
-
fs.writeFileSync(this.
|
|
911
|
+
fs.writeFileSync(this._versionDownloadPath, currentVersion);
|
|
809
912
|
} else {
|
|
810
|
-
const savedVersion = fs.readFileSync(this.
|
|
913
|
+
const savedVersion = fs.readFileSync(this._versionDownloadPath, "utf-8").trim();
|
|
811
914
|
if (currentVersion > savedVersion) {
|
|
812
915
|
shouldTrack = true;
|
|
813
916
|
firstDownload = false;
|
|
814
|
-
fs.writeFileSync(this.
|
|
917
|
+
fs.writeFileSync(this._versionDownloadPath, currentVersion);
|
|
815
918
|
}
|
|
816
919
|
}
|
|
817
920
|
if (shouldTrack) {
|
|
@@ -845,9 +948,6 @@ var Telemetry = class _Telemetry {
|
|
|
845
948
|
// ============================================================================
|
|
846
949
|
/**
|
|
847
950
|
* Track server run event directly from an MCPServer instance.
|
|
848
|
-
* This extracts the necessary data from the server and creates the event.
|
|
849
|
-
* @param server - The MCPServer instance (or any object conforming to MCPServerTelemetryInfo)
|
|
850
|
-
* @param transport - The transport type (e.g., "http", "stdio", "supabase")
|
|
851
951
|
*/
|
|
852
952
|
async trackServerRunFromServer(server, transport) {
|
|
853
953
|
if (!this.isEnabled) return;
|
|
@@ -893,37 +993,123 @@ var Telemetry = class _Telemetry {
|
|
|
893
993
|
const event = new ConnectorInitEvent(data);
|
|
894
994
|
await this.capture(event);
|
|
895
995
|
}
|
|
996
|
+
async trackClientAddServer(serverName, serverConfig) {
|
|
997
|
+
if (!this.isEnabled) return;
|
|
998
|
+
const event = new ClientAddServerEvent({ serverName, serverConfig });
|
|
999
|
+
await this.capture(event);
|
|
1000
|
+
}
|
|
1001
|
+
async trackClientRemoveServer(serverName) {
|
|
1002
|
+
if (!this.isEnabled) return;
|
|
1003
|
+
const event = new ClientRemoveServerEvent({ serverName });
|
|
1004
|
+
await this.capture(event);
|
|
1005
|
+
}
|
|
1006
|
+
// ============================================================================
|
|
1007
|
+
// React Hook / Browser specific events
|
|
1008
|
+
// ============================================================================
|
|
1009
|
+
async trackUseMcpConnection(data) {
|
|
1010
|
+
if (!this.isEnabled) return;
|
|
1011
|
+
await this.capture({
|
|
1012
|
+
name: "usemcp_connection",
|
|
1013
|
+
properties: {
|
|
1014
|
+
url_domain: new URL(data.url).hostname,
|
|
1015
|
+
// Only domain for privacy
|
|
1016
|
+
transport_type: data.transportType,
|
|
1017
|
+
success: data.success,
|
|
1018
|
+
error_type: data.errorType ?? null,
|
|
1019
|
+
connection_time_ms: data.connectionTimeMs ?? null,
|
|
1020
|
+
has_oauth: data.hasOAuth,
|
|
1021
|
+
has_sampling: data.hasSampling,
|
|
1022
|
+
has_elicitation: data.hasElicitation
|
|
1023
|
+
}
|
|
1024
|
+
});
|
|
1025
|
+
}
|
|
1026
|
+
async trackUseMcpToolCall(data) {
|
|
1027
|
+
if (!this.isEnabled) return;
|
|
1028
|
+
await this.capture({
|
|
1029
|
+
name: "usemcp_tool_call",
|
|
1030
|
+
properties: {
|
|
1031
|
+
tool_name: data.toolName,
|
|
1032
|
+
success: data.success,
|
|
1033
|
+
error_type: data.errorType ?? null,
|
|
1034
|
+
execution_time_ms: data.executionTimeMs ?? null
|
|
1035
|
+
}
|
|
1036
|
+
});
|
|
1037
|
+
}
|
|
1038
|
+
async trackUseMcpResourceRead(data) {
|
|
1039
|
+
if (!this.isEnabled) return;
|
|
1040
|
+
await this.capture({
|
|
1041
|
+
name: "usemcp_resource_read",
|
|
1042
|
+
properties: {
|
|
1043
|
+
resource_uri_scheme: data.resourceUri.split(":")[0],
|
|
1044
|
+
// Only scheme for privacy
|
|
1045
|
+
success: data.success,
|
|
1046
|
+
error_type: data.errorType ?? null
|
|
1047
|
+
}
|
|
1048
|
+
});
|
|
1049
|
+
}
|
|
1050
|
+
// ============================================================================
|
|
1051
|
+
// Browser-specific Methods
|
|
1052
|
+
// ============================================================================
|
|
1053
|
+
/**
|
|
1054
|
+
* Identify the current user (useful for linking sessions)
|
|
1055
|
+
* Browser only - no-op in Node.js
|
|
1056
|
+
*/
|
|
1057
|
+
identify(userId, properties) {
|
|
1058
|
+
if (this._posthogBrowserClient) {
|
|
1059
|
+
try {
|
|
1060
|
+
this._posthogBrowserClient.identify(userId, properties);
|
|
1061
|
+
} catch (e) {
|
|
1062
|
+
logger.debug(`Failed to identify user: ${e}`);
|
|
1063
|
+
}
|
|
1064
|
+
}
|
|
1065
|
+
}
|
|
1066
|
+
/**
|
|
1067
|
+
* Reset the user identity (useful for logout)
|
|
1068
|
+
* Browser only - no-op in Node.js
|
|
1069
|
+
*/
|
|
1070
|
+
reset() {
|
|
1071
|
+
if (this._posthogBrowserClient) {
|
|
1072
|
+
try {
|
|
1073
|
+
this._posthogBrowserClient.reset();
|
|
1074
|
+
} catch (e) {
|
|
1075
|
+
logger.debug(`Failed to reset user: ${e}`);
|
|
1076
|
+
}
|
|
1077
|
+
}
|
|
1078
|
+
this._currUserId = null;
|
|
1079
|
+
}
|
|
1080
|
+
// ============================================================================
|
|
1081
|
+
// Node.js-specific Methods
|
|
1082
|
+
// ============================================================================
|
|
1083
|
+
/**
|
|
1084
|
+
* Flush the telemetry queue (Node.js only)
|
|
1085
|
+
*/
|
|
896
1086
|
flush() {
|
|
897
|
-
if (this.
|
|
1087
|
+
if (this._posthogNodeClient) {
|
|
898
1088
|
try {
|
|
899
|
-
this.
|
|
1089
|
+
this._posthogNodeClient.flush();
|
|
900
1090
|
logger.debug("PostHog client telemetry queue flushed");
|
|
901
1091
|
} catch (e) {
|
|
902
1092
|
logger.debug(`Failed to flush PostHog client: ${e}`);
|
|
903
1093
|
}
|
|
904
1094
|
}
|
|
905
|
-
if (this._scarfClient) {
|
|
906
|
-
logger.debug("Scarf telemetry events sent immediately (no flush needed)");
|
|
907
|
-
}
|
|
908
1095
|
}
|
|
1096
|
+
/**
|
|
1097
|
+
* Shutdown the telemetry client (Node.js only)
|
|
1098
|
+
*/
|
|
909
1099
|
shutdown() {
|
|
910
|
-
if (this.
|
|
1100
|
+
if (this._posthogNodeClient) {
|
|
911
1101
|
try {
|
|
912
|
-
this.
|
|
1102
|
+
this._posthogNodeClient.shutdown();
|
|
913
1103
|
logger.debug("PostHog client shutdown successfully");
|
|
914
1104
|
} catch (e) {
|
|
915
1105
|
logger.debug(`Error shutting down PostHog client: ${e}`);
|
|
916
1106
|
}
|
|
917
1107
|
}
|
|
918
|
-
if (this._scarfClient) {
|
|
919
|
-
logger.debug("Scarf telemetry client shutdown (no action needed)");
|
|
920
|
-
}
|
|
921
1108
|
}
|
|
922
1109
|
};
|
|
923
|
-
|
|
924
|
-
// src/telemetry/index.ts
|
|
1110
|
+
var Tel = Telemetry;
|
|
925
1111
|
function setTelemetrySource(source) {
|
|
926
|
-
|
|
1112
|
+
Tel.getInstance().setSource(source);
|
|
927
1113
|
}
|
|
928
1114
|
__name(setTelemetrySource, "setTelemetrySource");
|
|
929
1115
|
|
|
@@ -938,5 +1124,6 @@ export {
|
|
|
938
1124
|
getPackageVersion,
|
|
939
1125
|
extractModelInfo,
|
|
940
1126
|
Telemetry,
|
|
1127
|
+
Tel,
|
|
941
1128
|
setTelemetrySource
|
|
942
1129
|
};
|