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.
Files changed (145) hide show
  1. package/README.md +9 -6
  2. package/dist/.tsbuildinfo +1 -1
  3. package/dist/{chunk-QREDNTLS.js → chunk-5S5DWSKI.js} +1 -1
  4. package/dist/{chunk-MUZ5WYE3.js → chunk-5UB2K5L6.js} +72 -14
  5. package/dist/{chunk-33U4IA4N.js → chunk-B5N3LQQU.js} +99 -5
  6. package/dist/{chunk-3R5PDYIN.js → chunk-J75I2C26.js} +39 -11
  7. package/dist/{chunk-U5BX3ISQ.js → chunk-KMTBWOVS.js} +22 -408
  8. package/dist/{chunk-D22NUQTL.js → chunk-LXYUQEEE.js} +235 -12
  9. package/dist/{chunk-ZQUCGISK.js → chunk-NNQUSDFU.js} +21 -5
  10. package/dist/chunk-PESKSVLQ.js +1129 -0
  11. package/dist/index.cjs +1190 -200
  12. package/dist/index.d.ts +6 -4
  13. package/dist/index.d.ts.map +1 -1
  14. package/dist/index.js +63 -23
  15. package/dist/src/adapters/langchain_adapter.d.ts +1 -1
  16. package/dist/src/adapters/langchain_adapter.d.ts.map +1 -1
  17. package/dist/src/agents/index.cjs +2263 -1626
  18. package/dist/src/agents/index.js +4 -4
  19. package/dist/src/agents/mcp_agent.d.ts +5 -0
  20. package/dist/src/agents/mcp_agent.d.ts.map +1 -1
  21. package/dist/src/auth/browser-provider.d.ts +2 -2
  22. package/dist/src/auth/browser-provider.d.ts.map +1 -1
  23. package/dist/src/auth/callback.d.ts.map +1 -1
  24. package/dist/src/auth/index.cjs +39 -11
  25. package/dist/src/auth/index.js +1 -1
  26. package/dist/src/auth/types.d.ts +1 -1
  27. package/dist/src/auth/types.d.ts.map +1 -1
  28. package/dist/src/browser.cjs +2672 -1754
  29. package/dist/src/browser.d.ts +5 -1
  30. package/dist/src/browser.d.ts.map +1 -1
  31. package/dist/src/browser.js +18 -5
  32. package/dist/src/client/base.d.ts.map +1 -1
  33. package/dist/src/client/browser.d.ts +6 -0
  34. package/dist/src/client/browser.d.ts.map +1 -1
  35. package/dist/src/client/connectors/codeMode.d.ts +1 -1
  36. package/dist/src/client/connectors/codeMode.d.ts.map +1 -1
  37. package/dist/src/client/executors/base.d.ts +1 -1
  38. package/dist/src/client/executors/base.d.ts.map +1 -1
  39. package/dist/src/client/prompts.cjs +4 -1
  40. package/dist/src/client/prompts.js +3 -2
  41. package/dist/src/client.d.ts +7 -1
  42. package/dist/src/client.d.ts.map +1 -1
  43. package/dist/src/connectors/base.d.ts +56 -6
  44. package/dist/src/connectors/base.d.ts.map +1 -1
  45. package/dist/src/connectors/http.d.ts.map +1 -1
  46. package/dist/src/connectors/stdio.d.ts.map +1 -1
  47. package/dist/src/connectors/websocket.d.ts +1 -1
  48. package/dist/src/connectors/websocket.d.ts.map +1 -1
  49. package/dist/src/oauth-helper.d.ts.map +1 -1
  50. package/dist/src/react/WidgetControls.d.ts.map +1 -1
  51. package/dist/src/react/index.cjs +1357 -43
  52. package/dist/src/react/index.d.ts +4 -1
  53. package/dist/src/react/index.d.ts.map +1 -1
  54. package/dist/src/react/index.js +14 -5
  55. package/dist/src/react/types.d.ts +1 -1
  56. package/dist/src/react/types.d.ts.map +1 -1
  57. package/dist/src/react/useMcp.d.ts.map +1 -1
  58. package/dist/src/server/endpoints/mount-mcp.d.ts +4 -1
  59. package/dist/src/server/endpoints/mount-mcp.d.ts.map +1 -1
  60. package/dist/src/server/index.cjs +1923 -287
  61. package/dist/src/server/index.d.ts +3 -2
  62. package/dist/src/server/index.d.ts.map +1 -1
  63. package/dist/src/server/index.js +488 -245
  64. package/dist/src/server/mcp-server.d.ts +77 -27
  65. package/dist/src/server/mcp-server.d.ts.map +1 -1
  66. package/dist/src/server/oauth/middleware.d.ts.map +1 -1
  67. package/dist/src/server/oauth/providers/auth0.d.ts +1 -1
  68. package/dist/src/server/oauth/providers/auth0.d.ts.map +1 -1
  69. package/dist/src/server/oauth/providers/custom.d.ts +4 -2
  70. package/dist/src/server/oauth/providers/custom.d.ts.map +1 -1
  71. package/dist/src/server/oauth/providers/keycloak.d.ts +1 -1
  72. package/dist/src/server/oauth/providers/keycloak.d.ts.map +1 -1
  73. package/dist/src/server/oauth/providers/supabase.d.ts +1 -1
  74. package/dist/src/server/oauth/providers/supabase.d.ts.map +1 -1
  75. package/dist/src/server/oauth/providers/types.d.ts +9 -5
  76. package/dist/src/server/oauth/providers/types.d.ts.map +1 -1
  77. package/dist/src/server/oauth/providers.d.ts +27 -9
  78. package/dist/src/server/oauth/providers.d.ts.map +1 -1
  79. package/dist/src/server/oauth/setup.d.ts +5 -4
  80. package/dist/src/server/oauth/setup.d.ts.map +1 -1
  81. package/dist/src/server/oauth/utils.d.ts +3 -2
  82. package/dist/src/server/oauth/utils.d.ts.map +1 -1
  83. package/dist/src/server/prompts/conversion.d.ts +1 -1
  84. package/dist/src/server/prompts/conversion.d.ts.map +1 -1
  85. package/dist/src/server/prompts/index.d.ts +6 -5
  86. package/dist/src/server/prompts/index.d.ts.map +1 -1
  87. package/dist/src/server/resources/conversion.d.ts +1 -1
  88. package/dist/src/server/resources/conversion.d.ts.map +1 -1
  89. package/dist/src/server/resources/index.d.ts +44 -25
  90. package/dist/src/server/resources/index.d.ts.map +1 -1
  91. package/dist/src/server/resources/subscriptions.d.ts +1 -1
  92. package/dist/src/server/resources/subscriptions.d.ts.map +1 -1
  93. package/dist/src/server/sessions/session-manager.d.ts +11 -5
  94. package/dist/src/server/sessions/session-manager.d.ts.map +1 -1
  95. package/dist/src/server/tools/tool-execution-helpers.d.ts +31 -8
  96. package/dist/src/server/tools/tool-execution-helpers.d.ts.map +1 -1
  97. package/dist/src/server/tools/tool-registration.d.ts +21 -7
  98. package/dist/src/server/tools/tool-registration.d.ts.map +1 -1
  99. package/dist/src/server/types/common.d.ts +25 -9
  100. package/dist/src/server/types/common.d.ts.map +1 -1
  101. package/dist/src/server/types/index.d.ts +3 -3
  102. package/dist/src/server/types/index.d.ts.map +1 -1
  103. package/dist/src/server/types/prompt.d.ts +3 -2
  104. package/dist/src/server/types/prompt.d.ts.map +1 -1
  105. package/dist/src/server/types/resource.d.ts +60 -10
  106. package/dist/src/server/types/resource.d.ts.map +1 -1
  107. package/dist/src/server/types/tool-context.d.ts +116 -1
  108. package/dist/src/server/types/tool-context.d.ts.map +1 -1
  109. package/dist/src/server/types/tool.d.ts +43 -2
  110. package/dist/src/server/types/tool.d.ts.map +1 -1
  111. package/dist/src/server/types/widget.d.ts +11 -1
  112. package/dist/src/server/types/widget.d.ts.map +1 -1
  113. package/dist/src/server/utils/response-helpers.d.ts +17 -29
  114. package/dist/src/server/utils/response-helpers.d.ts.map +1 -1
  115. package/dist/src/server/widgets/index.d.ts +3 -3
  116. package/dist/src/server/widgets/index.d.ts.map +1 -1
  117. package/dist/src/server/widgets/mount-widgets-dev.d.ts.map +1 -1
  118. package/dist/src/server/widgets/ui-resource-registration.d.ts +13 -25
  119. package/dist/src/server/widgets/ui-resource-registration.d.ts.map +1 -1
  120. package/dist/src/server/widgets/widget-helpers.d.ts +11 -6
  121. package/dist/src/server/widgets/widget-helpers.d.ts.map +1 -1
  122. package/dist/src/server/widgets/widget-types.d.ts +3 -3
  123. package/dist/src/server/widgets/widget-types.d.ts.map +1 -1
  124. package/dist/src/session.d.ts +372 -2
  125. package/dist/src/session.d.ts.map +1 -1
  126. package/dist/src/task_managers/sse.d.ts +2 -2
  127. package/dist/src/task_managers/sse.d.ts.map +1 -1
  128. package/dist/src/task_managers/stdio.d.ts +2 -2
  129. package/dist/src/task_managers/stdio.d.ts.map +1 -1
  130. package/dist/src/task_managers/streamable_http.d.ts +2 -2
  131. package/dist/src/task_managers/streamable_http.d.ts.map +1 -1
  132. package/dist/src/telemetry/events.d.ts +247 -0
  133. package/dist/src/telemetry/events.d.ts.map +1 -1
  134. package/dist/src/telemetry/index.d.ts +4 -4
  135. package/dist/src/telemetry/index.d.ts.map +1 -1
  136. package/dist/src/telemetry/telemetry.d.ts +122 -4
  137. package/dist/src/telemetry/telemetry.d.ts.map +1 -1
  138. package/dist/src/telemetry/utils.d.ts +1 -1
  139. package/dist/src/telemetry/utils.d.ts.map +1 -1
  140. package/dist/src/version.d.ts +8 -0
  141. package/dist/src/version.d.ts.map +1 -0
  142. package/dist/{tool-execution-helpers-BQJTPWPN.js → tool-execution-helpers-OOVLOJYH.js} +3 -2
  143. package/dist/tsup.config.d.ts.map +1 -1
  144. package/package.json +7 -5
  145. package/dist/chunk-MTHLLDCX.js +0 -97
@@ -0,0 +1,1129 @@
1
+ import {
2
+ logger
3
+ } from "./chunk-34R6SIER.js";
4
+ import {
5
+ __name,
6
+ __require
7
+ } from "./chunk-3GQAWCBQ.js";
8
+
9
+ // src/server/utils/runtime.ts
10
+ var isDeno = typeof globalThis.Deno !== "undefined";
11
+ function getEnv(key) {
12
+ if (isDeno) {
13
+ return globalThis.Deno.env.get(key);
14
+ }
15
+ return process.env[key];
16
+ }
17
+ __name(getEnv, "getEnv");
18
+ function getCwd() {
19
+ if (isDeno) {
20
+ return globalThis.Deno.cwd();
21
+ }
22
+ return process.cwd();
23
+ }
24
+ __name(getCwd, "getCwd");
25
+ var fsHelpers = {
26
+ async readFileSync(path, encoding = "utf8") {
27
+ if (isDeno) {
28
+ return await globalThis.Deno.readTextFile(path);
29
+ }
30
+ const { readFileSync } = await import("fs");
31
+ const result = readFileSync(path, encoding);
32
+ return typeof result === "string" ? result : result.toString(encoding);
33
+ },
34
+ async readFile(path) {
35
+ if (isDeno) {
36
+ const data = await globalThis.Deno.readFile(path);
37
+ return data.buffer;
38
+ }
39
+ const { readFileSync } = await import("fs");
40
+ const buffer = readFileSync(path);
41
+ return buffer.buffer.slice(
42
+ buffer.byteOffset,
43
+ buffer.byteOffset + buffer.byteLength
44
+ );
45
+ },
46
+ async existsSync(path) {
47
+ if (isDeno) {
48
+ try {
49
+ await globalThis.Deno.stat(path);
50
+ return true;
51
+ } catch {
52
+ return false;
53
+ }
54
+ }
55
+ const { existsSync } = await import("fs");
56
+ return existsSync(path);
57
+ },
58
+ async readdirSync(path) {
59
+ if (isDeno) {
60
+ const entries = [];
61
+ for await (const entry of globalThis.Deno.readDir(path)) {
62
+ entries.push(entry.name);
63
+ }
64
+ return entries;
65
+ }
66
+ const { readdirSync } = await import("fs");
67
+ return readdirSync(path);
68
+ }
69
+ };
70
+ var pathHelpers = {
71
+ join(...paths) {
72
+ if (isDeno) {
73
+ return paths.join("/").replace(/\/+/g, "/");
74
+ }
75
+ return paths.join("/").replace(/\/+/g, "/");
76
+ },
77
+ relative(from, to) {
78
+ const fromParts = from.split("/").filter((p) => p);
79
+ const toParts = to.split("/").filter((p) => p);
80
+ let i = 0;
81
+ while (i < fromParts.length && i < toParts.length && fromParts[i] === toParts[i]) {
82
+ i++;
83
+ }
84
+ const upCount = fromParts.length - i;
85
+ const relativeParts = [...Array(upCount).fill(".."), ...toParts.slice(i)];
86
+ return relativeParts.join("/");
87
+ }
88
+ };
89
+ function generateUUID() {
90
+ return globalThis.crypto.randomUUID();
91
+ }
92
+ __name(generateUUID, "generateUUID");
93
+
94
+ // src/version.ts
95
+ var VERSION = "1.10.0-canary.11";
96
+ function getPackageVersion() {
97
+ return VERSION;
98
+ }
99
+ __name(getPackageVersion, "getPackageVersion");
100
+
101
+ // src/telemetry/events.ts
102
+ var BaseTelemetryEvent = class {
103
+ static {
104
+ __name(this, "BaseTelemetryEvent");
105
+ }
106
+ };
107
+ var MCPAgentExecutionEvent = class extends BaseTelemetryEvent {
108
+ constructor(data) {
109
+ super();
110
+ this.data = data;
111
+ }
112
+ static {
113
+ __name(this, "MCPAgentExecutionEvent");
114
+ }
115
+ get name() {
116
+ return "mcp_agent_execution";
117
+ }
118
+ get properties() {
119
+ return {
120
+ // Core execution info
121
+ execution_method: this.data.executionMethod,
122
+ query: this.data.query,
123
+ query_length: this.data.query.length,
124
+ success: this.data.success,
125
+ // Agent configuration
126
+ model_provider: this.data.modelProvider,
127
+ model_name: this.data.modelName,
128
+ server_count: this.data.serverCount,
129
+ server_identifiers: this.data.serverIdentifiers,
130
+ total_tools_available: this.data.totalToolsAvailable,
131
+ tools_available_names: this.data.toolsAvailableNames,
132
+ max_steps_configured: this.data.maxStepsConfigured,
133
+ memory_enabled: this.data.memoryEnabled,
134
+ use_server_manager: this.data.useServerManager,
135
+ // Execution parameters (always include, even if null)
136
+ max_steps_used: this.data.maxStepsUsed,
137
+ manage_connector: this.data.manageConnector,
138
+ external_history_used: this.data.externalHistoryUsed,
139
+ // Execution results (always include, even if null)
140
+ steps_taken: this.data.stepsTaken ?? null,
141
+ tools_used_count: this.data.toolsUsedCount ?? null,
142
+ tools_used_names: this.data.toolsUsedNames ?? null,
143
+ response: this.data.response ?? null,
144
+ response_length: this.data.response ? this.data.response.length : null,
145
+ execution_time_ms: this.data.executionTimeMs ?? null,
146
+ error_type: this.data.errorType ?? null,
147
+ conversation_history_length: this.data.conversationHistoryLength ?? null
148
+ };
149
+ }
150
+ };
151
+ function createServerRunEventData(server, transport) {
152
+ const toolRegistrations = Array.from(server.registrations.tools.values());
153
+ const promptRegistrations = Array.from(server.registrations.prompts.values());
154
+ const resourceRegistrations = Array.from(
155
+ server.registrations.resources.values()
156
+ );
157
+ const templateRegistrations = Array.from(
158
+ server.registrations.resourceTemplates.values()
159
+ );
160
+ const allResources = resourceRegistrations.map((r) => ({
161
+ name: r.config.name,
162
+ title: r.config.title ?? null,
163
+ description: r.config.description ?? null,
164
+ uri: r.config.uri ?? null,
165
+ mime_type: r.config.mimeType ?? null
166
+ }));
167
+ const appsSdkResources = allResources.filter(
168
+ (r) => r.mime_type === "text/html+skybridge"
169
+ );
170
+ const mcpUiResources = allResources.filter(
171
+ (r) => r.mime_type === "text/uri-list" || r.mime_type === "text/html"
172
+ );
173
+ const mcpAppsResources = allResources.filter(
174
+ (r) => r.mime_type === "text/html+mcp"
175
+ );
176
+ return {
177
+ transport,
178
+ toolsNumber: server.registeredTools.length,
179
+ resourcesNumber: server.registeredResources.length,
180
+ promptsNumber: server.registeredPrompts.length,
181
+ auth: !!server.oauthProvider,
182
+ name: server.config.name,
183
+ description: server.config.description ?? null,
184
+ baseUrl: server.serverBaseUrl ?? null,
185
+ toolNames: server.registeredTools.length > 0 ? server.registeredTools : null,
186
+ resourceNames: server.registeredResources.length > 0 ? server.registeredResources : null,
187
+ promptNames: server.registeredPrompts.length > 0 ? server.registeredPrompts : null,
188
+ tools: toolRegistrations.length > 0 ? toolRegistrations.map((r) => ({
189
+ name: r.config.name,
190
+ title: r.config.title ?? null,
191
+ description: r.config.description ?? null,
192
+ input_schema: r.config.schema ? JSON.stringify(r.config.schema) : null,
193
+ output_schema: r.config.outputSchema ? JSON.stringify(r.config.outputSchema) : null
194
+ })) : null,
195
+ resources: allResources.length > 0 ? allResources : null,
196
+ prompts: promptRegistrations.length > 0 ? promptRegistrations.map((r) => ({
197
+ name: r.config.name,
198
+ title: r.config.title ?? null,
199
+ description: r.config.description ?? null,
200
+ args: r.config.args ? JSON.stringify(r.config.args) : null
201
+ })) : null,
202
+ templates: templateRegistrations.length > 0 ? templateRegistrations.map((r) => ({
203
+ name: r.config.name,
204
+ title: r.config.title ?? null,
205
+ description: r.config.description ?? null
206
+ })) : null,
207
+ capabilities: {
208
+ logging: true,
209
+ resources: { subscribe: true, listChanged: true }
210
+ },
211
+ appsSdkResources: appsSdkResources.length > 0 ? appsSdkResources : null,
212
+ appsSdkResourcesNumber: appsSdkResources.length,
213
+ mcpUiResources: mcpUiResources.length > 0 ? mcpUiResources : null,
214
+ mcpUiResourcesNumber: mcpUiResources.length,
215
+ mcpAppsResources: mcpAppsResources.length > 0 ? mcpAppsResources : null,
216
+ mcpAppsResourcesNumber: mcpAppsResources.length
217
+ };
218
+ }
219
+ __name(createServerRunEventData, "createServerRunEventData");
220
+ var ServerRunEvent = class extends BaseTelemetryEvent {
221
+ constructor(data) {
222
+ super();
223
+ this.data = data;
224
+ }
225
+ static {
226
+ __name(this, "ServerRunEvent");
227
+ }
228
+ get name() {
229
+ return "server_run";
230
+ }
231
+ get properties() {
232
+ return {
233
+ transport: this.data.transport,
234
+ tools_number: this.data.toolsNumber,
235
+ resources_number: this.data.resourcesNumber,
236
+ prompts_number: this.data.promptsNumber,
237
+ auth: this.data.auth,
238
+ name: this.data.name,
239
+ description: this.data.description ?? null,
240
+ base_url: this.data.baseUrl ?? null,
241
+ tool_names: this.data.toolNames ?? null,
242
+ resource_names: this.data.resourceNames ?? null,
243
+ prompt_names: this.data.promptNames ?? null,
244
+ tools: this.data.tools ?? null,
245
+ resources: this.data.resources ?? null,
246
+ prompts: this.data.prompts ?? null,
247
+ templates: this.data.templates ?? null,
248
+ capabilities: this.data.capabilities ? JSON.stringify(this.data.capabilities) : null,
249
+ apps_sdk_resources: this.data.appsSdkResources ? JSON.stringify(this.data.appsSdkResources) : null,
250
+ apps_sdk_resources_number: this.data.appsSdkResourcesNumber ?? 0,
251
+ mcp_ui_resources: this.data.mcpUiResources ? JSON.stringify(this.data.mcpUiResources) : null,
252
+ mcp_ui_resources_number: this.data.mcpUiResourcesNumber ?? 0,
253
+ mcp_apps_resources: this.data.mcpAppsResources ? JSON.stringify(this.data.mcpAppsResources) : null,
254
+ mcp_apps_resources_number: this.data.mcpAppsResourcesNumber ?? 0
255
+ };
256
+ }
257
+ };
258
+ var ServerInitializeEvent = class extends BaseTelemetryEvent {
259
+ constructor(data) {
260
+ super();
261
+ this.data = data;
262
+ }
263
+ static {
264
+ __name(this, "ServerInitializeEvent");
265
+ }
266
+ get name() {
267
+ return "server_initialize_call";
268
+ }
269
+ get properties() {
270
+ return {
271
+ protocol_version: this.data.protocolVersion,
272
+ client_info: JSON.stringify(this.data.clientInfo),
273
+ client_capabilities: JSON.stringify(this.data.clientCapabilities),
274
+ session_id: this.data.sessionId ?? null
275
+ };
276
+ }
277
+ };
278
+ var ServerToolCallEvent = class extends BaseTelemetryEvent {
279
+ constructor(data) {
280
+ super();
281
+ this.data = data;
282
+ }
283
+ static {
284
+ __name(this, "ServerToolCallEvent");
285
+ }
286
+ get name() {
287
+ return "server_tool_call";
288
+ }
289
+ get properties() {
290
+ return {
291
+ tool_name: this.data.toolName,
292
+ length_input_argument: this.data.lengthInputArgument,
293
+ success: this.data.success,
294
+ error_type: this.data.errorType ?? null,
295
+ execution_time_ms: this.data.executionTimeMs ?? null
296
+ };
297
+ }
298
+ };
299
+ var ServerResourceCallEvent = class extends BaseTelemetryEvent {
300
+ constructor(data) {
301
+ super();
302
+ this.data = data;
303
+ }
304
+ static {
305
+ __name(this, "ServerResourceCallEvent");
306
+ }
307
+ get name() {
308
+ return "server_resource_call";
309
+ }
310
+ get properties() {
311
+ return {
312
+ name: this.data.name,
313
+ description: this.data.description,
314
+ contents: this.data.contents,
315
+ success: this.data.success,
316
+ error_type: this.data.errorType ?? null
317
+ };
318
+ }
319
+ };
320
+ var ServerPromptCallEvent = class extends BaseTelemetryEvent {
321
+ constructor(data) {
322
+ super();
323
+ this.data = data;
324
+ }
325
+ static {
326
+ __name(this, "ServerPromptCallEvent");
327
+ }
328
+ get name() {
329
+ return "server_prompt_call";
330
+ }
331
+ get properties() {
332
+ return {
333
+ name: this.data.name,
334
+ description: this.data.description,
335
+ success: this.data.success,
336
+ error_type: this.data.errorType ?? null
337
+ };
338
+ }
339
+ };
340
+ var ServerContextEvent = class extends BaseTelemetryEvent {
341
+ constructor(data) {
342
+ super();
343
+ this.data = data;
344
+ }
345
+ static {
346
+ __name(this, "ServerContextEvent");
347
+ }
348
+ get name() {
349
+ return `server_context_${this.data.contextType}`;
350
+ }
351
+ get properties() {
352
+ return {
353
+ context_type: this.data.contextType,
354
+ notification_type: this.data.notificationType ?? null
355
+ };
356
+ }
357
+ };
358
+ var MCPClientInitEvent = class extends BaseTelemetryEvent {
359
+ constructor(data) {
360
+ super();
361
+ this.data = data;
362
+ }
363
+ static {
364
+ __name(this, "MCPClientInitEvent");
365
+ }
366
+ get name() {
367
+ return "mcpclient_init";
368
+ }
369
+ get properties() {
370
+ return {
371
+ code_mode: this.data.codeMode,
372
+ sandbox: this.data.sandbox,
373
+ all_callbacks: this.data.allCallbacks,
374
+ verify: this.data.verify,
375
+ servers: this.data.servers,
376
+ num_servers: this.data.numServers,
377
+ is_browser: this.data.isBrowser
378
+ };
379
+ }
380
+ };
381
+ var ConnectorInitEvent = class extends BaseTelemetryEvent {
382
+ constructor(data) {
383
+ super();
384
+ this.data = data;
385
+ }
386
+ static {
387
+ __name(this, "ConnectorInitEvent");
388
+ }
389
+ get name() {
390
+ return "connector_init";
391
+ }
392
+ get properties() {
393
+ return {
394
+ connector_type: this.data.connectorType,
395
+ server_command: this.data.serverCommand ?? null,
396
+ server_args: this.data.serverArgs ?? null,
397
+ server_url: this.data.serverUrl ?? null,
398
+ public_identifier: this.data.publicIdentifier ?? null
399
+ };
400
+ }
401
+ };
402
+ var ClientAddServerEvent = class extends BaseTelemetryEvent {
403
+ constructor(data) {
404
+ super();
405
+ this.data = data;
406
+ }
407
+ static {
408
+ __name(this, "ClientAddServerEvent");
409
+ }
410
+ get name() {
411
+ return "client_add_server";
412
+ }
413
+ get properties() {
414
+ const { serverName, serverConfig } = this.data;
415
+ const url = serverConfig.url;
416
+ return {
417
+ server_name: serverName,
418
+ server_url_domain: url ? this._extractHostname(url) : null,
419
+ transport: serverConfig.transport ?? null,
420
+ has_auth: !!(serverConfig.authToken || serverConfig.authProvider)
421
+ };
422
+ }
423
+ _extractHostname(url) {
424
+ try {
425
+ return new URL(url).hostname;
426
+ } catch {
427
+ return null;
428
+ }
429
+ }
430
+ };
431
+ var ClientRemoveServerEvent = class extends BaseTelemetryEvent {
432
+ constructor(data) {
433
+ super();
434
+ this.data = data;
435
+ }
436
+ static {
437
+ __name(this, "ClientRemoveServerEvent");
438
+ }
439
+ get name() {
440
+ return "client_remove_server";
441
+ }
442
+ get properties() {
443
+ return {
444
+ server_name: this.data.serverName
445
+ };
446
+ }
447
+ };
448
+
449
+ // src/telemetry/utils.ts
450
+ function getModelProvider(llm) {
451
+ return llm._llm_type || llm.constructor.name.toLowerCase();
452
+ }
453
+ __name(getModelProvider, "getModelProvider");
454
+ function getModelName(llm) {
455
+ if ("_identifyingParams" in llm) {
456
+ const identifyingParams = llm._identifyingParams;
457
+ if (typeof identifyingParams === "object" && identifyingParams !== null) {
458
+ for (const key of [
459
+ "model",
460
+ "modelName",
461
+ "model_name",
462
+ "modelId",
463
+ "model_id",
464
+ "deploymentName",
465
+ "deployment_name"
466
+ ]) {
467
+ if (key in identifyingParams) {
468
+ return String(identifyingParams[key]);
469
+ }
470
+ }
471
+ }
472
+ }
473
+ return llm.model || llm.modelName || llm.constructor.name;
474
+ }
475
+ __name(getModelName, "getModelName");
476
+ function extractModelInfo(llm) {
477
+ return [getModelProvider(llm), getModelName(llm)];
478
+ }
479
+ __name(extractModelInfo, "extractModelInfo");
480
+
481
+ // src/telemetry/telemetry.ts
482
+ var USER_ID_STORAGE_KEY = "mcp_use_user_id";
483
+ function detectRuntimeEnvironment() {
484
+ try {
485
+ if (typeof globalThis.Bun !== "undefined") {
486
+ return "bun";
487
+ }
488
+ if (typeof globalThis.Deno !== "undefined") {
489
+ return "deno";
490
+ }
491
+ if (typeof navigator !== "undefined" && navigator.userAgent?.includes("Cloudflare-Workers")) {
492
+ return "cloudflare-workers";
493
+ }
494
+ if (typeof globalThis.EdgeRuntime !== "undefined") {
495
+ return "edge";
496
+ }
497
+ if (typeof window !== "undefined" && typeof document !== "undefined") {
498
+ return "browser";
499
+ }
500
+ if (typeof process !== "undefined" && typeof process.versions?.node !== "undefined") {
501
+ return "node";
502
+ }
503
+ return "unknown";
504
+ } catch {
505
+ return "unknown";
506
+ }
507
+ }
508
+ __name(detectRuntimeEnvironment, "detectRuntimeEnvironment");
509
+ function getStorageCapability(env) {
510
+ switch (env) {
511
+ case "node":
512
+ case "bun":
513
+ return "filesystem";
514
+ case "browser":
515
+ try {
516
+ if (typeof localStorage !== "undefined") {
517
+ localStorage.setItem("__mcp_use_test__", "1");
518
+ localStorage.removeItem("__mcp_use_test__");
519
+ return "localStorage";
520
+ }
521
+ } catch {
522
+ }
523
+ return "session-only";
524
+ case "deno":
525
+ return "session-only";
526
+ default:
527
+ return "session-only";
528
+ }
529
+ }
530
+ __name(getStorageCapability, "getStorageCapability");
531
+ var cachedEnvironment = null;
532
+ function getRuntimeEnvironment() {
533
+ if (cachedEnvironment === null) {
534
+ cachedEnvironment = detectRuntimeEnvironment();
535
+ }
536
+ return cachedEnvironment;
537
+ }
538
+ __name(getRuntimeEnvironment, "getRuntimeEnvironment");
539
+ var ScarfEventLogger = class {
540
+ static {
541
+ __name(this, "ScarfEventLogger");
542
+ }
543
+ endpoint;
544
+ timeout;
545
+ constructor(endpoint, timeout = 3e3) {
546
+ this.endpoint = endpoint;
547
+ this.timeout = timeout;
548
+ }
549
+ async logEvent(properties) {
550
+ try {
551
+ const controller = new AbortController();
552
+ const timeoutId = setTimeout(() => controller.abort(), this.timeout);
553
+ const response = await fetch(this.endpoint, {
554
+ method: "POST",
555
+ headers: {
556
+ "Content-Type": "application/json"
557
+ },
558
+ body: JSON.stringify(properties),
559
+ signal: controller.signal
560
+ });
561
+ clearTimeout(timeoutId);
562
+ if (!response.ok) {
563
+ throw new Error(`HTTP error! status: ${response.status}`);
564
+ }
565
+ } catch (error) {
566
+ logger.debug(`Failed to send Scarf event: ${error}`);
567
+ }
568
+ }
569
+ };
570
+ var Telemetry = class _Telemetry {
571
+ static {
572
+ __name(this, "Telemetry");
573
+ }
574
+ static instance = null;
575
+ PROJECT_API_KEY = "phc_lyTtbYwvkdSbrcMQNPiKiiRWrrM1seyKIMjycSvItEI";
576
+ HOST = "https://eu.i.posthog.com";
577
+ SCARF_GATEWAY_URL = "https://mcpuse.gateway.scarf.sh/events-ts";
578
+ UNKNOWN_USER_ID = "UNKNOWN_USER_ID";
579
+ _currUserId = null;
580
+ _posthogNodeClient = null;
581
+ _posthogBrowserClient = null;
582
+ _posthogLoading = null;
583
+ _scarfClient = null;
584
+ _runtimeEnvironment;
585
+ _storageCapability;
586
+ _source;
587
+ // Node.js specific paths (lazily computed)
588
+ _userIdPath = null;
589
+ _versionDownloadPath = null;
590
+ constructor() {
591
+ this._runtimeEnvironment = getRuntimeEnvironment();
592
+ this._storageCapability = getStorageCapability(this._runtimeEnvironment);
593
+ this._source = typeof process !== "undefined" && process.env?.MCP_USE_TELEMETRY_SOURCE || this._runtimeEnvironment;
594
+ const telemetryDisabled = this._checkTelemetryDisabled();
595
+ const canSupportTelemetry = this._runtimeEnvironment !== "unknown";
596
+ if (telemetryDisabled) {
597
+ this._posthogNodeClient = null;
598
+ this._posthogBrowserClient = null;
599
+ this._scarfClient = null;
600
+ logger.debug("Telemetry disabled via environment/localStorage");
601
+ } else if (!canSupportTelemetry) {
602
+ this._posthogNodeClient = null;
603
+ this._posthogBrowserClient = null;
604
+ this._scarfClient = null;
605
+ logger.debug(
606
+ `Telemetry disabled - unknown environment: ${this._runtimeEnvironment}`
607
+ );
608
+ } else {
609
+ logger.info(
610
+ "Anonymized telemetry enabled. Set MCP_USE_ANONYMIZED_TELEMETRY=false to disable."
611
+ );
612
+ this._posthogLoading = this._initPostHog();
613
+ try {
614
+ this._scarfClient = new ScarfEventLogger(this.SCARF_GATEWAY_URL, 3e3);
615
+ } catch (e) {
616
+ logger.warn(`Failed to initialize Scarf telemetry: ${e}`);
617
+ this._scarfClient = null;
618
+ }
619
+ }
620
+ }
621
+ _checkTelemetryDisabled() {
622
+ if (typeof process !== "undefined" && process.env?.MCP_USE_ANONYMIZED_TELEMETRY?.toLowerCase() === "false") {
623
+ return true;
624
+ }
625
+ if (typeof localStorage !== "undefined" && localStorage.getItem("MCP_USE_ANONYMIZED_TELEMETRY") === "false") {
626
+ return true;
627
+ }
628
+ return false;
629
+ }
630
+ async _initPostHog() {
631
+ const isBrowser = this._runtimeEnvironment === "browser";
632
+ if (isBrowser) {
633
+ await this._initPostHogBrowser();
634
+ } else {
635
+ await this._initPostHogNode();
636
+ }
637
+ }
638
+ async _initPostHogBrowser() {
639
+ try {
640
+ const posthogModule = await import("posthog-js");
641
+ const posthog = posthogModule.default || posthogModule.posthog;
642
+ if (!posthog || typeof posthog.init !== "function") {
643
+ throw new Error("posthog-js module did not export expected interface");
644
+ }
645
+ posthog.init(this.PROJECT_API_KEY, {
646
+ api_host: this.HOST,
647
+ persistence: "localStorage",
648
+ autocapture: false,
649
+ // We only want explicit captures
650
+ capture_pageview: false,
651
+ // We don't want automatic pageview tracking
652
+ disable_session_recording: true,
653
+ // No session recording
654
+ loaded: /* @__PURE__ */ __name(() => {
655
+ logger.debug("PostHog browser client initialized");
656
+ }, "loaded")
657
+ });
658
+ this._posthogBrowserClient = posthog;
659
+ } catch (e) {
660
+ logger.warn(`Failed to initialize PostHog browser telemetry: ${e}`);
661
+ this._posthogBrowserClient = null;
662
+ }
663
+ }
664
+ async _initPostHogNode() {
665
+ try {
666
+ const { PostHog } = await import("posthog-node");
667
+ const isServerlessEnvironment = [
668
+ "cloudflare-workers",
669
+ "edge",
670
+ "deno"
671
+ ].includes(this._runtimeEnvironment);
672
+ const posthogOptions = {
673
+ host: this.HOST,
674
+ disableGeoip: false
675
+ };
676
+ if (isServerlessEnvironment) {
677
+ posthogOptions.flushAt = 1;
678
+ posthogOptions.flushInterval = 0;
679
+ }
680
+ this._posthogNodeClient = new PostHog(
681
+ this.PROJECT_API_KEY,
682
+ posthogOptions
683
+ );
684
+ logger.debug("PostHog Node.js client initialized");
685
+ } catch (e) {
686
+ logger.warn(`Failed to initialize PostHog Node.js telemetry: ${e}`);
687
+ this._posthogNodeClient = null;
688
+ }
689
+ }
690
+ /**
691
+ * Get the detected runtime environment
692
+ */
693
+ get runtimeEnvironment() {
694
+ return this._runtimeEnvironment;
695
+ }
696
+ /**
697
+ * Get the storage capability for this environment
698
+ */
699
+ get storageCapability() {
700
+ return this._storageCapability;
701
+ }
702
+ static getInstance() {
703
+ if (!_Telemetry.instance) {
704
+ _Telemetry.instance = new _Telemetry();
705
+ }
706
+ return _Telemetry.instance;
707
+ }
708
+ /**
709
+ * Set the source identifier for telemetry events.
710
+ * This allows tracking usage from different applications.
711
+ * @param source - The source identifier (e.g., "my-app", "cli", "vs-code-extension")
712
+ */
713
+ setSource(source) {
714
+ this._source = source;
715
+ logger.debug(`Telemetry source set to: ${source}`);
716
+ }
717
+ /**
718
+ * Get the current source identifier.
719
+ */
720
+ getSource() {
721
+ return this._source;
722
+ }
723
+ /**
724
+ * Check if telemetry is enabled.
725
+ */
726
+ get isEnabled() {
727
+ return this._posthogNodeClient !== null || this._posthogBrowserClient !== null || this._scarfClient !== null;
728
+ }
729
+ get userId() {
730
+ if (this._currUserId) {
731
+ return this._currUserId;
732
+ }
733
+ try {
734
+ switch (this._storageCapability) {
735
+ case "filesystem":
736
+ this._currUserId = this._getUserIdFromFilesystem();
737
+ break;
738
+ case "localStorage":
739
+ this._currUserId = this._getUserIdFromLocalStorage();
740
+ break;
741
+ case "session-only":
742
+ default:
743
+ this._currUserId = `session-${generateUUID()}`;
744
+ logger.debug(
745
+ `Using session-based user ID (${this._runtimeEnvironment} environment)`
746
+ );
747
+ break;
748
+ }
749
+ if (this._storageCapability === "filesystem" && this._currUserId) {
750
+ this._trackPackageDownloadInternal(this._currUserId, {
751
+ triggered_by: "user_id_property"
752
+ }).catch((e) => logger.debug(`Failed to track package download: ${e}`));
753
+ }
754
+ } catch (e) {
755
+ logger.debug(`Failed to get/create user ID: ${e}`);
756
+ this._currUserId = this.UNKNOWN_USER_ID;
757
+ }
758
+ return this._currUserId;
759
+ }
760
+ /**
761
+ * Get or create user ID from filesystem (Node.js/Bun)
762
+ */
763
+ _getUserIdFromFilesystem() {
764
+ const fs = __require("fs");
765
+ const os = __require("os");
766
+ const path = __require("path");
767
+ if (!this._userIdPath) {
768
+ this._userIdPath = path.join(
769
+ this._getCacheHome(os, path),
770
+ "mcp_use_3",
771
+ "telemetry_user_id"
772
+ );
773
+ }
774
+ const isFirstTime = !fs.existsSync(this._userIdPath);
775
+ if (isFirstTime) {
776
+ logger.debug(`Creating user ID path: ${this._userIdPath}`);
777
+ fs.mkdirSync(path.dirname(this._userIdPath), { recursive: true });
778
+ const newUserId = generateUUID();
779
+ fs.writeFileSync(this._userIdPath, newUserId);
780
+ logger.debug(`User ID path created: ${this._userIdPath}`);
781
+ return newUserId;
782
+ }
783
+ return fs.readFileSync(this._userIdPath, "utf-8").trim();
784
+ }
785
+ /**
786
+ * Get or create user ID from localStorage (Browser)
787
+ */
788
+ _getUserIdFromLocalStorage() {
789
+ try {
790
+ let userId = localStorage.getItem(USER_ID_STORAGE_KEY);
791
+ if (!userId) {
792
+ userId = generateUUID();
793
+ localStorage.setItem(USER_ID_STORAGE_KEY, userId);
794
+ logger.debug(`Created new browser user ID`);
795
+ }
796
+ return userId;
797
+ } catch (e) {
798
+ logger.debug(`localStorage access failed: ${e}`);
799
+ return `session-${generateUUID()}`;
800
+ }
801
+ }
802
+ _getCacheHome(os, path) {
803
+ const envVar = process.env.XDG_CACHE_HOME;
804
+ if (envVar && path.isAbsolute(envVar)) {
805
+ return envVar;
806
+ }
807
+ const platform = process.platform;
808
+ const homeDir = os.homedir();
809
+ if (platform === "win32") {
810
+ const appdata = process.env.LOCALAPPDATA || process.env.APPDATA;
811
+ if (appdata) {
812
+ return appdata;
813
+ }
814
+ return path.join(homeDir, "AppData", "Local");
815
+ } else if (platform === "darwin") {
816
+ return path.join(homeDir, "Library", "Caches");
817
+ } else {
818
+ return path.join(homeDir, ".cache");
819
+ }
820
+ }
821
+ async capture(event) {
822
+ if (this._posthogLoading) {
823
+ await this._posthogLoading;
824
+ }
825
+ if (!this._posthogNodeClient && !this._posthogBrowserClient && !this._scarfClient) {
826
+ return;
827
+ }
828
+ const properties = { ...event.properties };
829
+ properties.mcp_use_version = getPackageVersion();
830
+ properties.language = "typescript";
831
+ properties.source = this._source;
832
+ properties.runtime = this._runtimeEnvironment;
833
+ if (this._posthogNodeClient) {
834
+ try {
835
+ logger.debug(`CAPTURE: PostHog Node Event ${event.name}`);
836
+ this._posthogNodeClient.capture({
837
+ distinctId: this.userId,
838
+ event: event.name,
839
+ properties
840
+ });
841
+ } catch (e) {
842
+ logger.debug(`Failed to track PostHog Node event ${event.name}: ${e}`);
843
+ }
844
+ }
845
+ if (this._posthogBrowserClient) {
846
+ try {
847
+ logger.debug(`CAPTURE: PostHog Browser Event ${event.name}`);
848
+ this._posthogBrowserClient.capture(event.name, {
849
+ ...properties,
850
+ distinct_id: this.userId
851
+ });
852
+ } catch (e) {
853
+ logger.debug(
854
+ `Failed to track PostHog Browser event ${event.name}: ${e}`
855
+ );
856
+ }
857
+ }
858
+ if (this._scarfClient) {
859
+ try {
860
+ const scarfProperties = {
861
+ ...properties,
862
+ user_id: this.userId,
863
+ event: event.name
864
+ };
865
+ await this._scarfClient.logEvent(scarfProperties);
866
+ } catch (e) {
867
+ logger.debug(`Failed to track Scarf event ${event.name}: ${e}`);
868
+ }
869
+ }
870
+ }
871
+ // ============================================================================
872
+ // Package Download Tracking (Node.js only)
873
+ // ============================================================================
874
+ /**
875
+ * Track package download event.
876
+ * This is a public wrapper that safely accesses userId.
877
+ */
878
+ async trackPackageDownload(properties) {
879
+ return this._trackPackageDownloadInternal(this.userId, properties);
880
+ }
881
+ /**
882
+ * Internal method to track package download with explicit userId.
883
+ */
884
+ async _trackPackageDownloadInternal(userId, properties) {
885
+ if (!this._scarfClient) {
886
+ return;
887
+ }
888
+ if (this._storageCapability !== "filesystem") {
889
+ return;
890
+ }
891
+ try {
892
+ const fs = __require("fs");
893
+ const path = __require("path");
894
+ const os = __require("os");
895
+ if (!this._versionDownloadPath) {
896
+ this._versionDownloadPath = path.join(
897
+ this._getCacheHome(os, path),
898
+ "mcp_use",
899
+ "download_version"
900
+ );
901
+ }
902
+ const currentVersion = getPackageVersion();
903
+ let shouldTrack = false;
904
+ let firstDownload = false;
905
+ if (!fs.existsSync(this._versionDownloadPath)) {
906
+ shouldTrack = true;
907
+ firstDownload = true;
908
+ fs.mkdirSync(path.dirname(this._versionDownloadPath), {
909
+ recursive: true
910
+ });
911
+ fs.writeFileSync(this._versionDownloadPath, currentVersion);
912
+ } else {
913
+ const savedVersion = fs.readFileSync(this._versionDownloadPath, "utf-8").trim();
914
+ if (currentVersion > savedVersion) {
915
+ shouldTrack = true;
916
+ firstDownload = false;
917
+ fs.writeFileSync(this._versionDownloadPath, currentVersion);
918
+ }
919
+ }
920
+ if (shouldTrack) {
921
+ logger.debug(
922
+ `Tracking package download event with properties: ${JSON.stringify(properties)}`
923
+ );
924
+ const eventProperties = { ...properties || {} };
925
+ eventProperties.mcp_use_version = currentVersion;
926
+ eventProperties.user_id = userId;
927
+ eventProperties.event = "package_download";
928
+ eventProperties.first_download = firstDownload;
929
+ eventProperties.language = "typescript";
930
+ eventProperties.source = this._source;
931
+ eventProperties.runtime = this._runtimeEnvironment;
932
+ await this._scarfClient.logEvent(eventProperties);
933
+ }
934
+ } catch (e) {
935
+ logger.debug(`Failed to track Scarf package_download event: ${e}`);
936
+ }
937
+ }
938
+ // ============================================================================
939
+ // Agent Events
940
+ // ============================================================================
941
+ async trackAgentExecution(data) {
942
+ if (!this.isEnabled) return;
943
+ const event = new MCPAgentExecutionEvent(data);
944
+ await this.capture(event);
945
+ }
946
+ // ============================================================================
947
+ // Server Events
948
+ // ============================================================================
949
+ /**
950
+ * Track server run event directly from an MCPServer instance.
951
+ */
952
+ async trackServerRunFromServer(server, transport) {
953
+ if (!this.isEnabled) return;
954
+ const data = createServerRunEventData(server, transport);
955
+ const event = new ServerRunEvent(data);
956
+ await this.capture(event);
957
+ }
958
+ async trackServerInitialize(data) {
959
+ if (!this.isEnabled) return;
960
+ const event = new ServerInitializeEvent(data);
961
+ await this.capture(event);
962
+ }
963
+ async trackServerToolCall(data) {
964
+ if (!this.isEnabled) return;
965
+ const event = new ServerToolCallEvent(data);
966
+ await this.capture(event);
967
+ }
968
+ async trackServerResourceCall(data) {
969
+ if (!this.isEnabled) return;
970
+ const event = new ServerResourceCallEvent(data);
971
+ await this.capture(event);
972
+ }
973
+ async trackServerPromptCall(data) {
974
+ if (!this.isEnabled) return;
975
+ const event = new ServerPromptCallEvent(data);
976
+ await this.capture(event);
977
+ }
978
+ async trackServerContext(data) {
979
+ if (!this.isEnabled) return;
980
+ const event = new ServerContextEvent(data);
981
+ await this.capture(event);
982
+ }
983
+ // ============================================================================
984
+ // Client Events
985
+ // ============================================================================
986
+ async trackMCPClientInit(data) {
987
+ if (!this.isEnabled) return;
988
+ const event = new MCPClientInitEvent(data);
989
+ await this.capture(event);
990
+ }
991
+ async trackConnectorInit(data) {
992
+ if (!this.isEnabled) return;
993
+ const event = new ConnectorInitEvent(data);
994
+ await this.capture(event);
995
+ }
996
+ async trackClientAddServer(serverName, serverConfig) {
997
+ if (!this.isEnabled) return;
998
+ const event = new ClientAddServerEvent({ serverName, serverConfig });
999
+ await this.capture(event);
1000
+ }
1001
+ async trackClientRemoveServer(serverName) {
1002
+ if (!this.isEnabled) return;
1003
+ const event = new ClientRemoveServerEvent({ serverName });
1004
+ await this.capture(event);
1005
+ }
1006
+ // ============================================================================
1007
+ // React Hook / Browser specific events
1008
+ // ============================================================================
1009
+ async trackUseMcpConnection(data) {
1010
+ if (!this.isEnabled) return;
1011
+ await this.capture({
1012
+ name: "usemcp_connection",
1013
+ properties: {
1014
+ url_domain: new URL(data.url).hostname,
1015
+ // Only domain for privacy
1016
+ transport_type: data.transportType,
1017
+ success: data.success,
1018
+ error_type: data.errorType ?? null,
1019
+ connection_time_ms: data.connectionTimeMs ?? null,
1020
+ has_oauth: data.hasOAuth,
1021
+ has_sampling: data.hasSampling,
1022
+ has_elicitation: data.hasElicitation
1023
+ }
1024
+ });
1025
+ }
1026
+ async trackUseMcpToolCall(data) {
1027
+ if (!this.isEnabled) return;
1028
+ await this.capture({
1029
+ name: "usemcp_tool_call",
1030
+ properties: {
1031
+ tool_name: data.toolName,
1032
+ success: data.success,
1033
+ error_type: data.errorType ?? null,
1034
+ execution_time_ms: data.executionTimeMs ?? null
1035
+ }
1036
+ });
1037
+ }
1038
+ async trackUseMcpResourceRead(data) {
1039
+ if (!this.isEnabled) return;
1040
+ await this.capture({
1041
+ name: "usemcp_resource_read",
1042
+ properties: {
1043
+ resource_uri_scheme: data.resourceUri.split(":")[0],
1044
+ // Only scheme for privacy
1045
+ success: data.success,
1046
+ error_type: data.errorType ?? null
1047
+ }
1048
+ });
1049
+ }
1050
+ // ============================================================================
1051
+ // Browser-specific Methods
1052
+ // ============================================================================
1053
+ /**
1054
+ * Identify the current user (useful for linking sessions)
1055
+ * Browser only - no-op in Node.js
1056
+ */
1057
+ identify(userId, properties) {
1058
+ if (this._posthogBrowserClient) {
1059
+ try {
1060
+ this._posthogBrowserClient.identify(userId, properties);
1061
+ } catch (e) {
1062
+ logger.debug(`Failed to identify user: ${e}`);
1063
+ }
1064
+ }
1065
+ }
1066
+ /**
1067
+ * Reset the user identity (useful for logout)
1068
+ * Browser only - no-op in Node.js
1069
+ */
1070
+ reset() {
1071
+ if (this._posthogBrowserClient) {
1072
+ try {
1073
+ this._posthogBrowserClient.reset();
1074
+ } catch (e) {
1075
+ logger.debug(`Failed to reset user: ${e}`);
1076
+ }
1077
+ }
1078
+ this._currUserId = null;
1079
+ }
1080
+ // ============================================================================
1081
+ // Node.js-specific Methods
1082
+ // ============================================================================
1083
+ /**
1084
+ * Flush the telemetry queue (Node.js only)
1085
+ */
1086
+ flush() {
1087
+ if (this._posthogNodeClient) {
1088
+ try {
1089
+ this._posthogNodeClient.flush();
1090
+ logger.debug("PostHog client telemetry queue flushed");
1091
+ } catch (e) {
1092
+ logger.debug(`Failed to flush PostHog client: ${e}`);
1093
+ }
1094
+ }
1095
+ }
1096
+ /**
1097
+ * Shutdown the telemetry client (Node.js only)
1098
+ */
1099
+ shutdown() {
1100
+ if (this._posthogNodeClient) {
1101
+ try {
1102
+ this._posthogNodeClient.shutdown();
1103
+ logger.debug("PostHog client shutdown successfully");
1104
+ } catch (e) {
1105
+ logger.debug(`Error shutting down PostHog client: ${e}`);
1106
+ }
1107
+ }
1108
+ }
1109
+ };
1110
+ var Tel = Telemetry;
1111
+ function setTelemetrySource(source) {
1112
+ Tel.getInstance().setSource(source);
1113
+ }
1114
+ __name(setTelemetrySource, "setTelemetrySource");
1115
+
1116
+ export {
1117
+ isDeno,
1118
+ getEnv,
1119
+ getCwd,
1120
+ fsHelpers,
1121
+ pathHelpers,
1122
+ generateUUID,
1123
+ VERSION,
1124
+ getPackageVersion,
1125
+ extractModelInfo,
1126
+ Telemetry,
1127
+ Tel,
1128
+ setTelemetrySource
1129
+ };