mcp-use 1.9.1-canary.0 → 1.10.0-canary.10
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-6EYDSXO6.js +942 -0
- package/dist/{chunk-D22NUQTL.js → chunk-BFSVTG6G.js} +213 -12
- package/dist/{chunk-KHTTBIRP.js → chunk-BPP5XYP6.js} +156 -5
- package/dist/{chunk-3R5PDYIN.js → chunk-J75I2C26.js} +39 -11
- package/dist/{chunk-5URNFWCQ.js → chunk-LWVK6RXA.js} +8 -3
- package/dist/{chunk-MUZ5WYE3.js → chunk-NBSNYHID.js} +22 -13
- package/dist/{chunk-U5BX3ISQ.js → chunk-NRALSDBH.js} +22 -408
- package/dist/{chunk-ZQUCGISK.js → chunk-PL645KUX.js} +21 -5
- package/dist/{chunk-QREDNTLS.js → chunk-ZMA4JG4C.js} +1 -1
- package/dist/{context-storage-TXQ4DVSS.js → context-storage-NA4MHWOZ.js} +3 -1
- package/dist/index.cjs +854 -122
- package/dist/index.d.ts +6 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +57 -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 +2071 -1620
- 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 +3299 -2601
- package/dist/src/browser.d.ts +2 -1
- package/dist/src/browser.d.ts.map +1 -1
- package/dist/src/browser.js +10 -5
- package/dist/src/client/browser.d.ts +5 -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 +13 -4
- 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 +1098 -47
- package/dist/src/react/index.d.ts +1 -1
- package/dist/src/react/index.d.ts.map +1 -1
- package/dist/src/react/index.js +5 -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/context-storage.d.ts +8 -1
- package/dist/src/server/context-storage.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 +2162 -287
- package/dist/src/server/index.d.ts +4 -3
- package/dist/src/server/index.d.ts.map +1 -1
- package/dist/src/server/index.js +870 -261
- package/dist/src/server/mcp-server.d.ts +107 -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 +45 -25
- package/dist/src/server/resources/index.d.ts.map +1 -1
- package/dist/src/server/resources/subscriptions.d.ts +54 -0
- package/dist/src/server/resources/subscriptions.d.ts.map +1 -0
- package/dist/src/server/sessions/session-manager.d.ts +17 -5
- package/dist/src/server/sessions/session-manager.d.ts.map +1 -1
- package/dist/src/server/tools/tool-execution-helpers.d.ts +59 -23
- 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 +132 -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 +65 -33
- 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 +219 -0
- package/dist/src/telemetry/events.d.ts.map +1 -1
- package/dist/src/telemetry/index.d.ts +2 -2
- package/dist/src/telemetry/index.d.ts.map +1 -1
- package/dist/src/telemetry/telemetry.d.ts +56 -1
- package/dist/src/telemetry/telemetry.d.ts.map +1 -1
- package/dist/src/telemetry/utils.d.ts +1 -1
- package/dist/src/telemetry/utils.d.ts.map +1 -1
- package/dist/src/version.d.ts +8 -0
- package/dist/src/version.d.ts.map +1 -0
- package/dist/{tool-execution-helpers-IVUDHXMK.js → tool-execution-helpers-XFVBSRXM.js} +9 -2
- package/dist/tsup.config.d.ts.map +1 -1
- package/package.json +6 -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 fs3 = await import("fs");
|
|
39
|
+
const path3 = await import("path");
|
|
40
|
+
return { fs: fs3.default, path: path3.default };
|
|
41
41
|
} catch {
|
|
42
42
|
return { fs: null, path: null };
|
|
43
43
|
}
|
|
@@ -1078,11 +1078,13 @@ __export(index_exports, {
|
|
|
1078
1078
|
StdioConnector: () => StdioConnector,
|
|
1079
1079
|
Telemetry: () => Telemetry,
|
|
1080
1080
|
ThemeProvider: () => ThemeProvider,
|
|
1081
|
+
VERSION: () => VERSION,
|
|
1081
1082
|
VMCodeExecutor: () => VMCodeExecutor,
|
|
1082
1083
|
WebSocketConnector: () => WebSocketConnector,
|
|
1083
1084
|
WidgetControls: () => WidgetControls,
|
|
1084
1085
|
createOAuthMCPConfig: () => createOAuthMCPConfig,
|
|
1085
1086
|
createReadableStreamFromGenerator: () => createReadableStreamFromGenerator,
|
|
1087
|
+
getPackageVersion: () => getPackageVersion,
|
|
1086
1088
|
isVMAvailable: () => isVMAvailable,
|
|
1087
1089
|
loadConfigFile: () => loadConfigFile,
|
|
1088
1090
|
logger: () => logger,
|
|
@@ -2513,9 +2515,9 @@ var ObservabilityManager = class {
|
|
|
2513
2515
|
};
|
|
2514
2516
|
|
|
2515
2517
|
// src/telemetry/telemetry.ts
|
|
2516
|
-
var
|
|
2518
|
+
var fs = __toESM(require("fs"), 1);
|
|
2517
2519
|
var os = __toESM(require("os"), 1);
|
|
2518
|
-
var
|
|
2520
|
+
var path = __toESM(require("path"), 1);
|
|
2519
2521
|
var import_posthog_node = require("posthog-node");
|
|
2520
2522
|
|
|
2521
2523
|
// src/server/utils/runtime.ts
|
|
@@ -2578,23 +2580,265 @@ var MCPAgentExecutionEvent = class extends BaseTelemetryEvent {
|
|
|
2578
2580
|
};
|
|
2579
2581
|
}
|
|
2580
2582
|
};
|
|
2583
|
+
function createServerRunEventData(server, transport) {
|
|
2584
|
+
const toolRegistrations = Array.from(server.registrations.tools.values());
|
|
2585
|
+
const promptRegistrations = Array.from(server.registrations.prompts.values());
|
|
2586
|
+
const resourceRegistrations = Array.from(
|
|
2587
|
+
server.registrations.resources.values()
|
|
2588
|
+
);
|
|
2589
|
+
const templateRegistrations = Array.from(
|
|
2590
|
+
server.registrations.resourceTemplates.values()
|
|
2591
|
+
);
|
|
2592
|
+
const allResources = resourceRegistrations.map((r) => ({
|
|
2593
|
+
name: r.config.name,
|
|
2594
|
+
title: r.config.title ?? null,
|
|
2595
|
+
description: r.config.description ?? null,
|
|
2596
|
+
uri: r.config.uri ?? null,
|
|
2597
|
+
mime_type: r.config.mimeType ?? null
|
|
2598
|
+
}));
|
|
2599
|
+
const appsSdkResources = allResources.filter(
|
|
2600
|
+
(r) => r.mime_type === "text/html+skybridge"
|
|
2601
|
+
);
|
|
2602
|
+
const mcpUiResources = allResources.filter(
|
|
2603
|
+
(r) => r.mime_type === "text/uri-list" || r.mime_type === "text/html"
|
|
2604
|
+
);
|
|
2605
|
+
const mcpAppsResources = allResources.filter(
|
|
2606
|
+
(r) => r.mime_type === "text/html+mcp"
|
|
2607
|
+
);
|
|
2608
|
+
return {
|
|
2609
|
+
transport,
|
|
2610
|
+
toolsNumber: server.registeredTools.length,
|
|
2611
|
+
resourcesNumber: server.registeredResources.length,
|
|
2612
|
+
promptsNumber: server.registeredPrompts.length,
|
|
2613
|
+
auth: !!server.oauthProvider,
|
|
2614
|
+
name: server.config.name,
|
|
2615
|
+
description: server.config.description ?? null,
|
|
2616
|
+
baseUrl: server.serverBaseUrl ?? null,
|
|
2617
|
+
toolNames: server.registeredTools.length > 0 ? server.registeredTools : null,
|
|
2618
|
+
resourceNames: server.registeredResources.length > 0 ? server.registeredResources : null,
|
|
2619
|
+
promptNames: server.registeredPrompts.length > 0 ? server.registeredPrompts : null,
|
|
2620
|
+
tools: toolRegistrations.length > 0 ? toolRegistrations.map((r) => ({
|
|
2621
|
+
name: r.config.name,
|
|
2622
|
+
title: r.config.title ?? null,
|
|
2623
|
+
description: r.config.description ?? null,
|
|
2624
|
+
input_schema: r.config.schema ? JSON.stringify(r.config.schema) : null,
|
|
2625
|
+
output_schema: r.config.outputSchema ? JSON.stringify(r.config.outputSchema) : null
|
|
2626
|
+
})) : null,
|
|
2627
|
+
resources: allResources.length > 0 ? allResources : null,
|
|
2628
|
+
prompts: promptRegistrations.length > 0 ? promptRegistrations.map((r) => ({
|
|
2629
|
+
name: r.config.name,
|
|
2630
|
+
title: r.config.title ?? null,
|
|
2631
|
+
description: r.config.description ?? null,
|
|
2632
|
+
args: r.config.args ? JSON.stringify(r.config.args) : null
|
|
2633
|
+
})) : null,
|
|
2634
|
+
templates: templateRegistrations.length > 0 ? templateRegistrations.map((r) => ({
|
|
2635
|
+
name: r.config.name,
|
|
2636
|
+
title: r.config.title ?? null,
|
|
2637
|
+
description: r.config.description ?? null
|
|
2638
|
+
})) : null,
|
|
2639
|
+
capabilities: {
|
|
2640
|
+
logging: true,
|
|
2641
|
+
resources: { subscribe: true, listChanged: true }
|
|
2642
|
+
},
|
|
2643
|
+
appsSdkResources: appsSdkResources.length > 0 ? appsSdkResources : null,
|
|
2644
|
+
appsSdkResourcesNumber: appsSdkResources.length,
|
|
2645
|
+
mcpUiResources: mcpUiResources.length > 0 ? mcpUiResources : null,
|
|
2646
|
+
mcpUiResourcesNumber: mcpUiResources.length,
|
|
2647
|
+
mcpAppsResources: mcpAppsResources.length > 0 ? mcpAppsResources : null,
|
|
2648
|
+
mcpAppsResourcesNumber: mcpAppsResources.length
|
|
2649
|
+
};
|
|
2650
|
+
}
|
|
2651
|
+
__name(createServerRunEventData, "createServerRunEventData");
|
|
2652
|
+
var ServerRunEvent = class extends BaseTelemetryEvent {
|
|
2653
|
+
constructor(data) {
|
|
2654
|
+
super();
|
|
2655
|
+
this.data = data;
|
|
2656
|
+
}
|
|
2657
|
+
static {
|
|
2658
|
+
__name(this, "ServerRunEvent");
|
|
2659
|
+
}
|
|
2660
|
+
get name() {
|
|
2661
|
+
return "server_run";
|
|
2662
|
+
}
|
|
2663
|
+
get properties() {
|
|
2664
|
+
return {
|
|
2665
|
+
transport: this.data.transport,
|
|
2666
|
+
tools_number: this.data.toolsNumber,
|
|
2667
|
+
resources_number: this.data.resourcesNumber,
|
|
2668
|
+
prompts_number: this.data.promptsNumber,
|
|
2669
|
+
auth: this.data.auth,
|
|
2670
|
+
name: this.data.name,
|
|
2671
|
+
description: this.data.description ?? null,
|
|
2672
|
+
base_url: this.data.baseUrl ?? null,
|
|
2673
|
+
tool_names: this.data.toolNames ?? null,
|
|
2674
|
+
resource_names: this.data.resourceNames ?? null,
|
|
2675
|
+
prompt_names: this.data.promptNames ?? null,
|
|
2676
|
+
tools: this.data.tools ?? null,
|
|
2677
|
+
resources: this.data.resources ?? null,
|
|
2678
|
+
prompts: this.data.prompts ?? null,
|
|
2679
|
+
templates: this.data.templates ?? null,
|
|
2680
|
+
capabilities: this.data.capabilities ? JSON.stringify(this.data.capabilities) : null,
|
|
2681
|
+
apps_sdk_resources: this.data.appsSdkResources ? JSON.stringify(this.data.appsSdkResources) : null,
|
|
2682
|
+
apps_sdk_resources_number: this.data.appsSdkResourcesNumber ?? 0,
|
|
2683
|
+
mcp_ui_resources: this.data.mcpUiResources ? JSON.stringify(this.data.mcpUiResources) : null,
|
|
2684
|
+
mcp_ui_resources_number: this.data.mcpUiResourcesNumber ?? 0,
|
|
2685
|
+
mcp_apps_resources: this.data.mcpAppsResources ? JSON.stringify(this.data.mcpAppsResources) : null,
|
|
2686
|
+
mcp_apps_resources_number: this.data.mcpAppsResourcesNumber ?? 0
|
|
2687
|
+
};
|
|
2688
|
+
}
|
|
2689
|
+
};
|
|
2690
|
+
var ServerInitializeEvent = class extends BaseTelemetryEvent {
|
|
2691
|
+
constructor(data) {
|
|
2692
|
+
super();
|
|
2693
|
+
this.data = data;
|
|
2694
|
+
}
|
|
2695
|
+
static {
|
|
2696
|
+
__name(this, "ServerInitializeEvent");
|
|
2697
|
+
}
|
|
2698
|
+
get name() {
|
|
2699
|
+
return "server_initialize_call";
|
|
2700
|
+
}
|
|
2701
|
+
get properties() {
|
|
2702
|
+
return {
|
|
2703
|
+
protocol_version: this.data.protocolVersion,
|
|
2704
|
+
client_info: JSON.stringify(this.data.clientInfo),
|
|
2705
|
+
client_capabilities: JSON.stringify(this.data.clientCapabilities),
|
|
2706
|
+
session_id: this.data.sessionId ?? null
|
|
2707
|
+
};
|
|
2708
|
+
}
|
|
2709
|
+
};
|
|
2710
|
+
var ServerToolCallEvent = class extends BaseTelemetryEvent {
|
|
2711
|
+
constructor(data) {
|
|
2712
|
+
super();
|
|
2713
|
+
this.data = data;
|
|
2714
|
+
}
|
|
2715
|
+
static {
|
|
2716
|
+
__name(this, "ServerToolCallEvent");
|
|
2717
|
+
}
|
|
2718
|
+
get name() {
|
|
2719
|
+
return "server_tool_call";
|
|
2720
|
+
}
|
|
2721
|
+
get properties() {
|
|
2722
|
+
return {
|
|
2723
|
+
tool_name: this.data.toolName,
|
|
2724
|
+
length_input_argument: this.data.lengthInputArgument,
|
|
2725
|
+
success: this.data.success,
|
|
2726
|
+
error_type: this.data.errorType ?? null,
|
|
2727
|
+
execution_time_ms: this.data.executionTimeMs ?? null
|
|
2728
|
+
};
|
|
2729
|
+
}
|
|
2730
|
+
};
|
|
2731
|
+
var ServerResourceCallEvent = class extends BaseTelemetryEvent {
|
|
2732
|
+
constructor(data) {
|
|
2733
|
+
super();
|
|
2734
|
+
this.data = data;
|
|
2735
|
+
}
|
|
2736
|
+
static {
|
|
2737
|
+
__name(this, "ServerResourceCallEvent");
|
|
2738
|
+
}
|
|
2739
|
+
get name() {
|
|
2740
|
+
return "server_resource_call";
|
|
2741
|
+
}
|
|
2742
|
+
get properties() {
|
|
2743
|
+
return {
|
|
2744
|
+
name: this.data.name,
|
|
2745
|
+
description: this.data.description,
|
|
2746
|
+
contents: this.data.contents,
|
|
2747
|
+
success: this.data.success,
|
|
2748
|
+
error_type: this.data.errorType ?? null
|
|
2749
|
+
};
|
|
2750
|
+
}
|
|
2751
|
+
};
|
|
2752
|
+
var ServerPromptCallEvent = class extends BaseTelemetryEvent {
|
|
2753
|
+
constructor(data) {
|
|
2754
|
+
super();
|
|
2755
|
+
this.data = data;
|
|
2756
|
+
}
|
|
2757
|
+
static {
|
|
2758
|
+
__name(this, "ServerPromptCallEvent");
|
|
2759
|
+
}
|
|
2760
|
+
get name() {
|
|
2761
|
+
return "server_prompt_call";
|
|
2762
|
+
}
|
|
2763
|
+
get properties() {
|
|
2764
|
+
return {
|
|
2765
|
+
name: this.data.name,
|
|
2766
|
+
description: this.data.description,
|
|
2767
|
+
success: this.data.success,
|
|
2768
|
+
error_type: this.data.errorType ?? null
|
|
2769
|
+
};
|
|
2770
|
+
}
|
|
2771
|
+
};
|
|
2772
|
+
var ServerContextEvent = class extends BaseTelemetryEvent {
|
|
2773
|
+
constructor(data) {
|
|
2774
|
+
super();
|
|
2775
|
+
this.data = data;
|
|
2776
|
+
}
|
|
2777
|
+
static {
|
|
2778
|
+
__name(this, "ServerContextEvent");
|
|
2779
|
+
}
|
|
2780
|
+
get name() {
|
|
2781
|
+
return `server_context_${this.data.contextType}`;
|
|
2782
|
+
}
|
|
2783
|
+
get properties() {
|
|
2784
|
+
return {
|
|
2785
|
+
context_type: this.data.contextType,
|
|
2786
|
+
notification_type: this.data.notificationType ?? null
|
|
2787
|
+
};
|
|
2788
|
+
}
|
|
2789
|
+
};
|
|
2790
|
+
var MCPClientInitEvent = class extends BaseTelemetryEvent {
|
|
2791
|
+
constructor(data) {
|
|
2792
|
+
super();
|
|
2793
|
+
this.data = data;
|
|
2794
|
+
}
|
|
2795
|
+
static {
|
|
2796
|
+
__name(this, "MCPClientInitEvent");
|
|
2797
|
+
}
|
|
2798
|
+
get name() {
|
|
2799
|
+
return "mcpclient_init";
|
|
2800
|
+
}
|
|
2801
|
+
get properties() {
|
|
2802
|
+
return {
|
|
2803
|
+
code_mode: this.data.codeMode,
|
|
2804
|
+
sandbox: this.data.sandbox,
|
|
2805
|
+
all_callbacks: this.data.allCallbacks,
|
|
2806
|
+
verify: this.data.verify,
|
|
2807
|
+
servers: this.data.servers,
|
|
2808
|
+
num_servers: this.data.numServers
|
|
2809
|
+
};
|
|
2810
|
+
}
|
|
2811
|
+
};
|
|
2812
|
+
var ConnectorInitEvent = class extends BaseTelemetryEvent {
|
|
2813
|
+
constructor(data) {
|
|
2814
|
+
super();
|
|
2815
|
+
this.data = data;
|
|
2816
|
+
}
|
|
2817
|
+
static {
|
|
2818
|
+
__name(this, "ConnectorInitEvent");
|
|
2819
|
+
}
|
|
2820
|
+
get name() {
|
|
2821
|
+
return "connector_init";
|
|
2822
|
+
}
|
|
2823
|
+
get properties() {
|
|
2824
|
+
return {
|
|
2825
|
+
connector_type: this.data.connectorType,
|
|
2826
|
+
server_command: this.data.serverCommand ?? null,
|
|
2827
|
+
server_args: this.data.serverArgs ?? null,
|
|
2828
|
+
server_url: this.data.serverUrl ?? null,
|
|
2829
|
+
public_identifier: this.data.publicIdentifier ?? null
|
|
2830
|
+
};
|
|
2831
|
+
}
|
|
2832
|
+
};
|
|
2581
2833
|
|
|
2582
|
-
// src/
|
|
2583
|
-
var
|
|
2584
|
-
var path = __toESM(require("path"), 1);
|
|
2834
|
+
// src/version.ts
|
|
2835
|
+
var VERSION = "1.10.0-canary.10";
|
|
2585
2836
|
function getPackageVersion() {
|
|
2586
|
-
|
|
2587
|
-
if (typeof __dirname === "undefined" || typeof fs === "undefined") {
|
|
2588
|
-
return "unknown";
|
|
2589
|
-
}
|
|
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
|
-
}
|
|
2837
|
+
return VERSION;
|
|
2596
2838
|
}
|
|
2597
2839
|
__name(getPackageVersion, "getPackageVersion");
|
|
2840
|
+
|
|
2841
|
+
// src/telemetry/utils.ts
|
|
2598
2842
|
function getModelProvider(llm) {
|
|
2599
2843
|
return llm._llm_type || llm.constructor.name.toLowerCase();
|
|
2600
2844
|
}
|
|
@@ -2627,20 +2871,66 @@ function extractModelInfo(llm) {
|
|
|
2627
2871
|
__name(extractModelInfo, "extractModelInfo");
|
|
2628
2872
|
|
|
2629
2873
|
// src/telemetry/telemetry.ts
|
|
2630
|
-
|
|
2874
|
+
var USER_ID_STORAGE_KEY = "mcp_use_user_id";
|
|
2875
|
+
function detectRuntimeEnvironment() {
|
|
2631
2876
|
try {
|
|
2877
|
+
if (typeof globalThis.Bun !== "undefined") {
|
|
2878
|
+
return "bun";
|
|
2879
|
+
}
|
|
2880
|
+
if (typeof globalThis.Deno !== "undefined") {
|
|
2881
|
+
return "deno";
|
|
2882
|
+
}
|
|
2632
2883
|
if (typeof navigator !== "undefined" && navigator.userAgent?.includes("Cloudflare-Workers")) {
|
|
2633
|
-
return
|
|
2884
|
+
return "cloudflare-workers";
|
|
2634
2885
|
}
|
|
2635
|
-
if (typeof globalThis.EdgeRuntime !== "undefined"
|
|
2636
|
-
return
|
|
2886
|
+
if (typeof globalThis.EdgeRuntime !== "undefined") {
|
|
2887
|
+
return "edge";
|
|
2637
2888
|
}
|
|
2638
|
-
|
|
2639
|
-
|
|
2640
|
-
|
|
2889
|
+
if (typeof process !== "undefined" && typeof process.versions?.node !== "undefined" && typeof fs !== "undefined" && typeof fs.existsSync === "function") {
|
|
2890
|
+
return "node";
|
|
2891
|
+
}
|
|
2892
|
+
if (typeof window !== "undefined" && typeof document !== "undefined") {
|
|
2893
|
+
return "browser";
|
|
2894
|
+
}
|
|
2895
|
+
return "unknown";
|
|
2641
2896
|
} catch {
|
|
2642
|
-
return
|
|
2897
|
+
return "unknown";
|
|
2898
|
+
}
|
|
2899
|
+
}
|
|
2900
|
+
__name(detectRuntimeEnvironment, "detectRuntimeEnvironment");
|
|
2901
|
+
function getStorageCapability(env) {
|
|
2902
|
+
switch (env) {
|
|
2903
|
+
case "node":
|
|
2904
|
+
case "bun":
|
|
2905
|
+
return "filesystem";
|
|
2906
|
+
case "browser":
|
|
2907
|
+
try {
|
|
2908
|
+
if (typeof localStorage !== "undefined") {
|
|
2909
|
+
localStorage.setItem("__mcp_use_test__", "1");
|
|
2910
|
+
localStorage.removeItem("__mcp_use_test__");
|
|
2911
|
+
return "localStorage";
|
|
2912
|
+
}
|
|
2913
|
+
} catch {
|
|
2914
|
+
}
|
|
2915
|
+
return "session-only";
|
|
2916
|
+
case "deno":
|
|
2917
|
+
return "session-only";
|
|
2918
|
+
default:
|
|
2919
|
+
return "session-only";
|
|
2920
|
+
}
|
|
2921
|
+
}
|
|
2922
|
+
__name(getStorageCapability, "getStorageCapability");
|
|
2923
|
+
var cachedEnvironment = null;
|
|
2924
|
+
function getRuntimeEnvironment() {
|
|
2925
|
+
if (cachedEnvironment === null) {
|
|
2926
|
+
cachedEnvironment = detectRuntimeEnvironment();
|
|
2643
2927
|
}
|
|
2928
|
+
return cachedEnvironment;
|
|
2929
|
+
}
|
|
2930
|
+
__name(getRuntimeEnvironment, "getRuntimeEnvironment");
|
|
2931
|
+
function isNodeJSEnvironment2() {
|
|
2932
|
+
const env = getRuntimeEnvironment();
|
|
2933
|
+
return env === "node" || env === "bun";
|
|
2644
2934
|
}
|
|
2645
2935
|
__name(isNodeJSEnvironment2, "isNodeJSEnvironment");
|
|
2646
2936
|
var ScarfEventLogger = class {
|
|
@@ -2679,7 +2969,7 @@ function getCacheHome() {
|
|
|
2679
2969
|
return "/tmp/mcp_use_cache";
|
|
2680
2970
|
}
|
|
2681
2971
|
const envVar = process.env.XDG_CACHE_HOME;
|
|
2682
|
-
if (envVar &&
|
|
2972
|
+
if (envVar && path.isAbsolute(envVar)) {
|
|
2683
2973
|
return envVar;
|
|
2684
2974
|
}
|
|
2685
2975
|
const platform = process.platform;
|
|
@@ -2689,11 +2979,11 @@ function getCacheHome() {
|
|
|
2689
2979
|
if (appdata) {
|
|
2690
2980
|
return appdata;
|
|
2691
2981
|
}
|
|
2692
|
-
return
|
|
2982
|
+
return path.join(homeDir, "AppData", "Local");
|
|
2693
2983
|
} else if (platform === "darwin") {
|
|
2694
|
-
return
|
|
2984
|
+
return path.join(homeDir, "Library", "Caches");
|
|
2695
2985
|
} else {
|
|
2696
|
-
return
|
|
2986
|
+
return path.join(homeDir, ".cache");
|
|
2697
2987
|
}
|
|
2698
2988
|
}
|
|
2699
2989
|
__name(getCacheHome, "getCacheHome");
|
|
@@ -2702,12 +2992,12 @@ var Telemetry = class _Telemetry {
|
|
|
2702
2992
|
__name(this, "Telemetry");
|
|
2703
2993
|
}
|
|
2704
2994
|
static instance = null;
|
|
2705
|
-
USER_ID_PATH =
|
|
2995
|
+
USER_ID_PATH = path.join(
|
|
2706
2996
|
getCacheHome(),
|
|
2707
2997
|
"mcp_use_3",
|
|
2708
2998
|
"telemetry_user_id"
|
|
2709
2999
|
);
|
|
2710
|
-
VERSION_DOWNLOAD_PATH =
|
|
3000
|
+
VERSION_DOWNLOAD_PATH = path.join(
|
|
2711
3001
|
getCacheHome(),
|
|
2712
3002
|
"mcp_use",
|
|
2713
3003
|
"download_version"
|
|
@@ -2719,32 +3009,53 @@ var Telemetry = class _Telemetry {
|
|
|
2719
3009
|
_currUserId = null;
|
|
2720
3010
|
_posthogClient = null;
|
|
2721
3011
|
_scarfClient = null;
|
|
2722
|
-
|
|
3012
|
+
_runtimeEnvironment;
|
|
3013
|
+
_storageCapability;
|
|
3014
|
+
_source;
|
|
2723
3015
|
constructor() {
|
|
2724
|
-
|
|
3016
|
+
this._runtimeEnvironment = getRuntimeEnvironment();
|
|
3017
|
+
this._storageCapability = getStorageCapability(this._runtimeEnvironment);
|
|
3018
|
+
this._source = typeof process !== "undefined" && process.env?.MCP_USE_TELEMETRY_SOURCE || this._runtimeEnvironment;
|
|
2725
3019
|
const telemetryDisabled = typeof process !== "undefined" && process.env?.MCP_USE_ANONYMIZED_TELEMETRY?.toLowerCase() === "false" || false;
|
|
2726
|
-
|
|
3020
|
+
const canSupportTelemetry = this._runtimeEnvironment !== "unknown";
|
|
3021
|
+
const isServerlessEnvironment = [
|
|
3022
|
+
"cloudflare-workers",
|
|
3023
|
+
"edge",
|
|
3024
|
+
"deno"
|
|
3025
|
+
].includes(this._runtimeEnvironment);
|
|
2727
3026
|
if (telemetryDisabled) {
|
|
2728
3027
|
this._posthogClient = null;
|
|
2729
3028
|
this._scarfClient = null;
|
|
2730
3029
|
logger.debug("Telemetry disabled via environment variable");
|
|
2731
|
-
} else if (!
|
|
3030
|
+
} else if (!canSupportTelemetry) {
|
|
2732
3031
|
this._posthogClient = null;
|
|
2733
3032
|
this._scarfClient = null;
|
|
2734
3033
|
logger.debug(
|
|
2735
|
-
|
|
3034
|
+
`Telemetry disabled - unknown environment: ${this._runtimeEnvironment}`
|
|
2736
3035
|
);
|
|
2737
3036
|
} else {
|
|
2738
3037
|
logger.info(
|
|
2739
3038
|
"Anonymized telemetry enabled. Set MCP_USE_ANONYMIZED_TELEMETRY=false to disable."
|
|
2740
3039
|
);
|
|
2741
|
-
|
|
2742
|
-
|
|
2743
|
-
|
|
2744
|
-
|
|
2745
|
-
|
|
2746
|
-
|
|
2747
|
-
|
|
3040
|
+
if (this._runtimeEnvironment !== "browser") {
|
|
3041
|
+
try {
|
|
3042
|
+
const posthogOptions = {
|
|
3043
|
+
host: this.HOST,
|
|
3044
|
+
disableGeoip: false
|
|
3045
|
+
};
|
|
3046
|
+
if (isServerlessEnvironment) {
|
|
3047
|
+
posthogOptions.flushAt = 1;
|
|
3048
|
+
posthogOptions.flushInterval = 0;
|
|
3049
|
+
}
|
|
3050
|
+
this._posthogClient = new import_posthog_node.PostHog(
|
|
3051
|
+
this.PROJECT_API_KEY,
|
|
3052
|
+
posthogOptions
|
|
3053
|
+
);
|
|
3054
|
+
} catch (e) {
|
|
3055
|
+
logger.warn(`Failed to initialize PostHog telemetry: ${e}`);
|
|
3056
|
+
this._posthogClient = null;
|
|
3057
|
+
}
|
|
3058
|
+
} else {
|
|
2748
3059
|
this._posthogClient = null;
|
|
2749
3060
|
}
|
|
2750
3061
|
try {
|
|
@@ -2755,6 +3066,18 @@ var Telemetry = class _Telemetry {
|
|
|
2755
3066
|
}
|
|
2756
3067
|
}
|
|
2757
3068
|
}
|
|
3069
|
+
/**
|
|
3070
|
+
* Get the detected runtime environment
|
|
3071
|
+
*/
|
|
3072
|
+
get runtimeEnvironment() {
|
|
3073
|
+
return this._runtimeEnvironment;
|
|
3074
|
+
}
|
|
3075
|
+
/**
|
|
3076
|
+
* Get the storage capability for this environment
|
|
3077
|
+
*/
|
|
3078
|
+
get storageCapability() {
|
|
3079
|
+
return this._storageCapability;
|
|
3080
|
+
}
|
|
2758
3081
|
static getInstance() {
|
|
2759
3082
|
if (!_Telemetry.instance) {
|
|
2760
3083
|
_Telemetry.instance = new _Telemetry();
|
|
@@ -2776,36 +3099,80 @@ var Telemetry = class _Telemetry {
|
|
|
2776
3099
|
getSource() {
|
|
2777
3100
|
return this._source;
|
|
2778
3101
|
}
|
|
3102
|
+
/**
|
|
3103
|
+
* Check if telemetry is enabled.
|
|
3104
|
+
* Returns false if telemetry was disabled via environment variable or if not in Node.js environment.
|
|
3105
|
+
*/
|
|
3106
|
+
get isEnabled() {
|
|
3107
|
+
return this._posthogClient !== null || this._scarfClient !== null;
|
|
3108
|
+
}
|
|
2779
3109
|
get userId() {
|
|
2780
3110
|
if (this._currUserId) {
|
|
2781
3111
|
return this._currUserId;
|
|
2782
3112
|
}
|
|
2783
|
-
if (!isNodeJSEnvironment2()) {
|
|
2784
|
-
this._currUserId = this.UNKNOWN_USER_ID;
|
|
2785
|
-
return this._currUserId;
|
|
2786
|
-
}
|
|
2787
3113
|
try {
|
|
2788
|
-
|
|
2789
|
-
|
|
2790
|
-
|
|
2791
|
-
|
|
2792
|
-
|
|
2793
|
-
|
|
2794
|
-
|
|
2795
|
-
|
|
2796
|
-
|
|
2797
|
-
|
|
3114
|
+
switch (this._storageCapability) {
|
|
3115
|
+
case "filesystem":
|
|
3116
|
+
this._currUserId = this.getUserIdFromFilesystem();
|
|
3117
|
+
break;
|
|
3118
|
+
case "localStorage":
|
|
3119
|
+
this._currUserId = this.getUserIdFromLocalStorage();
|
|
3120
|
+
break;
|
|
3121
|
+
case "session-only":
|
|
3122
|
+
default:
|
|
3123
|
+
this._currUserId = `session-${generateUUID()}`;
|
|
3124
|
+
logger.debug(
|
|
3125
|
+
`Using session-based user ID (${this._runtimeEnvironment} environment)`
|
|
3126
|
+
);
|
|
3127
|
+
break;
|
|
3128
|
+
}
|
|
3129
|
+
if (this._storageCapability === "filesystem" && this._currUserId) {
|
|
3130
|
+
this.trackPackageDownloadInternal(this._currUserId, {
|
|
3131
|
+
triggered_by: "user_id_property"
|
|
3132
|
+
}).catch((e) => logger.debug(`Failed to track package download: ${e}`));
|
|
2798
3133
|
}
|
|
2799
|
-
this.trackPackageDownload({
|
|
2800
|
-
triggered_by: "user_id_property"
|
|
2801
|
-
}).catch((e) => logger.debug(`Failed to track package download: ${e}`));
|
|
2802
3134
|
} catch (e) {
|
|
2803
3135
|
logger.debug(`Failed to get/create user ID: ${e}`);
|
|
2804
3136
|
this._currUserId = this.UNKNOWN_USER_ID;
|
|
2805
3137
|
}
|
|
2806
3138
|
return this._currUserId;
|
|
2807
3139
|
}
|
|
3140
|
+
/**
|
|
3141
|
+
* Get or create user ID from filesystem (Node.js/Bun)
|
|
3142
|
+
*/
|
|
3143
|
+
getUserIdFromFilesystem() {
|
|
3144
|
+
const isFirstTime = !fs.existsSync(this.USER_ID_PATH);
|
|
3145
|
+
if (isFirstTime) {
|
|
3146
|
+
logger.debug(`Creating user ID path: ${this.USER_ID_PATH}`);
|
|
3147
|
+
fs.mkdirSync(path.dirname(this.USER_ID_PATH), { recursive: true });
|
|
3148
|
+
const newUserId = generateUUID();
|
|
3149
|
+
fs.writeFileSync(this.USER_ID_PATH, newUserId);
|
|
3150
|
+
logger.debug(`User ID path created: ${this.USER_ID_PATH}`);
|
|
3151
|
+
return newUserId;
|
|
3152
|
+
}
|
|
3153
|
+
return fs.readFileSync(this.USER_ID_PATH, "utf-8").trim();
|
|
3154
|
+
}
|
|
3155
|
+
/**
|
|
3156
|
+
* Get or create user ID from localStorage (Browser)
|
|
3157
|
+
*/
|
|
3158
|
+
getUserIdFromLocalStorage() {
|
|
3159
|
+
try {
|
|
3160
|
+
let userId = localStorage.getItem(USER_ID_STORAGE_KEY);
|
|
3161
|
+
if (!userId) {
|
|
3162
|
+
userId = generateUUID();
|
|
3163
|
+
localStorage.setItem(USER_ID_STORAGE_KEY, userId);
|
|
3164
|
+
logger.debug(`Created new browser user ID`);
|
|
3165
|
+
}
|
|
3166
|
+
return userId;
|
|
3167
|
+
} catch (e) {
|
|
3168
|
+
logger.debug(`localStorage access failed: ${e}`);
|
|
3169
|
+
return `session-${generateUUID()}`;
|
|
3170
|
+
}
|
|
3171
|
+
}
|
|
2808
3172
|
async capture(event) {
|
|
3173
|
+
logger.debug(
|
|
3174
|
+
`CAPTURE: posthog: ${this._posthogClient !== null}, scarf: ${this._scarfClient !== null}`
|
|
3175
|
+
);
|
|
2809
3176
|
if (!this._posthogClient && !this._scarfClient) {
|
|
2810
3177
|
return;
|
|
2811
3178
|
}
|
|
@@ -2815,6 +3182,11 @@ var Telemetry = class _Telemetry {
|
|
|
2815
3182
|
properties.mcp_use_version = getPackageVersion();
|
|
2816
3183
|
properties.language = "typescript";
|
|
2817
3184
|
properties.source = this._source;
|
|
3185
|
+
properties.runtime = this._runtimeEnvironment;
|
|
3186
|
+
logger.debug(`CAPTURE: PostHog Event ${event.name}`);
|
|
3187
|
+
logger.debug(
|
|
3188
|
+
`CAPTURE: PostHog Properties ${JSON.stringify(properties)}`
|
|
3189
|
+
);
|
|
2818
3190
|
this._posthogClient.capture({
|
|
2819
3191
|
distinctId: this.userId,
|
|
2820
3192
|
event: event.name,
|
|
@@ -2832,36 +3204,48 @@ var Telemetry = class _Telemetry {
|
|
|
2832
3204
|
properties.event = event.name;
|
|
2833
3205
|
properties.language = "typescript";
|
|
2834
3206
|
properties.source = this._source;
|
|
3207
|
+
properties.runtime = this._runtimeEnvironment;
|
|
2835
3208
|
await this._scarfClient.logEvent(properties);
|
|
2836
3209
|
} catch (e) {
|
|
2837
3210
|
logger.debug(`Failed to track Scarf event ${event.name}: ${e}`);
|
|
2838
3211
|
}
|
|
2839
3212
|
}
|
|
2840
3213
|
}
|
|
3214
|
+
/**
|
|
3215
|
+
* Track package download event.
|
|
3216
|
+
* This is a public wrapper that safely accesses userId.
|
|
3217
|
+
*/
|
|
2841
3218
|
async trackPackageDownload(properties) {
|
|
3219
|
+
return this.trackPackageDownloadInternal(this.userId, properties);
|
|
3220
|
+
}
|
|
3221
|
+
/**
|
|
3222
|
+
* Internal method to track package download with explicit userId.
|
|
3223
|
+
* This avoids circular dependency when called from the userId getter.
|
|
3224
|
+
*/
|
|
3225
|
+
async trackPackageDownloadInternal(userId, properties) {
|
|
2842
3226
|
if (!this._scarfClient) {
|
|
2843
3227
|
return;
|
|
2844
3228
|
}
|
|
2845
|
-
if (
|
|
3229
|
+
if (this._storageCapability !== "filesystem") {
|
|
2846
3230
|
return;
|
|
2847
3231
|
}
|
|
2848
3232
|
try {
|
|
2849
3233
|
const currentVersion = getPackageVersion();
|
|
2850
3234
|
let shouldTrack = false;
|
|
2851
3235
|
let firstDownload = false;
|
|
2852
|
-
if (!
|
|
3236
|
+
if (!fs.existsSync(this.VERSION_DOWNLOAD_PATH)) {
|
|
2853
3237
|
shouldTrack = true;
|
|
2854
3238
|
firstDownload = true;
|
|
2855
|
-
|
|
3239
|
+
fs.mkdirSync(path.dirname(this.VERSION_DOWNLOAD_PATH), {
|
|
2856
3240
|
recursive: true
|
|
2857
3241
|
});
|
|
2858
|
-
|
|
3242
|
+
fs.writeFileSync(this.VERSION_DOWNLOAD_PATH, currentVersion);
|
|
2859
3243
|
} else {
|
|
2860
|
-
const savedVersion =
|
|
3244
|
+
const savedVersion = fs.readFileSync(this.VERSION_DOWNLOAD_PATH, "utf-8").trim();
|
|
2861
3245
|
if (currentVersion > savedVersion) {
|
|
2862
3246
|
shouldTrack = true;
|
|
2863
3247
|
firstDownload = false;
|
|
2864
|
-
|
|
3248
|
+
fs.writeFileSync(this.VERSION_DOWNLOAD_PATH, currentVersion);
|
|
2865
3249
|
}
|
|
2866
3250
|
}
|
|
2867
3251
|
if (shouldTrack) {
|
|
@@ -2870,21 +3254,79 @@ var Telemetry = class _Telemetry {
|
|
|
2870
3254
|
);
|
|
2871
3255
|
const eventProperties = { ...properties || {} };
|
|
2872
3256
|
eventProperties.mcp_use_version = currentVersion;
|
|
2873
|
-
eventProperties.user_id =
|
|
3257
|
+
eventProperties.user_id = userId;
|
|
2874
3258
|
eventProperties.event = "package_download";
|
|
2875
3259
|
eventProperties.first_download = firstDownload;
|
|
2876
3260
|
eventProperties.language = "typescript";
|
|
2877
3261
|
eventProperties.source = this._source;
|
|
3262
|
+
eventProperties.runtime = this._runtimeEnvironment;
|
|
2878
3263
|
await this._scarfClient.logEvent(eventProperties);
|
|
2879
3264
|
}
|
|
2880
3265
|
} catch (e) {
|
|
2881
3266
|
logger.debug(`Failed to track Scarf package_download event: ${e}`);
|
|
2882
3267
|
}
|
|
2883
3268
|
}
|
|
3269
|
+
// ============================================================================
|
|
3270
|
+
// Agent Events
|
|
3271
|
+
// ============================================================================
|
|
2884
3272
|
async trackAgentExecution(data) {
|
|
3273
|
+
if (!this.isEnabled) return;
|
|
2885
3274
|
const event = new MCPAgentExecutionEvent(data);
|
|
2886
3275
|
await this.capture(event);
|
|
2887
3276
|
}
|
|
3277
|
+
// ============================================================================
|
|
3278
|
+
// Server Events
|
|
3279
|
+
// ============================================================================
|
|
3280
|
+
/**
|
|
3281
|
+
* Track server run event directly from an MCPServer instance.
|
|
3282
|
+
* This extracts the necessary data from the server and creates the event.
|
|
3283
|
+
* @param server - The MCPServer instance (or any object conforming to MCPServerTelemetryInfo)
|
|
3284
|
+
* @param transport - The transport type (e.g., "http", "stdio", "supabase")
|
|
3285
|
+
*/
|
|
3286
|
+
async trackServerRunFromServer(server, transport) {
|
|
3287
|
+
if (!this.isEnabled) return;
|
|
3288
|
+
const data = createServerRunEventData(server, transport);
|
|
3289
|
+
const event = new ServerRunEvent(data);
|
|
3290
|
+
await this.capture(event);
|
|
3291
|
+
}
|
|
3292
|
+
async trackServerInitialize(data) {
|
|
3293
|
+
if (!this.isEnabled) return;
|
|
3294
|
+
const event = new ServerInitializeEvent(data);
|
|
3295
|
+
await this.capture(event);
|
|
3296
|
+
}
|
|
3297
|
+
async trackServerToolCall(data) {
|
|
3298
|
+
if (!this.isEnabled) return;
|
|
3299
|
+
const event = new ServerToolCallEvent(data);
|
|
3300
|
+
await this.capture(event);
|
|
3301
|
+
}
|
|
3302
|
+
async trackServerResourceCall(data) {
|
|
3303
|
+
if (!this.isEnabled) return;
|
|
3304
|
+
const event = new ServerResourceCallEvent(data);
|
|
3305
|
+
await this.capture(event);
|
|
3306
|
+
}
|
|
3307
|
+
async trackServerPromptCall(data) {
|
|
3308
|
+
if (!this.isEnabled) return;
|
|
3309
|
+
const event = new ServerPromptCallEvent(data);
|
|
3310
|
+
await this.capture(event);
|
|
3311
|
+
}
|
|
3312
|
+
async trackServerContext(data) {
|
|
3313
|
+
if (!this.isEnabled) return;
|
|
3314
|
+
const event = new ServerContextEvent(data);
|
|
3315
|
+
await this.capture(event);
|
|
3316
|
+
}
|
|
3317
|
+
// ============================================================================
|
|
3318
|
+
// Client Events
|
|
3319
|
+
// ============================================================================
|
|
3320
|
+
async trackMCPClientInit(data) {
|
|
3321
|
+
if (!this.isEnabled) return;
|
|
3322
|
+
const event = new MCPClientInitEvent(data);
|
|
3323
|
+
await this.capture(event);
|
|
3324
|
+
}
|
|
3325
|
+
async trackConnectorInit(data) {
|
|
3326
|
+
if (!this.isEnabled) return;
|
|
3327
|
+
const event = new ConnectorInitEvent(data);
|
|
3328
|
+
await this.capture(event);
|
|
3329
|
+
}
|
|
2888
3330
|
flush() {
|
|
2889
3331
|
if (this._posthogClient) {
|
|
2890
3332
|
try {
|
|
@@ -3246,6 +3688,13 @@ var MCPAgent = class {
|
|
|
3246
3688
|
static {
|
|
3247
3689
|
__name(this, "MCPAgent");
|
|
3248
3690
|
}
|
|
3691
|
+
/**
|
|
3692
|
+
* Get the mcp-use package version.
|
|
3693
|
+
* Works in all environments (Node.js, browser, Cloudflare Workers, Deno, etc.)
|
|
3694
|
+
*/
|
|
3695
|
+
static getPackageVersion() {
|
|
3696
|
+
return getPackageVersion();
|
|
3697
|
+
}
|
|
3249
3698
|
llm;
|
|
3250
3699
|
client;
|
|
3251
3700
|
connectors;
|
|
@@ -3969,7 +4418,7 @@ var MCPAgent = class {
|
|
|
3969
4418
|
const historyToUse = externalHistory ?? this.conversationHistory;
|
|
3970
4419
|
const langchainHistory = [];
|
|
3971
4420
|
for (const msg of historyToUse) {
|
|
3972
|
-
if (this._isHumanMessageLike(msg) || this._isAIMessageLike(msg)) {
|
|
4421
|
+
if (this._isHumanMessageLike(msg) || this._isAIMessageLike(msg) || this._isToolMessageLike(msg)) {
|
|
3973
4422
|
langchainHistory.push(msg);
|
|
3974
4423
|
}
|
|
3975
4424
|
}
|
|
@@ -4102,9 +4551,9 @@ var MCPAgent = class {
|
|
|
4102
4551
|
}
|
|
4103
4552
|
}
|
|
4104
4553
|
if (this.memoryEnabled) {
|
|
4105
|
-
|
|
4106
|
-
|
|
4107
|
-
this.addToHistory(
|
|
4554
|
+
const newMessages = accumulatedMessages.slice(langchainHistory.length);
|
|
4555
|
+
for (const msg of newMessages) {
|
|
4556
|
+
this.addToHistory(msg);
|
|
4108
4557
|
}
|
|
4109
4558
|
}
|
|
4110
4559
|
if (outputSchema && finalOutput) {
|
|
@@ -4539,7 +4988,9 @@ ${formatPrompt}`
|
|
|
4539
4988
|
let chunkCount = 0;
|
|
4540
4989
|
for await (const chunk of stream) {
|
|
4541
4990
|
chunkCount++;
|
|
4542
|
-
logger.
|
|
4991
|
+
logger.debug(
|
|
4992
|
+
`Chunk ${chunkCount}: ${JSON.stringify(chunk, null, 2)}`
|
|
4993
|
+
);
|
|
4543
4994
|
if (typeof chunk === "string") {
|
|
4544
4995
|
try {
|
|
4545
4996
|
structuredResult = JSON.parse(chunk);
|
|
@@ -4556,7 +5007,9 @@ ${formatPrompt}`
|
|
|
4556
5007
|
}
|
|
4557
5008
|
}
|
|
4558
5009
|
if (chunkCount % 10 === 0) {
|
|
4559
|
-
logger.
|
|
5010
|
+
logger.debug(
|
|
5011
|
+
`\u{1F504} Structured output streaming: ${chunkCount} chunks`
|
|
5012
|
+
);
|
|
4560
5013
|
}
|
|
4561
5014
|
}
|
|
4562
5015
|
logger.info(
|
|
@@ -4723,6 +5176,190 @@ var MCPSession = class {
|
|
|
4723
5176
|
getRoots() {
|
|
4724
5177
|
return this.connector.getRoots();
|
|
4725
5178
|
}
|
|
5179
|
+
/**
|
|
5180
|
+
* Get the cached list of tools from the server.
|
|
5181
|
+
*
|
|
5182
|
+
* @returns Array of available tools
|
|
5183
|
+
*
|
|
5184
|
+
* @example
|
|
5185
|
+
* ```typescript
|
|
5186
|
+
* const tools = session.tools;
|
|
5187
|
+
* console.log(`Available tools: ${tools.map(t => t.name).join(", ")}`);
|
|
5188
|
+
* ```
|
|
5189
|
+
*/
|
|
5190
|
+
get tools() {
|
|
5191
|
+
return this.connector.tools;
|
|
5192
|
+
}
|
|
5193
|
+
/**
|
|
5194
|
+
* Get the server capabilities advertised during initialization.
|
|
5195
|
+
*
|
|
5196
|
+
* @returns Server capabilities object
|
|
5197
|
+
*/
|
|
5198
|
+
get serverCapabilities() {
|
|
5199
|
+
return this.connector.serverCapabilities;
|
|
5200
|
+
}
|
|
5201
|
+
/**
|
|
5202
|
+
* Get the server information (name and version).
|
|
5203
|
+
*
|
|
5204
|
+
* @returns Server info object or null if not available
|
|
5205
|
+
*/
|
|
5206
|
+
get serverInfo() {
|
|
5207
|
+
return this.connector.serverInfo;
|
|
5208
|
+
}
|
|
5209
|
+
/**
|
|
5210
|
+
* Call a tool on the server.
|
|
5211
|
+
*
|
|
5212
|
+
* @param name - Name of the tool to call
|
|
5213
|
+
* @param args - Arguments to pass to the tool
|
|
5214
|
+
* @param options - Optional request options (timeout, progress handlers, etc.)
|
|
5215
|
+
* @returns Result from the tool execution
|
|
5216
|
+
*
|
|
5217
|
+
* @example
|
|
5218
|
+
* ```typescript
|
|
5219
|
+
* const result = await session.callTool("add", { a: 5, b: 3 });
|
|
5220
|
+
* console.log(`Result: ${result.content[0].text}`);
|
|
5221
|
+
* ```
|
|
5222
|
+
*/
|
|
5223
|
+
async callTool(name, args, options) {
|
|
5224
|
+
return this.connector.callTool(name, args, options);
|
|
5225
|
+
}
|
|
5226
|
+
/**
|
|
5227
|
+
* List resources from the server with optional pagination.
|
|
5228
|
+
*
|
|
5229
|
+
* @param cursor - Optional cursor for pagination
|
|
5230
|
+
* @param options - Request options
|
|
5231
|
+
* @returns Resource list with optional nextCursor for pagination
|
|
5232
|
+
*
|
|
5233
|
+
* @example
|
|
5234
|
+
* ```typescript
|
|
5235
|
+
* const result = await session.listResources();
|
|
5236
|
+
* console.log(`Found ${result.resources.length} resources`);
|
|
5237
|
+
* ```
|
|
5238
|
+
*/
|
|
5239
|
+
async listResources(cursor, options) {
|
|
5240
|
+
return this.connector.listResources(cursor, options);
|
|
5241
|
+
}
|
|
5242
|
+
/**
|
|
5243
|
+
* List all resources from the server, automatically handling pagination.
|
|
5244
|
+
*
|
|
5245
|
+
* @param options - Request options
|
|
5246
|
+
* @returns Complete list of all resources
|
|
5247
|
+
*
|
|
5248
|
+
* @example
|
|
5249
|
+
* ```typescript
|
|
5250
|
+
* const result = await session.listAllResources();
|
|
5251
|
+
* console.log(`Total resources: ${result.resources.length}`);
|
|
5252
|
+
* ```
|
|
5253
|
+
*/
|
|
5254
|
+
async listAllResources(options) {
|
|
5255
|
+
return this.connector.listAllResources(options);
|
|
5256
|
+
}
|
|
5257
|
+
/**
|
|
5258
|
+
* List resource templates from the server.
|
|
5259
|
+
*
|
|
5260
|
+
* @param options - Request options
|
|
5261
|
+
* @returns List of available resource templates
|
|
5262
|
+
*
|
|
5263
|
+
* @example
|
|
5264
|
+
* ```typescript
|
|
5265
|
+
* const result = await session.listResourceTemplates();
|
|
5266
|
+
* console.log(`Available templates: ${result.resourceTemplates.length}`);
|
|
5267
|
+
* ```
|
|
5268
|
+
*/
|
|
5269
|
+
async listResourceTemplates(options) {
|
|
5270
|
+
return this.connector.listResourceTemplates(options);
|
|
5271
|
+
}
|
|
5272
|
+
/**
|
|
5273
|
+
* Read a resource by URI.
|
|
5274
|
+
*
|
|
5275
|
+
* @param uri - URI of the resource to read
|
|
5276
|
+
* @param options - Request options
|
|
5277
|
+
* @returns Resource content
|
|
5278
|
+
*
|
|
5279
|
+
* @example
|
|
5280
|
+
* ```typescript
|
|
5281
|
+
* const resource = await session.readResource("file:///path/to/file.txt");
|
|
5282
|
+
* console.log(resource.contents);
|
|
5283
|
+
* ```
|
|
5284
|
+
*/
|
|
5285
|
+
async readResource(uri, options) {
|
|
5286
|
+
return this.connector.readResource(uri, options);
|
|
5287
|
+
}
|
|
5288
|
+
/**
|
|
5289
|
+
* Subscribe to resource updates.
|
|
5290
|
+
*
|
|
5291
|
+
* @param uri - URI of the resource to subscribe to
|
|
5292
|
+
* @param options - Request options
|
|
5293
|
+
*
|
|
5294
|
+
* @example
|
|
5295
|
+
* ```typescript
|
|
5296
|
+
* await session.subscribeToResource("file:///path/to/file.txt");
|
|
5297
|
+
* // Now you'll receive notifications when this resource changes
|
|
5298
|
+
* ```
|
|
5299
|
+
*/
|
|
5300
|
+
async subscribeToResource(uri, options) {
|
|
5301
|
+
return this.connector.subscribeToResource(uri, options);
|
|
5302
|
+
}
|
|
5303
|
+
/**
|
|
5304
|
+
* Unsubscribe from resource updates.
|
|
5305
|
+
*
|
|
5306
|
+
* @param uri - URI of the resource to unsubscribe from
|
|
5307
|
+
* @param options - Request options
|
|
5308
|
+
*
|
|
5309
|
+
* @example
|
|
5310
|
+
* ```typescript
|
|
5311
|
+
* await session.unsubscribeFromResource("file:///path/to/file.txt");
|
|
5312
|
+
* ```
|
|
5313
|
+
*/
|
|
5314
|
+
async unsubscribeFromResource(uri, options) {
|
|
5315
|
+
return this.connector.unsubscribeFromResource(uri, options);
|
|
5316
|
+
}
|
|
5317
|
+
/**
|
|
5318
|
+
* List available prompts from the server.
|
|
5319
|
+
*
|
|
5320
|
+
* @returns List of available prompts
|
|
5321
|
+
*
|
|
5322
|
+
* @example
|
|
5323
|
+
* ```typescript
|
|
5324
|
+
* const result = await session.listPrompts();
|
|
5325
|
+
* console.log(`Available prompts: ${result.prompts.length}`);
|
|
5326
|
+
* ```
|
|
5327
|
+
*/
|
|
5328
|
+
async listPrompts() {
|
|
5329
|
+
return this.connector.listPrompts();
|
|
5330
|
+
}
|
|
5331
|
+
/**
|
|
5332
|
+
* Get a specific prompt with arguments.
|
|
5333
|
+
*
|
|
5334
|
+
* @param name - Name of the prompt to get
|
|
5335
|
+
* @param args - Arguments for the prompt
|
|
5336
|
+
* @returns Prompt result
|
|
5337
|
+
*
|
|
5338
|
+
* @example
|
|
5339
|
+
* ```typescript
|
|
5340
|
+
* const prompt = await session.getPrompt("greeting", { name: "Alice" });
|
|
5341
|
+
* console.log(prompt.messages);
|
|
5342
|
+
* ```
|
|
5343
|
+
*/
|
|
5344
|
+
async getPrompt(name, args) {
|
|
5345
|
+
return this.connector.getPrompt(name, args);
|
|
5346
|
+
}
|
|
5347
|
+
/**
|
|
5348
|
+
* Send a raw request through the client.
|
|
5349
|
+
*
|
|
5350
|
+
* @param method - MCP method name
|
|
5351
|
+
* @param params - Request parameters
|
|
5352
|
+
* @param options - Request options
|
|
5353
|
+
* @returns Response from the server
|
|
5354
|
+
*
|
|
5355
|
+
* @example
|
|
5356
|
+
* ```typescript
|
|
5357
|
+
* const result = await session.request("custom/method", { key: "value" });
|
|
5358
|
+
* ```
|
|
5359
|
+
*/
|
|
5360
|
+
async request(method, params = null, options) {
|
|
5361
|
+
return this.connector.request(method, params, options);
|
|
5362
|
+
}
|
|
4726
5363
|
};
|
|
4727
5364
|
|
|
4728
5365
|
// src/client/base.ts
|
|
@@ -5479,7 +6116,7 @@ var VMCodeExecutor = class extends BaseCodeExecutor {
|
|
|
5479
6116
|
};
|
|
5480
6117
|
|
|
5481
6118
|
// src/connectors/base.ts
|
|
5482
|
-
var import_types = require("@modelcontextprotocol
|
|
6119
|
+
var import_types = require("@mcp-use/modelcontextprotocol-sdk/types.js");
|
|
5483
6120
|
init_logging();
|
|
5484
6121
|
var BaseConnector = class {
|
|
5485
6122
|
static {
|
|
@@ -5500,6 +6137,17 @@ var BaseConnector = class {
|
|
|
5500
6137
|
this.rootsCache = [...opts.roots];
|
|
5501
6138
|
}
|
|
5502
6139
|
}
|
|
6140
|
+
/**
|
|
6141
|
+
* Track connector initialization event
|
|
6142
|
+
* Should be called by subclasses after successful connection
|
|
6143
|
+
*/
|
|
6144
|
+
trackConnectorInit(data) {
|
|
6145
|
+
const connectorType = this.constructor.name;
|
|
6146
|
+
Telemetry.getInstance().trackConnectorInit({
|
|
6147
|
+
connectorType,
|
|
6148
|
+
...data
|
|
6149
|
+
}).catch((e) => logger.debug(`Failed to track connector init: ${e}`));
|
|
6150
|
+
}
|
|
5503
6151
|
/**
|
|
5504
6152
|
* Register a handler for server notifications
|
|
5505
6153
|
*
|
|
@@ -5708,7 +6356,7 @@ var BaseConnector = class {
|
|
|
5708
6356
|
}
|
|
5709
6357
|
logger.debug("Caching server capabilities & tools");
|
|
5710
6358
|
const capabilities = this.client.getServerCapabilities();
|
|
5711
|
-
this.capabilitiesCache = capabilities;
|
|
6359
|
+
this.capabilitiesCache = capabilities || null;
|
|
5712
6360
|
const serverInfo = this.client.getServerVersion();
|
|
5713
6361
|
this.serverInfoCache = serverInfo || null;
|
|
5714
6362
|
const listToolsRes = await this.client.listTools(
|
|
@@ -5730,7 +6378,7 @@ var BaseConnector = class {
|
|
|
5730
6378
|
}
|
|
5731
6379
|
/** Expose cached server capabilities. */
|
|
5732
6380
|
get serverCapabilities() {
|
|
5733
|
-
return this.capabilitiesCache;
|
|
6381
|
+
return this.capabilitiesCache || {};
|
|
5734
6382
|
}
|
|
5735
6383
|
/** Expose cached server info. */
|
|
5736
6384
|
get serverInfo() {
|
|
@@ -5797,7 +6445,8 @@ var BaseConnector = class {
|
|
|
5797
6445
|
} while (cursor);
|
|
5798
6446
|
return { resources: allResources };
|
|
5799
6447
|
} catch (err) {
|
|
5800
|
-
|
|
6448
|
+
const error = err;
|
|
6449
|
+
if (error.code === -32601) {
|
|
5801
6450
|
logger.debug("Server advertised resources but method not found");
|
|
5802
6451
|
return { resources: [] };
|
|
5803
6452
|
}
|
|
@@ -5864,7 +6513,8 @@ var BaseConnector = class {
|
|
|
5864
6513
|
logger.debug("Listing prompts");
|
|
5865
6514
|
return await this.client.listPrompts();
|
|
5866
6515
|
} catch (err) {
|
|
5867
|
-
|
|
6516
|
+
const error = err;
|
|
6517
|
+
if (error.code === -32601) {
|
|
5868
6518
|
logger.debug("Server advertised prompts but method not found");
|
|
5869
6519
|
return { prompts: [] };
|
|
5870
6520
|
}
|
|
@@ -6123,12 +6773,12 @@ var CodeModeConnector = class extends BaseConnector {
|
|
|
6123
6773
|
var import_node_fs = require("fs");
|
|
6124
6774
|
|
|
6125
6775
|
// src/connectors/http.ts
|
|
6126
|
-
var import_client = require("@modelcontextprotocol
|
|
6127
|
-
var import_streamableHttp = require("@modelcontextprotocol
|
|
6776
|
+
var import_client = require("@mcp-use/modelcontextprotocol-sdk/client/index.js");
|
|
6777
|
+
var import_streamableHttp = require("@mcp-use/modelcontextprotocol-sdk/client/streamableHttp.js");
|
|
6128
6778
|
init_logging();
|
|
6129
6779
|
|
|
6130
6780
|
// src/task_managers/sse.ts
|
|
6131
|
-
var import_sse = require("@modelcontextprotocol
|
|
6781
|
+
var import_sse = require("@mcp-use/modelcontextprotocol-sdk/client/sse.js");
|
|
6132
6782
|
init_logging();
|
|
6133
6783
|
|
|
6134
6784
|
// src/task_managers/base.ts
|
|
@@ -6341,15 +6991,16 @@ var HttpConnector = class extends BaseConnector {
|
|
|
6341
6991
|
let fallbackReason = "Unknown error";
|
|
6342
6992
|
let is401Error = false;
|
|
6343
6993
|
if (err instanceof import_streamableHttp.StreamableHTTPError) {
|
|
6344
|
-
|
|
6345
|
-
|
|
6994
|
+
const streamableErr = err;
|
|
6995
|
+
is401Error = streamableErr.code === 401;
|
|
6996
|
+
if (streamableErr.code === 400 && streamableErr.message.includes("Missing session ID")) {
|
|
6346
6997
|
fallbackReason = "Server requires session ID (FastMCP compatibility) - using SSE transport";
|
|
6347
6998
|
logger.warn(`\u26A0\uFE0F ${fallbackReason}`);
|
|
6348
|
-
} else if (
|
|
6349
|
-
fallbackReason = `Server returned ${
|
|
6999
|
+
} else if (streamableErr.code === 404 || streamableErr.code === 405) {
|
|
7000
|
+
fallbackReason = `Server returned ${streamableErr.code} - server likely doesn't support streamable HTTP`;
|
|
6350
7001
|
logger.debug(fallbackReason);
|
|
6351
7002
|
} else {
|
|
6352
|
-
fallbackReason = `Server returned ${
|
|
7003
|
+
fallbackReason = `Server returned ${streamableErr.code}: ${streamableErr.message}`;
|
|
6353
7004
|
logger.debug(fallbackReason);
|
|
6354
7005
|
}
|
|
6355
7006
|
} else if (err instanceof Error) {
|
|
@@ -6489,6 +7140,10 @@ var HttpConnector = class extends BaseConnector {
|
|
|
6489
7140
|
logger.debug(
|
|
6490
7141
|
`Successfully connected to MCP implementation via streamable HTTP: ${baseUrl}`
|
|
6491
7142
|
);
|
|
7143
|
+
this.trackConnectorInit({
|
|
7144
|
+
serverUrl: this.baseUrl,
|
|
7145
|
+
publicIdentifier: `${this.baseUrl} (streamable-http)`
|
|
7146
|
+
});
|
|
6492
7147
|
} catch (err) {
|
|
6493
7148
|
await this.cleanupResources();
|
|
6494
7149
|
throw err;
|
|
@@ -6536,6 +7191,10 @@ var HttpConnector = class extends BaseConnector {
|
|
|
6536
7191
|
logger.debug(
|
|
6537
7192
|
`Successfully connected to MCP implementation via HTTP/SSE: ${baseUrl}`
|
|
6538
7193
|
);
|
|
7194
|
+
this.trackConnectorInit({
|
|
7195
|
+
serverUrl: this.baseUrl,
|
|
7196
|
+
publicIdentifier: `${this.baseUrl} (sse)`
|
|
7197
|
+
});
|
|
6539
7198
|
} catch (err) {
|
|
6540
7199
|
await this.cleanupResources();
|
|
6541
7200
|
throw err;
|
|
@@ -6558,11 +7217,11 @@ var HttpConnector = class extends BaseConnector {
|
|
|
6558
7217
|
|
|
6559
7218
|
// src/connectors/stdio.ts
|
|
6560
7219
|
var import_node_process = __toESM(require("process"), 1);
|
|
6561
|
-
var import_client2 = require("@modelcontextprotocol
|
|
7220
|
+
var import_client2 = require("@mcp-use/modelcontextprotocol-sdk/client/index.js");
|
|
6562
7221
|
init_logging();
|
|
6563
7222
|
|
|
6564
7223
|
// src/task_managers/stdio.ts
|
|
6565
|
-
var import_stdio = require("@modelcontextprotocol
|
|
7224
|
+
var import_stdio = require("@mcp-use/modelcontextprotocol-sdk/client/stdio.js");
|
|
6566
7225
|
init_logging();
|
|
6567
7226
|
var StdioConnectionManager = class extends ConnectionManager {
|
|
6568
7227
|
static {
|
|
@@ -6691,6 +7350,11 @@ var StdioConnector = class extends BaseConnector {
|
|
|
6691
7350
|
logger.debug(
|
|
6692
7351
|
`Successfully connected to MCP implementation: ${this.command}`
|
|
6693
7352
|
);
|
|
7353
|
+
this.trackConnectorInit({
|
|
7354
|
+
serverCommand: this.command,
|
|
7355
|
+
serverArgs: this.args,
|
|
7356
|
+
publicIdentifier: `${this.command} ${this.args.join(" ")}`
|
|
7357
|
+
});
|
|
6694
7358
|
} catch (err) {
|
|
6695
7359
|
logger.error(`Failed to connect to MCP implementation: ${err}`);
|
|
6696
7360
|
await this.cleanupResources();
|
|
@@ -7024,6 +7688,13 @@ var MCPClient = class _MCPClient extends BaseMCPClient {
|
|
|
7024
7688
|
static {
|
|
7025
7689
|
__name(this, "MCPClient");
|
|
7026
7690
|
}
|
|
7691
|
+
/**
|
|
7692
|
+
* Get the mcp-use package version.
|
|
7693
|
+
* Works in all environments (Node.js, browser, Cloudflare Workers, Deno, etc.)
|
|
7694
|
+
*/
|
|
7695
|
+
static getPackageVersion() {
|
|
7696
|
+
return getPackageVersion();
|
|
7697
|
+
}
|
|
7027
7698
|
codeMode = false;
|
|
7028
7699
|
_codeExecutor = null;
|
|
7029
7700
|
_customCodeExecutor = null;
|
|
@@ -7061,12 +7732,28 @@ var MCPClient = class _MCPClient extends BaseMCPClient {
|
|
|
7061
7732
|
if (this.codeMode) {
|
|
7062
7733
|
this._setupCodeModeConnector();
|
|
7063
7734
|
}
|
|
7735
|
+
this._trackClientInit();
|
|
7736
|
+
}
|
|
7737
|
+
_trackClientInit() {
|
|
7738
|
+
const servers = Object.keys(this.config.mcpServers ?? {});
|
|
7739
|
+
const hasSamplingCallback = !!this._samplingCallback;
|
|
7740
|
+
const hasElicitationCallback = !!this._elicitationCallback;
|
|
7741
|
+
Telemetry.getInstance().trackMCPClientInit({
|
|
7742
|
+
codeMode: this.codeMode,
|
|
7743
|
+
sandbox: false,
|
|
7744
|
+
// Sandbox not supported in TS yet
|
|
7745
|
+
allCallbacks: hasSamplingCallback && hasElicitationCallback,
|
|
7746
|
+
verify: false,
|
|
7747
|
+
// No verify option in TS client
|
|
7748
|
+
servers,
|
|
7749
|
+
numServers: servers.length
|
|
7750
|
+
}).catch((e) => logger.debug(`Failed to track MCPClient init: ${e}`));
|
|
7064
7751
|
}
|
|
7065
7752
|
static fromDict(cfg, options) {
|
|
7066
7753
|
return new _MCPClient(cfg, options);
|
|
7067
7754
|
}
|
|
7068
|
-
static fromConfigFile(
|
|
7069
|
-
return new _MCPClient(loadConfigFile(
|
|
7755
|
+
static fromConfigFile(path3, options) {
|
|
7756
|
+
return new _MCPClient(loadConfigFile(path3), options);
|
|
7070
7757
|
}
|
|
7071
7758
|
/**
|
|
7072
7759
|
* Save configuration to a file (Node.js only)
|
|
@@ -7310,19 +7997,20 @@ var OAuthHelper = class {
|
|
|
7310
7997
|
);
|
|
7311
7998
|
return false;
|
|
7312
7999
|
} catch (error) {
|
|
8000
|
+
const err = error;
|
|
7313
8001
|
console.warn(
|
|
7314
8002
|
"\u26A0\uFE0F [OAuthHelper] Could not check auth requirement for:",
|
|
7315
8003
|
serverUrl,
|
|
7316
8004
|
error
|
|
7317
8005
|
);
|
|
7318
|
-
if (
|
|
8006
|
+
if (err.name === "TypeError" && (err.message?.includes("CORS") || err.message?.includes("Failed to fetch"))) {
|
|
7319
8007
|
console.log(
|
|
7320
8008
|
"\u{1F50D} [OAuthHelper] CORS blocked direct check, using heuristics for:",
|
|
7321
8009
|
serverUrl
|
|
7322
8010
|
);
|
|
7323
8011
|
return this.checkAuthByHeuristics(serverUrl);
|
|
7324
8012
|
}
|
|
7325
|
-
if (
|
|
8013
|
+
if (err.name === "AbortError") {
|
|
7326
8014
|
console.log(
|
|
7327
8015
|
"\u23F0 [OAuthHelper] Request timeout, assuming no auth required for:",
|
|
7328
8016
|
serverUrl
|
|
@@ -7345,15 +8033,15 @@ var OAuthHelper = class {
|
|
|
7345
8033
|
// GitHub Copilot
|
|
7346
8034
|
/api\.github\.com/i,
|
|
7347
8035
|
// GitHub API
|
|
7348
|
-
|
|
7349
|
-
// Google APIs
|
|
8036
|
+
/[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.googleapis\.com/i,
|
|
8037
|
+
// Google APIs (DNS-safe, max 63 chars per label)
|
|
7350
8038
|
/api\.openai\.com/i,
|
|
7351
8039
|
// OpenAI
|
|
7352
8040
|
/api\.anthropic\.com/i,
|
|
7353
8041
|
// Anthropic
|
|
7354
|
-
|
|
8042
|
+
/[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.atlassian\.net/i,
|
|
7355
8043
|
// Atlassian (Jira, Confluence)
|
|
7356
|
-
|
|
8044
|
+
/[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.slack\.com/i,
|
|
7357
8045
|
// Slack
|
|
7358
8046
|
/api\.notion\.com/i,
|
|
7359
8047
|
// Notion
|
|
@@ -7367,7 +8055,7 @@ var OAuthHelper = class {
|
|
|
7367
8055
|
// Local development
|
|
7368
8056
|
/\.local/i,
|
|
7369
8057
|
// Local development
|
|
7370
|
-
/mcp
|
|
8058
|
+
/mcp\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.com/i
|
|
7371
8059
|
// Generic MCP server pattern (often public)
|
|
7372
8060
|
];
|
|
7373
8061
|
for (const pattern of noAuthPatterns) {
|
|
@@ -7917,7 +8605,7 @@ var BrowserOAuthClientProvider = class {
|
|
|
7917
8605
|
};
|
|
7918
8606
|
|
|
7919
8607
|
// src/auth/callback.ts
|
|
7920
|
-
var import_auth = require("@modelcontextprotocol
|
|
8608
|
+
var import_auth = require("@mcp-use/modelcontextprotocol-sdk/client/auth.js");
|
|
7921
8609
|
async function onMcpAuthorization() {
|
|
7922
8610
|
const queryParams = new URLSearchParams(window.location.search);
|
|
7923
8611
|
const code = queryParams.get("code");
|
|
@@ -8025,16 +8713,44 @@ async function onMcpAuthorization() {
|
|
|
8025
8713
|
);
|
|
8026
8714
|
}
|
|
8027
8715
|
try {
|
|
8028
|
-
document.body.innerHTML =
|
|
8029
|
-
|
|
8030
|
-
|
|
8031
|
-
|
|
8032
|
-
|
|
8033
|
-
|
|
8034
|
-
|
|
8035
|
-
|
|
8036
|
-
|
|
8037
|
-
|
|
8716
|
+
document.body.innerHTML = "";
|
|
8717
|
+
const container = document.createElement("div");
|
|
8718
|
+
container.style.fontFamily = "sans-serif";
|
|
8719
|
+
container.style.padding = "20px";
|
|
8720
|
+
const heading = document.createElement("h1");
|
|
8721
|
+
heading.textContent = "Authentication Error";
|
|
8722
|
+
container.appendChild(heading);
|
|
8723
|
+
const errorPara = document.createElement("p");
|
|
8724
|
+
errorPara.style.color = "red";
|
|
8725
|
+
errorPara.style.backgroundColor = "#ffebeb";
|
|
8726
|
+
errorPara.style.border = "1px solid red";
|
|
8727
|
+
errorPara.style.padding = "10px";
|
|
8728
|
+
errorPara.style.borderRadius = "4px";
|
|
8729
|
+
errorPara.textContent = errorMessage;
|
|
8730
|
+
container.appendChild(errorPara);
|
|
8731
|
+
const closePara = document.createElement("p");
|
|
8732
|
+
closePara.textContent = "You can close this window or ";
|
|
8733
|
+
const closeLink = document.createElement("a");
|
|
8734
|
+
closeLink.href = "#";
|
|
8735
|
+
closeLink.textContent = "click here to close";
|
|
8736
|
+
closeLink.onclick = (e) => {
|
|
8737
|
+
e.preventDefault();
|
|
8738
|
+
window.close();
|
|
8739
|
+
return false;
|
|
8740
|
+
};
|
|
8741
|
+
closePara.appendChild(closeLink);
|
|
8742
|
+
closePara.appendChild(document.createTextNode("."));
|
|
8743
|
+
container.appendChild(closePara);
|
|
8744
|
+
if (err instanceof Error && err.stack) {
|
|
8745
|
+
const stackPre = document.createElement("pre");
|
|
8746
|
+
stackPre.style.fontSize = "0.8em";
|
|
8747
|
+
stackPre.style.color = "#555";
|
|
8748
|
+
stackPre.style.marginTop = "20px";
|
|
8749
|
+
stackPre.style.whiteSpace = "pre-wrap";
|
|
8750
|
+
stackPre.textContent = err.stack;
|
|
8751
|
+
container.appendChild(stackPre);
|
|
8752
|
+
}
|
|
8753
|
+
document.body.appendChild(container);
|
|
8038
8754
|
} catch (displayError) {
|
|
8039
8755
|
console.error(
|
|
8040
8756
|
`${logPrefix} Could not display error in callback window:`,
|
|
@@ -8060,6 +8776,13 @@ var BrowserMCPClient = class _BrowserMCPClient extends BaseMCPClient {
|
|
|
8060
8776
|
static {
|
|
8061
8777
|
__name(this, "BrowserMCPClient");
|
|
8062
8778
|
}
|
|
8779
|
+
/**
|
|
8780
|
+
* Get the mcp-use package version.
|
|
8781
|
+
* Works in all environments (Node.js, browser, Cloudflare Workers, Deno, etc.)
|
|
8782
|
+
*/
|
|
8783
|
+
static getPackageVersion() {
|
|
8784
|
+
return getPackageVersion();
|
|
8785
|
+
}
|
|
8063
8786
|
constructor(config) {
|
|
8064
8787
|
super(config);
|
|
8065
8788
|
}
|
|
@@ -8367,15 +9090,16 @@ function useMcp(options) {
|
|
|
8367
9090
|
}
|
|
8368
9091
|
return "success";
|
|
8369
9092
|
} catch (err) {
|
|
8370
|
-
const
|
|
8371
|
-
|
|
9093
|
+
const error2 = err;
|
|
9094
|
+
const errorMessage = error2?.message || String(err);
|
|
9095
|
+
if (error2.code === 401 || errorMessage.includes("401") || errorMessage.includes("Unauthorized")) {
|
|
8372
9096
|
if (authProviderRef.current) {
|
|
8373
9097
|
addLog(
|
|
8374
9098
|
"info",
|
|
8375
9099
|
"Authentication required. OAuth provider available."
|
|
8376
9100
|
);
|
|
8377
9101
|
try {
|
|
8378
|
-
const { auth: auth2 } = await import("@modelcontextprotocol
|
|
9102
|
+
const { auth: auth2 } = await import("@mcp-use/modelcontextprotocol-sdk/client/auth.js");
|
|
8379
9103
|
const baseUrl = new URL(url).origin;
|
|
8380
9104
|
auth2(authProviderRef.current, { serverUrl: baseUrl }).catch(
|
|
8381
9105
|
() => {
|
|
@@ -8416,7 +9140,10 @@ function useMcp(options) {
|
|
|
8416
9140
|
);
|
|
8417
9141
|
return "failed";
|
|
8418
9142
|
}
|
|
8419
|
-
failConnection(
|
|
9143
|
+
failConnection(
|
|
9144
|
+
errorMessage,
|
|
9145
|
+
error2 instanceof Error ? error2 : new Error(String(error2))
|
|
9146
|
+
);
|
|
8420
9147
|
return "failed";
|
|
8421
9148
|
}
|
|
8422
9149
|
}, "tryConnectWithTransport");
|
|
@@ -8540,7 +9267,7 @@ function useMcp(options) {
|
|
|
8540
9267
|
});
|
|
8541
9268
|
authProviderRef.current = freshAuthProvider;
|
|
8542
9269
|
addLog("info", "Triggering fresh OAuth authorization...");
|
|
8543
|
-
const { auth: auth2 } = await import("@modelcontextprotocol
|
|
9270
|
+
const { auth: auth2 } = await import("@mcp-use/modelcontextprotocol-sdk/client/auth.js");
|
|
8544
9271
|
const baseUrl = new URL(url).origin;
|
|
8545
9272
|
auth2(freshAuthProvider, {
|
|
8546
9273
|
serverUrl: baseUrl
|
|
@@ -8548,7 +9275,7 @@ function useMcp(options) {
|
|
|
8548
9275
|
addLog(
|
|
8549
9276
|
"info",
|
|
8550
9277
|
"OAuth flow initiated:",
|
|
8551
|
-
err
|
|
9278
|
+
err instanceof Error ? err.message : "Redirecting..."
|
|
8552
9279
|
);
|
|
8553
9280
|
});
|
|
8554
9281
|
} catch (authError) {
|
|
@@ -9284,7 +10011,8 @@ function WidgetControls({
|
|
|
9284
10011
|
const result = await callTool(toolName, args);
|
|
9285
10012
|
setActionResult(`Success: ${JSON.stringify(result, null, 2)}`);
|
|
9286
10013
|
} catch (error) {
|
|
9287
|
-
|
|
10014
|
+
const err = error;
|
|
10015
|
+
setActionResult(`Error: ${err.message}`);
|
|
9288
10016
|
}
|
|
9289
10017
|
}, "handleCallTool");
|
|
9290
10018
|
const handleSendFollowUpMessage = /* @__PURE__ */ __name(async () => {
|
|
@@ -9293,7 +10021,8 @@ function WidgetControls({
|
|
|
9293
10021
|
await sendFollowUpMessage(followUpMessage);
|
|
9294
10022
|
setActionResult("Follow-up message sent successfully");
|
|
9295
10023
|
} catch (error) {
|
|
9296
|
-
|
|
10024
|
+
const err = error;
|
|
10025
|
+
setActionResult(`Error: ${err.message}`);
|
|
9297
10026
|
}
|
|
9298
10027
|
}, "handleSendFollowUpMessage");
|
|
9299
10028
|
const handleOpenExternal = /* @__PURE__ */ __name(() => {
|
|
@@ -9301,7 +10030,8 @@ function WidgetControls({
|
|
|
9301
10030
|
openExternal(externalUrl);
|
|
9302
10031
|
setActionResult(`Opened external link: ${externalUrl}`);
|
|
9303
10032
|
} catch (error) {
|
|
9304
|
-
|
|
10033
|
+
const err = error;
|
|
10034
|
+
setActionResult(`Error: ${err.message}`);
|
|
9305
10035
|
}
|
|
9306
10036
|
}, "handleOpenExternal");
|
|
9307
10037
|
const handleRequestDisplayMode = /* @__PURE__ */ __name(async (mode) => {
|
|
@@ -9310,7 +10040,8 @@ function WidgetControls({
|
|
|
9310
10040
|
const result = await requestDisplayMode(mode);
|
|
9311
10041
|
setActionResult(`Display mode granted: ${result.mode}`);
|
|
9312
10042
|
} catch (error) {
|
|
9313
|
-
|
|
10043
|
+
const err = error;
|
|
10044
|
+
setActionResult(`Error: ${err.message}`);
|
|
9314
10045
|
}
|
|
9315
10046
|
}, "handleRequestDisplayMode");
|
|
9316
10047
|
const handleSetState = /* @__PURE__ */ __name(async () => {
|
|
@@ -9320,7 +10051,8 @@ function WidgetControls({
|
|
|
9320
10051
|
await setState(newState);
|
|
9321
10052
|
setActionResult(`State updated: ${JSON.stringify(newState, null, 2)}`);
|
|
9322
10053
|
} catch (error) {
|
|
9323
|
-
|
|
10054
|
+
const err = error;
|
|
10055
|
+
setActionResult(`Error: ${err.message}`);
|
|
9324
10056
|
}
|
|
9325
10057
|
}, "handleSetState");
|
|
9326
10058
|
const handleFullscreen = /* @__PURE__ */ __name(async () => {
|
|
@@ -9597,8 +10329,8 @@ __name(WidgetControls, "WidgetControls");
|
|
|
9597
10329
|
var import_react7 = __toESM(require("react"), 1);
|
|
9598
10330
|
function getBasename() {
|
|
9599
10331
|
if (typeof window === "undefined") return "/";
|
|
9600
|
-
const
|
|
9601
|
-
const match =
|
|
10332
|
+
const path3 = window.location.pathname;
|
|
10333
|
+
const match = path3.match(/^(\/inspector\/api\/dev-widget\/[^/]+)/);
|
|
9602
10334
|
if (match) {
|
|
9603
10335
|
return match[1];
|
|
9604
10336
|
}
|