mcp-use 1.9.1-canary.1 → 1.10.0-canary.11
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/README.md +9 -6
- package/dist/.tsbuildinfo +1 -1
- package/dist/{chunk-QREDNTLS.js → chunk-5S5DWSKI.js} +1 -1
- package/dist/{chunk-MUZ5WYE3.js → chunk-5UB2K5L6.js} +72 -14
- package/dist/{chunk-33U4IA4N.js → chunk-B5N3LQQU.js} +99 -5
- package/dist/{chunk-3R5PDYIN.js → chunk-J75I2C26.js} +39 -11
- package/dist/{chunk-U5BX3ISQ.js → chunk-KMTBWOVS.js} +22 -408
- package/dist/{chunk-D22NUQTL.js → chunk-LXYUQEEE.js} +235 -12
- package/dist/{chunk-ZQUCGISK.js → chunk-NNQUSDFU.js} +21 -5
- package/dist/chunk-PESKSVLQ.js +1129 -0
- package/dist/index.cjs +1190 -200
- package/dist/index.d.ts +6 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +63 -23
- package/dist/src/adapters/langchain_adapter.d.ts +1 -1
- package/dist/src/adapters/langchain_adapter.d.ts.map +1 -1
- package/dist/src/agents/index.cjs +2263 -1626
- 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/auth/browser-provider.d.ts +2 -2
- package/dist/src/auth/browser-provider.d.ts.map +1 -1
- package/dist/src/auth/callback.d.ts.map +1 -1
- package/dist/src/auth/index.cjs +39 -11
- package/dist/src/auth/index.js +1 -1
- package/dist/src/auth/types.d.ts +1 -1
- package/dist/src/auth/types.d.ts.map +1 -1
- package/dist/src/browser.cjs +2672 -1754
- package/dist/src/browser.d.ts +5 -1
- package/dist/src/browser.d.ts.map +1 -1
- package/dist/src/browser.js +18 -5
- package/dist/src/client/base.d.ts.map +1 -1
- package/dist/src/client/browser.d.ts +6 -0
- package/dist/src/client/browser.d.ts.map +1 -1
- package/dist/src/client/connectors/codeMode.d.ts +1 -1
- package/dist/src/client/connectors/codeMode.d.ts.map +1 -1
- package/dist/src/client/executors/base.d.ts +1 -1
- package/dist/src/client/executors/base.d.ts.map +1 -1
- package/dist/src/client/prompts.cjs +4 -1
- package/dist/src/client/prompts.js +3 -2
- package/dist/src/client.d.ts +7 -1
- package/dist/src/client.d.ts.map +1 -1
- package/dist/src/connectors/base.d.ts +56 -6
- 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/connectors/websocket.d.ts +1 -1
- package/dist/src/connectors/websocket.d.ts.map +1 -1
- package/dist/src/oauth-helper.d.ts.map +1 -1
- package/dist/src/react/WidgetControls.d.ts.map +1 -1
- package/dist/src/react/index.cjs +1357 -43
- package/dist/src/react/index.d.ts +4 -1
- package/dist/src/react/index.d.ts.map +1 -1
- package/dist/src/react/index.js +14 -5
- package/dist/src/react/types.d.ts +1 -1
- package/dist/src/react/types.d.ts.map +1 -1
- package/dist/src/react/useMcp.d.ts.map +1 -1
- package/dist/src/server/endpoints/mount-mcp.d.ts +4 -1
- package/dist/src/server/endpoints/mount-mcp.d.ts.map +1 -1
- package/dist/src/server/index.cjs +1923 -287
- package/dist/src/server/index.d.ts +3 -2
- package/dist/src/server/index.d.ts.map +1 -1
- package/dist/src/server/index.js +488 -245
- package/dist/src/server/mcp-server.d.ts +77 -27
- package/dist/src/server/mcp-server.d.ts.map +1 -1
- package/dist/src/server/oauth/middleware.d.ts.map +1 -1
- package/dist/src/server/oauth/providers/auth0.d.ts +1 -1
- package/dist/src/server/oauth/providers/auth0.d.ts.map +1 -1
- package/dist/src/server/oauth/providers/custom.d.ts +4 -2
- package/dist/src/server/oauth/providers/custom.d.ts.map +1 -1
- package/dist/src/server/oauth/providers/keycloak.d.ts +1 -1
- package/dist/src/server/oauth/providers/keycloak.d.ts.map +1 -1
- package/dist/src/server/oauth/providers/supabase.d.ts +1 -1
- package/dist/src/server/oauth/providers/supabase.d.ts.map +1 -1
- package/dist/src/server/oauth/providers/types.d.ts +9 -5
- package/dist/src/server/oauth/providers/types.d.ts.map +1 -1
- package/dist/src/server/oauth/providers.d.ts +27 -9
- package/dist/src/server/oauth/providers.d.ts.map +1 -1
- package/dist/src/server/oauth/setup.d.ts +5 -4
- package/dist/src/server/oauth/setup.d.ts.map +1 -1
- package/dist/src/server/oauth/utils.d.ts +3 -2
- package/dist/src/server/oauth/utils.d.ts.map +1 -1
- package/dist/src/server/prompts/conversion.d.ts +1 -1
- package/dist/src/server/prompts/conversion.d.ts.map +1 -1
- package/dist/src/server/prompts/index.d.ts +6 -5
- package/dist/src/server/prompts/index.d.ts.map +1 -1
- package/dist/src/server/resources/conversion.d.ts +1 -1
- package/dist/src/server/resources/conversion.d.ts.map +1 -1
- package/dist/src/server/resources/index.d.ts +44 -25
- package/dist/src/server/resources/index.d.ts.map +1 -1
- package/dist/src/server/resources/subscriptions.d.ts +1 -1
- package/dist/src/server/resources/subscriptions.d.ts.map +1 -1
- package/dist/src/server/sessions/session-manager.d.ts +11 -5
- package/dist/src/server/sessions/session-manager.d.ts.map +1 -1
- package/dist/src/server/tools/tool-execution-helpers.d.ts +31 -8
- package/dist/src/server/tools/tool-execution-helpers.d.ts.map +1 -1
- package/dist/src/server/tools/tool-registration.d.ts +21 -7
- package/dist/src/server/tools/tool-registration.d.ts.map +1 -1
- package/dist/src/server/types/common.d.ts +25 -9
- package/dist/src/server/types/common.d.ts.map +1 -1
- package/dist/src/server/types/index.d.ts +3 -3
- package/dist/src/server/types/index.d.ts.map +1 -1
- package/dist/src/server/types/prompt.d.ts +3 -2
- package/dist/src/server/types/prompt.d.ts.map +1 -1
- package/dist/src/server/types/resource.d.ts +60 -10
- package/dist/src/server/types/resource.d.ts.map +1 -1
- package/dist/src/server/types/tool-context.d.ts +116 -1
- package/dist/src/server/types/tool-context.d.ts.map +1 -1
- package/dist/src/server/types/tool.d.ts +43 -2
- package/dist/src/server/types/tool.d.ts.map +1 -1
- package/dist/src/server/types/widget.d.ts +11 -1
- package/dist/src/server/types/widget.d.ts.map +1 -1
- package/dist/src/server/utils/response-helpers.d.ts +17 -29
- package/dist/src/server/utils/response-helpers.d.ts.map +1 -1
- package/dist/src/server/widgets/index.d.ts +3 -3
- package/dist/src/server/widgets/index.d.ts.map +1 -1
- package/dist/src/server/widgets/mount-widgets-dev.d.ts.map +1 -1
- package/dist/src/server/widgets/ui-resource-registration.d.ts +13 -25
- package/dist/src/server/widgets/ui-resource-registration.d.ts.map +1 -1
- package/dist/src/server/widgets/widget-helpers.d.ts +11 -6
- package/dist/src/server/widgets/widget-helpers.d.ts.map +1 -1
- package/dist/src/server/widgets/widget-types.d.ts +3 -3
- package/dist/src/server/widgets/widget-types.d.ts.map +1 -1
- package/dist/src/session.d.ts +372 -2
- package/dist/src/session.d.ts.map +1 -1
- package/dist/src/task_managers/sse.d.ts +2 -2
- package/dist/src/task_managers/sse.d.ts.map +1 -1
- package/dist/src/task_managers/stdio.d.ts +2 -2
- package/dist/src/task_managers/stdio.d.ts.map +1 -1
- package/dist/src/task_managers/streamable_http.d.ts +2 -2
- package/dist/src/task_managers/streamable_http.d.ts.map +1 -1
- package/dist/src/telemetry/events.d.ts +247 -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 +122 -4
- 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-BQJTPWPN.js → tool-execution-helpers-OOVLOJYH.js} +3 -2
- package/dist/tsup.config.d.ts.map +1 -1
- package/package.json +7 -5
- package/dist/chunk-MTHLLDCX.js +0 -97
package/dist/index.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 fs2 = await import("fs");
|
|
39
|
+
const path2 = await import("path");
|
|
40
|
+
return { fs: fs2.default, path: path2.default };
|
|
41
41
|
} catch {
|
|
42
42
|
return { fs: null, path: null };
|
|
43
43
|
}
|
|
@@ -1053,6 +1053,7 @@ __export(index_exports, {
|
|
|
1053
1053
|
BaseCodeExecutor: () => BaseCodeExecutor,
|
|
1054
1054
|
BaseConnector: () => BaseConnector,
|
|
1055
1055
|
BrowserOAuthClientProvider: () => BrowserOAuthClientProvider,
|
|
1056
|
+
BrowserTelemetry: () => Tel,
|
|
1056
1057
|
ConnectMCPServerTool: () => ConnectMCPServerTool,
|
|
1057
1058
|
E2BCodeExecutor: () => E2BCodeExecutor,
|
|
1058
1059
|
ElicitationDeclinedError: () => ElicitationDeclinedError,
|
|
@@ -1076,17 +1077,21 @@ __export(index_exports, {
|
|
|
1076
1077
|
RemoteAgent: () => RemoteAgent,
|
|
1077
1078
|
ServerManager: () => ServerManager,
|
|
1078
1079
|
StdioConnector: () => StdioConnector,
|
|
1080
|
+
Tel: () => Tel,
|
|
1079
1081
|
Telemetry: () => Telemetry,
|
|
1080
1082
|
ThemeProvider: () => ThemeProvider,
|
|
1083
|
+
VERSION: () => VERSION,
|
|
1081
1084
|
VMCodeExecutor: () => VMCodeExecutor,
|
|
1082
1085
|
WebSocketConnector: () => WebSocketConnector,
|
|
1083
1086
|
WidgetControls: () => WidgetControls,
|
|
1084
1087
|
createOAuthMCPConfig: () => createOAuthMCPConfig,
|
|
1085
1088
|
createReadableStreamFromGenerator: () => createReadableStreamFromGenerator,
|
|
1089
|
+
getPackageVersion: () => getPackageVersion,
|
|
1086
1090
|
isVMAvailable: () => isVMAvailable,
|
|
1087
1091
|
loadConfigFile: () => loadConfigFile,
|
|
1088
1092
|
logger: () => logger,
|
|
1089
1093
|
onMcpAuthorization: () => onMcpAuthorization,
|
|
1094
|
+
setBrowserTelemetrySource: () => setTelemetrySource,
|
|
1090
1095
|
setTelemetrySource: () => setTelemetrySource,
|
|
1091
1096
|
streamEventsToAISDK: () => streamEventsToAISDK,
|
|
1092
1097
|
streamEventsToAISDKWithTools: () => streamEventsToAISDKWithTools,
|
|
@@ -2512,22 +2517,6 @@ var ObservabilityManager = class {
|
|
|
2512
2517
|
}
|
|
2513
2518
|
};
|
|
2514
2519
|
|
|
2515
|
-
// src/telemetry/telemetry.ts
|
|
2516
|
-
var fs2 = __toESM(require("fs"), 1);
|
|
2517
|
-
var os = __toESM(require("os"), 1);
|
|
2518
|
-
var path2 = __toESM(require("path"), 1);
|
|
2519
|
-
var import_posthog_node = require("posthog-node");
|
|
2520
|
-
|
|
2521
|
-
// src/server/utils/runtime.ts
|
|
2522
|
-
var isDeno = typeof globalThis.Deno !== "undefined";
|
|
2523
|
-
function generateUUID() {
|
|
2524
|
-
return globalThis.crypto.randomUUID();
|
|
2525
|
-
}
|
|
2526
|
-
__name(generateUUID, "generateUUID");
|
|
2527
|
-
|
|
2528
|
-
// src/telemetry/telemetry.ts
|
|
2529
|
-
init_logging();
|
|
2530
|
-
|
|
2531
2520
|
// src/telemetry/events.ts
|
|
2532
2521
|
var BaseTelemetryEvent = class {
|
|
2533
2522
|
static {
|
|
@@ -2578,23 +2567,322 @@ var MCPAgentExecutionEvent = class extends BaseTelemetryEvent {
|
|
|
2578
2567
|
};
|
|
2579
2568
|
}
|
|
2580
2569
|
};
|
|
2581
|
-
|
|
2582
|
-
|
|
2583
|
-
|
|
2584
|
-
|
|
2585
|
-
|
|
2586
|
-
|
|
2587
|
-
|
|
2588
|
-
|
|
2570
|
+
function createServerRunEventData(server, transport) {
|
|
2571
|
+
const toolRegistrations = Array.from(server.registrations.tools.values());
|
|
2572
|
+
const promptRegistrations = Array.from(server.registrations.prompts.values());
|
|
2573
|
+
const resourceRegistrations = Array.from(
|
|
2574
|
+
server.registrations.resources.values()
|
|
2575
|
+
);
|
|
2576
|
+
const templateRegistrations = Array.from(
|
|
2577
|
+
server.registrations.resourceTemplates.values()
|
|
2578
|
+
);
|
|
2579
|
+
const allResources = resourceRegistrations.map((r) => ({
|
|
2580
|
+
name: r.config.name,
|
|
2581
|
+
title: r.config.title ?? null,
|
|
2582
|
+
description: r.config.description ?? null,
|
|
2583
|
+
uri: r.config.uri ?? null,
|
|
2584
|
+
mime_type: r.config.mimeType ?? null
|
|
2585
|
+
}));
|
|
2586
|
+
const appsSdkResources = allResources.filter(
|
|
2587
|
+
(r) => r.mime_type === "text/html+skybridge"
|
|
2588
|
+
);
|
|
2589
|
+
const mcpUiResources = allResources.filter(
|
|
2590
|
+
(r) => r.mime_type === "text/uri-list" || r.mime_type === "text/html"
|
|
2591
|
+
);
|
|
2592
|
+
const mcpAppsResources = allResources.filter(
|
|
2593
|
+
(r) => r.mime_type === "text/html+mcp"
|
|
2594
|
+
);
|
|
2595
|
+
return {
|
|
2596
|
+
transport,
|
|
2597
|
+
toolsNumber: server.registeredTools.length,
|
|
2598
|
+
resourcesNumber: server.registeredResources.length,
|
|
2599
|
+
promptsNumber: server.registeredPrompts.length,
|
|
2600
|
+
auth: !!server.oauthProvider,
|
|
2601
|
+
name: server.config.name,
|
|
2602
|
+
description: server.config.description ?? null,
|
|
2603
|
+
baseUrl: server.serverBaseUrl ?? null,
|
|
2604
|
+
toolNames: server.registeredTools.length > 0 ? server.registeredTools : null,
|
|
2605
|
+
resourceNames: server.registeredResources.length > 0 ? server.registeredResources : null,
|
|
2606
|
+
promptNames: server.registeredPrompts.length > 0 ? server.registeredPrompts : null,
|
|
2607
|
+
tools: toolRegistrations.length > 0 ? toolRegistrations.map((r) => ({
|
|
2608
|
+
name: r.config.name,
|
|
2609
|
+
title: r.config.title ?? null,
|
|
2610
|
+
description: r.config.description ?? null,
|
|
2611
|
+
input_schema: r.config.schema ? JSON.stringify(r.config.schema) : null,
|
|
2612
|
+
output_schema: r.config.outputSchema ? JSON.stringify(r.config.outputSchema) : null
|
|
2613
|
+
})) : null,
|
|
2614
|
+
resources: allResources.length > 0 ? allResources : null,
|
|
2615
|
+
prompts: promptRegistrations.length > 0 ? promptRegistrations.map((r) => ({
|
|
2616
|
+
name: r.config.name,
|
|
2617
|
+
title: r.config.title ?? null,
|
|
2618
|
+
description: r.config.description ?? null,
|
|
2619
|
+
args: r.config.args ? JSON.stringify(r.config.args) : null
|
|
2620
|
+
})) : null,
|
|
2621
|
+
templates: templateRegistrations.length > 0 ? templateRegistrations.map((r) => ({
|
|
2622
|
+
name: r.config.name,
|
|
2623
|
+
title: r.config.title ?? null,
|
|
2624
|
+
description: r.config.description ?? null
|
|
2625
|
+
})) : null,
|
|
2626
|
+
capabilities: {
|
|
2627
|
+
logging: true,
|
|
2628
|
+
resources: { subscribe: true, listChanged: true }
|
|
2629
|
+
},
|
|
2630
|
+
appsSdkResources: appsSdkResources.length > 0 ? appsSdkResources : null,
|
|
2631
|
+
appsSdkResourcesNumber: appsSdkResources.length,
|
|
2632
|
+
mcpUiResources: mcpUiResources.length > 0 ? mcpUiResources : null,
|
|
2633
|
+
mcpUiResourcesNumber: mcpUiResources.length,
|
|
2634
|
+
mcpAppsResources: mcpAppsResources.length > 0 ? mcpAppsResources : null,
|
|
2635
|
+
mcpAppsResourcesNumber: mcpAppsResources.length
|
|
2636
|
+
};
|
|
2637
|
+
}
|
|
2638
|
+
__name(createServerRunEventData, "createServerRunEventData");
|
|
2639
|
+
var ServerRunEvent = class extends BaseTelemetryEvent {
|
|
2640
|
+
constructor(data) {
|
|
2641
|
+
super();
|
|
2642
|
+
this.data = data;
|
|
2643
|
+
}
|
|
2644
|
+
static {
|
|
2645
|
+
__name(this, "ServerRunEvent");
|
|
2646
|
+
}
|
|
2647
|
+
get name() {
|
|
2648
|
+
return "server_run";
|
|
2649
|
+
}
|
|
2650
|
+
get properties() {
|
|
2651
|
+
return {
|
|
2652
|
+
transport: this.data.transport,
|
|
2653
|
+
tools_number: this.data.toolsNumber,
|
|
2654
|
+
resources_number: this.data.resourcesNumber,
|
|
2655
|
+
prompts_number: this.data.promptsNumber,
|
|
2656
|
+
auth: this.data.auth,
|
|
2657
|
+
name: this.data.name,
|
|
2658
|
+
description: this.data.description ?? null,
|
|
2659
|
+
base_url: this.data.baseUrl ?? null,
|
|
2660
|
+
tool_names: this.data.toolNames ?? null,
|
|
2661
|
+
resource_names: this.data.resourceNames ?? null,
|
|
2662
|
+
prompt_names: this.data.promptNames ?? null,
|
|
2663
|
+
tools: this.data.tools ?? null,
|
|
2664
|
+
resources: this.data.resources ?? null,
|
|
2665
|
+
prompts: this.data.prompts ?? null,
|
|
2666
|
+
templates: this.data.templates ?? null,
|
|
2667
|
+
capabilities: this.data.capabilities ? JSON.stringify(this.data.capabilities) : null,
|
|
2668
|
+
apps_sdk_resources: this.data.appsSdkResources ? JSON.stringify(this.data.appsSdkResources) : null,
|
|
2669
|
+
apps_sdk_resources_number: this.data.appsSdkResourcesNumber ?? 0,
|
|
2670
|
+
mcp_ui_resources: this.data.mcpUiResources ? JSON.stringify(this.data.mcpUiResources) : null,
|
|
2671
|
+
mcp_ui_resources_number: this.data.mcpUiResourcesNumber ?? 0,
|
|
2672
|
+
mcp_apps_resources: this.data.mcpAppsResources ? JSON.stringify(this.data.mcpAppsResources) : null,
|
|
2673
|
+
mcp_apps_resources_number: this.data.mcpAppsResourcesNumber ?? 0
|
|
2674
|
+
};
|
|
2675
|
+
}
|
|
2676
|
+
};
|
|
2677
|
+
var ServerInitializeEvent = class extends BaseTelemetryEvent {
|
|
2678
|
+
constructor(data) {
|
|
2679
|
+
super();
|
|
2680
|
+
this.data = data;
|
|
2681
|
+
}
|
|
2682
|
+
static {
|
|
2683
|
+
__name(this, "ServerInitializeEvent");
|
|
2684
|
+
}
|
|
2685
|
+
get name() {
|
|
2686
|
+
return "server_initialize_call";
|
|
2687
|
+
}
|
|
2688
|
+
get properties() {
|
|
2689
|
+
return {
|
|
2690
|
+
protocol_version: this.data.protocolVersion,
|
|
2691
|
+
client_info: JSON.stringify(this.data.clientInfo),
|
|
2692
|
+
client_capabilities: JSON.stringify(this.data.clientCapabilities),
|
|
2693
|
+
session_id: this.data.sessionId ?? null
|
|
2694
|
+
};
|
|
2695
|
+
}
|
|
2696
|
+
};
|
|
2697
|
+
var ServerToolCallEvent = class extends BaseTelemetryEvent {
|
|
2698
|
+
constructor(data) {
|
|
2699
|
+
super();
|
|
2700
|
+
this.data = data;
|
|
2701
|
+
}
|
|
2702
|
+
static {
|
|
2703
|
+
__name(this, "ServerToolCallEvent");
|
|
2704
|
+
}
|
|
2705
|
+
get name() {
|
|
2706
|
+
return "server_tool_call";
|
|
2707
|
+
}
|
|
2708
|
+
get properties() {
|
|
2709
|
+
return {
|
|
2710
|
+
tool_name: this.data.toolName,
|
|
2711
|
+
length_input_argument: this.data.lengthInputArgument,
|
|
2712
|
+
success: this.data.success,
|
|
2713
|
+
error_type: this.data.errorType ?? null,
|
|
2714
|
+
execution_time_ms: this.data.executionTimeMs ?? null
|
|
2715
|
+
};
|
|
2716
|
+
}
|
|
2717
|
+
};
|
|
2718
|
+
var ServerResourceCallEvent = class extends BaseTelemetryEvent {
|
|
2719
|
+
constructor(data) {
|
|
2720
|
+
super();
|
|
2721
|
+
this.data = data;
|
|
2722
|
+
}
|
|
2723
|
+
static {
|
|
2724
|
+
__name(this, "ServerResourceCallEvent");
|
|
2725
|
+
}
|
|
2726
|
+
get name() {
|
|
2727
|
+
return "server_resource_call";
|
|
2728
|
+
}
|
|
2729
|
+
get properties() {
|
|
2730
|
+
return {
|
|
2731
|
+
name: this.data.name,
|
|
2732
|
+
description: this.data.description,
|
|
2733
|
+
contents: this.data.contents,
|
|
2734
|
+
success: this.data.success,
|
|
2735
|
+
error_type: this.data.errorType ?? null
|
|
2736
|
+
};
|
|
2737
|
+
}
|
|
2738
|
+
};
|
|
2739
|
+
var ServerPromptCallEvent = class extends BaseTelemetryEvent {
|
|
2740
|
+
constructor(data) {
|
|
2741
|
+
super();
|
|
2742
|
+
this.data = data;
|
|
2743
|
+
}
|
|
2744
|
+
static {
|
|
2745
|
+
__name(this, "ServerPromptCallEvent");
|
|
2746
|
+
}
|
|
2747
|
+
get name() {
|
|
2748
|
+
return "server_prompt_call";
|
|
2749
|
+
}
|
|
2750
|
+
get properties() {
|
|
2751
|
+
return {
|
|
2752
|
+
name: this.data.name,
|
|
2753
|
+
description: this.data.description,
|
|
2754
|
+
success: this.data.success,
|
|
2755
|
+
error_type: this.data.errorType ?? null
|
|
2756
|
+
};
|
|
2757
|
+
}
|
|
2758
|
+
};
|
|
2759
|
+
var ServerContextEvent = class extends BaseTelemetryEvent {
|
|
2760
|
+
constructor(data) {
|
|
2761
|
+
super();
|
|
2762
|
+
this.data = data;
|
|
2763
|
+
}
|
|
2764
|
+
static {
|
|
2765
|
+
__name(this, "ServerContextEvent");
|
|
2766
|
+
}
|
|
2767
|
+
get name() {
|
|
2768
|
+
return `server_context_${this.data.contextType}`;
|
|
2769
|
+
}
|
|
2770
|
+
get properties() {
|
|
2771
|
+
return {
|
|
2772
|
+
context_type: this.data.contextType,
|
|
2773
|
+
notification_type: this.data.notificationType ?? null
|
|
2774
|
+
};
|
|
2775
|
+
}
|
|
2776
|
+
};
|
|
2777
|
+
var MCPClientInitEvent = class extends BaseTelemetryEvent {
|
|
2778
|
+
constructor(data) {
|
|
2779
|
+
super();
|
|
2780
|
+
this.data = data;
|
|
2781
|
+
}
|
|
2782
|
+
static {
|
|
2783
|
+
__name(this, "MCPClientInitEvent");
|
|
2784
|
+
}
|
|
2785
|
+
get name() {
|
|
2786
|
+
return "mcpclient_init";
|
|
2787
|
+
}
|
|
2788
|
+
get properties() {
|
|
2789
|
+
return {
|
|
2790
|
+
code_mode: this.data.codeMode,
|
|
2791
|
+
sandbox: this.data.sandbox,
|
|
2792
|
+
all_callbacks: this.data.allCallbacks,
|
|
2793
|
+
verify: this.data.verify,
|
|
2794
|
+
servers: this.data.servers,
|
|
2795
|
+
num_servers: this.data.numServers,
|
|
2796
|
+
is_browser: this.data.isBrowser
|
|
2797
|
+
};
|
|
2798
|
+
}
|
|
2799
|
+
};
|
|
2800
|
+
var ConnectorInitEvent = class extends BaseTelemetryEvent {
|
|
2801
|
+
constructor(data) {
|
|
2802
|
+
super();
|
|
2803
|
+
this.data = data;
|
|
2804
|
+
}
|
|
2805
|
+
static {
|
|
2806
|
+
__name(this, "ConnectorInitEvent");
|
|
2807
|
+
}
|
|
2808
|
+
get name() {
|
|
2809
|
+
return "connector_init";
|
|
2810
|
+
}
|
|
2811
|
+
get properties() {
|
|
2812
|
+
return {
|
|
2813
|
+
connector_type: this.data.connectorType,
|
|
2814
|
+
server_command: this.data.serverCommand ?? null,
|
|
2815
|
+
server_args: this.data.serverArgs ?? null,
|
|
2816
|
+
server_url: this.data.serverUrl ?? null,
|
|
2817
|
+
public_identifier: this.data.publicIdentifier ?? null
|
|
2818
|
+
};
|
|
2819
|
+
}
|
|
2820
|
+
};
|
|
2821
|
+
var ClientAddServerEvent = class extends BaseTelemetryEvent {
|
|
2822
|
+
constructor(data) {
|
|
2823
|
+
super();
|
|
2824
|
+
this.data = data;
|
|
2825
|
+
}
|
|
2826
|
+
static {
|
|
2827
|
+
__name(this, "ClientAddServerEvent");
|
|
2828
|
+
}
|
|
2829
|
+
get name() {
|
|
2830
|
+
return "client_add_server";
|
|
2831
|
+
}
|
|
2832
|
+
get properties() {
|
|
2833
|
+
const { serverName, serverConfig } = this.data;
|
|
2834
|
+
const url = serverConfig.url;
|
|
2835
|
+
return {
|
|
2836
|
+
server_name: serverName,
|
|
2837
|
+
server_url_domain: url ? this._extractHostname(url) : null,
|
|
2838
|
+
transport: serverConfig.transport ?? null,
|
|
2839
|
+
has_auth: !!(serverConfig.authToken || serverConfig.authProvider)
|
|
2840
|
+
};
|
|
2841
|
+
}
|
|
2842
|
+
_extractHostname(url) {
|
|
2843
|
+
try {
|
|
2844
|
+
return new URL(url).hostname;
|
|
2845
|
+
} catch {
|
|
2846
|
+
return null;
|
|
2589
2847
|
}
|
|
2590
|
-
const packagePath = path.join(__dirname, "../../package.json");
|
|
2591
|
-
const packageJson = JSON.parse(fs.readFileSync(packagePath, "utf-8"));
|
|
2592
|
-
return packageJson.version || "unknown";
|
|
2593
|
-
} catch {
|
|
2594
|
-
return "unknown";
|
|
2595
2848
|
}
|
|
2849
|
+
};
|
|
2850
|
+
var ClientRemoveServerEvent = class extends BaseTelemetryEvent {
|
|
2851
|
+
constructor(data) {
|
|
2852
|
+
super();
|
|
2853
|
+
this.data = data;
|
|
2854
|
+
}
|
|
2855
|
+
static {
|
|
2856
|
+
__name(this, "ClientRemoveServerEvent");
|
|
2857
|
+
}
|
|
2858
|
+
get name() {
|
|
2859
|
+
return "client_remove_server";
|
|
2860
|
+
}
|
|
2861
|
+
get properties() {
|
|
2862
|
+
return {
|
|
2863
|
+
server_name: this.data.serverName
|
|
2864
|
+
};
|
|
2865
|
+
}
|
|
2866
|
+
};
|
|
2867
|
+
|
|
2868
|
+
// src/server/utils/runtime.ts
|
|
2869
|
+
var isDeno = typeof globalThis.Deno !== "undefined";
|
|
2870
|
+
function generateUUID() {
|
|
2871
|
+
return globalThis.crypto.randomUUID();
|
|
2872
|
+
}
|
|
2873
|
+
__name(generateUUID, "generateUUID");
|
|
2874
|
+
|
|
2875
|
+
// src/telemetry/telemetry.ts
|
|
2876
|
+
init_logging();
|
|
2877
|
+
|
|
2878
|
+
// src/version.ts
|
|
2879
|
+
var VERSION = "1.10.0-canary.11";
|
|
2880
|
+
function getPackageVersion() {
|
|
2881
|
+
return VERSION;
|
|
2596
2882
|
}
|
|
2597
2883
|
__name(getPackageVersion, "getPackageVersion");
|
|
2884
|
+
|
|
2885
|
+
// src/telemetry/utils.ts
|
|
2598
2886
|
function getModelProvider(llm) {
|
|
2599
2887
|
return llm._llm_type || llm.constructor.name.toLowerCase();
|
|
2600
2888
|
}
|
|
@@ -2627,22 +2915,63 @@ function extractModelInfo(llm) {
|
|
|
2627
2915
|
__name(extractModelInfo, "extractModelInfo");
|
|
2628
2916
|
|
|
2629
2917
|
// src/telemetry/telemetry.ts
|
|
2630
|
-
|
|
2918
|
+
var USER_ID_STORAGE_KEY = "mcp_use_user_id";
|
|
2919
|
+
function detectRuntimeEnvironment() {
|
|
2631
2920
|
try {
|
|
2921
|
+
if (typeof globalThis.Bun !== "undefined") {
|
|
2922
|
+
return "bun";
|
|
2923
|
+
}
|
|
2924
|
+
if (typeof globalThis.Deno !== "undefined") {
|
|
2925
|
+
return "deno";
|
|
2926
|
+
}
|
|
2632
2927
|
if (typeof navigator !== "undefined" && navigator.userAgent?.includes("Cloudflare-Workers")) {
|
|
2633
|
-
return
|
|
2928
|
+
return "cloudflare-workers";
|
|
2634
2929
|
}
|
|
2635
|
-
if (typeof globalThis.EdgeRuntime !== "undefined"
|
|
2636
|
-
return
|
|
2930
|
+
if (typeof globalThis.EdgeRuntime !== "undefined") {
|
|
2931
|
+
return "edge";
|
|
2637
2932
|
}
|
|
2638
|
-
|
|
2639
|
-
|
|
2640
|
-
|
|
2933
|
+
if (typeof window !== "undefined" && typeof document !== "undefined") {
|
|
2934
|
+
return "browser";
|
|
2935
|
+
}
|
|
2936
|
+
if (typeof process !== "undefined" && typeof process.versions?.node !== "undefined") {
|
|
2937
|
+
return "node";
|
|
2938
|
+
}
|
|
2939
|
+
return "unknown";
|
|
2641
2940
|
} catch {
|
|
2642
|
-
return
|
|
2941
|
+
return "unknown";
|
|
2942
|
+
}
|
|
2943
|
+
}
|
|
2944
|
+
__name(detectRuntimeEnvironment, "detectRuntimeEnvironment");
|
|
2945
|
+
function getStorageCapability(env) {
|
|
2946
|
+
switch (env) {
|
|
2947
|
+
case "node":
|
|
2948
|
+
case "bun":
|
|
2949
|
+
return "filesystem";
|
|
2950
|
+
case "browser":
|
|
2951
|
+
try {
|
|
2952
|
+
if (typeof localStorage !== "undefined") {
|
|
2953
|
+
localStorage.setItem("__mcp_use_test__", "1");
|
|
2954
|
+
localStorage.removeItem("__mcp_use_test__");
|
|
2955
|
+
return "localStorage";
|
|
2956
|
+
}
|
|
2957
|
+
} catch {
|
|
2958
|
+
}
|
|
2959
|
+
return "session-only";
|
|
2960
|
+
case "deno":
|
|
2961
|
+
return "session-only";
|
|
2962
|
+
default:
|
|
2963
|
+
return "session-only";
|
|
2964
|
+
}
|
|
2965
|
+
}
|
|
2966
|
+
__name(getStorageCapability, "getStorageCapability");
|
|
2967
|
+
var cachedEnvironment = null;
|
|
2968
|
+
function getRuntimeEnvironment() {
|
|
2969
|
+
if (cachedEnvironment === null) {
|
|
2970
|
+
cachedEnvironment = detectRuntimeEnvironment();
|
|
2643
2971
|
}
|
|
2972
|
+
return cachedEnvironment;
|
|
2644
2973
|
}
|
|
2645
|
-
__name(
|
|
2974
|
+
__name(getRuntimeEnvironment, "getRuntimeEnvironment");
|
|
2646
2975
|
var ScarfEventLogger = class {
|
|
2647
2976
|
static {
|
|
2648
2977
|
__name(this, "ScarfEventLogger");
|
|
@@ -2674,79 +3003,49 @@ var ScarfEventLogger = class {
|
|
|
2674
3003
|
}
|
|
2675
3004
|
}
|
|
2676
3005
|
};
|
|
2677
|
-
function getCacheHome() {
|
|
2678
|
-
if (!isNodeJSEnvironment2()) {
|
|
2679
|
-
return "/tmp/mcp_use_cache";
|
|
2680
|
-
}
|
|
2681
|
-
const envVar = process.env.XDG_CACHE_HOME;
|
|
2682
|
-
if (envVar && path2.isAbsolute(envVar)) {
|
|
2683
|
-
return envVar;
|
|
2684
|
-
}
|
|
2685
|
-
const platform = process.platform;
|
|
2686
|
-
const homeDir = os.homedir();
|
|
2687
|
-
if (platform === "win32") {
|
|
2688
|
-
const appdata = process.env.LOCALAPPDATA || process.env.APPDATA;
|
|
2689
|
-
if (appdata) {
|
|
2690
|
-
return appdata;
|
|
2691
|
-
}
|
|
2692
|
-
return path2.join(homeDir, "AppData", "Local");
|
|
2693
|
-
} else if (platform === "darwin") {
|
|
2694
|
-
return path2.join(homeDir, "Library", "Caches");
|
|
2695
|
-
} else {
|
|
2696
|
-
return path2.join(homeDir, ".cache");
|
|
2697
|
-
}
|
|
2698
|
-
}
|
|
2699
|
-
__name(getCacheHome, "getCacheHome");
|
|
2700
3006
|
var Telemetry = class _Telemetry {
|
|
2701
3007
|
static {
|
|
2702
3008
|
__name(this, "Telemetry");
|
|
2703
3009
|
}
|
|
2704
3010
|
static instance = null;
|
|
2705
|
-
USER_ID_PATH = path2.join(
|
|
2706
|
-
getCacheHome(),
|
|
2707
|
-
"mcp_use_3",
|
|
2708
|
-
"telemetry_user_id"
|
|
2709
|
-
);
|
|
2710
|
-
VERSION_DOWNLOAD_PATH = path2.join(
|
|
2711
|
-
getCacheHome(),
|
|
2712
|
-
"mcp_use",
|
|
2713
|
-
"download_version"
|
|
2714
|
-
);
|
|
2715
3011
|
PROJECT_API_KEY = "phc_lyTtbYwvkdSbrcMQNPiKiiRWrrM1seyKIMjycSvItEI";
|
|
2716
3012
|
HOST = "https://eu.i.posthog.com";
|
|
2717
3013
|
SCARF_GATEWAY_URL = "https://mcpuse.gateway.scarf.sh/events-ts";
|
|
2718
3014
|
UNKNOWN_USER_ID = "UNKNOWN_USER_ID";
|
|
2719
3015
|
_currUserId = null;
|
|
2720
|
-
|
|
3016
|
+
_posthogNodeClient = null;
|
|
3017
|
+
_posthogBrowserClient = null;
|
|
3018
|
+
_posthogLoading = null;
|
|
2721
3019
|
_scarfClient = null;
|
|
2722
|
-
|
|
3020
|
+
_runtimeEnvironment;
|
|
3021
|
+
_storageCapability;
|
|
3022
|
+
_source;
|
|
3023
|
+
// Node.js specific paths (lazily computed)
|
|
3024
|
+
_userIdPath = null;
|
|
3025
|
+
_versionDownloadPath = null;
|
|
2723
3026
|
constructor() {
|
|
2724
|
-
|
|
2725
|
-
|
|
2726
|
-
this._source = typeof process !== "undefined" && process.env?.MCP_USE_TELEMETRY_SOURCE ||
|
|
3027
|
+
this._runtimeEnvironment = getRuntimeEnvironment();
|
|
3028
|
+
this._storageCapability = getStorageCapability(this._runtimeEnvironment);
|
|
3029
|
+
this._source = typeof process !== "undefined" && process.env?.MCP_USE_TELEMETRY_SOURCE || this._runtimeEnvironment;
|
|
3030
|
+
const telemetryDisabled = this._checkTelemetryDisabled();
|
|
3031
|
+
const canSupportTelemetry = this._runtimeEnvironment !== "unknown";
|
|
2727
3032
|
if (telemetryDisabled) {
|
|
2728
|
-
this.
|
|
3033
|
+
this._posthogNodeClient = null;
|
|
3034
|
+
this._posthogBrowserClient = null;
|
|
2729
3035
|
this._scarfClient = null;
|
|
2730
|
-
logger.debug("Telemetry disabled via environment
|
|
2731
|
-
} else if (!
|
|
2732
|
-
this.
|
|
3036
|
+
logger.debug("Telemetry disabled via environment/localStorage");
|
|
3037
|
+
} else if (!canSupportTelemetry) {
|
|
3038
|
+
this._posthogNodeClient = null;
|
|
3039
|
+
this._posthogBrowserClient = null;
|
|
2733
3040
|
this._scarfClient = null;
|
|
2734
3041
|
logger.debug(
|
|
2735
|
-
|
|
3042
|
+
`Telemetry disabled - unknown environment: ${this._runtimeEnvironment}`
|
|
2736
3043
|
);
|
|
2737
3044
|
} else {
|
|
2738
3045
|
logger.info(
|
|
2739
3046
|
"Anonymized telemetry enabled. Set MCP_USE_ANONYMIZED_TELEMETRY=false to disable."
|
|
2740
3047
|
);
|
|
2741
|
-
|
|
2742
|
-
this._posthogClient = new import_posthog_node.PostHog(this.PROJECT_API_KEY, {
|
|
2743
|
-
host: this.HOST,
|
|
2744
|
-
disableGeoip: false
|
|
2745
|
-
});
|
|
2746
|
-
} catch (e) {
|
|
2747
|
-
logger.warn(`Failed to initialize PostHog telemetry: ${e}`);
|
|
2748
|
-
this._posthogClient = null;
|
|
2749
|
-
}
|
|
3048
|
+
this._posthogLoading = this._initPostHog();
|
|
2750
3049
|
try {
|
|
2751
3050
|
this._scarfClient = new ScarfEventLogger(this.SCARF_GATEWAY_URL, 3e3);
|
|
2752
3051
|
} catch (e) {
|
|
@@ -2755,6 +3054,87 @@ var Telemetry = class _Telemetry {
|
|
|
2755
3054
|
}
|
|
2756
3055
|
}
|
|
2757
3056
|
}
|
|
3057
|
+
_checkTelemetryDisabled() {
|
|
3058
|
+
if (typeof process !== "undefined" && process.env?.MCP_USE_ANONYMIZED_TELEMETRY?.toLowerCase() === "false") {
|
|
3059
|
+
return true;
|
|
3060
|
+
}
|
|
3061
|
+
if (typeof localStorage !== "undefined" && localStorage.getItem("MCP_USE_ANONYMIZED_TELEMETRY") === "false") {
|
|
3062
|
+
return true;
|
|
3063
|
+
}
|
|
3064
|
+
return false;
|
|
3065
|
+
}
|
|
3066
|
+
async _initPostHog() {
|
|
3067
|
+
const isBrowser = this._runtimeEnvironment === "browser";
|
|
3068
|
+
if (isBrowser) {
|
|
3069
|
+
await this._initPostHogBrowser();
|
|
3070
|
+
} else {
|
|
3071
|
+
await this._initPostHogNode();
|
|
3072
|
+
}
|
|
3073
|
+
}
|
|
3074
|
+
async _initPostHogBrowser() {
|
|
3075
|
+
try {
|
|
3076
|
+
const posthogModule = await import("posthog-js");
|
|
3077
|
+
const posthog = posthogModule.default || posthogModule.posthog;
|
|
3078
|
+
if (!posthog || typeof posthog.init !== "function") {
|
|
3079
|
+
throw new Error("posthog-js module did not export expected interface");
|
|
3080
|
+
}
|
|
3081
|
+
posthog.init(this.PROJECT_API_KEY, {
|
|
3082
|
+
api_host: this.HOST,
|
|
3083
|
+
persistence: "localStorage",
|
|
3084
|
+
autocapture: false,
|
|
3085
|
+
// We only want explicit captures
|
|
3086
|
+
capture_pageview: false,
|
|
3087
|
+
// We don't want automatic pageview tracking
|
|
3088
|
+
disable_session_recording: true,
|
|
3089
|
+
// No session recording
|
|
3090
|
+
loaded: /* @__PURE__ */ __name(() => {
|
|
3091
|
+
logger.debug("PostHog browser client initialized");
|
|
3092
|
+
}, "loaded")
|
|
3093
|
+
});
|
|
3094
|
+
this._posthogBrowserClient = posthog;
|
|
3095
|
+
} catch (e) {
|
|
3096
|
+
logger.warn(`Failed to initialize PostHog browser telemetry: ${e}`);
|
|
3097
|
+
this._posthogBrowserClient = null;
|
|
3098
|
+
}
|
|
3099
|
+
}
|
|
3100
|
+
async _initPostHogNode() {
|
|
3101
|
+
try {
|
|
3102
|
+
const { PostHog } = await import("posthog-node");
|
|
3103
|
+
const isServerlessEnvironment = [
|
|
3104
|
+
"cloudflare-workers",
|
|
3105
|
+
"edge",
|
|
3106
|
+
"deno"
|
|
3107
|
+
].includes(this._runtimeEnvironment);
|
|
3108
|
+
const posthogOptions = {
|
|
3109
|
+
host: this.HOST,
|
|
3110
|
+
disableGeoip: false
|
|
3111
|
+
};
|
|
3112
|
+
if (isServerlessEnvironment) {
|
|
3113
|
+
posthogOptions.flushAt = 1;
|
|
3114
|
+
posthogOptions.flushInterval = 0;
|
|
3115
|
+
}
|
|
3116
|
+
this._posthogNodeClient = new PostHog(
|
|
3117
|
+
this.PROJECT_API_KEY,
|
|
3118
|
+
posthogOptions
|
|
3119
|
+
);
|
|
3120
|
+
logger.debug("PostHog Node.js client initialized");
|
|
3121
|
+
} catch (e) {
|
|
3122
|
+
logger.warn(`Failed to initialize PostHog Node.js telemetry: ${e}`);
|
|
3123
|
+
this._posthogNodeClient = null;
|
|
3124
|
+
}
|
|
3125
|
+
}
|
|
3126
|
+
/**
|
|
3127
|
+
* Get the detected runtime environment
|
|
3128
|
+
*/
|
|
3129
|
+
get runtimeEnvironment() {
|
|
3130
|
+
return this._runtimeEnvironment;
|
|
3131
|
+
}
|
|
3132
|
+
/**
|
|
3133
|
+
* Get the storage capability for this environment
|
|
3134
|
+
*/
|
|
3135
|
+
get storageCapability() {
|
|
3136
|
+
return this._storageCapability;
|
|
3137
|
+
}
|
|
2758
3138
|
static getInstance() {
|
|
2759
3139
|
if (!_Telemetry.instance) {
|
|
2760
3140
|
_Telemetry.instance = new _Telemetry();
|
|
@@ -2776,92 +3156,201 @@ var Telemetry = class _Telemetry {
|
|
|
2776
3156
|
getSource() {
|
|
2777
3157
|
return this._source;
|
|
2778
3158
|
}
|
|
3159
|
+
/**
|
|
3160
|
+
* Check if telemetry is enabled.
|
|
3161
|
+
*/
|
|
3162
|
+
get isEnabled() {
|
|
3163
|
+
return this._posthogNodeClient !== null || this._posthogBrowserClient !== null || this._scarfClient !== null;
|
|
3164
|
+
}
|
|
2779
3165
|
get userId() {
|
|
2780
3166
|
if (this._currUserId) {
|
|
2781
3167
|
return this._currUserId;
|
|
2782
3168
|
}
|
|
2783
|
-
if (!isNodeJSEnvironment2()) {
|
|
2784
|
-
this._currUserId = this.UNKNOWN_USER_ID;
|
|
2785
|
-
return this._currUserId;
|
|
2786
|
-
}
|
|
2787
3169
|
try {
|
|
2788
|
-
|
|
2789
|
-
|
|
2790
|
-
|
|
2791
|
-
|
|
2792
|
-
|
|
2793
|
-
|
|
2794
|
-
|
|
2795
|
-
|
|
2796
|
-
|
|
2797
|
-
|
|
3170
|
+
switch (this._storageCapability) {
|
|
3171
|
+
case "filesystem":
|
|
3172
|
+
this._currUserId = this._getUserIdFromFilesystem();
|
|
3173
|
+
break;
|
|
3174
|
+
case "localStorage":
|
|
3175
|
+
this._currUserId = this._getUserIdFromLocalStorage();
|
|
3176
|
+
break;
|
|
3177
|
+
case "session-only":
|
|
3178
|
+
default:
|
|
3179
|
+
this._currUserId = `session-${generateUUID()}`;
|
|
3180
|
+
logger.debug(
|
|
3181
|
+
`Using session-based user ID (${this._runtimeEnvironment} environment)`
|
|
3182
|
+
);
|
|
3183
|
+
break;
|
|
3184
|
+
}
|
|
3185
|
+
if (this._storageCapability === "filesystem" && this._currUserId) {
|
|
3186
|
+
this._trackPackageDownloadInternal(this._currUserId, {
|
|
3187
|
+
triggered_by: "user_id_property"
|
|
3188
|
+
}).catch((e) => logger.debug(`Failed to track package download: ${e}`));
|
|
2798
3189
|
}
|
|
2799
|
-
this.trackPackageDownload({
|
|
2800
|
-
triggered_by: "user_id_property"
|
|
2801
|
-
}).catch((e) => logger.debug(`Failed to track package download: ${e}`));
|
|
2802
3190
|
} catch (e) {
|
|
2803
3191
|
logger.debug(`Failed to get/create user ID: ${e}`);
|
|
2804
3192
|
this._currUserId = this.UNKNOWN_USER_ID;
|
|
2805
3193
|
}
|
|
2806
3194
|
return this._currUserId;
|
|
2807
3195
|
}
|
|
3196
|
+
/**
|
|
3197
|
+
* Get or create user ID from filesystem (Node.js/Bun)
|
|
3198
|
+
*/
|
|
3199
|
+
_getUserIdFromFilesystem() {
|
|
3200
|
+
const fs2 = require("fs");
|
|
3201
|
+
const os = require("os");
|
|
3202
|
+
const path2 = require("path");
|
|
3203
|
+
if (!this._userIdPath) {
|
|
3204
|
+
this._userIdPath = path2.join(
|
|
3205
|
+
this._getCacheHome(os, path2),
|
|
3206
|
+
"mcp_use_3",
|
|
3207
|
+
"telemetry_user_id"
|
|
3208
|
+
);
|
|
3209
|
+
}
|
|
3210
|
+
const isFirstTime = !fs2.existsSync(this._userIdPath);
|
|
3211
|
+
if (isFirstTime) {
|
|
3212
|
+
logger.debug(`Creating user ID path: ${this._userIdPath}`);
|
|
3213
|
+
fs2.mkdirSync(path2.dirname(this._userIdPath), { recursive: true });
|
|
3214
|
+
const newUserId = generateUUID();
|
|
3215
|
+
fs2.writeFileSync(this._userIdPath, newUserId);
|
|
3216
|
+
logger.debug(`User ID path created: ${this._userIdPath}`);
|
|
3217
|
+
return newUserId;
|
|
3218
|
+
}
|
|
3219
|
+
return fs2.readFileSync(this._userIdPath, "utf-8").trim();
|
|
3220
|
+
}
|
|
3221
|
+
/**
|
|
3222
|
+
* Get or create user ID from localStorage (Browser)
|
|
3223
|
+
*/
|
|
3224
|
+
_getUserIdFromLocalStorage() {
|
|
3225
|
+
try {
|
|
3226
|
+
let userId = localStorage.getItem(USER_ID_STORAGE_KEY);
|
|
3227
|
+
if (!userId) {
|
|
3228
|
+
userId = generateUUID();
|
|
3229
|
+
localStorage.setItem(USER_ID_STORAGE_KEY, userId);
|
|
3230
|
+
logger.debug(`Created new browser user ID`);
|
|
3231
|
+
}
|
|
3232
|
+
return userId;
|
|
3233
|
+
} catch (e) {
|
|
3234
|
+
logger.debug(`localStorage access failed: ${e}`);
|
|
3235
|
+
return `session-${generateUUID()}`;
|
|
3236
|
+
}
|
|
3237
|
+
}
|
|
3238
|
+
_getCacheHome(os, path2) {
|
|
3239
|
+
const envVar = process.env.XDG_CACHE_HOME;
|
|
3240
|
+
if (envVar && path2.isAbsolute(envVar)) {
|
|
3241
|
+
return envVar;
|
|
3242
|
+
}
|
|
3243
|
+
const platform = process.platform;
|
|
3244
|
+
const homeDir = os.homedir();
|
|
3245
|
+
if (platform === "win32") {
|
|
3246
|
+
const appdata = process.env.LOCALAPPDATA || process.env.APPDATA;
|
|
3247
|
+
if (appdata) {
|
|
3248
|
+
return appdata;
|
|
3249
|
+
}
|
|
3250
|
+
return path2.join(homeDir, "AppData", "Local");
|
|
3251
|
+
} else if (platform === "darwin") {
|
|
3252
|
+
return path2.join(homeDir, "Library", "Caches");
|
|
3253
|
+
} else {
|
|
3254
|
+
return path2.join(homeDir, ".cache");
|
|
3255
|
+
}
|
|
3256
|
+
}
|
|
2808
3257
|
async capture(event) {
|
|
2809
|
-
if (
|
|
3258
|
+
if (this._posthogLoading) {
|
|
3259
|
+
await this._posthogLoading;
|
|
3260
|
+
}
|
|
3261
|
+
if (!this._posthogNodeClient && !this._posthogBrowserClient && !this._scarfClient) {
|
|
2810
3262
|
return;
|
|
2811
3263
|
}
|
|
2812
|
-
|
|
3264
|
+
const properties = { ...event.properties };
|
|
3265
|
+
properties.mcp_use_version = getPackageVersion();
|
|
3266
|
+
properties.language = "typescript";
|
|
3267
|
+
properties.source = this._source;
|
|
3268
|
+
properties.runtime = this._runtimeEnvironment;
|
|
3269
|
+
if (this._posthogNodeClient) {
|
|
2813
3270
|
try {
|
|
2814
|
-
|
|
2815
|
-
|
|
2816
|
-
properties.language = "typescript";
|
|
2817
|
-
properties.source = this._source;
|
|
2818
|
-
this._posthogClient.capture({
|
|
3271
|
+
logger.debug(`CAPTURE: PostHog Node Event ${event.name}`);
|
|
3272
|
+
this._posthogNodeClient.capture({
|
|
2819
3273
|
distinctId: this.userId,
|
|
2820
3274
|
event: event.name,
|
|
2821
3275
|
properties
|
|
2822
3276
|
});
|
|
2823
3277
|
} catch (e) {
|
|
2824
|
-
logger.debug(`Failed to track PostHog event ${event.name}: ${e}`);
|
|
3278
|
+
logger.debug(`Failed to track PostHog Node event ${event.name}: ${e}`);
|
|
3279
|
+
}
|
|
3280
|
+
}
|
|
3281
|
+
if (this._posthogBrowserClient) {
|
|
3282
|
+
try {
|
|
3283
|
+
logger.debug(`CAPTURE: PostHog Browser Event ${event.name}`);
|
|
3284
|
+
this._posthogBrowserClient.capture(event.name, {
|
|
3285
|
+
...properties,
|
|
3286
|
+
distinct_id: this.userId
|
|
3287
|
+
});
|
|
3288
|
+
} catch (e) {
|
|
3289
|
+
logger.debug(
|
|
3290
|
+
`Failed to track PostHog Browser event ${event.name}: ${e}`
|
|
3291
|
+
);
|
|
2825
3292
|
}
|
|
2826
3293
|
}
|
|
2827
3294
|
if (this._scarfClient) {
|
|
2828
3295
|
try {
|
|
2829
|
-
const
|
|
2830
|
-
|
|
2831
|
-
|
|
2832
|
-
|
|
2833
|
-
|
|
2834
|
-
|
|
2835
|
-
await this._scarfClient.logEvent(properties);
|
|
3296
|
+
const scarfProperties = {
|
|
3297
|
+
...properties,
|
|
3298
|
+
user_id: this.userId,
|
|
3299
|
+
event: event.name
|
|
3300
|
+
};
|
|
3301
|
+
await this._scarfClient.logEvent(scarfProperties);
|
|
2836
3302
|
} catch (e) {
|
|
2837
3303
|
logger.debug(`Failed to track Scarf event ${event.name}: ${e}`);
|
|
2838
3304
|
}
|
|
2839
3305
|
}
|
|
2840
3306
|
}
|
|
3307
|
+
// ============================================================================
|
|
3308
|
+
// Package Download Tracking (Node.js only)
|
|
3309
|
+
// ============================================================================
|
|
3310
|
+
/**
|
|
3311
|
+
* Track package download event.
|
|
3312
|
+
* This is a public wrapper that safely accesses userId.
|
|
3313
|
+
*/
|
|
2841
3314
|
async trackPackageDownload(properties) {
|
|
3315
|
+
return this._trackPackageDownloadInternal(this.userId, properties);
|
|
3316
|
+
}
|
|
3317
|
+
/**
|
|
3318
|
+
* Internal method to track package download with explicit userId.
|
|
3319
|
+
*/
|
|
3320
|
+
async _trackPackageDownloadInternal(userId, properties) {
|
|
2842
3321
|
if (!this._scarfClient) {
|
|
2843
3322
|
return;
|
|
2844
3323
|
}
|
|
2845
|
-
if (
|
|
3324
|
+
if (this._storageCapability !== "filesystem") {
|
|
2846
3325
|
return;
|
|
2847
3326
|
}
|
|
2848
3327
|
try {
|
|
3328
|
+
const fs2 = require("fs");
|
|
3329
|
+
const path2 = require("path");
|
|
3330
|
+
const os = require("os");
|
|
3331
|
+
if (!this._versionDownloadPath) {
|
|
3332
|
+
this._versionDownloadPath = path2.join(
|
|
3333
|
+
this._getCacheHome(os, path2),
|
|
3334
|
+
"mcp_use",
|
|
3335
|
+
"download_version"
|
|
3336
|
+
);
|
|
3337
|
+
}
|
|
2849
3338
|
const currentVersion = getPackageVersion();
|
|
2850
3339
|
let shouldTrack = false;
|
|
2851
3340
|
let firstDownload = false;
|
|
2852
|
-
if (!fs2.existsSync(this.
|
|
3341
|
+
if (!fs2.existsSync(this._versionDownloadPath)) {
|
|
2853
3342
|
shouldTrack = true;
|
|
2854
3343
|
firstDownload = true;
|
|
2855
|
-
fs2.mkdirSync(path2.dirname(this.
|
|
3344
|
+
fs2.mkdirSync(path2.dirname(this._versionDownloadPath), {
|
|
2856
3345
|
recursive: true
|
|
2857
3346
|
});
|
|
2858
|
-
fs2.writeFileSync(this.
|
|
3347
|
+
fs2.writeFileSync(this._versionDownloadPath, currentVersion);
|
|
2859
3348
|
} else {
|
|
2860
|
-
const savedVersion = fs2.readFileSync(this.
|
|
3349
|
+
const savedVersion = fs2.readFileSync(this._versionDownloadPath, "utf-8").trim();
|
|
2861
3350
|
if (currentVersion > savedVersion) {
|
|
2862
3351
|
shouldTrack = true;
|
|
2863
3352
|
firstDownload = false;
|
|
2864
|
-
fs2.writeFileSync(this.
|
|
3353
|
+
fs2.writeFileSync(this._versionDownloadPath, currentVersion);
|
|
2865
3354
|
}
|
|
2866
3355
|
}
|
|
2867
3356
|
if (shouldTrack) {
|
|
@@ -2870,52 +3359,193 @@ var Telemetry = class _Telemetry {
|
|
|
2870
3359
|
);
|
|
2871
3360
|
const eventProperties = { ...properties || {} };
|
|
2872
3361
|
eventProperties.mcp_use_version = currentVersion;
|
|
2873
|
-
eventProperties.user_id =
|
|
3362
|
+
eventProperties.user_id = userId;
|
|
2874
3363
|
eventProperties.event = "package_download";
|
|
2875
3364
|
eventProperties.first_download = firstDownload;
|
|
2876
3365
|
eventProperties.language = "typescript";
|
|
2877
3366
|
eventProperties.source = this._source;
|
|
3367
|
+
eventProperties.runtime = this._runtimeEnvironment;
|
|
2878
3368
|
await this._scarfClient.logEvent(eventProperties);
|
|
2879
3369
|
}
|
|
2880
3370
|
} catch (e) {
|
|
2881
3371
|
logger.debug(`Failed to track Scarf package_download event: ${e}`);
|
|
2882
3372
|
}
|
|
2883
3373
|
}
|
|
3374
|
+
// ============================================================================
|
|
3375
|
+
// Agent Events
|
|
3376
|
+
// ============================================================================
|
|
2884
3377
|
async trackAgentExecution(data) {
|
|
3378
|
+
if (!this.isEnabled) return;
|
|
2885
3379
|
const event = new MCPAgentExecutionEvent(data);
|
|
2886
3380
|
await this.capture(event);
|
|
2887
3381
|
}
|
|
3382
|
+
// ============================================================================
|
|
3383
|
+
// Server Events
|
|
3384
|
+
// ============================================================================
|
|
3385
|
+
/**
|
|
3386
|
+
* Track server run event directly from an MCPServer instance.
|
|
3387
|
+
*/
|
|
3388
|
+
async trackServerRunFromServer(server, transport) {
|
|
3389
|
+
if (!this.isEnabled) return;
|
|
3390
|
+
const data = createServerRunEventData(server, transport);
|
|
3391
|
+
const event = new ServerRunEvent(data);
|
|
3392
|
+
await this.capture(event);
|
|
3393
|
+
}
|
|
3394
|
+
async trackServerInitialize(data) {
|
|
3395
|
+
if (!this.isEnabled) return;
|
|
3396
|
+
const event = new ServerInitializeEvent(data);
|
|
3397
|
+
await this.capture(event);
|
|
3398
|
+
}
|
|
3399
|
+
async trackServerToolCall(data) {
|
|
3400
|
+
if (!this.isEnabled) return;
|
|
3401
|
+
const event = new ServerToolCallEvent(data);
|
|
3402
|
+
await this.capture(event);
|
|
3403
|
+
}
|
|
3404
|
+
async trackServerResourceCall(data) {
|
|
3405
|
+
if (!this.isEnabled) return;
|
|
3406
|
+
const event = new ServerResourceCallEvent(data);
|
|
3407
|
+
await this.capture(event);
|
|
3408
|
+
}
|
|
3409
|
+
async trackServerPromptCall(data) {
|
|
3410
|
+
if (!this.isEnabled) return;
|
|
3411
|
+
const event = new ServerPromptCallEvent(data);
|
|
3412
|
+
await this.capture(event);
|
|
3413
|
+
}
|
|
3414
|
+
async trackServerContext(data) {
|
|
3415
|
+
if (!this.isEnabled) return;
|
|
3416
|
+
const event = new ServerContextEvent(data);
|
|
3417
|
+
await this.capture(event);
|
|
3418
|
+
}
|
|
3419
|
+
// ============================================================================
|
|
3420
|
+
// Client Events
|
|
3421
|
+
// ============================================================================
|
|
3422
|
+
async trackMCPClientInit(data) {
|
|
3423
|
+
if (!this.isEnabled) return;
|
|
3424
|
+
const event = new MCPClientInitEvent(data);
|
|
3425
|
+
await this.capture(event);
|
|
3426
|
+
}
|
|
3427
|
+
async trackConnectorInit(data) {
|
|
3428
|
+
if (!this.isEnabled) return;
|
|
3429
|
+
const event = new ConnectorInitEvent(data);
|
|
3430
|
+
await this.capture(event);
|
|
3431
|
+
}
|
|
3432
|
+
async trackClientAddServer(serverName, serverConfig) {
|
|
3433
|
+
if (!this.isEnabled) return;
|
|
3434
|
+
const event = new ClientAddServerEvent({ serverName, serverConfig });
|
|
3435
|
+
await this.capture(event);
|
|
3436
|
+
}
|
|
3437
|
+
async trackClientRemoveServer(serverName) {
|
|
3438
|
+
if (!this.isEnabled) return;
|
|
3439
|
+
const event = new ClientRemoveServerEvent({ serverName });
|
|
3440
|
+
await this.capture(event);
|
|
3441
|
+
}
|
|
3442
|
+
// ============================================================================
|
|
3443
|
+
// React Hook / Browser specific events
|
|
3444
|
+
// ============================================================================
|
|
3445
|
+
async trackUseMcpConnection(data) {
|
|
3446
|
+
if (!this.isEnabled) return;
|
|
3447
|
+
await this.capture({
|
|
3448
|
+
name: "usemcp_connection",
|
|
3449
|
+
properties: {
|
|
3450
|
+
url_domain: new URL(data.url).hostname,
|
|
3451
|
+
// Only domain for privacy
|
|
3452
|
+
transport_type: data.transportType,
|
|
3453
|
+
success: data.success,
|
|
3454
|
+
error_type: data.errorType ?? null,
|
|
3455
|
+
connection_time_ms: data.connectionTimeMs ?? null,
|
|
3456
|
+
has_oauth: data.hasOAuth,
|
|
3457
|
+
has_sampling: data.hasSampling,
|
|
3458
|
+
has_elicitation: data.hasElicitation
|
|
3459
|
+
}
|
|
3460
|
+
});
|
|
3461
|
+
}
|
|
3462
|
+
async trackUseMcpToolCall(data) {
|
|
3463
|
+
if (!this.isEnabled) return;
|
|
3464
|
+
await this.capture({
|
|
3465
|
+
name: "usemcp_tool_call",
|
|
3466
|
+
properties: {
|
|
3467
|
+
tool_name: data.toolName,
|
|
3468
|
+
success: data.success,
|
|
3469
|
+
error_type: data.errorType ?? null,
|
|
3470
|
+
execution_time_ms: data.executionTimeMs ?? null
|
|
3471
|
+
}
|
|
3472
|
+
});
|
|
3473
|
+
}
|
|
3474
|
+
async trackUseMcpResourceRead(data) {
|
|
3475
|
+
if (!this.isEnabled) return;
|
|
3476
|
+
await this.capture({
|
|
3477
|
+
name: "usemcp_resource_read",
|
|
3478
|
+
properties: {
|
|
3479
|
+
resource_uri_scheme: data.resourceUri.split(":")[0],
|
|
3480
|
+
// Only scheme for privacy
|
|
3481
|
+
success: data.success,
|
|
3482
|
+
error_type: data.errorType ?? null
|
|
3483
|
+
}
|
|
3484
|
+
});
|
|
3485
|
+
}
|
|
3486
|
+
// ============================================================================
|
|
3487
|
+
// Browser-specific Methods
|
|
3488
|
+
// ============================================================================
|
|
3489
|
+
/**
|
|
3490
|
+
* Identify the current user (useful for linking sessions)
|
|
3491
|
+
* Browser only - no-op in Node.js
|
|
3492
|
+
*/
|
|
3493
|
+
identify(userId, properties) {
|
|
3494
|
+
if (this._posthogBrowserClient) {
|
|
3495
|
+
try {
|
|
3496
|
+
this._posthogBrowserClient.identify(userId, properties);
|
|
3497
|
+
} catch (e) {
|
|
3498
|
+
logger.debug(`Failed to identify user: ${e}`);
|
|
3499
|
+
}
|
|
3500
|
+
}
|
|
3501
|
+
}
|
|
3502
|
+
/**
|
|
3503
|
+
* Reset the user identity (useful for logout)
|
|
3504
|
+
* Browser only - no-op in Node.js
|
|
3505
|
+
*/
|
|
3506
|
+
reset() {
|
|
3507
|
+
if (this._posthogBrowserClient) {
|
|
3508
|
+
try {
|
|
3509
|
+
this._posthogBrowserClient.reset();
|
|
3510
|
+
} catch (e) {
|
|
3511
|
+
logger.debug(`Failed to reset user: ${e}`);
|
|
3512
|
+
}
|
|
3513
|
+
}
|
|
3514
|
+
this._currUserId = null;
|
|
3515
|
+
}
|
|
3516
|
+
// ============================================================================
|
|
3517
|
+
// Node.js-specific Methods
|
|
3518
|
+
// ============================================================================
|
|
3519
|
+
/**
|
|
3520
|
+
* Flush the telemetry queue (Node.js only)
|
|
3521
|
+
*/
|
|
2888
3522
|
flush() {
|
|
2889
|
-
if (this.
|
|
3523
|
+
if (this._posthogNodeClient) {
|
|
2890
3524
|
try {
|
|
2891
|
-
this.
|
|
3525
|
+
this._posthogNodeClient.flush();
|
|
2892
3526
|
logger.debug("PostHog client telemetry queue flushed");
|
|
2893
3527
|
} catch (e) {
|
|
2894
3528
|
logger.debug(`Failed to flush PostHog client: ${e}`);
|
|
2895
3529
|
}
|
|
2896
3530
|
}
|
|
2897
|
-
if (this._scarfClient) {
|
|
2898
|
-
logger.debug("Scarf telemetry events sent immediately (no flush needed)");
|
|
2899
|
-
}
|
|
2900
3531
|
}
|
|
3532
|
+
/**
|
|
3533
|
+
* Shutdown the telemetry client (Node.js only)
|
|
3534
|
+
*/
|
|
2901
3535
|
shutdown() {
|
|
2902
|
-
if (this.
|
|
3536
|
+
if (this._posthogNodeClient) {
|
|
2903
3537
|
try {
|
|
2904
|
-
this.
|
|
3538
|
+
this._posthogNodeClient.shutdown();
|
|
2905
3539
|
logger.debug("PostHog client shutdown successfully");
|
|
2906
3540
|
} catch (e) {
|
|
2907
3541
|
logger.debug(`Error shutting down PostHog client: ${e}`);
|
|
2908
3542
|
}
|
|
2909
3543
|
}
|
|
2910
|
-
if (this._scarfClient) {
|
|
2911
|
-
logger.debug("Scarf telemetry client shutdown (no action needed)");
|
|
2912
|
-
}
|
|
2913
3544
|
}
|
|
2914
3545
|
};
|
|
2915
|
-
|
|
2916
|
-
// src/telemetry/index.ts
|
|
3546
|
+
var Tel = Telemetry;
|
|
2917
3547
|
function setTelemetrySource(source) {
|
|
2918
|
-
|
|
3548
|
+
Tel.getInstance().setSource(source);
|
|
2919
3549
|
}
|
|
2920
3550
|
__name(setTelemetrySource, "setTelemetrySource");
|
|
2921
3551
|
|
|
@@ -3246,6 +3876,13 @@ var MCPAgent = class {
|
|
|
3246
3876
|
static {
|
|
3247
3877
|
__name(this, "MCPAgent");
|
|
3248
3878
|
}
|
|
3879
|
+
/**
|
|
3880
|
+
* Get the mcp-use package version.
|
|
3881
|
+
* Works in all environments (Node.js, browser, Cloudflare Workers, Deno, etc.)
|
|
3882
|
+
*/
|
|
3883
|
+
static getPackageVersion() {
|
|
3884
|
+
return getPackageVersion();
|
|
3885
|
+
}
|
|
3249
3886
|
llm;
|
|
3250
3887
|
client;
|
|
3251
3888
|
connectors;
|
|
@@ -3969,7 +4606,7 @@ var MCPAgent = class {
|
|
|
3969
4606
|
const historyToUse = externalHistory ?? this.conversationHistory;
|
|
3970
4607
|
const langchainHistory = [];
|
|
3971
4608
|
for (const msg of historyToUse) {
|
|
3972
|
-
if (this._isHumanMessageLike(msg) || this._isAIMessageLike(msg)) {
|
|
4609
|
+
if (this._isHumanMessageLike(msg) || this._isAIMessageLike(msg) || this._isToolMessageLike(msg)) {
|
|
3973
4610
|
langchainHistory.push(msg);
|
|
3974
4611
|
}
|
|
3975
4612
|
}
|
|
@@ -4102,9 +4739,9 @@ var MCPAgent = class {
|
|
|
4102
4739
|
}
|
|
4103
4740
|
}
|
|
4104
4741
|
if (this.memoryEnabled) {
|
|
4105
|
-
|
|
4106
|
-
|
|
4107
|
-
this.addToHistory(
|
|
4742
|
+
const newMessages = accumulatedMessages.slice(langchainHistory.length);
|
|
4743
|
+
for (const msg of newMessages) {
|
|
4744
|
+
this.addToHistory(msg);
|
|
4108
4745
|
}
|
|
4109
4746
|
}
|
|
4110
4747
|
if (outputSchema && finalOutput) {
|
|
@@ -4539,7 +5176,9 @@ ${formatPrompt}`
|
|
|
4539
5176
|
let chunkCount = 0;
|
|
4540
5177
|
for await (const chunk of stream) {
|
|
4541
5178
|
chunkCount++;
|
|
4542
|
-
logger.
|
|
5179
|
+
logger.debug(
|
|
5180
|
+
`Chunk ${chunkCount}: ${JSON.stringify(chunk, null, 2)}`
|
|
5181
|
+
);
|
|
4543
5182
|
if (typeof chunk === "string") {
|
|
4544
5183
|
try {
|
|
4545
5184
|
structuredResult = JSON.parse(chunk);
|
|
@@ -4556,7 +5195,9 @@ ${formatPrompt}`
|
|
|
4556
5195
|
}
|
|
4557
5196
|
}
|
|
4558
5197
|
if (chunkCount % 10 === 0) {
|
|
4559
|
-
logger.
|
|
5198
|
+
logger.debug(
|
|
5199
|
+
`\u{1F504} Structured output streaming: ${chunkCount} chunks`
|
|
5200
|
+
);
|
|
4560
5201
|
}
|
|
4561
5202
|
}
|
|
4562
5203
|
logger.info(
|
|
@@ -4723,6 +5364,190 @@ var MCPSession = class {
|
|
|
4723
5364
|
getRoots() {
|
|
4724
5365
|
return this.connector.getRoots();
|
|
4725
5366
|
}
|
|
5367
|
+
/**
|
|
5368
|
+
* Get the cached list of tools from the server.
|
|
5369
|
+
*
|
|
5370
|
+
* @returns Array of available tools
|
|
5371
|
+
*
|
|
5372
|
+
* @example
|
|
5373
|
+
* ```typescript
|
|
5374
|
+
* const tools = session.tools;
|
|
5375
|
+
* console.log(`Available tools: ${tools.map(t => t.name).join(", ")}`);
|
|
5376
|
+
* ```
|
|
5377
|
+
*/
|
|
5378
|
+
get tools() {
|
|
5379
|
+
return this.connector.tools;
|
|
5380
|
+
}
|
|
5381
|
+
/**
|
|
5382
|
+
* Get the server capabilities advertised during initialization.
|
|
5383
|
+
*
|
|
5384
|
+
* @returns Server capabilities object
|
|
5385
|
+
*/
|
|
5386
|
+
get serverCapabilities() {
|
|
5387
|
+
return this.connector.serverCapabilities;
|
|
5388
|
+
}
|
|
5389
|
+
/**
|
|
5390
|
+
* Get the server information (name and version).
|
|
5391
|
+
*
|
|
5392
|
+
* @returns Server info object or null if not available
|
|
5393
|
+
*/
|
|
5394
|
+
get serverInfo() {
|
|
5395
|
+
return this.connector.serverInfo;
|
|
5396
|
+
}
|
|
5397
|
+
/**
|
|
5398
|
+
* Call a tool on the server.
|
|
5399
|
+
*
|
|
5400
|
+
* @param name - Name of the tool to call
|
|
5401
|
+
* @param args - Arguments to pass to the tool
|
|
5402
|
+
* @param options - Optional request options (timeout, progress handlers, etc.)
|
|
5403
|
+
* @returns Result from the tool execution
|
|
5404
|
+
*
|
|
5405
|
+
* @example
|
|
5406
|
+
* ```typescript
|
|
5407
|
+
* const result = await session.callTool("add", { a: 5, b: 3 });
|
|
5408
|
+
* console.log(`Result: ${result.content[0].text}`);
|
|
5409
|
+
* ```
|
|
5410
|
+
*/
|
|
5411
|
+
async callTool(name, args, options) {
|
|
5412
|
+
return this.connector.callTool(name, args, options);
|
|
5413
|
+
}
|
|
5414
|
+
/**
|
|
5415
|
+
* List resources from the server with optional pagination.
|
|
5416
|
+
*
|
|
5417
|
+
* @param cursor - Optional cursor for pagination
|
|
5418
|
+
* @param options - Request options
|
|
5419
|
+
* @returns Resource list with optional nextCursor for pagination
|
|
5420
|
+
*
|
|
5421
|
+
* @example
|
|
5422
|
+
* ```typescript
|
|
5423
|
+
* const result = await session.listResources();
|
|
5424
|
+
* console.log(`Found ${result.resources.length} resources`);
|
|
5425
|
+
* ```
|
|
5426
|
+
*/
|
|
5427
|
+
async listResources(cursor, options) {
|
|
5428
|
+
return this.connector.listResources(cursor, options);
|
|
5429
|
+
}
|
|
5430
|
+
/**
|
|
5431
|
+
* List all resources from the server, automatically handling pagination.
|
|
5432
|
+
*
|
|
5433
|
+
* @param options - Request options
|
|
5434
|
+
* @returns Complete list of all resources
|
|
5435
|
+
*
|
|
5436
|
+
* @example
|
|
5437
|
+
* ```typescript
|
|
5438
|
+
* const result = await session.listAllResources();
|
|
5439
|
+
* console.log(`Total resources: ${result.resources.length}`);
|
|
5440
|
+
* ```
|
|
5441
|
+
*/
|
|
5442
|
+
async listAllResources(options) {
|
|
5443
|
+
return this.connector.listAllResources(options);
|
|
5444
|
+
}
|
|
5445
|
+
/**
|
|
5446
|
+
* List resource templates from the server.
|
|
5447
|
+
*
|
|
5448
|
+
* @param options - Request options
|
|
5449
|
+
* @returns List of available resource templates
|
|
5450
|
+
*
|
|
5451
|
+
* @example
|
|
5452
|
+
* ```typescript
|
|
5453
|
+
* const result = await session.listResourceTemplates();
|
|
5454
|
+
* console.log(`Available templates: ${result.resourceTemplates.length}`);
|
|
5455
|
+
* ```
|
|
5456
|
+
*/
|
|
5457
|
+
async listResourceTemplates(options) {
|
|
5458
|
+
return this.connector.listResourceTemplates(options);
|
|
5459
|
+
}
|
|
5460
|
+
/**
|
|
5461
|
+
* Read a resource by URI.
|
|
5462
|
+
*
|
|
5463
|
+
* @param uri - URI of the resource to read
|
|
5464
|
+
* @param options - Request options
|
|
5465
|
+
* @returns Resource content
|
|
5466
|
+
*
|
|
5467
|
+
* @example
|
|
5468
|
+
* ```typescript
|
|
5469
|
+
* const resource = await session.readResource("file:///path/to/file.txt");
|
|
5470
|
+
* console.log(resource.contents);
|
|
5471
|
+
* ```
|
|
5472
|
+
*/
|
|
5473
|
+
async readResource(uri, options) {
|
|
5474
|
+
return this.connector.readResource(uri, options);
|
|
5475
|
+
}
|
|
5476
|
+
/**
|
|
5477
|
+
* Subscribe to resource updates.
|
|
5478
|
+
*
|
|
5479
|
+
* @param uri - URI of the resource to subscribe to
|
|
5480
|
+
* @param options - Request options
|
|
5481
|
+
*
|
|
5482
|
+
* @example
|
|
5483
|
+
* ```typescript
|
|
5484
|
+
* await session.subscribeToResource("file:///path/to/file.txt");
|
|
5485
|
+
* // Now you'll receive notifications when this resource changes
|
|
5486
|
+
* ```
|
|
5487
|
+
*/
|
|
5488
|
+
async subscribeToResource(uri, options) {
|
|
5489
|
+
return this.connector.subscribeToResource(uri, options);
|
|
5490
|
+
}
|
|
5491
|
+
/**
|
|
5492
|
+
* Unsubscribe from resource updates.
|
|
5493
|
+
*
|
|
5494
|
+
* @param uri - URI of the resource to unsubscribe from
|
|
5495
|
+
* @param options - Request options
|
|
5496
|
+
*
|
|
5497
|
+
* @example
|
|
5498
|
+
* ```typescript
|
|
5499
|
+
* await session.unsubscribeFromResource("file:///path/to/file.txt");
|
|
5500
|
+
* ```
|
|
5501
|
+
*/
|
|
5502
|
+
async unsubscribeFromResource(uri, options) {
|
|
5503
|
+
return this.connector.unsubscribeFromResource(uri, options);
|
|
5504
|
+
}
|
|
5505
|
+
/**
|
|
5506
|
+
* List available prompts from the server.
|
|
5507
|
+
*
|
|
5508
|
+
* @returns List of available prompts
|
|
5509
|
+
*
|
|
5510
|
+
* @example
|
|
5511
|
+
* ```typescript
|
|
5512
|
+
* const result = await session.listPrompts();
|
|
5513
|
+
* console.log(`Available prompts: ${result.prompts.length}`);
|
|
5514
|
+
* ```
|
|
5515
|
+
*/
|
|
5516
|
+
async listPrompts() {
|
|
5517
|
+
return this.connector.listPrompts();
|
|
5518
|
+
}
|
|
5519
|
+
/**
|
|
5520
|
+
* Get a specific prompt with arguments.
|
|
5521
|
+
*
|
|
5522
|
+
* @param name - Name of the prompt to get
|
|
5523
|
+
* @param args - Arguments for the prompt
|
|
5524
|
+
* @returns Prompt result
|
|
5525
|
+
*
|
|
5526
|
+
* @example
|
|
5527
|
+
* ```typescript
|
|
5528
|
+
* const prompt = await session.getPrompt("greeting", { name: "Alice" });
|
|
5529
|
+
* console.log(prompt.messages);
|
|
5530
|
+
* ```
|
|
5531
|
+
*/
|
|
5532
|
+
async getPrompt(name, args) {
|
|
5533
|
+
return this.connector.getPrompt(name, args);
|
|
5534
|
+
}
|
|
5535
|
+
/**
|
|
5536
|
+
* Send a raw request through the client.
|
|
5537
|
+
*
|
|
5538
|
+
* @param method - MCP method name
|
|
5539
|
+
* @param params - Request parameters
|
|
5540
|
+
* @param options - Request options
|
|
5541
|
+
* @returns Response from the server
|
|
5542
|
+
*
|
|
5543
|
+
* @example
|
|
5544
|
+
* ```typescript
|
|
5545
|
+
* const result = await session.request("custom/method", { key: "value" });
|
|
5546
|
+
* ```
|
|
5547
|
+
*/
|
|
5548
|
+
async request(method, params = null, options) {
|
|
5549
|
+
return this.connector.request(method, params, options);
|
|
5550
|
+
}
|
|
4726
5551
|
};
|
|
4727
5552
|
|
|
4728
5553
|
// src/client/base.ts
|
|
@@ -4744,11 +5569,13 @@ var BaseMCPClient = class {
|
|
|
4744
5569
|
addServer(name, serverConfig) {
|
|
4745
5570
|
this.config.mcpServers = this.config.mcpServers || {};
|
|
4746
5571
|
this.config.mcpServers[name] = serverConfig;
|
|
5572
|
+
Tel.getInstance().trackClientAddServer(name, serverConfig);
|
|
4747
5573
|
}
|
|
4748
5574
|
removeServer(name) {
|
|
4749
5575
|
if (this.config.mcpServers?.[name]) {
|
|
4750
5576
|
delete this.config.mcpServers[name];
|
|
4751
5577
|
this.activeSessions = this.activeSessions.filter((n) => n !== name);
|
|
5578
|
+
Tel.getInstance().trackClientRemoveServer(name);
|
|
4752
5579
|
}
|
|
4753
5580
|
}
|
|
4754
5581
|
getServerNames() {
|
|
@@ -5479,7 +6306,7 @@ var VMCodeExecutor = class extends BaseCodeExecutor {
|
|
|
5479
6306
|
};
|
|
5480
6307
|
|
|
5481
6308
|
// src/connectors/base.ts
|
|
5482
|
-
var import_types = require("@modelcontextprotocol
|
|
6309
|
+
var import_types = require("@mcp-use/modelcontextprotocol-sdk/types.js");
|
|
5483
6310
|
init_logging();
|
|
5484
6311
|
var BaseConnector = class {
|
|
5485
6312
|
static {
|
|
@@ -5500,6 +6327,17 @@ var BaseConnector = class {
|
|
|
5500
6327
|
this.rootsCache = [...opts.roots];
|
|
5501
6328
|
}
|
|
5502
6329
|
}
|
|
6330
|
+
/**
|
|
6331
|
+
* Track connector initialization event
|
|
6332
|
+
* Should be called by subclasses after successful connection
|
|
6333
|
+
*/
|
|
6334
|
+
trackConnectorInit(data) {
|
|
6335
|
+
const connectorType = this.constructor.name;
|
|
6336
|
+
Telemetry.getInstance().trackConnectorInit({
|
|
6337
|
+
connectorType,
|
|
6338
|
+
...data
|
|
6339
|
+
}).catch((e) => logger.debug(`Failed to track connector init: ${e}`));
|
|
6340
|
+
}
|
|
5503
6341
|
/**
|
|
5504
6342
|
* Register a handler for server notifications
|
|
5505
6343
|
*
|
|
@@ -5708,7 +6546,7 @@ var BaseConnector = class {
|
|
|
5708
6546
|
}
|
|
5709
6547
|
logger.debug("Caching server capabilities & tools");
|
|
5710
6548
|
const capabilities = this.client.getServerCapabilities();
|
|
5711
|
-
this.capabilitiesCache = capabilities;
|
|
6549
|
+
this.capabilitiesCache = capabilities || null;
|
|
5712
6550
|
const serverInfo = this.client.getServerVersion();
|
|
5713
6551
|
this.serverInfoCache = serverInfo || null;
|
|
5714
6552
|
const listToolsRes = await this.client.listTools(
|
|
@@ -5730,7 +6568,7 @@ var BaseConnector = class {
|
|
|
5730
6568
|
}
|
|
5731
6569
|
/** Expose cached server capabilities. */
|
|
5732
6570
|
get serverCapabilities() {
|
|
5733
|
-
return this.capabilitiesCache;
|
|
6571
|
+
return this.capabilitiesCache || {};
|
|
5734
6572
|
}
|
|
5735
6573
|
/** Expose cached server info. */
|
|
5736
6574
|
get serverInfo() {
|
|
@@ -5797,7 +6635,8 @@ var BaseConnector = class {
|
|
|
5797
6635
|
} while (cursor);
|
|
5798
6636
|
return { resources: allResources };
|
|
5799
6637
|
} catch (err) {
|
|
5800
|
-
|
|
6638
|
+
const error = err;
|
|
6639
|
+
if (error.code === -32601) {
|
|
5801
6640
|
logger.debug("Server advertised resources but method not found");
|
|
5802
6641
|
return { resources: [] };
|
|
5803
6642
|
}
|
|
@@ -5864,7 +6703,8 @@ var BaseConnector = class {
|
|
|
5864
6703
|
logger.debug("Listing prompts");
|
|
5865
6704
|
return await this.client.listPrompts();
|
|
5866
6705
|
} catch (err) {
|
|
5867
|
-
|
|
6706
|
+
const error = err;
|
|
6707
|
+
if (error.code === -32601) {
|
|
5868
6708
|
logger.debug("Server advertised prompts but method not found");
|
|
5869
6709
|
return { prompts: [] };
|
|
5870
6710
|
}
|
|
@@ -6123,12 +6963,12 @@ var CodeModeConnector = class extends BaseConnector {
|
|
|
6123
6963
|
var import_node_fs = require("fs");
|
|
6124
6964
|
|
|
6125
6965
|
// src/connectors/http.ts
|
|
6126
|
-
var import_client = require("@modelcontextprotocol
|
|
6127
|
-
var import_streamableHttp = require("@modelcontextprotocol
|
|
6966
|
+
var import_client = require("@mcp-use/modelcontextprotocol-sdk/client/index.js");
|
|
6967
|
+
var import_streamableHttp = require("@mcp-use/modelcontextprotocol-sdk/client/streamableHttp.js");
|
|
6128
6968
|
init_logging();
|
|
6129
6969
|
|
|
6130
6970
|
// src/task_managers/sse.ts
|
|
6131
|
-
var import_sse = require("@modelcontextprotocol
|
|
6971
|
+
var import_sse = require("@mcp-use/modelcontextprotocol-sdk/client/sse.js");
|
|
6132
6972
|
init_logging();
|
|
6133
6973
|
|
|
6134
6974
|
// src/task_managers/base.ts
|
|
@@ -6341,15 +7181,16 @@ var HttpConnector = class extends BaseConnector {
|
|
|
6341
7181
|
let fallbackReason = "Unknown error";
|
|
6342
7182
|
let is401Error = false;
|
|
6343
7183
|
if (err instanceof import_streamableHttp.StreamableHTTPError) {
|
|
6344
|
-
|
|
6345
|
-
|
|
7184
|
+
const streamableErr = err;
|
|
7185
|
+
is401Error = streamableErr.code === 401;
|
|
7186
|
+
if (streamableErr.code === 400 && streamableErr.message.includes("Missing session ID")) {
|
|
6346
7187
|
fallbackReason = "Server requires session ID (FastMCP compatibility) - using SSE transport";
|
|
6347
7188
|
logger.warn(`\u26A0\uFE0F ${fallbackReason}`);
|
|
6348
|
-
} else if (
|
|
6349
|
-
fallbackReason = `Server returned ${
|
|
7189
|
+
} else if (streamableErr.code === 404 || streamableErr.code === 405) {
|
|
7190
|
+
fallbackReason = `Server returned ${streamableErr.code} - server likely doesn't support streamable HTTP`;
|
|
6350
7191
|
logger.debug(fallbackReason);
|
|
6351
7192
|
} else {
|
|
6352
|
-
fallbackReason = `Server returned ${
|
|
7193
|
+
fallbackReason = `Server returned ${streamableErr.code}: ${streamableErr.message}`;
|
|
6353
7194
|
logger.debug(fallbackReason);
|
|
6354
7195
|
}
|
|
6355
7196
|
} else if (err instanceof Error) {
|
|
@@ -6489,6 +7330,10 @@ var HttpConnector = class extends BaseConnector {
|
|
|
6489
7330
|
logger.debug(
|
|
6490
7331
|
`Successfully connected to MCP implementation via streamable HTTP: ${baseUrl}`
|
|
6491
7332
|
);
|
|
7333
|
+
this.trackConnectorInit({
|
|
7334
|
+
serverUrl: this.baseUrl,
|
|
7335
|
+
publicIdentifier: `${this.baseUrl} (streamable-http)`
|
|
7336
|
+
});
|
|
6492
7337
|
} catch (err) {
|
|
6493
7338
|
await this.cleanupResources();
|
|
6494
7339
|
throw err;
|
|
@@ -6536,6 +7381,10 @@ var HttpConnector = class extends BaseConnector {
|
|
|
6536
7381
|
logger.debug(
|
|
6537
7382
|
`Successfully connected to MCP implementation via HTTP/SSE: ${baseUrl}`
|
|
6538
7383
|
);
|
|
7384
|
+
this.trackConnectorInit({
|
|
7385
|
+
serverUrl: this.baseUrl,
|
|
7386
|
+
publicIdentifier: `${this.baseUrl} (sse)`
|
|
7387
|
+
});
|
|
6539
7388
|
} catch (err) {
|
|
6540
7389
|
await this.cleanupResources();
|
|
6541
7390
|
throw err;
|
|
@@ -6558,11 +7407,11 @@ var HttpConnector = class extends BaseConnector {
|
|
|
6558
7407
|
|
|
6559
7408
|
// src/connectors/stdio.ts
|
|
6560
7409
|
var import_node_process = __toESM(require("process"), 1);
|
|
6561
|
-
var import_client2 = require("@modelcontextprotocol
|
|
7410
|
+
var import_client2 = require("@mcp-use/modelcontextprotocol-sdk/client/index.js");
|
|
6562
7411
|
init_logging();
|
|
6563
7412
|
|
|
6564
7413
|
// src/task_managers/stdio.ts
|
|
6565
|
-
var import_stdio = require("@modelcontextprotocol
|
|
7414
|
+
var import_stdio = require("@mcp-use/modelcontextprotocol-sdk/client/stdio.js");
|
|
6566
7415
|
init_logging();
|
|
6567
7416
|
var StdioConnectionManager = class extends ConnectionManager {
|
|
6568
7417
|
static {
|
|
@@ -6691,6 +7540,11 @@ var StdioConnector = class extends BaseConnector {
|
|
|
6691
7540
|
logger.debug(
|
|
6692
7541
|
`Successfully connected to MCP implementation: ${this.command}`
|
|
6693
7542
|
);
|
|
7543
|
+
this.trackConnectorInit({
|
|
7544
|
+
serverCommand: this.command,
|
|
7545
|
+
serverArgs: this.args,
|
|
7546
|
+
publicIdentifier: `${this.command} ${this.args.join(" ")}`
|
|
7547
|
+
});
|
|
6694
7548
|
} catch (err) {
|
|
6695
7549
|
logger.error(`Failed to connect to MCP implementation: ${err}`);
|
|
6696
7550
|
await this.cleanupResources();
|
|
@@ -7024,6 +7878,13 @@ var MCPClient = class _MCPClient extends BaseMCPClient {
|
|
|
7024
7878
|
static {
|
|
7025
7879
|
__name(this, "MCPClient");
|
|
7026
7880
|
}
|
|
7881
|
+
/**
|
|
7882
|
+
* Get the mcp-use package version.
|
|
7883
|
+
* Works in all environments (Node.js, browser, Cloudflare Workers, Deno, etc.)
|
|
7884
|
+
*/
|
|
7885
|
+
static getPackageVersion() {
|
|
7886
|
+
return getPackageVersion();
|
|
7887
|
+
}
|
|
7027
7888
|
codeMode = false;
|
|
7028
7889
|
_codeExecutor = null;
|
|
7029
7890
|
_customCodeExecutor = null;
|
|
@@ -7061,12 +7922,30 @@ var MCPClient = class _MCPClient extends BaseMCPClient {
|
|
|
7061
7922
|
if (this.codeMode) {
|
|
7062
7923
|
this._setupCodeModeConnector();
|
|
7063
7924
|
}
|
|
7925
|
+
this._trackClientInit();
|
|
7926
|
+
}
|
|
7927
|
+
_trackClientInit() {
|
|
7928
|
+
const servers = Object.keys(this.config.mcpServers ?? {});
|
|
7929
|
+
const hasSamplingCallback = !!this._samplingCallback;
|
|
7930
|
+
const hasElicitationCallback = !!this._elicitationCallback;
|
|
7931
|
+
Tel.getInstance().trackMCPClientInit({
|
|
7932
|
+
codeMode: this.codeMode,
|
|
7933
|
+
sandbox: false,
|
|
7934
|
+
// Sandbox not supported in TS yet
|
|
7935
|
+
allCallbacks: hasSamplingCallback && hasElicitationCallback,
|
|
7936
|
+
verify: false,
|
|
7937
|
+
// No verify option in TS client
|
|
7938
|
+
servers,
|
|
7939
|
+
numServers: servers.length,
|
|
7940
|
+
isBrowser: false
|
|
7941
|
+
// Node.js MCPClient
|
|
7942
|
+
}).catch((e) => logger.debug(`Failed to track MCPClient init: ${e}`));
|
|
7064
7943
|
}
|
|
7065
7944
|
static fromDict(cfg, options) {
|
|
7066
7945
|
return new _MCPClient(cfg, options);
|
|
7067
7946
|
}
|
|
7068
|
-
static fromConfigFile(
|
|
7069
|
-
return new _MCPClient(loadConfigFile(
|
|
7947
|
+
static fromConfigFile(path2, options) {
|
|
7948
|
+
return new _MCPClient(loadConfigFile(path2), options);
|
|
7070
7949
|
}
|
|
7071
7950
|
/**
|
|
7072
7951
|
* Save configuration to a file (Node.js only)
|
|
@@ -7310,19 +8189,20 @@ var OAuthHelper = class {
|
|
|
7310
8189
|
);
|
|
7311
8190
|
return false;
|
|
7312
8191
|
} catch (error) {
|
|
8192
|
+
const err = error;
|
|
7313
8193
|
console.warn(
|
|
7314
8194
|
"\u26A0\uFE0F [OAuthHelper] Could not check auth requirement for:",
|
|
7315
8195
|
serverUrl,
|
|
7316
8196
|
error
|
|
7317
8197
|
);
|
|
7318
|
-
if (
|
|
8198
|
+
if (err.name === "TypeError" && (err.message?.includes("CORS") || err.message?.includes("Failed to fetch"))) {
|
|
7319
8199
|
console.log(
|
|
7320
8200
|
"\u{1F50D} [OAuthHelper] CORS blocked direct check, using heuristics for:",
|
|
7321
8201
|
serverUrl
|
|
7322
8202
|
);
|
|
7323
8203
|
return this.checkAuthByHeuristics(serverUrl);
|
|
7324
8204
|
}
|
|
7325
|
-
if (
|
|
8205
|
+
if (err.name === "AbortError") {
|
|
7326
8206
|
console.log(
|
|
7327
8207
|
"\u23F0 [OAuthHelper] Request timeout, assuming no auth required for:",
|
|
7328
8208
|
serverUrl
|
|
@@ -7345,15 +8225,15 @@ var OAuthHelper = class {
|
|
|
7345
8225
|
// GitHub Copilot
|
|
7346
8226
|
/api\.github\.com/i,
|
|
7347
8227
|
// GitHub API
|
|
7348
|
-
|
|
7349
|
-
// Google APIs
|
|
8228
|
+
/[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.googleapis\.com/i,
|
|
8229
|
+
// Google APIs (DNS-safe, max 63 chars per label)
|
|
7350
8230
|
/api\.openai\.com/i,
|
|
7351
8231
|
// OpenAI
|
|
7352
8232
|
/api\.anthropic\.com/i,
|
|
7353
8233
|
// Anthropic
|
|
7354
|
-
|
|
8234
|
+
/[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.atlassian\.net/i,
|
|
7355
8235
|
// Atlassian (Jira, Confluence)
|
|
7356
|
-
|
|
8236
|
+
/[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.slack\.com/i,
|
|
7357
8237
|
// Slack
|
|
7358
8238
|
/api\.notion\.com/i,
|
|
7359
8239
|
// Notion
|
|
@@ -7367,7 +8247,7 @@ var OAuthHelper = class {
|
|
|
7367
8247
|
// Local development
|
|
7368
8248
|
/\.local/i,
|
|
7369
8249
|
// Local development
|
|
7370
|
-
/mcp
|
|
8250
|
+
/mcp\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.com/i
|
|
7371
8251
|
// Generic MCP server pattern (often public)
|
|
7372
8252
|
];
|
|
7373
8253
|
for (const pattern of noAuthPatterns) {
|
|
@@ -7917,7 +8797,7 @@ var BrowserOAuthClientProvider = class {
|
|
|
7917
8797
|
};
|
|
7918
8798
|
|
|
7919
8799
|
// src/auth/callback.ts
|
|
7920
|
-
var import_auth = require("@modelcontextprotocol
|
|
8800
|
+
var import_auth = require("@mcp-use/modelcontextprotocol-sdk/client/auth.js");
|
|
7921
8801
|
async function onMcpAuthorization() {
|
|
7922
8802
|
const queryParams = new URLSearchParams(window.location.search);
|
|
7923
8803
|
const code = queryParams.get("code");
|
|
@@ -8025,16 +8905,44 @@ async function onMcpAuthorization() {
|
|
|
8025
8905
|
);
|
|
8026
8906
|
}
|
|
8027
8907
|
try {
|
|
8028
|
-
document.body.innerHTML =
|
|
8029
|
-
|
|
8030
|
-
|
|
8031
|
-
|
|
8032
|
-
|
|
8033
|
-
|
|
8034
|
-
|
|
8035
|
-
|
|
8036
|
-
|
|
8037
|
-
|
|
8908
|
+
document.body.innerHTML = "";
|
|
8909
|
+
const container = document.createElement("div");
|
|
8910
|
+
container.style.fontFamily = "sans-serif";
|
|
8911
|
+
container.style.padding = "20px";
|
|
8912
|
+
const heading = document.createElement("h1");
|
|
8913
|
+
heading.textContent = "Authentication Error";
|
|
8914
|
+
container.appendChild(heading);
|
|
8915
|
+
const errorPara = document.createElement("p");
|
|
8916
|
+
errorPara.style.color = "red";
|
|
8917
|
+
errorPara.style.backgroundColor = "#ffebeb";
|
|
8918
|
+
errorPara.style.border = "1px solid red";
|
|
8919
|
+
errorPara.style.padding = "10px";
|
|
8920
|
+
errorPara.style.borderRadius = "4px";
|
|
8921
|
+
errorPara.textContent = errorMessage;
|
|
8922
|
+
container.appendChild(errorPara);
|
|
8923
|
+
const closePara = document.createElement("p");
|
|
8924
|
+
closePara.textContent = "You can close this window or ";
|
|
8925
|
+
const closeLink = document.createElement("a");
|
|
8926
|
+
closeLink.href = "#";
|
|
8927
|
+
closeLink.textContent = "click here to close";
|
|
8928
|
+
closeLink.onclick = (e) => {
|
|
8929
|
+
e.preventDefault();
|
|
8930
|
+
window.close();
|
|
8931
|
+
return false;
|
|
8932
|
+
};
|
|
8933
|
+
closePara.appendChild(closeLink);
|
|
8934
|
+
closePara.appendChild(document.createTextNode("."));
|
|
8935
|
+
container.appendChild(closePara);
|
|
8936
|
+
if (err instanceof Error && err.stack) {
|
|
8937
|
+
const stackPre = document.createElement("pre");
|
|
8938
|
+
stackPre.style.fontSize = "0.8em";
|
|
8939
|
+
stackPre.style.color = "#555";
|
|
8940
|
+
stackPre.style.marginTop = "20px";
|
|
8941
|
+
stackPre.style.whiteSpace = "pre-wrap";
|
|
8942
|
+
stackPre.textContent = err.stack;
|
|
8943
|
+
container.appendChild(stackPre);
|
|
8944
|
+
}
|
|
8945
|
+
document.body.appendChild(container);
|
|
8038
8946
|
} catch (displayError) {
|
|
8039
8947
|
console.error(
|
|
8040
8948
|
`${logPrefix} Could not display error in callback window:`,
|
|
@@ -8056,12 +8964,39 @@ __name(onMcpAuthorization, "onMcpAuthorization");
|
|
|
8056
8964
|
var import_react = require("react");
|
|
8057
8965
|
|
|
8058
8966
|
// src/client/browser.ts
|
|
8967
|
+
init_logging();
|
|
8059
8968
|
var BrowserMCPClient = class _BrowserMCPClient extends BaseMCPClient {
|
|
8060
8969
|
static {
|
|
8061
8970
|
__name(this, "BrowserMCPClient");
|
|
8062
8971
|
}
|
|
8972
|
+
/**
|
|
8973
|
+
* Get the mcp-use package version.
|
|
8974
|
+
* Works in all environments (Node.js, browser, Cloudflare Workers, Deno, etc.)
|
|
8975
|
+
*/
|
|
8976
|
+
static getPackageVersion() {
|
|
8977
|
+
return getPackageVersion();
|
|
8978
|
+
}
|
|
8063
8979
|
constructor(config) {
|
|
8064
8980
|
super(config);
|
|
8981
|
+
this._trackClientInit();
|
|
8982
|
+
}
|
|
8983
|
+
_trackClientInit() {
|
|
8984
|
+
const servers = Object.keys(this.config.mcpServers ?? {});
|
|
8985
|
+
Tel.getInstance().trackMCPClientInit({
|
|
8986
|
+
codeMode: false,
|
|
8987
|
+
// Browser client doesn't support code mode
|
|
8988
|
+
sandbox: false,
|
|
8989
|
+
// Sandbox not supported in browser
|
|
8990
|
+
allCallbacks: false,
|
|
8991
|
+
// Will be set per-server
|
|
8992
|
+
verify: false,
|
|
8993
|
+
servers,
|
|
8994
|
+
numServers: servers.length,
|
|
8995
|
+
isBrowser: true
|
|
8996
|
+
// Browser MCPClient
|
|
8997
|
+
}).catch(
|
|
8998
|
+
(e) => logger.debug(`Failed to track BrowserMCPClient init: ${e}`)
|
|
8999
|
+
);
|
|
8065
9000
|
}
|
|
8066
9001
|
static fromDict(cfg) {
|
|
8067
9002
|
return new _BrowserMCPClient(cfg);
|
|
@@ -8240,8 +9175,20 @@ function useMcp(options) {
|
|
|
8240
9175
|
}
|
|
8241
9176
|
}
|
|
8242
9177
|
connectingRef.current = false;
|
|
9178
|
+
if (url) {
|
|
9179
|
+
Tel.getInstance().trackUseMcpConnection({
|
|
9180
|
+
url,
|
|
9181
|
+
transportType,
|
|
9182
|
+
success: false,
|
|
9183
|
+
errorType: connectionError?.name || "UnknownError",
|
|
9184
|
+
hasOAuth: !!authProviderRef.current,
|
|
9185
|
+
hasSampling: !!samplingCallback,
|
|
9186
|
+
hasElicitation: !!onElicitation
|
|
9187
|
+
}).catch(() => {
|
|
9188
|
+
});
|
|
9189
|
+
}
|
|
8243
9190
|
},
|
|
8244
|
-
[addLog]
|
|
9191
|
+
[addLog, url, transportType, samplingCallback, onElicitation]
|
|
8245
9192
|
);
|
|
8246
9193
|
const connect = (0, import_react.useCallback)(async () => {
|
|
8247
9194
|
if (!enabled || !url) {
|
|
@@ -8350,6 +9297,15 @@ function useMcp(options) {
|
|
|
8350
9297
|
);
|
|
8351
9298
|
setState("ready");
|
|
8352
9299
|
successfulTransportRef.current = transportTypeParam;
|
|
9300
|
+
Tel.getInstance().trackUseMcpConnection({
|
|
9301
|
+
url,
|
|
9302
|
+
transportType: transportTypeParam,
|
|
9303
|
+
success: true,
|
|
9304
|
+
hasOAuth: !!authProviderRef.current,
|
|
9305
|
+
hasSampling: !!samplingCallback,
|
|
9306
|
+
hasElicitation: !!onElicitation
|
|
9307
|
+
}).catch(() => {
|
|
9308
|
+
});
|
|
8353
9309
|
setTools(session.connector.tools || []);
|
|
8354
9310
|
const resourcesResult = await session.connector.listAllResources();
|
|
8355
9311
|
setResources(resourcesResult.resources || []);
|
|
@@ -8367,15 +9323,16 @@ function useMcp(options) {
|
|
|
8367
9323
|
}
|
|
8368
9324
|
return "success";
|
|
8369
9325
|
} catch (err) {
|
|
8370
|
-
const
|
|
8371
|
-
|
|
9326
|
+
const error2 = err;
|
|
9327
|
+
const errorMessage = error2?.message || String(err);
|
|
9328
|
+
if (error2.code === 401 || errorMessage.includes("401") || errorMessage.includes("Unauthorized")) {
|
|
8372
9329
|
if (authProviderRef.current) {
|
|
8373
9330
|
addLog(
|
|
8374
9331
|
"info",
|
|
8375
9332
|
"Authentication required. OAuth provider available."
|
|
8376
9333
|
);
|
|
8377
9334
|
try {
|
|
8378
|
-
const { auth: auth2 } = await import("@modelcontextprotocol
|
|
9335
|
+
const { auth: auth2 } = await import("@mcp-use/modelcontextprotocol-sdk/client/auth.js");
|
|
8379
9336
|
const baseUrl = new URL(url).origin;
|
|
8380
9337
|
auth2(authProviderRef.current, { serverUrl: baseUrl }).catch(
|
|
8381
9338
|
() => {
|
|
@@ -8416,7 +9373,10 @@ function useMcp(options) {
|
|
|
8416
9373
|
);
|
|
8417
9374
|
return "failed";
|
|
8418
9375
|
}
|
|
8419
|
-
failConnection(
|
|
9376
|
+
failConnection(
|
|
9377
|
+
errorMessage,
|
|
9378
|
+
error2 instanceof Error ? error2 : new Error(String(error2))
|
|
9379
|
+
);
|
|
8420
9380
|
return "failed";
|
|
8421
9381
|
}
|
|
8422
9382
|
}, "tryConnectWithTransport");
|
|
@@ -8470,6 +9430,7 @@ function useMcp(options) {
|
|
|
8470
9430
|
);
|
|
8471
9431
|
}
|
|
8472
9432
|
addLog("info", `Calling tool: ${name}`, args);
|
|
9433
|
+
const startTime = Date.now();
|
|
8473
9434
|
try {
|
|
8474
9435
|
const serverName = "inspector-server";
|
|
8475
9436
|
const session = clientRef.current.getSession(serverName);
|
|
@@ -8482,9 +9443,22 @@ function useMcp(options) {
|
|
|
8482
9443
|
options2
|
|
8483
9444
|
);
|
|
8484
9445
|
addLog("info", `Tool "${name}" call successful:`, result);
|
|
9446
|
+
Tel.getInstance().trackUseMcpToolCall({
|
|
9447
|
+
toolName: name,
|
|
9448
|
+
success: true,
|
|
9449
|
+
executionTimeMs: Date.now() - startTime
|
|
9450
|
+
}).catch(() => {
|
|
9451
|
+
});
|
|
8485
9452
|
return result;
|
|
8486
9453
|
} catch (err) {
|
|
8487
9454
|
addLog("error", `Tool "${name}" call failed:`, err);
|
|
9455
|
+
Tel.getInstance().trackUseMcpToolCall({
|
|
9456
|
+
toolName: name,
|
|
9457
|
+
success: false,
|
|
9458
|
+
errorType: err instanceof Error ? err.name : "UnknownError",
|
|
9459
|
+
executionTimeMs: Date.now() - startTime
|
|
9460
|
+
}).catch(() => {
|
|
9461
|
+
});
|
|
8488
9462
|
throw err;
|
|
8489
9463
|
}
|
|
8490
9464
|
},
|
|
@@ -8540,7 +9514,7 @@ function useMcp(options) {
|
|
|
8540
9514
|
});
|
|
8541
9515
|
authProviderRef.current = freshAuthProvider;
|
|
8542
9516
|
addLog("info", "Triggering fresh OAuth authorization...");
|
|
8543
|
-
const { auth: auth2 } = await import("@modelcontextprotocol
|
|
9517
|
+
const { auth: auth2 } = await import("@mcp-use/modelcontextprotocol-sdk/client/auth.js");
|
|
8544
9518
|
const baseUrl = new URL(url).origin;
|
|
8545
9519
|
auth2(freshAuthProvider, {
|
|
8546
9520
|
serverUrl: baseUrl
|
|
@@ -8548,7 +9522,7 @@ function useMcp(options) {
|
|
|
8548
9522
|
addLog(
|
|
8549
9523
|
"info",
|
|
8550
9524
|
"OAuth flow initiated:",
|
|
8551
|
-
err
|
|
9525
|
+
err instanceof Error ? err.message : "Redirecting..."
|
|
8552
9526
|
);
|
|
8553
9527
|
});
|
|
8554
9528
|
} catch (authError) {
|
|
@@ -8634,9 +9608,20 @@ function useMcp(options) {
|
|
|
8634
9608
|
}
|
|
8635
9609
|
const result = await session.connector.readResource(uri);
|
|
8636
9610
|
addLog("info", "Resource read successful:", result);
|
|
9611
|
+
Tel.getInstance().trackUseMcpResourceRead({
|
|
9612
|
+
resourceUri: uri,
|
|
9613
|
+
success: true
|
|
9614
|
+
}).catch(() => {
|
|
9615
|
+
});
|
|
8637
9616
|
return result;
|
|
8638
9617
|
} catch (err) {
|
|
8639
9618
|
addLog("error", "Resource read failed:", err);
|
|
9619
|
+
Tel.getInstance().trackUseMcpResourceRead({
|
|
9620
|
+
resourceUri: uri,
|
|
9621
|
+
success: false,
|
|
9622
|
+
errorType: err instanceof Error ? err.name : "UnknownError"
|
|
9623
|
+
}).catch(() => {
|
|
9624
|
+
});
|
|
8640
9625
|
throw err;
|
|
8641
9626
|
}
|
|
8642
9627
|
},
|
|
@@ -9284,7 +10269,8 @@ function WidgetControls({
|
|
|
9284
10269
|
const result = await callTool(toolName, args);
|
|
9285
10270
|
setActionResult(`Success: ${JSON.stringify(result, null, 2)}`);
|
|
9286
10271
|
} catch (error) {
|
|
9287
|
-
|
|
10272
|
+
const err = error;
|
|
10273
|
+
setActionResult(`Error: ${err.message}`);
|
|
9288
10274
|
}
|
|
9289
10275
|
}, "handleCallTool");
|
|
9290
10276
|
const handleSendFollowUpMessage = /* @__PURE__ */ __name(async () => {
|
|
@@ -9293,7 +10279,8 @@ function WidgetControls({
|
|
|
9293
10279
|
await sendFollowUpMessage(followUpMessage);
|
|
9294
10280
|
setActionResult("Follow-up message sent successfully");
|
|
9295
10281
|
} catch (error) {
|
|
9296
|
-
|
|
10282
|
+
const err = error;
|
|
10283
|
+
setActionResult(`Error: ${err.message}`);
|
|
9297
10284
|
}
|
|
9298
10285
|
}, "handleSendFollowUpMessage");
|
|
9299
10286
|
const handleOpenExternal = /* @__PURE__ */ __name(() => {
|
|
@@ -9301,7 +10288,8 @@ function WidgetControls({
|
|
|
9301
10288
|
openExternal(externalUrl);
|
|
9302
10289
|
setActionResult(`Opened external link: ${externalUrl}`);
|
|
9303
10290
|
} catch (error) {
|
|
9304
|
-
|
|
10291
|
+
const err = error;
|
|
10292
|
+
setActionResult(`Error: ${err.message}`);
|
|
9305
10293
|
}
|
|
9306
10294
|
}, "handleOpenExternal");
|
|
9307
10295
|
const handleRequestDisplayMode = /* @__PURE__ */ __name(async (mode) => {
|
|
@@ -9310,7 +10298,8 @@ function WidgetControls({
|
|
|
9310
10298
|
const result = await requestDisplayMode(mode);
|
|
9311
10299
|
setActionResult(`Display mode granted: ${result.mode}`);
|
|
9312
10300
|
} catch (error) {
|
|
9313
|
-
|
|
10301
|
+
const err = error;
|
|
10302
|
+
setActionResult(`Error: ${err.message}`);
|
|
9314
10303
|
}
|
|
9315
10304
|
}, "handleRequestDisplayMode");
|
|
9316
10305
|
const handleSetState = /* @__PURE__ */ __name(async () => {
|
|
@@ -9320,7 +10309,8 @@ function WidgetControls({
|
|
|
9320
10309
|
await setState(newState);
|
|
9321
10310
|
setActionResult(`State updated: ${JSON.stringify(newState, null, 2)}`);
|
|
9322
10311
|
} catch (error) {
|
|
9323
|
-
|
|
10312
|
+
const err = error;
|
|
10313
|
+
setActionResult(`Error: ${err.message}`);
|
|
9324
10314
|
}
|
|
9325
10315
|
}, "handleSetState");
|
|
9326
10316
|
const handleFullscreen = /* @__PURE__ */ __name(async () => {
|
|
@@ -9597,8 +10587,8 @@ __name(WidgetControls, "WidgetControls");
|
|
|
9597
10587
|
var import_react7 = __toESM(require("react"), 1);
|
|
9598
10588
|
function getBasename() {
|
|
9599
10589
|
if (typeof window === "undefined") return "/";
|
|
9600
|
-
const
|
|
9601
|
-
const match =
|
|
10590
|
+
const path2 = window.location.pathname;
|
|
10591
|
+
const match = path2.match(/^(\/inspector\/api\/dev-widget\/[^/]+)/);
|
|
9602
10592
|
if (match) {
|
|
9603
10593
|
return match[1];
|
|
9604
10594
|
}
|