mcp-use 1.10.0-canary.6 → 1.10.0-canary.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/.tsbuildinfo +1 -1
- package/dist/{chunk-464BT6EX.js → chunk-6W6MURTQ.js} +2 -2
- package/dist/{chunk-XU3C6BYJ.js → chunk-BBOYAKT6.js} +14 -0
- package/dist/{chunk-FWN7BKNM.js → chunk-CAIRNNL6.js} +14 -1
- package/dist/chunk-ITRC7CNB.js +942 -0
- package/dist/{chunk-7RUUAWVB.js → chunk-J75I2C26.js} +38 -10
- package/dist/{chunk-7AZ4YFTN.js → chunk-MSA3YBQE.js} +1 -1
- package/dist/{chunk-T4B7QDPT.js → chunk-QBKQ6JN2.js} +20 -4
- package/dist/{chunk-YMJL66MY.js → chunk-X5QAXENQ.js} +12 -402
- package/dist/index.cjs +617 -86
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +51 -18
- package/dist/src/agents/index.cjs +2050 -1603
- package/dist/src/agents/index.js +4 -4
- package/dist/src/agents/mcp_agent.d.ts +5 -0
- package/dist/src/agents/mcp_agent.d.ts.map +1 -1
- package/dist/src/auth/callback.d.ts.map +1 -1
- package/dist/src/auth/index.cjs +38 -10
- package/dist/src/auth/index.js +1 -1
- package/dist/src/browser.cjs +3277 -2770
- package/dist/src/browser.d.ts +1 -0
- 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/prompts.cjs +12 -3
- package/dist/src/client/prompts.js +3 -2
- package/dist/src/client.d.ts +6 -0
- package/dist/src/client.d.ts.map +1 -1
- package/dist/src/connectors/base.d.ts +20 -10
- package/dist/src/connectors/base.d.ts.map +1 -1
- package/dist/src/connectors/http.d.ts.map +1 -1
- package/dist/src/connectors/stdio.d.ts.map +1 -1
- package/dist/src/react/index.cjs +877 -22
- package/dist/src/react/index.js +5 -5
- package/dist/src/server/endpoints/mount-mcp.d.ts.map +1 -1
- package/dist/src/server/index.cjs +1352 -78
- package/dist/src/server/index.d.ts +1 -0
- package/dist/src/server/index.d.ts.map +1 -1
- package/dist/src/server/index.js +199 -53
- package/dist/src/server/mcp-server.d.ts +31 -6
- package/dist/src/server/mcp-server.d.ts.map +1 -1
- package/dist/src/server/tools/tool-execution-helpers.d.ts.map +1 -1
- package/dist/src/server/widgets/mount-widgets-dev.d.ts.map +1 -1
- package/dist/src/telemetry/events.d.ts +219 -0
- package/dist/src/telemetry/events.d.ts.map +1 -1
- package/dist/src/telemetry/index.d.ts +2 -2
- package/dist/src/telemetry/index.d.ts.map +1 -1
- package/dist/src/telemetry/telemetry.d.ts +56 -1
- package/dist/src/telemetry/telemetry.d.ts.map +1 -1
- package/dist/src/telemetry/utils.d.ts +1 -1
- package/dist/src/telemetry/utils.d.ts.map +1 -1
- package/dist/src/version.d.ts +8 -0
- package/dist/src/version.d.ts.map +1 -0
- package/dist/{tool-execution-helpers-M5RO4YO2.js → tool-execution-helpers-BMGQQKS2.js} +3 -2
- package/package.json +5 -4
- package/dist/chunk-MTHLLDCX.js +0 -97
|
@@ -55,48 +55,48 @@ var init_runtime = __esm({
|
|
|
55
55
|
__name(getEnv, "getEnv");
|
|
56
56
|
__name(getCwd, "getCwd");
|
|
57
57
|
fsHelpers = {
|
|
58
|
-
async readFileSync(
|
|
58
|
+
async readFileSync(path2, encoding = "utf8") {
|
|
59
59
|
if (isDeno) {
|
|
60
|
-
return await globalThis.Deno.readTextFile(
|
|
60
|
+
return await globalThis.Deno.readTextFile(path2);
|
|
61
61
|
}
|
|
62
|
-
const { readFileSync } = await import("fs");
|
|
63
|
-
const result =
|
|
62
|
+
const { readFileSync: readFileSync2 } = await import("fs");
|
|
63
|
+
const result = readFileSync2(path2, encoding);
|
|
64
64
|
return typeof result === "string" ? result : result.toString(encoding);
|
|
65
65
|
},
|
|
66
|
-
async readFile(
|
|
66
|
+
async readFile(path2) {
|
|
67
67
|
if (isDeno) {
|
|
68
|
-
const data = await globalThis.Deno.readFile(
|
|
68
|
+
const data = await globalThis.Deno.readFile(path2);
|
|
69
69
|
return data.buffer;
|
|
70
70
|
}
|
|
71
|
-
const { readFileSync } = await import("fs");
|
|
72
|
-
const buffer =
|
|
71
|
+
const { readFileSync: readFileSync2 } = await import("fs");
|
|
72
|
+
const buffer = readFileSync2(path2);
|
|
73
73
|
return buffer.buffer.slice(
|
|
74
74
|
buffer.byteOffset,
|
|
75
75
|
buffer.byteOffset + buffer.byteLength
|
|
76
76
|
);
|
|
77
77
|
},
|
|
78
|
-
async existsSync(
|
|
78
|
+
async existsSync(path2) {
|
|
79
79
|
if (isDeno) {
|
|
80
80
|
try {
|
|
81
|
-
await globalThis.Deno.stat(
|
|
81
|
+
await globalThis.Deno.stat(path2);
|
|
82
82
|
return true;
|
|
83
83
|
} catch {
|
|
84
84
|
return false;
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
|
-
const { existsSync } = await import("fs");
|
|
88
|
-
return
|
|
87
|
+
const { existsSync: existsSync2 } = await import("fs");
|
|
88
|
+
return existsSync2(path2);
|
|
89
89
|
},
|
|
90
|
-
async readdirSync(
|
|
90
|
+
async readdirSync(path2) {
|
|
91
91
|
if (isDeno) {
|
|
92
92
|
const entries = [];
|
|
93
|
-
for await (const entry of globalThis.Deno.readDir(
|
|
93
|
+
for await (const entry of globalThis.Deno.readDir(path2)) {
|
|
94
94
|
entries.push(entry.name);
|
|
95
95
|
}
|
|
96
96
|
return entries;
|
|
97
97
|
}
|
|
98
98
|
const { readdirSync } = await import("fs");
|
|
99
|
-
return readdirSync(
|
|
99
|
+
return readdirSync(path2);
|
|
100
100
|
}
|
|
101
101
|
};
|
|
102
102
|
pathHelpers = {
|
|
@@ -122,6 +122,1121 @@ var init_runtime = __esm({
|
|
|
122
122
|
}
|
|
123
123
|
});
|
|
124
124
|
|
|
125
|
+
// src/logging.ts
|
|
126
|
+
async function getNodeModules() {
|
|
127
|
+
if (typeof process !== "undefined" && process.platform) {
|
|
128
|
+
try {
|
|
129
|
+
const fs2 = await import("fs");
|
|
130
|
+
const path2 = await import("path");
|
|
131
|
+
return { fs: fs2.default, path: path2.default };
|
|
132
|
+
} catch {
|
|
133
|
+
return { fs: null, path: null };
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return { fs: null, path: null };
|
|
137
|
+
}
|
|
138
|
+
function loadWinstonSync() {
|
|
139
|
+
if (typeof require !== "undefined") {
|
|
140
|
+
try {
|
|
141
|
+
winston = require("winston");
|
|
142
|
+
} catch {
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
async function getWinston() {
|
|
147
|
+
if (!winston) {
|
|
148
|
+
winston = await import("winston");
|
|
149
|
+
}
|
|
150
|
+
return winston;
|
|
151
|
+
}
|
|
152
|
+
function isNodeJSEnvironment() {
|
|
153
|
+
try {
|
|
154
|
+
if (typeof navigator !== "undefined" && navigator.userAgent?.includes("Cloudflare-Workers")) {
|
|
155
|
+
return false;
|
|
156
|
+
}
|
|
157
|
+
if (typeof globalThis.EdgeRuntime !== "undefined" || typeof globalThis.Deno !== "undefined") {
|
|
158
|
+
return false;
|
|
159
|
+
}
|
|
160
|
+
const hasNodeGlobals = typeof process !== "undefined" && typeof process.platform !== "undefined" && typeof __dirname !== "undefined";
|
|
161
|
+
return hasNodeGlobals;
|
|
162
|
+
} catch {
|
|
163
|
+
return false;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
function resolveLevel(env) {
|
|
167
|
+
const envValue = typeof process !== "undefined" && process.env ? env : void 0;
|
|
168
|
+
switch (envValue?.trim()) {
|
|
169
|
+
case "2":
|
|
170
|
+
return "debug";
|
|
171
|
+
case "1":
|
|
172
|
+
return "info";
|
|
173
|
+
default:
|
|
174
|
+
return "info";
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
var winston, DEFAULT_LOGGER_NAME, SimpleConsoleLogger, Logger, logger;
|
|
178
|
+
var init_logging = __esm({
|
|
179
|
+
"src/logging.ts"() {
|
|
180
|
+
"use strict";
|
|
181
|
+
__name(getNodeModules, "getNodeModules");
|
|
182
|
+
winston = null;
|
|
183
|
+
__name(loadWinstonSync, "loadWinstonSync");
|
|
184
|
+
__name(getWinston, "getWinston");
|
|
185
|
+
DEFAULT_LOGGER_NAME = "mcp-use";
|
|
186
|
+
__name(isNodeJSEnvironment, "isNodeJSEnvironment");
|
|
187
|
+
SimpleConsoleLogger = class {
|
|
188
|
+
static {
|
|
189
|
+
__name(this, "SimpleConsoleLogger");
|
|
190
|
+
}
|
|
191
|
+
_level;
|
|
192
|
+
name;
|
|
193
|
+
constructor(name = DEFAULT_LOGGER_NAME, level = "info") {
|
|
194
|
+
this.name = name;
|
|
195
|
+
this._level = level;
|
|
196
|
+
}
|
|
197
|
+
shouldLog(level) {
|
|
198
|
+
const levels = [
|
|
199
|
+
"error",
|
|
200
|
+
"warn",
|
|
201
|
+
"info",
|
|
202
|
+
"http",
|
|
203
|
+
"verbose",
|
|
204
|
+
"debug",
|
|
205
|
+
"silly"
|
|
206
|
+
];
|
|
207
|
+
const currentIndex = levels.indexOf(this._level);
|
|
208
|
+
const messageIndex = levels.indexOf(level);
|
|
209
|
+
return messageIndex <= currentIndex;
|
|
210
|
+
}
|
|
211
|
+
formatMessage(level, message) {
|
|
212
|
+
const timestamp = (/* @__PURE__ */ new Date()).toLocaleTimeString("en-US", { hour12: false });
|
|
213
|
+
return `${timestamp} [${this.name}] ${level}: ${message}`;
|
|
214
|
+
}
|
|
215
|
+
error(message) {
|
|
216
|
+
if (this.shouldLog("error")) {
|
|
217
|
+
console.error(this.formatMessage("error", message));
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
warn(message) {
|
|
221
|
+
if (this.shouldLog("warn")) {
|
|
222
|
+
console.warn(this.formatMessage("warn", message));
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
info(message) {
|
|
226
|
+
if (this.shouldLog("info")) {
|
|
227
|
+
console.info(this.formatMessage("info", message));
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
debug(message) {
|
|
231
|
+
if (this.shouldLog("debug")) {
|
|
232
|
+
console.debug(this.formatMessage("debug", message));
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
http(message) {
|
|
236
|
+
if (this.shouldLog("http")) {
|
|
237
|
+
console.log(this.formatMessage("http", message));
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
verbose(message) {
|
|
241
|
+
if (this.shouldLog("verbose")) {
|
|
242
|
+
console.log(this.formatMessage("verbose", message));
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
silly(message) {
|
|
246
|
+
if (this.shouldLog("silly")) {
|
|
247
|
+
console.log(this.formatMessage("silly", message));
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
// Make it compatible with Winston interface
|
|
251
|
+
get level() {
|
|
252
|
+
return this._level;
|
|
253
|
+
}
|
|
254
|
+
set level(newLevel) {
|
|
255
|
+
this._level = newLevel;
|
|
256
|
+
}
|
|
257
|
+
};
|
|
258
|
+
__name(resolveLevel, "resolveLevel");
|
|
259
|
+
Logger = class {
|
|
260
|
+
static {
|
|
261
|
+
__name(this, "Logger");
|
|
262
|
+
}
|
|
263
|
+
static instances = {};
|
|
264
|
+
static simpleInstances = {};
|
|
265
|
+
static currentFormat = "minimal";
|
|
266
|
+
static get(name = DEFAULT_LOGGER_NAME) {
|
|
267
|
+
if (!isNodeJSEnvironment()) {
|
|
268
|
+
if (!this.simpleInstances[name]) {
|
|
269
|
+
const debugEnv = typeof process !== "undefined" && process.env?.DEBUG || void 0;
|
|
270
|
+
this.simpleInstances[name] = new SimpleConsoleLogger(
|
|
271
|
+
name,
|
|
272
|
+
resolveLevel(debugEnv)
|
|
273
|
+
);
|
|
274
|
+
}
|
|
275
|
+
return this.simpleInstances[name];
|
|
276
|
+
}
|
|
277
|
+
if (!this.instances[name]) {
|
|
278
|
+
if (!winston) {
|
|
279
|
+
throw new Error("Winston not loaded - call Logger.configure() first");
|
|
280
|
+
}
|
|
281
|
+
const { createLogger, format } = winston;
|
|
282
|
+
const { combine, timestamp, label, colorize, splat } = format;
|
|
283
|
+
this.instances[name] = createLogger({
|
|
284
|
+
level: resolveLevel(process.env.DEBUG),
|
|
285
|
+
format: combine(
|
|
286
|
+
colorize(),
|
|
287
|
+
splat(),
|
|
288
|
+
label({ label: name }),
|
|
289
|
+
timestamp({ format: "HH:mm:ss" }),
|
|
290
|
+
this.getFormatter()
|
|
291
|
+
),
|
|
292
|
+
transports: []
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
return this.instances[name];
|
|
296
|
+
}
|
|
297
|
+
static getFormatter() {
|
|
298
|
+
if (!winston) {
|
|
299
|
+
throw new Error("Winston not loaded");
|
|
300
|
+
}
|
|
301
|
+
const { format } = winston;
|
|
302
|
+
const { printf } = format;
|
|
303
|
+
const minimalFormatter = printf(({ level, message, label, timestamp }) => {
|
|
304
|
+
return `${timestamp} [${label}] ${level}: ${message}`;
|
|
305
|
+
});
|
|
306
|
+
const detailedFormatter = printf(({ level, message, label, timestamp }) => {
|
|
307
|
+
return `${timestamp} [${label}] ${level.toUpperCase()}: ${message}`;
|
|
308
|
+
});
|
|
309
|
+
const emojiFormatter = printf(({ level, message, label, timestamp }) => {
|
|
310
|
+
return `${timestamp} [${label}] ${level.toUpperCase()}: ${message}`;
|
|
311
|
+
});
|
|
312
|
+
switch (this.currentFormat) {
|
|
313
|
+
case "minimal":
|
|
314
|
+
return minimalFormatter;
|
|
315
|
+
case "detailed":
|
|
316
|
+
return detailedFormatter;
|
|
317
|
+
case "emoji":
|
|
318
|
+
return emojiFormatter;
|
|
319
|
+
default:
|
|
320
|
+
return minimalFormatter;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
static async configure(options = {}) {
|
|
324
|
+
const { level, console: console2 = true, file, format = "minimal" } = options;
|
|
325
|
+
const debugEnv = typeof process !== "undefined" && process.env?.DEBUG || void 0;
|
|
326
|
+
const resolvedLevel = level ?? resolveLevel(debugEnv);
|
|
327
|
+
this.currentFormat = format;
|
|
328
|
+
if (!isNodeJSEnvironment()) {
|
|
329
|
+
Object.values(this.simpleInstances).forEach((logger2) => {
|
|
330
|
+
logger2.level = resolvedLevel;
|
|
331
|
+
});
|
|
332
|
+
return;
|
|
333
|
+
}
|
|
334
|
+
await getWinston();
|
|
335
|
+
if (!winston) {
|
|
336
|
+
throw new Error("Failed to load winston");
|
|
337
|
+
}
|
|
338
|
+
const root = this.get();
|
|
339
|
+
root.level = resolvedLevel;
|
|
340
|
+
const winstonRoot = root;
|
|
341
|
+
winstonRoot.clear();
|
|
342
|
+
if (console2) {
|
|
343
|
+
winstonRoot.add(new winston.transports.Console());
|
|
344
|
+
}
|
|
345
|
+
if (file) {
|
|
346
|
+
const { fs: nodeFs, path: nodePath } = await getNodeModules();
|
|
347
|
+
if (nodeFs && nodePath) {
|
|
348
|
+
const dir = nodePath.dirname(nodePath.resolve(file));
|
|
349
|
+
if (!nodeFs.existsSync(dir)) {
|
|
350
|
+
nodeFs.mkdirSync(dir, { recursive: true });
|
|
351
|
+
}
|
|
352
|
+
winstonRoot.add(new winston.transports.File({ filename: file }));
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
const { format: winstonFormat } = winston;
|
|
356
|
+
const { combine, timestamp, label, colorize, splat } = winstonFormat;
|
|
357
|
+
Object.values(this.instances).forEach((logger2) => {
|
|
358
|
+
if (logger2 && "format" in logger2) {
|
|
359
|
+
logger2.level = resolvedLevel;
|
|
360
|
+
logger2.format = combine(
|
|
361
|
+
colorize(),
|
|
362
|
+
splat(),
|
|
363
|
+
label({ label: DEFAULT_LOGGER_NAME }),
|
|
364
|
+
timestamp({ format: "HH:mm:ss" }),
|
|
365
|
+
this.getFormatter()
|
|
366
|
+
);
|
|
367
|
+
}
|
|
368
|
+
});
|
|
369
|
+
}
|
|
370
|
+
static setDebug(enabled) {
|
|
371
|
+
let level;
|
|
372
|
+
if (enabled === 2 || enabled === true) level = "debug";
|
|
373
|
+
else if (enabled === 1) level = "info";
|
|
374
|
+
else level = "info";
|
|
375
|
+
Object.values(this.simpleInstances).forEach((logger2) => {
|
|
376
|
+
logger2.level = level;
|
|
377
|
+
});
|
|
378
|
+
Object.values(this.instances).forEach((logger2) => {
|
|
379
|
+
if (logger2) {
|
|
380
|
+
logger2.level = level;
|
|
381
|
+
}
|
|
382
|
+
});
|
|
383
|
+
if (typeof process !== "undefined" && process.env) {
|
|
384
|
+
process.env.DEBUG = enabled ? enabled === true ? "2" : String(enabled) : "0";
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
static setFormat(format) {
|
|
388
|
+
this.currentFormat = format;
|
|
389
|
+
this.configure({ format });
|
|
390
|
+
}
|
|
391
|
+
};
|
|
392
|
+
if (isNodeJSEnvironment()) {
|
|
393
|
+
loadWinstonSync();
|
|
394
|
+
if (winston) {
|
|
395
|
+
Logger.configure();
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
logger = Logger.get();
|
|
399
|
+
}
|
|
400
|
+
});
|
|
401
|
+
|
|
402
|
+
// src/telemetry/events.ts
|
|
403
|
+
function createServerRunEventData(server, transport) {
|
|
404
|
+
const toolRegistrations = Array.from(server.registrations.tools.values());
|
|
405
|
+
const promptRegistrations = Array.from(server.registrations.prompts.values());
|
|
406
|
+
const resourceRegistrations = Array.from(
|
|
407
|
+
server.registrations.resources.values()
|
|
408
|
+
);
|
|
409
|
+
const templateRegistrations = Array.from(
|
|
410
|
+
server.registrations.resourceTemplates.values()
|
|
411
|
+
);
|
|
412
|
+
const allResources = resourceRegistrations.map((r) => ({
|
|
413
|
+
name: r.config.name,
|
|
414
|
+
title: r.config.title ?? null,
|
|
415
|
+
description: r.config.description ?? null,
|
|
416
|
+
uri: r.config.uri ?? null,
|
|
417
|
+
mime_type: r.config.mimeType ?? null
|
|
418
|
+
}));
|
|
419
|
+
const appsSdkResources = allResources.filter(
|
|
420
|
+
(r) => r.mime_type === "text/html+skybridge"
|
|
421
|
+
);
|
|
422
|
+
const mcpUiResources = allResources.filter(
|
|
423
|
+
(r) => r.mime_type === "text/uri-list" || r.mime_type === "text/html"
|
|
424
|
+
);
|
|
425
|
+
const mcpAppsResources = allResources.filter(
|
|
426
|
+
(r) => r.mime_type === "text/html+mcp"
|
|
427
|
+
);
|
|
428
|
+
return {
|
|
429
|
+
transport,
|
|
430
|
+
toolsNumber: server.registeredTools.length,
|
|
431
|
+
resourcesNumber: server.registeredResources.length,
|
|
432
|
+
promptsNumber: server.registeredPrompts.length,
|
|
433
|
+
auth: !!server.oauthProvider,
|
|
434
|
+
name: server.config.name,
|
|
435
|
+
description: server.config.description ?? null,
|
|
436
|
+
baseUrl: server.serverBaseUrl ?? null,
|
|
437
|
+
toolNames: server.registeredTools.length > 0 ? server.registeredTools : null,
|
|
438
|
+
resourceNames: server.registeredResources.length > 0 ? server.registeredResources : null,
|
|
439
|
+
promptNames: server.registeredPrompts.length > 0 ? server.registeredPrompts : null,
|
|
440
|
+
tools: toolRegistrations.length > 0 ? toolRegistrations.map((r) => ({
|
|
441
|
+
name: r.config.name,
|
|
442
|
+
title: r.config.title ?? null,
|
|
443
|
+
description: r.config.description ?? null,
|
|
444
|
+
input_schema: r.config.schema ? JSON.stringify(r.config.schema) : null,
|
|
445
|
+
output_schema: r.config.outputSchema ? JSON.stringify(r.config.outputSchema) : null
|
|
446
|
+
})) : null,
|
|
447
|
+
resources: allResources.length > 0 ? allResources : null,
|
|
448
|
+
prompts: promptRegistrations.length > 0 ? promptRegistrations.map((r) => ({
|
|
449
|
+
name: r.config.name,
|
|
450
|
+
title: r.config.title ?? null,
|
|
451
|
+
description: r.config.description ?? null,
|
|
452
|
+
args: r.config.args ? JSON.stringify(r.config.args) : null
|
|
453
|
+
})) : null,
|
|
454
|
+
templates: templateRegistrations.length > 0 ? templateRegistrations.map((r) => ({
|
|
455
|
+
name: r.config.name,
|
|
456
|
+
title: r.config.title ?? null,
|
|
457
|
+
description: r.config.description ?? null
|
|
458
|
+
})) : null,
|
|
459
|
+
capabilities: {
|
|
460
|
+
logging: true,
|
|
461
|
+
resources: { subscribe: true, listChanged: true }
|
|
462
|
+
},
|
|
463
|
+
appsSdkResources: appsSdkResources.length > 0 ? appsSdkResources : null,
|
|
464
|
+
appsSdkResourcesNumber: appsSdkResources.length,
|
|
465
|
+
mcpUiResources: mcpUiResources.length > 0 ? mcpUiResources : null,
|
|
466
|
+
mcpUiResourcesNumber: mcpUiResources.length,
|
|
467
|
+
mcpAppsResources: mcpAppsResources.length > 0 ? mcpAppsResources : null,
|
|
468
|
+
mcpAppsResourcesNumber: mcpAppsResources.length
|
|
469
|
+
};
|
|
470
|
+
}
|
|
471
|
+
var BaseTelemetryEvent, MCPAgentExecutionEvent, ServerRunEvent, ServerInitializeEvent, ServerToolCallEvent, ServerResourceCallEvent, ServerPromptCallEvent, ServerContextEvent, MCPClientInitEvent, ConnectorInitEvent;
|
|
472
|
+
var init_events = __esm({
|
|
473
|
+
"src/telemetry/events.ts"() {
|
|
474
|
+
"use strict";
|
|
475
|
+
BaseTelemetryEvent = class {
|
|
476
|
+
static {
|
|
477
|
+
__name(this, "BaseTelemetryEvent");
|
|
478
|
+
}
|
|
479
|
+
};
|
|
480
|
+
MCPAgentExecutionEvent = class extends BaseTelemetryEvent {
|
|
481
|
+
constructor(data) {
|
|
482
|
+
super();
|
|
483
|
+
this.data = data;
|
|
484
|
+
}
|
|
485
|
+
static {
|
|
486
|
+
__name(this, "MCPAgentExecutionEvent");
|
|
487
|
+
}
|
|
488
|
+
get name() {
|
|
489
|
+
return "mcp_agent_execution";
|
|
490
|
+
}
|
|
491
|
+
get properties() {
|
|
492
|
+
return {
|
|
493
|
+
// Core execution info
|
|
494
|
+
execution_method: this.data.executionMethod,
|
|
495
|
+
query: this.data.query,
|
|
496
|
+
query_length: this.data.query.length,
|
|
497
|
+
success: this.data.success,
|
|
498
|
+
// Agent configuration
|
|
499
|
+
model_provider: this.data.modelProvider,
|
|
500
|
+
model_name: this.data.modelName,
|
|
501
|
+
server_count: this.data.serverCount,
|
|
502
|
+
server_identifiers: this.data.serverIdentifiers,
|
|
503
|
+
total_tools_available: this.data.totalToolsAvailable,
|
|
504
|
+
tools_available_names: this.data.toolsAvailableNames,
|
|
505
|
+
max_steps_configured: this.data.maxStepsConfigured,
|
|
506
|
+
memory_enabled: this.data.memoryEnabled,
|
|
507
|
+
use_server_manager: this.data.useServerManager,
|
|
508
|
+
// Execution parameters (always include, even if null)
|
|
509
|
+
max_steps_used: this.data.maxStepsUsed,
|
|
510
|
+
manage_connector: this.data.manageConnector,
|
|
511
|
+
external_history_used: this.data.externalHistoryUsed,
|
|
512
|
+
// Execution results (always include, even if null)
|
|
513
|
+
steps_taken: this.data.stepsTaken ?? null,
|
|
514
|
+
tools_used_count: this.data.toolsUsedCount ?? null,
|
|
515
|
+
tools_used_names: this.data.toolsUsedNames ?? null,
|
|
516
|
+
response: this.data.response ?? null,
|
|
517
|
+
response_length: this.data.response ? this.data.response.length : null,
|
|
518
|
+
execution_time_ms: this.data.executionTimeMs ?? null,
|
|
519
|
+
error_type: this.data.errorType ?? null,
|
|
520
|
+
conversation_history_length: this.data.conversationHistoryLength ?? null
|
|
521
|
+
};
|
|
522
|
+
}
|
|
523
|
+
};
|
|
524
|
+
__name(createServerRunEventData, "createServerRunEventData");
|
|
525
|
+
ServerRunEvent = class extends BaseTelemetryEvent {
|
|
526
|
+
constructor(data) {
|
|
527
|
+
super();
|
|
528
|
+
this.data = data;
|
|
529
|
+
}
|
|
530
|
+
static {
|
|
531
|
+
__name(this, "ServerRunEvent");
|
|
532
|
+
}
|
|
533
|
+
get name() {
|
|
534
|
+
return "server_run";
|
|
535
|
+
}
|
|
536
|
+
get properties() {
|
|
537
|
+
return {
|
|
538
|
+
transport: this.data.transport,
|
|
539
|
+
tools_number: this.data.toolsNumber,
|
|
540
|
+
resources_number: this.data.resourcesNumber,
|
|
541
|
+
prompts_number: this.data.promptsNumber,
|
|
542
|
+
auth: this.data.auth,
|
|
543
|
+
name: this.data.name,
|
|
544
|
+
description: this.data.description ?? null,
|
|
545
|
+
base_url: this.data.baseUrl ?? null,
|
|
546
|
+
tool_names: this.data.toolNames ?? null,
|
|
547
|
+
resource_names: this.data.resourceNames ?? null,
|
|
548
|
+
prompt_names: this.data.promptNames ?? null,
|
|
549
|
+
tools: this.data.tools ?? null,
|
|
550
|
+
resources: this.data.resources ?? null,
|
|
551
|
+
prompts: this.data.prompts ?? null,
|
|
552
|
+
templates: this.data.templates ?? null,
|
|
553
|
+
capabilities: this.data.capabilities ? JSON.stringify(this.data.capabilities) : null,
|
|
554
|
+
apps_sdk_resources: this.data.appsSdkResources ? JSON.stringify(this.data.appsSdkResources) : null,
|
|
555
|
+
apps_sdk_resources_number: this.data.appsSdkResourcesNumber ?? 0,
|
|
556
|
+
mcp_ui_resources: this.data.mcpUiResources ? JSON.stringify(this.data.mcpUiResources) : null,
|
|
557
|
+
mcp_ui_resources_number: this.data.mcpUiResourcesNumber ?? 0,
|
|
558
|
+
mcp_apps_resources: this.data.mcpAppsResources ? JSON.stringify(this.data.mcpAppsResources) : null,
|
|
559
|
+
mcp_apps_resources_number: this.data.mcpAppsResourcesNumber ?? 0
|
|
560
|
+
};
|
|
561
|
+
}
|
|
562
|
+
};
|
|
563
|
+
ServerInitializeEvent = class extends BaseTelemetryEvent {
|
|
564
|
+
constructor(data) {
|
|
565
|
+
super();
|
|
566
|
+
this.data = data;
|
|
567
|
+
}
|
|
568
|
+
static {
|
|
569
|
+
__name(this, "ServerInitializeEvent");
|
|
570
|
+
}
|
|
571
|
+
get name() {
|
|
572
|
+
return "server_initialize_call";
|
|
573
|
+
}
|
|
574
|
+
get properties() {
|
|
575
|
+
return {
|
|
576
|
+
protocol_version: this.data.protocolVersion,
|
|
577
|
+
client_info: JSON.stringify(this.data.clientInfo),
|
|
578
|
+
client_capabilities: JSON.stringify(this.data.clientCapabilities),
|
|
579
|
+
session_id: this.data.sessionId ?? null
|
|
580
|
+
};
|
|
581
|
+
}
|
|
582
|
+
};
|
|
583
|
+
ServerToolCallEvent = class extends BaseTelemetryEvent {
|
|
584
|
+
constructor(data) {
|
|
585
|
+
super();
|
|
586
|
+
this.data = data;
|
|
587
|
+
}
|
|
588
|
+
static {
|
|
589
|
+
__name(this, "ServerToolCallEvent");
|
|
590
|
+
}
|
|
591
|
+
get name() {
|
|
592
|
+
return "server_tool_call";
|
|
593
|
+
}
|
|
594
|
+
get properties() {
|
|
595
|
+
return {
|
|
596
|
+
tool_name: this.data.toolName,
|
|
597
|
+
length_input_argument: this.data.lengthInputArgument,
|
|
598
|
+
success: this.data.success,
|
|
599
|
+
error_type: this.data.errorType ?? null,
|
|
600
|
+
execution_time_ms: this.data.executionTimeMs ?? null
|
|
601
|
+
};
|
|
602
|
+
}
|
|
603
|
+
};
|
|
604
|
+
ServerResourceCallEvent = class extends BaseTelemetryEvent {
|
|
605
|
+
constructor(data) {
|
|
606
|
+
super();
|
|
607
|
+
this.data = data;
|
|
608
|
+
}
|
|
609
|
+
static {
|
|
610
|
+
__name(this, "ServerResourceCallEvent");
|
|
611
|
+
}
|
|
612
|
+
get name() {
|
|
613
|
+
return "server_resource_call";
|
|
614
|
+
}
|
|
615
|
+
get properties() {
|
|
616
|
+
return {
|
|
617
|
+
name: this.data.name,
|
|
618
|
+
description: this.data.description,
|
|
619
|
+
contents: this.data.contents,
|
|
620
|
+
success: this.data.success,
|
|
621
|
+
error_type: this.data.errorType ?? null
|
|
622
|
+
};
|
|
623
|
+
}
|
|
624
|
+
};
|
|
625
|
+
ServerPromptCallEvent = class extends BaseTelemetryEvent {
|
|
626
|
+
constructor(data) {
|
|
627
|
+
super();
|
|
628
|
+
this.data = data;
|
|
629
|
+
}
|
|
630
|
+
static {
|
|
631
|
+
__name(this, "ServerPromptCallEvent");
|
|
632
|
+
}
|
|
633
|
+
get name() {
|
|
634
|
+
return "server_prompt_call";
|
|
635
|
+
}
|
|
636
|
+
get properties() {
|
|
637
|
+
return {
|
|
638
|
+
name: this.data.name,
|
|
639
|
+
description: this.data.description,
|
|
640
|
+
success: this.data.success,
|
|
641
|
+
error_type: this.data.errorType ?? null
|
|
642
|
+
};
|
|
643
|
+
}
|
|
644
|
+
};
|
|
645
|
+
ServerContextEvent = class extends BaseTelemetryEvent {
|
|
646
|
+
constructor(data) {
|
|
647
|
+
super();
|
|
648
|
+
this.data = data;
|
|
649
|
+
}
|
|
650
|
+
static {
|
|
651
|
+
__name(this, "ServerContextEvent");
|
|
652
|
+
}
|
|
653
|
+
get name() {
|
|
654
|
+
return `server_context_${this.data.contextType}`;
|
|
655
|
+
}
|
|
656
|
+
get properties() {
|
|
657
|
+
return {
|
|
658
|
+
context_type: this.data.contextType,
|
|
659
|
+
notification_type: this.data.notificationType ?? null
|
|
660
|
+
};
|
|
661
|
+
}
|
|
662
|
+
};
|
|
663
|
+
MCPClientInitEvent = class extends BaseTelemetryEvent {
|
|
664
|
+
constructor(data) {
|
|
665
|
+
super();
|
|
666
|
+
this.data = data;
|
|
667
|
+
}
|
|
668
|
+
static {
|
|
669
|
+
__name(this, "MCPClientInitEvent");
|
|
670
|
+
}
|
|
671
|
+
get name() {
|
|
672
|
+
return "mcpclient_init";
|
|
673
|
+
}
|
|
674
|
+
get properties() {
|
|
675
|
+
return {
|
|
676
|
+
code_mode: this.data.codeMode,
|
|
677
|
+
sandbox: this.data.sandbox,
|
|
678
|
+
all_callbacks: this.data.allCallbacks,
|
|
679
|
+
verify: this.data.verify,
|
|
680
|
+
servers: this.data.servers,
|
|
681
|
+
num_servers: this.data.numServers
|
|
682
|
+
};
|
|
683
|
+
}
|
|
684
|
+
};
|
|
685
|
+
ConnectorInitEvent = class extends BaseTelemetryEvent {
|
|
686
|
+
constructor(data) {
|
|
687
|
+
super();
|
|
688
|
+
this.data = data;
|
|
689
|
+
}
|
|
690
|
+
static {
|
|
691
|
+
__name(this, "ConnectorInitEvent");
|
|
692
|
+
}
|
|
693
|
+
get name() {
|
|
694
|
+
return "connector_init";
|
|
695
|
+
}
|
|
696
|
+
get properties() {
|
|
697
|
+
return {
|
|
698
|
+
connector_type: this.data.connectorType,
|
|
699
|
+
server_command: this.data.serverCommand ?? null,
|
|
700
|
+
server_args: this.data.serverArgs ?? null,
|
|
701
|
+
server_url: this.data.serverUrl ?? null,
|
|
702
|
+
public_identifier: this.data.publicIdentifier ?? null
|
|
703
|
+
};
|
|
704
|
+
}
|
|
705
|
+
};
|
|
706
|
+
}
|
|
707
|
+
});
|
|
708
|
+
|
|
709
|
+
// src/version.ts
|
|
710
|
+
function getPackageVersion() {
|
|
711
|
+
return VERSION;
|
|
712
|
+
}
|
|
713
|
+
var VERSION;
|
|
714
|
+
var init_version = __esm({
|
|
715
|
+
"src/version.ts"() {
|
|
716
|
+
"use strict";
|
|
717
|
+
VERSION = "1.10.0-canary.8";
|
|
718
|
+
__name(getPackageVersion, "getPackageVersion");
|
|
719
|
+
}
|
|
720
|
+
});
|
|
721
|
+
|
|
722
|
+
// src/telemetry/utils.ts
|
|
723
|
+
var init_utils = __esm({
|
|
724
|
+
"src/telemetry/utils.ts"() {
|
|
725
|
+
"use strict";
|
|
726
|
+
init_version();
|
|
727
|
+
}
|
|
728
|
+
});
|
|
729
|
+
|
|
730
|
+
// src/telemetry/telemetry.ts
|
|
731
|
+
function detectRuntimeEnvironment() {
|
|
732
|
+
try {
|
|
733
|
+
if (typeof globalThis.Bun !== "undefined") {
|
|
734
|
+
return "bun";
|
|
735
|
+
}
|
|
736
|
+
if (typeof globalThis.Deno !== "undefined") {
|
|
737
|
+
return "deno";
|
|
738
|
+
}
|
|
739
|
+
if (typeof navigator !== "undefined" && navigator.userAgent?.includes("Cloudflare-Workers")) {
|
|
740
|
+
return "cloudflare-workers";
|
|
741
|
+
}
|
|
742
|
+
if (typeof globalThis.EdgeRuntime !== "undefined") {
|
|
743
|
+
return "edge";
|
|
744
|
+
}
|
|
745
|
+
if (typeof process !== "undefined" && typeof process.versions?.node !== "undefined" && typeof fs !== "undefined" && typeof fs.existsSync === "function") {
|
|
746
|
+
return "node";
|
|
747
|
+
}
|
|
748
|
+
if (typeof window !== "undefined" && typeof document !== "undefined") {
|
|
749
|
+
return "browser";
|
|
750
|
+
}
|
|
751
|
+
return "unknown";
|
|
752
|
+
} catch {
|
|
753
|
+
return "unknown";
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
function getStorageCapability(env) {
|
|
757
|
+
switch (env) {
|
|
758
|
+
case "node":
|
|
759
|
+
case "bun":
|
|
760
|
+
return "filesystem";
|
|
761
|
+
case "browser":
|
|
762
|
+
try {
|
|
763
|
+
if (typeof localStorage !== "undefined") {
|
|
764
|
+
localStorage.setItem("__mcp_use_test__", "1");
|
|
765
|
+
localStorage.removeItem("__mcp_use_test__");
|
|
766
|
+
return "localStorage";
|
|
767
|
+
}
|
|
768
|
+
} catch {
|
|
769
|
+
}
|
|
770
|
+
return "session-only";
|
|
771
|
+
case "deno":
|
|
772
|
+
return "session-only";
|
|
773
|
+
default:
|
|
774
|
+
return "session-only";
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
function getRuntimeEnvironment() {
|
|
778
|
+
if (cachedEnvironment === null) {
|
|
779
|
+
cachedEnvironment = detectRuntimeEnvironment();
|
|
780
|
+
}
|
|
781
|
+
return cachedEnvironment;
|
|
782
|
+
}
|
|
783
|
+
function isNodeJSEnvironment2() {
|
|
784
|
+
const env = getRuntimeEnvironment();
|
|
785
|
+
return env === "node" || env === "bun";
|
|
786
|
+
}
|
|
787
|
+
function getCacheHome() {
|
|
788
|
+
if (!isNodeJSEnvironment2()) {
|
|
789
|
+
return "/tmp/mcp_use_cache";
|
|
790
|
+
}
|
|
791
|
+
const envVar = process.env.XDG_CACHE_HOME;
|
|
792
|
+
if (envVar && path.isAbsolute(envVar)) {
|
|
793
|
+
return envVar;
|
|
794
|
+
}
|
|
795
|
+
const platform = process.platform;
|
|
796
|
+
const homeDir = os.homedir();
|
|
797
|
+
if (platform === "win32") {
|
|
798
|
+
const appdata = process.env.LOCALAPPDATA || process.env.APPDATA;
|
|
799
|
+
if (appdata) {
|
|
800
|
+
return appdata;
|
|
801
|
+
}
|
|
802
|
+
return path.join(homeDir, "AppData", "Local");
|
|
803
|
+
} else if (platform === "darwin") {
|
|
804
|
+
return path.join(homeDir, "Library", "Caches");
|
|
805
|
+
} else {
|
|
806
|
+
return path.join(homeDir, ".cache");
|
|
807
|
+
}
|
|
808
|
+
}
|
|
809
|
+
var fs, os, path, import_posthog_node, USER_ID_STORAGE_KEY, cachedEnvironment, ScarfEventLogger, Telemetry;
|
|
810
|
+
var init_telemetry = __esm({
|
|
811
|
+
"src/telemetry/telemetry.ts"() {
|
|
812
|
+
"use strict";
|
|
813
|
+
fs = __toESM(require("fs"), 1);
|
|
814
|
+
os = __toESM(require("os"), 1);
|
|
815
|
+
path = __toESM(require("path"), 1);
|
|
816
|
+
import_posthog_node = require("posthog-node");
|
|
817
|
+
init_runtime();
|
|
818
|
+
init_logging();
|
|
819
|
+
init_events();
|
|
820
|
+
init_utils();
|
|
821
|
+
USER_ID_STORAGE_KEY = "mcp_use_user_id";
|
|
822
|
+
__name(detectRuntimeEnvironment, "detectRuntimeEnvironment");
|
|
823
|
+
__name(getStorageCapability, "getStorageCapability");
|
|
824
|
+
cachedEnvironment = null;
|
|
825
|
+
__name(getRuntimeEnvironment, "getRuntimeEnvironment");
|
|
826
|
+
__name(isNodeJSEnvironment2, "isNodeJSEnvironment");
|
|
827
|
+
ScarfEventLogger = class {
|
|
828
|
+
static {
|
|
829
|
+
__name(this, "ScarfEventLogger");
|
|
830
|
+
}
|
|
831
|
+
endpoint;
|
|
832
|
+
timeout;
|
|
833
|
+
constructor(endpoint, timeout = 3e3) {
|
|
834
|
+
this.endpoint = endpoint;
|
|
835
|
+
this.timeout = timeout;
|
|
836
|
+
}
|
|
837
|
+
async logEvent(properties) {
|
|
838
|
+
try {
|
|
839
|
+
const controller = new AbortController();
|
|
840
|
+
const timeoutId = setTimeout(() => controller.abort(), this.timeout);
|
|
841
|
+
const response = await fetch(this.endpoint, {
|
|
842
|
+
method: "POST",
|
|
843
|
+
headers: {
|
|
844
|
+
"Content-Type": "application/json"
|
|
845
|
+
},
|
|
846
|
+
body: JSON.stringify(properties),
|
|
847
|
+
signal: controller.signal
|
|
848
|
+
});
|
|
849
|
+
clearTimeout(timeoutId);
|
|
850
|
+
if (!response.ok) {
|
|
851
|
+
throw new Error(`HTTP error! status: ${response.status}`);
|
|
852
|
+
}
|
|
853
|
+
} catch (error2) {
|
|
854
|
+
logger.debug(`Failed to send Scarf event: ${error2}`);
|
|
855
|
+
}
|
|
856
|
+
}
|
|
857
|
+
};
|
|
858
|
+
__name(getCacheHome, "getCacheHome");
|
|
859
|
+
Telemetry = class _Telemetry {
|
|
860
|
+
static {
|
|
861
|
+
__name(this, "Telemetry");
|
|
862
|
+
}
|
|
863
|
+
static instance = null;
|
|
864
|
+
USER_ID_PATH = path.join(
|
|
865
|
+
getCacheHome(),
|
|
866
|
+
"mcp_use_3",
|
|
867
|
+
"telemetry_user_id"
|
|
868
|
+
);
|
|
869
|
+
VERSION_DOWNLOAD_PATH = path.join(
|
|
870
|
+
getCacheHome(),
|
|
871
|
+
"mcp_use",
|
|
872
|
+
"download_version"
|
|
873
|
+
);
|
|
874
|
+
PROJECT_API_KEY = "phc_lyTtbYwvkdSbrcMQNPiKiiRWrrM1seyKIMjycSvItEI";
|
|
875
|
+
HOST = "https://eu.i.posthog.com";
|
|
876
|
+
SCARF_GATEWAY_URL = "https://mcpuse.gateway.scarf.sh/events-ts";
|
|
877
|
+
UNKNOWN_USER_ID = "UNKNOWN_USER_ID";
|
|
878
|
+
_currUserId = null;
|
|
879
|
+
_posthogClient = null;
|
|
880
|
+
_scarfClient = null;
|
|
881
|
+
_runtimeEnvironment;
|
|
882
|
+
_storageCapability;
|
|
883
|
+
_source;
|
|
884
|
+
constructor() {
|
|
885
|
+
this._runtimeEnvironment = getRuntimeEnvironment();
|
|
886
|
+
this._storageCapability = getStorageCapability(this._runtimeEnvironment);
|
|
887
|
+
this._source = typeof process !== "undefined" && process.env?.MCP_USE_TELEMETRY_SOURCE || this._runtimeEnvironment;
|
|
888
|
+
const telemetryDisabled = typeof process !== "undefined" && process.env?.MCP_USE_ANONYMIZED_TELEMETRY?.toLowerCase() === "false" || false;
|
|
889
|
+
const canSupportTelemetry = this._runtimeEnvironment !== "unknown";
|
|
890
|
+
const isServerlessEnvironment = [
|
|
891
|
+
"cloudflare-workers",
|
|
892
|
+
"edge",
|
|
893
|
+
"deno"
|
|
894
|
+
].includes(this._runtimeEnvironment);
|
|
895
|
+
if (telemetryDisabled) {
|
|
896
|
+
this._posthogClient = null;
|
|
897
|
+
this._scarfClient = null;
|
|
898
|
+
logger.debug("Telemetry disabled via environment variable");
|
|
899
|
+
} else if (!canSupportTelemetry) {
|
|
900
|
+
this._posthogClient = null;
|
|
901
|
+
this._scarfClient = null;
|
|
902
|
+
logger.debug(
|
|
903
|
+
`Telemetry disabled - unknown environment: ${this._runtimeEnvironment}`
|
|
904
|
+
);
|
|
905
|
+
} else {
|
|
906
|
+
logger.info(
|
|
907
|
+
"Anonymized telemetry enabled. Set MCP_USE_ANONYMIZED_TELEMETRY=false to disable."
|
|
908
|
+
);
|
|
909
|
+
if (this._runtimeEnvironment !== "browser") {
|
|
910
|
+
try {
|
|
911
|
+
const posthogOptions = {
|
|
912
|
+
host: this.HOST,
|
|
913
|
+
disableGeoip: false
|
|
914
|
+
};
|
|
915
|
+
if (isServerlessEnvironment) {
|
|
916
|
+
posthogOptions.flushAt = 1;
|
|
917
|
+
posthogOptions.flushInterval = 0;
|
|
918
|
+
}
|
|
919
|
+
this._posthogClient = new import_posthog_node.PostHog(
|
|
920
|
+
this.PROJECT_API_KEY,
|
|
921
|
+
posthogOptions
|
|
922
|
+
);
|
|
923
|
+
} catch (e) {
|
|
924
|
+
logger.warn(`Failed to initialize PostHog telemetry: ${e}`);
|
|
925
|
+
this._posthogClient = null;
|
|
926
|
+
}
|
|
927
|
+
} else {
|
|
928
|
+
this._posthogClient = null;
|
|
929
|
+
}
|
|
930
|
+
try {
|
|
931
|
+
this._scarfClient = new ScarfEventLogger(this.SCARF_GATEWAY_URL, 3e3);
|
|
932
|
+
} catch (e) {
|
|
933
|
+
logger.warn(`Failed to initialize Scarf telemetry: ${e}`);
|
|
934
|
+
this._scarfClient = null;
|
|
935
|
+
}
|
|
936
|
+
}
|
|
937
|
+
}
|
|
938
|
+
/**
|
|
939
|
+
* Get the detected runtime environment
|
|
940
|
+
*/
|
|
941
|
+
get runtimeEnvironment() {
|
|
942
|
+
return this._runtimeEnvironment;
|
|
943
|
+
}
|
|
944
|
+
/**
|
|
945
|
+
* Get the storage capability for this environment
|
|
946
|
+
*/
|
|
947
|
+
get storageCapability() {
|
|
948
|
+
return this._storageCapability;
|
|
949
|
+
}
|
|
950
|
+
static getInstance() {
|
|
951
|
+
if (!_Telemetry.instance) {
|
|
952
|
+
_Telemetry.instance = new _Telemetry();
|
|
953
|
+
}
|
|
954
|
+
return _Telemetry.instance;
|
|
955
|
+
}
|
|
956
|
+
/**
|
|
957
|
+
* Set the source identifier for telemetry events.
|
|
958
|
+
* This allows tracking usage from different applications.
|
|
959
|
+
* @param source - The source identifier (e.g., "my-app", "cli", "vs-code-extension")
|
|
960
|
+
*/
|
|
961
|
+
setSource(source) {
|
|
962
|
+
this._source = source;
|
|
963
|
+
logger.debug(`Telemetry source set to: ${source}`);
|
|
964
|
+
}
|
|
965
|
+
/**
|
|
966
|
+
* Get the current source identifier.
|
|
967
|
+
*/
|
|
968
|
+
getSource() {
|
|
969
|
+
return this._source;
|
|
970
|
+
}
|
|
971
|
+
/**
|
|
972
|
+
* Check if telemetry is enabled.
|
|
973
|
+
* Returns false if telemetry was disabled via environment variable or if not in Node.js environment.
|
|
974
|
+
*/
|
|
975
|
+
get isEnabled() {
|
|
976
|
+
return this._posthogClient !== null || this._scarfClient !== null;
|
|
977
|
+
}
|
|
978
|
+
get userId() {
|
|
979
|
+
if (this._currUserId) {
|
|
980
|
+
return this._currUserId;
|
|
981
|
+
}
|
|
982
|
+
try {
|
|
983
|
+
switch (this._storageCapability) {
|
|
984
|
+
case "filesystem":
|
|
985
|
+
this._currUserId = this.getUserIdFromFilesystem();
|
|
986
|
+
break;
|
|
987
|
+
case "localStorage":
|
|
988
|
+
this._currUserId = this.getUserIdFromLocalStorage();
|
|
989
|
+
break;
|
|
990
|
+
case "session-only":
|
|
991
|
+
default:
|
|
992
|
+
this._currUserId = `session-${generateUUID()}`;
|
|
993
|
+
logger.debug(
|
|
994
|
+
`Using session-based user ID (${this._runtimeEnvironment} environment)`
|
|
995
|
+
);
|
|
996
|
+
break;
|
|
997
|
+
}
|
|
998
|
+
if (this._storageCapability === "filesystem" && this._currUserId) {
|
|
999
|
+
this.trackPackageDownloadInternal(this._currUserId, {
|
|
1000
|
+
triggered_by: "user_id_property"
|
|
1001
|
+
}).catch((e) => logger.debug(`Failed to track package download: ${e}`));
|
|
1002
|
+
}
|
|
1003
|
+
} catch (e) {
|
|
1004
|
+
logger.debug(`Failed to get/create user ID: ${e}`);
|
|
1005
|
+
this._currUserId = this.UNKNOWN_USER_ID;
|
|
1006
|
+
}
|
|
1007
|
+
return this._currUserId;
|
|
1008
|
+
}
|
|
1009
|
+
/**
|
|
1010
|
+
* Get or create user ID from filesystem (Node.js/Bun)
|
|
1011
|
+
*/
|
|
1012
|
+
getUserIdFromFilesystem() {
|
|
1013
|
+
const isFirstTime = !fs.existsSync(this.USER_ID_PATH);
|
|
1014
|
+
if (isFirstTime) {
|
|
1015
|
+
logger.debug(`Creating user ID path: ${this.USER_ID_PATH}`);
|
|
1016
|
+
fs.mkdirSync(path.dirname(this.USER_ID_PATH), { recursive: true });
|
|
1017
|
+
const newUserId = generateUUID();
|
|
1018
|
+
fs.writeFileSync(this.USER_ID_PATH, newUserId);
|
|
1019
|
+
logger.debug(`User ID path created: ${this.USER_ID_PATH}`);
|
|
1020
|
+
return newUserId;
|
|
1021
|
+
}
|
|
1022
|
+
return fs.readFileSync(this.USER_ID_PATH, "utf-8").trim();
|
|
1023
|
+
}
|
|
1024
|
+
/**
|
|
1025
|
+
* Get or create user ID from localStorage (Browser)
|
|
1026
|
+
*/
|
|
1027
|
+
getUserIdFromLocalStorage() {
|
|
1028
|
+
try {
|
|
1029
|
+
let userId = localStorage.getItem(USER_ID_STORAGE_KEY);
|
|
1030
|
+
if (!userId) {
|
|
1031
|
+
userId = generateUUID();
|
|
1032
|
+
localStorage.setItem(USER_ID_STORAGE_KEY, userId);
|
|
1033
|
+
logger.debug(`Created new browser user ID`);
|
|
1034
|
+
}
|
|
1035
|
+
return userId;
|
|
1036
|
+
} catch (e) {
|
|
1037
|
+
logger.debug(`localStorage access failed: ${e}`);
|
|
1038
|
+
return `session-${generateUUID()}`;
|
|
1039
|
+
}
|
|
1040
|
+
}
|
|
1041
|
+
async capture(event) {
|
|
1042
|
+
logger.debug(
|
|
1043
|
+
`CAPTURE: posthog: ${this._posthogClient !== null}, scarf: ${this._scarfClient !== null}`
|
|
1044
|
+
);
|
|
1045
|
+
if (!this._posthogClient && !this._scarfClient) {
|
|
1046
|
+
return;
|
|
1047
|
+
}
|
|
1048
|
+
if (this._posthogClient) {
|
|
1049
|
+
try {
|
|
1050
|
+
const properties = { ...event.properties };
|
|
1051
|
+
properties.mcp_use_version = getPackageVersion();
|
|
1052
|
+
properties.language = "typescript";
|
|
1053
|
+
properties.source = this._source;
|
|
1054
|
+
properties.runtime = this._runtimeEnvironment;
|
|
1055
|
+
logger.debug(`CAPTURE: PostHog Event ${event.name}`);
|
|
1056
|
+
logger.debug(
|
|
1057
|
+
`CAPTURE: PostHog Properties ${JSON.stringify(properties)}`
|
|
1058
|
+
);
|
|
1059
|
+
this._posthogClient.capture({
|
|
1060
|
+
distinctId: this.userId,
|
|
1061
|
+
event: event.name,
|
|
1062
|
+
properties
|
|
1063
|
+
});
|
|
1064
|
+
} catch (e) {
|
|
1065
|
+
logger.debug(`Failed to track PostHog event ${event.name}: ${e}`);
|
|
1066
|
+
}
|
|
1067
|
+
}
|
|
1068
|
+
if (this._scarfClient) {
|
|
1069
|
+
try {
|
|
1070
|
+
const properties = {};
|
|
1071
|
+
properties.mcp_use_version = getPackageVersion();
|
|
1072
|
+
properties.user_id = this.userId;
|
|
1073
|
+
properties.event = event.name;
|
|
1074
|
+
properties.language = "typescript";
|
|
1075
|
+
properties.source = this._source;
|
|
1076
|
+
properties.runtime = this._runtimeEnvironment;
|
|
1077
|
+
await this._scarfClient.logEvent(properties);
|
|
1078
|
+
} catch (e) {
|
|
1079
|
+
logger.debug(`Failed to track Scarf event ${event.name}: ${e}`);
|
|
1080
|
+
}
|
|
1081
|
+
}
|
|
1082
|
+
}
|
|
1083
|
+
/**
|
|
1084
|
+
* Track package download event.
|
|
1085
|
+
* This is a public wrapper that safely accesses userId.
|
|
1086
|
+
*/
|
|
1087
|
+
async trackPackageDownload(properties) {
|
|
1088
|
+
return this.trackPackageDownloadInternal(this.userId, properties);
|
|
1089
|
+
}
|
|
1090
|
+
/**
|
|
1091
|
+
* Internal method to track package download with explicit userId.
|
|
1092
|
+
* This avoids circular dependency when called from the userId getter.
|
|
1093
|
+
*/
|
|
1094
|
+
async trackPackageDownloadInternal(userId, properties) {
|
|
1095
|
+
if (!this._scarfClient) {
|
|
1096
|
+
return;
|
|
1097
|
+
}
|
|
1098
|
+
if (this._storageCapability !== "filesystem") {
|
|
1099
|
+
return;
|
|
1100
|
+
}
|
|
1101
|
+
try {
|
|
1102
|
+
const currentVersion = getPackageVersion();
|
|
1103
|
+
let shouldTrack = false;
|
|
1104
|
+
let firstDownload = false;
|
|
1105
|
+
if (!fs.existsSync(this.VERSION_DOWNLOAD_PATH)) {
|
|
1106
|
+
shouldTrack = true;
|
|
1107
|
+
firstDownload = true;
|
|
1108
|
+
fs.mkdirSync(path.dirname(this.VERSION_DOWNLOAD_PATH), {
|
|
1109
|
+
recursive: true
|
|
1110
|
+
});
|
|
1111
|
+
fs.writeFileSync(this.VERSION_DOWNLOAD_PATH, currentVersion);
|
|
1112
|
+
} else {
|
|
1113
|
+
const savedVersion = fs.readFileSync(this.VERSION_DOWNLOAD_PATH, "utf-8").trim();
|
|
1114
|
+
if (currentVersion > savedVersion) {
|
|
1115
|
+
shouldTrack = true;
|
|
1116
|
+
firstDownload = false;
|
|
1117
|
+
fs.writeFileSync(this.VERSION_DOWNLOAD_PATH, currentVersion);
|
|
1118
|
+
}
|
|
1119
|
+
}
|
|
1120
|
+
if (shouldTrack) {
|
|
1121
|
+
logger.debug(
|
|
1122
|
+
`Tracking package download event with properties: ${JSON.stringify(properties)}`
|
|
1123
|
+
);
|
|
1124
|
+
const eventProperties = { ...properties || {} };
|
|
1125
|
+
eventProperties.mcp_use_version = currentVersion;
|
|
1126
|
+
eventProperties.user_id = userId;
|
|
1127
|
+
eventProperties.event = "package_download";
|
|
1128
|
+
eventProperties.first_download = firstDownload;
|
|
1129
|
+
eventProperties.language = "typescript";
|
|
1130
|
+
eventProperties.source = this._source;
|
|
1131
|
+
eventProperties.runtime = this._runtimeEnvironment;
|
|
1132
|
+
await this._scarfClient.logEvent(eventProperties);
|
|
1133
|
+
}
|
|
1134
|
+
} catch (e) {
|
|
1135
|
+
logger.debug(`Failed to track Scarf package_download event: ${e}`);
|
|
1136
|
+
}
|
|
1137
|
+
}
|
|
1138
|
+
// ============================================================================
|
|
1139
|
+
// Agent Events
|
|
1140
|
+
// ============================================================================
|
|
1141
|
+
async trackAgentExecution(data) {
|
|
1142
|
+
if (!this.isEnabled) return;
|
|
1143
|
+
const event = new MCPAgentExecutionEvent(data);
|
|
1144
|
+
await this.capture(event);
|
|
1145
|
+
}
|
|
1146
|
+
// ============================================================================
|
|
1147
|
+
// Server Events
|
|
1148
|
+
// ============================================================================
|
|
1149
|
+
/**
|
|
1150
|
+
* Track server run event directly from an MCPServer instance.
|
|
1151
|
+
* This extracts the necessary data from the server and creates the event.
|
|
1152
|
+
* @param server - The MCPServer instance (or any object conforming to MCPServerTelemetryInfo)
|
|
1153
|
+
* @param transport - The transport type (e.g., "http", "stdio", "supabase")
|
|
1154
|
+
*/
|
|
1155
|
+
async trackServerRunFromServer(server, transport) {
|
|
1156
|
+
if (!this.isEnabled) return;
|
|
1157
|
+
const data = createServerRunEventData(server, transport);
|
|
1158
|
+
const event = new ServerRunEvent(data);
|
|
1159
|
+
await this.capture(event);
|
|
1160
|
+
}
|
|
1161
|
+
async trackServerInitialize(data) {
|
|
1162
|
+
if (!this.isEnabled) return;
|
|
1163
|
+
const event = new ServerInitializeEvent(data);
|
|
1164
|
+
await this.capture(event);
|
|
1165
|
+
}
|
|
1166
|
+
async trackServerToolCall(data) {
|
|
1167
|
+
if (!this.isEnabled) return;
|
|
1168
|
+
const event = new ServerToolCallEvent(data);
|
|
1169
|
+
await this.capture(event);
|
|
1170
|
+
}
|
|
1171
|
+
async trackServerResourceCall(data) {
|
|
1172
|
+
if (!this.isEnabled) return;
|
|
1173
|
+
const event = new ServerResourceCallEvent(data);
|
|
1174
|
+
await this.capture(event);
|
|
1175
|
+
}
|
|
1176
|
+
async trackServerPromptCall(data) {
|
|
1177
|
+
if (!this.isEnabled) return;
|
|
1178
|
+
const event = new ServerPromptCallEvent(data);
|
|
1179
|
+
await this.capture(event);
|
|
1180
|
+
}
|
|
1181
|
+
async trackServerContext(data) {
|
|
1182
|
+
if (!this.isEnabled) return;
|
|
1183
|
+
const event = new ServerContextEvent(data);
|
|
1184
|
+
await this.capture(event);
|
|
1185
|
+
}
|
|
1186
|
+
// ============================================================================
|
|
1187
|
+
// Client Events
|
|
1188
|
+
// ============================================================================
|
|
1189
|
+
async trackMCPClientInit(data) {
|
|
1190
|
+
if (!this.isEnabled) return;
|
|
1191
|
+
const event = new MCPClientInitEvent(data);
|
|
1192
|
+
await this.capture(event);
|
|
1193
|
+
}
|
|
1194
|
+
async trackConnectorInit(data) {
|
|
1195
|
+
if (!this.isEnabled) return;
|
|
1196
|
+
const event = new ConnectorInitEvent(data);
|
|
1197
|
+
await this.capture(event);
|
|
1198
|
+
}
|
|
1199
|
+
flush() {
|
|
1200
|
+
if (this._posthogClient) {
|
|
1201
|
+
try {
|
|
1202
|
+
this._posthogClient.flush();
|
|
1203
|
+
logger.debug("PostHog client telemetry queue flushed");
|
|
1204
|
+
} catch (e) {
|
|
1205
|
+
logger.debug(`Failed to flush PostHog client: ${e}`);
|
|
1206
|
+
}
|
|
1207
|
+
}
|
|
1208
|
+
if (this._scarfClient) {
|
|
1209
|
+
logger.debug("Scarf telemetry events sent immediately (no flush needed)");
|
|
1210
|
+
}
|
|
1211
|
+
}
|
|
1212
|
+
shutdown() {
|
|
1213
|
+
if (this._posthogClient) {
|
|
1214
|
+
try {
|
|
1215
|
+
this._posthogClient.shutdown();
|
|
1216
|
+
logger.debug("PostHog client shutdown successfully");
|
|
1217
|
+
} catch (e) {
|
|
1218
|
+
logger.debug(`Error shutting down PostHog client: ${e}`);
|
|
1219
|
+
}
|
|
1220
|
+
}
|
|
1221
|
+
if (this._scarfClient) {
|
|
1222
|
+
logger.debug("Scarf telemetry client shutdown (no action needed)");
|
|
1223
|
+
}
|
|
1224
|
+
}
|
|
1225
|
+
};
|
|
1226
|
+
}
|
|
1227
|
+
});
|
|
1228
|
+
|
|
1229
|
+
// src/telemetry/index.ts
|
|
1230
|
+
var init_telemetry2 = __esm({
|
|
1231
|
+
"src/telemetry/index.ts"() {
|
|
1232
|
+
"use strict";
|
|
1233
|
+
init_telemetry();
|
|
1234
|
+
init_events();
|
|
1235
|
+
init_telemetry();
|
|
1236
|
+
init_utils();
|
|
1237
|
+
}
|
|
1238
|
+
});
|
|
1239
|
+
|
|
125
1240
|
// src/server/context-storage.ts
|
|
126
1241
|
var context_storage_exports = {};
|
|
127
1242
|
__export(context_storage_exports, {
|
|
@@ -373,6 +1488,9 @@ function createSampleMethod(createMessage, progressToken, sendNotification2) {
|
|
|
373
1488
|
`Sampling timed out after ${timeout}ms`
|
|
374
1489
|
);
|
|
375
1490
|
console.log("[SAMPLING DEBUG] Got result:", result);
|
|
1491
|
+
Telemetry.getInstance().trackServerContext({
|
|
1492
|
+
contextType: "sample"
|
|
1493
|
+
}).catch((e) => console.debug(`Failed to track sample context: ${e}`));
|
|
376
1494
|
return result;
|
|
377
1495
|
} catch (error2) {
|
|
378
1496
|
console.error("[SAMPLING DEBUG] Error during sampling:", error2);
|
|
@@ -395,6 +1513,9 @@ function createElicitMethod(elicitInput) {
|
|
|
395
1513
|
const { timeout } = options ?? {};
|
|
396
1514
|
const sdkTimeout = timeout && timeout !== Infinity ? timeout : 2147483647;
|
|
397
1515
|
const result = await elicitInput(sdkParams, { timeout: sdkTimeout });
|
|
1516
|
+
Telemetry.getInstance().trackServerContext({
|
|
1517
|
+
contextType: "elicit"
|
|
1518
|
+
}).catch((e) => console.debug(`Failed to track elicit context: ${e}`));
|
|
398
1519
|
if (zodSchema && result.action === "accept" && result.data) {
|
|
399
1520
|
try {
|
|
400
1521
|
const validatedData = zodSchema.parse(result.data);
|
|
@@ -443,7 +1564,7 @@ function createLogMethod(sendNotification2, minLogLevel) {
|
|
|
443
1564
|
if (!sendNotification2) {
|
|
444
1565
|
return void 0;
|
|
445
1566
|
}
|
|
446
|
-
return async (level, message,
|
|
1567
|
+
return async (level, message, logger2) => {
|
|
447
1568
|
if (!shouldLogMessage(level, minLogLevel)) {
|
|
448
1569
|
return;
|
|
449
1570
|
}
|
|
@@ -452,9 +1573,15 @@ function createLogMethod(sendNotification2, minLogLevel) {
|
|
|
452
1573
|
params: {
|
|
453
1574
|
level,
|
|
454
1575
|
data: message,
|
|
455
|
-
logger:
|
|
1576
|
+
logger: logger2 || "tool"
|
|
456
1577
|
}
|
|
457
1578
|
});
|
|
1579
|
+
Telemetry.getInstance().trackServerContext({
|
|
1580
|
+
contextType: "notification",
|
|
1581
|
+
notificationType: "message"
|
|
1582
|
+
}).catch(
|
|
1583
|
+
(e) => console.debug(`Failed to track notification context: ${e}`)
|
|
1584
|
+
);
|
|
458
1585
|
};
|
|
459
1586
|
}
|
|
460
1587
|
function createClientCapabilityChecker(clientCapabilities) {
|
|
@@ -556,6 +1683,7 @@ var init_tool_execution_helpers = __esm({
|
|
|
556
1683
|
import_zod_json_schema_compat = require("@mcp-use/modelcontextprotocol-sdk/server/zod-json-schema-compat.js");
|
|
557
1684
|
init_errors();
|
|
558
1685
|
init_runtime();
|
|
1686
|
+
init_telemetry2();
|
|
559
1687
|
__name(findSessionContext, "findSessionContext");
|
|
560
1688
|
__name(sendProgressNotification, "sendProgressNotification");
|
|
561
1689
|
__name(withTimeout, "withTimeout");
|
|
@@ -787,6 +1915,7 @@ var init_conversion2 = __esm({
|
|
|
787
1915
|
var server_exports = {};
|
|
788
1916
|
__export(server_exports, {
|
|
789
1917
|
MCPServer: () => MCPServer,
|
|
1918
|
+
VERSION: () => VERSION,
|
|
790
1919
|
adaptConnectMiddleware: () => adaptConnectMiddleware,
|
|
791
1920
|
adaptMiddleware: () => adaptMiddleware,
|
|
792
1921
|
array: () => array,
|
|
@@ -801,6 +1930,7 @@ __export(server_exports, {
|
|
|
801
1930
|
css: () => css,
|
|
802
1931
|
error: () => error,
|
|
803
1932
|
getAuth: () => getAuth,
|
|
1933
|
+
getPackageVersion: () => getPackageVersion,
|
|
804
1934
|
getRequestContext: () => getRequestContext,
|
|
805
1935
|
hasAnyScope: () => hasAnyScope,
|
|
806
1936
|
hasRequestContext: () => hasRequestContext,
|
|
@@ -831,6 +1961,8 @@ module.exports = __toCommonJS(server_exports);
|
|
|
831
1961
|
var import_mcp2 = require("@mcp-use/modelcontextprotocol-sdk/server/mcp.js");
|
|
832
1962
|
var import_types2 = require("@mcp-use/modelcontextprotocol-sdk/types.js");
|
|
833
1963
|
var import_zod2 = require("zod");
|
|
1964
|
+
init_telemetry2();
|
|
1965
|
+
init_version();
|
|
834
1966
|
|
|
835
1967
|
// src/server/widgets/index.ts
|
|
836
1968
|
init_runtime();
|
|
@@ -1497,11 +2629,11 @@ function createHonoProxy(target, app) {
|
|
|
1497
2629
|
if (prop === "use") {
|
|
1498
2630
|
return async (...args) => {
|
|
1499
2631
|
const hasPath = typeof args[0] === "string";
|
|
1500
|
-
const
|
|
2632
|
+
const path2 = hasPath ? args[0] : "*";
|
|
1501
2633
|
const handlers = hasPath ? args.slice(1) : args;
|
|
1502
2634
|
const adaptedHandlers = handlers.map((handler) => {
|
|
1503
2635
|
if (isExpressMiddleware(handler)) {
|
|
1504
|
-
return { __isExpressMiddleware: true, handler, path };
|
|
2636
|
+
return { __isExpressMiddleware: true, handler, path: path2 };
|
|
1505
2637
|
}
|
|
1506
2638
|
return handler;
|
|
1507
2639
|
});
|
|
@@ -1517,13 +2649,13 @@ function createHonoProxy(target, app) {
|
|
|
1517
2649
|
h.path
|
|
1518
2650
|
);
|
|
1519
2651
|
if (hasPath) {
|
|
1520
|
-
app.use(
|
|
2652
|
+
app.use(path2, adapted);
|
|
1521
2653
|
} else {
|
|
1522
2654
|
app.use(adapted);
|
|
1523
2655
|
}
|
|
1524
2656
|
} else {
|
|
1525
2657
|
if (hasPath) {
|
|
1526
|
-
app.use(
|
|
2658
|
+
app.use(path2, h);
|
|
1527
2659
|
} else {
|
|
1528
2660
|
app.use(h);
|
|
1529
2661
|
}
|
|
@@ -1934,12 +3066,12 @@ __name(setupPublicRoutes, "setupPublicRoutes");
|
|
|
1934
3066
|
// src/server/widgets/mount-widgets-dev.ts
|
|
1935
3067
|
var TMP_MCP_USE_DIR = ".mcp-use";
|
|
1936
3068
|
async function mountWidgetsDev(app, serverConfig, registerWidget, options) {
|
|
1937
|
-
const { promises:
|
|
3069
|
+
const { promises: fs2 } = await import("fs");
|
|
1938
3070
|
const baseRoute = options?.baseRoute || "/mcp-use/widgets";
|
|
1939
3071
|
const resourcesDir = options?.resourcesDir || "resources";
|
|
1940
3072
|
const srcDir = pathHelpers.join(getCwd(), resourcesDir);
|
|
1941
3073
|
try {
|
|
1942
|
-
await
|
|
3074
|
+
await fs2.access(srcDir);
|
|
1943
3075
|
} catch (error2) {
|
|
1944
3076
|
console.log(
|
|
1945
3077
|
`[WIDGETS] No ${resourcesDir}/ directory found - skipping widget serving`
|
|
@@ -1948,7 +3080,7 @@ async function mountWidgetsDev(app, serverConfig, registerWidget, options) {
|
|
|
1948
3080
|
}
|
|
1949
3081
|
const entries = [];
|
|
1950
3082
|
try {
|
|
1951
|
-
const files = await
|
|
3083
|
+
const files = await fs2.readdir(srcDir, { withFileTypes: true });
|
|
1952
3084
|
for (const dirent of files) {
|
|
1953
3085
|
if (dirent.name.startsWith("._") || dirent.name.startsWith(".DS_Store")) {
|
|
1954
3086
|
continue;
|
|
@@ -1961,7 +3093,7 @@ async function mountWidgetsDev(app, serverConfig, registerWidget, options) {
|
|
|
1961
3093
|
} else if (dirent.isDirectory()) {
|
|
1962
3094
|
const widgetPath = pathHelpers.join(srcDir, dirent.name, "widget.tsx");
|
|
1963
3095
|
try {
|
|
1964
|
-
await
|
|
3096
|
+
await fs2.access(widgetPath);
|
|
1965
3097
|
entries.push({
|
|
1966
3098
|
name: dirent.name,
|
|
1967
3099
|
path: widgetPath
|
|
@@ -1979,7 +3111,7 @@ async function mountWidgetsDev(app, serverConfig, registerWidget, options) {
|
|
|
1979
3111
|
return;
|
|
1980
3112
|
}
|
|
1981
3113
|
const tempDir = pathHelpers.join(getCwd(), TMP_MCP_USE_DIR);
|
|
1982
|
-
await
|
|
3114
|
+
await fs2.mkdir(tempDir, { recursive: true }).catch(() => {
|
|
1983
3115
|
});
|
|
1984
3116
|
let createServer;
|
|
1985
3117
|
let react;
|
|
@@ -2013,7 +3145,7 @@ async function mountWidgetsDev(app, serverConfig, registerWidget, options) {
|
|
|
2013
3145
|
});
|
|
2014
3146
|
for (const widget2 of widgets) {
|
|
2015
3147
|
const widgetTempDir = pathHelpers.join(tempDir, widget2.name);
|
|
2016
|
-
await
|
|
3148
|
+
await fs2.mkdir(widgetTempDir, { recursive: true });
|
|
2017
3149
|
const resourcesPath = pathHelpers.join(getCwd(), resourcesDir);
|
|
2018
3150
|
const relativeResourcesPath = pathHelpers.relative(widgetTempDir, resourcesPath).replace(/\\/g, "/");
|
|
2019
3151
|
const cssContent = `@import "tailwindcss";
|
|
@@ -2021,7 +3153,7 @@ async function mountWidgetsDev(app, serverConfig, registerWidget, options) {
|
|
|
2021
3153
|
/* Configure Tailwind to scan the resources directory */
|
|
2022
3154
|
@source "${relativeResourcesPath}";
|
|
2023
3155
|
`;
|
|
2024
|
-
await
|
|
3156
|
+
await fs2.writeFile(
|
|
2025
3157
|
pathHelpers.join(widgetTempDir, "styles.css"),
|
|
2026
3158
|
cssContent,
|
|
2027
3159
|
"utf8"
|
|
@@ -2049,12 +3181,12 @@ if (container && Component) {
|
|
|
2049
3181
|
<script type="module" src="${baseRoute}/${widget2.name}/entry.tsx"></script>
|
|
2050
3182
|
</body>
|
|
2051
3183
|
</html>`;
|
|
2052
|
-
await
|
|
3184
|
+
await fs2.writeFile(
|
|
2053
3185
|
pathHelpers.join(widgetTempDir, "entry.tsx"),
|
|
2054
3186
|
entryContent,
|
|
2055
3187
|
"utf8"
|
|
2056
3188
|
);
|
|
2057
|
-
await
|
|
3189
|
+
await fs2.writeFile(
|
|
2058
3190
|
pathHelpers.join(widgetTempDir, "index.html"),
|
|
2059
3191
|
htmlContent,
|
|
2060
3192
|
"utf8"
|
|
@@ -2088,10 +3220,42 @@ if (container && Component) {
|
|
|
2088
3220
|
console.log(`[WIDGETS] Watching resources directory: ${resourcesPath}`);
|
|
2089
3221
|
}
|
|
2090
3222
|
};
|
|
3223
|
+
const nodeStubsPlugin = {
|
|
3224
|
+
name: "node-stubs",
|
|
3225
|
+
enforce: "pre",
|
|
3226
|
+
resolveId(id) {
|
|
3227
|
+
if (id === "posthog-node" || id.startsWith("posthog-node/")) {
|
|
3228
|
+
return "\0virtual:posthog-node-stub";
|
|
3229
|
+
}
|
|
3230
|
+
return null;
|
|
3231
|
+
},
|
|
3232
|
+
load(id) {
|
|
3233
|
+
if (id === "\0virtual:posthog-node-stub") {
|
|
3234
|
+
return `
|
|
3235
|
+
export class PostHog {
|
|
3236
|
+
constructor() {}
|
|
3237
|
+
capture() {}
|
|
3238
|
+
identify() {}
|
|
3239
|
+
alias() {}
|
|
3240
|
+
flush() { return Promise.resolve(); }
|
|
3241
|
+
shutdown() { return Promise.resolve(); }
|
|
3242
|
+
}
|
|
3243
|
+
export default PostHog;
|
|
3244
|
+
`;
|
|
3245
|
+
}
|
|
3246
|
+
return null;
|
|
3247
|
+
}
|
|
3248
|
+
};
|
|
2091
3249
|
const viteServer = await createServer({
|
|
2092
3250
|
root: tempDir,
|
|
2093
3251
|
base: baseRoute + "/",
|
|
2094
|
-
plugins: [
|
|
3252
|
+
plugins: [
|
|
3253
|
+
nodeStubsPlugin,
|
|
3254
|
+
ssrCssPlugin,
|
|
3255
|
+
watchResourcesPlugin,
|
|
3256
|
+
tailwindcss(),
|
|
3257
|
+
react()
|
|
3258
|
+
],
|
|
2095
3259
|
resolve: {
|
|
2096
3260
|
alias: {
|
|
2097
3261
|
"@": pathHelpers.join(getCwd(), resourcesDir)
|
|
@@ -2112,12 +3276,15 @@ if (container && Component) {
|
|
|
2112
3276
|
// Explicitly tell Vite to watch files outside root
|
|
2113
3277
|
// This is needed because widget entry files import from resources directory
|
|
2114
3278
|
optimizeDeps: {
|
|
2115
|
-
//
|
|
2116
|
-
|
|
3279
|
+
// Exclude Node.js-only packages from browser bundling
|
|
3280
|
+
// posthog-node is for server-side telemetry and doesn't work in browser
|
|
3281
|
+
exclude: ["posthog-node"]
|
|
2117
3282
|
},
|
|
2118
3283
|
ssr: {
|
|
2119
3284
|
// Force Vite to transform these packages in SSR instead of using external requires
|
|
2120
|
-
noExternal: ["@openai/apps-sdk-ui", "react-router"]
|
|
3285
|
+
noExternal: ["@openai/apps-sdk-ui", "react-router"],
|
|
3286
|
+
// Mark Node.js-only packages as external in SSR mode
|
|
3287
|
+
external: ["posthog-node"]
|
|
2121
3288
|
},
|
|
2122
3289
|
define: {
|
|
2123
3290
|
// Define process.env for SSR context
|
|
@@ -3305,6 +4472,7 @@ __name(startIdleCleanup, "startIdleCleanup");
|
|
|
3305
4472
|
|
|
3306
4473
|
// src/server/endpoints/mount-mcp.ts
|
|
3307
4474
|
init_runtime();
|
|
4475
|
+
init_telemetry2();
|
|
3308
4476
|
async function mountMcp(app, mcpServerInstance, sessions, config, isProductionMode2) {
|
|
3309
4477
|
const { FetchStreamableHTTPServerTransport } = await import("@mcp-use/modelcontextprotocol-sdk/experimental/fetch-streamable-http/index.js");
|
|
3310
4478
|
const idleTimeoutMs = config.sessionIdleTimeoutMs ?? 3e5;
|
|
@@ -3344,6 +4512,8 @@ async function mountMcp(app, mcpServerInstance, sessions, config, isProductionMo
|
|
|
3344
4512
|
});
|
|
3345
4513
|
server.server.oninitialized = () => {
|
|
3346
4514
|
const clientCapabilities = server.server.getClientCapabilities();
|
|
4515
|
+
const clientInfo = server.server.getClientInfo?.() || {};
|
|
4516
|
+
const protocolVersion = server.server.getProtocolVersion?.() || "unknown";
|
|
3347
4517
|
if (clientCapabilities && sessions.has(sid)) {
|
|
3348
4518
|
const session = sessions.get(sid);
|
|
3349
4519
|
session.clientCapabilities = clientCapabilities;
|
|
@@ -3352,6 +4522,14 @@ async function mountMcp(app, mcpServerInstance, sessions, config, isProductionMo
|
|
|
3352
4522
|
Object.keys(clientCapabilities)
|
|
3353
4523
|
);
|
|
3354
4524
|
}
|
|
4525
|
+
Telemetry.getInstance().trackServerInitialize({
|
|
4526
|
+
protocolVersion: String(protocolVersion),
|
|
4527
|
+
clientInfo: clientInfo || {},
|
|
4528
|
+
clientCapabilities: clientCapabilities || {},
|
|
4529
|
+
sessionId: sid
|
|
4530
|
+
}).catch(
|
|
4531
|
+
(e) => console.debug(`Failed to track server initialize: ${e}`)
|
|
4532
|
+
);
|
|
3355
4533
|
};
|
|
3356
4534
|
}, "onsessioninitialized"),
|
|
3357
4535
|
onsessionclosed: /* @__PURE__ */ __name((sid) => {
|
|
@@ -3655,7 +4833,14 @@ var MCPServerClass = class {
|
|
|
3655
4833
|
__name(this, "MCPServerClass");
|
|
3656
4834
|
}
|
|
3657
4835
|
/**
|
|
3658
|
-
*
|
|
4836
|
+
* Get the mcp-use package version.
|
|
4837
|
+
* Works in all environments (Node.js, browser, Cloudflare Workers, Deno, etc.)
|
|
4838
|
+
*/
|
|
4839
|
+
static getPackageVersion() {
|
|
4840
|
+
return getPackageVersion();
|
|
4841
|
+
}
|
|
4842
|
+
/**
|
|
4843
|
+
* Native MCP server instance from @modelcontextprotocol/sdk
|
|
3659
4844
|
* Exposed publicly for advanced use cases
|
|
3660
4845
|
*/
|
|
3661
4846
|
nativeServer;
|
|
@@ -3684,10 +4869,11 @@ var MCPServerClass = class {
|
|
|
3684
4869
|
oauthProvider;
|
|
3685
4870
|
oauthMiddleware;
|
|
3686
4871
|
/**
|
|
3687
|
-
* Storage for
|
|
4872
|
+
* Storage for registrations that can be replayed on new server instances
|
|
3688
4873
|
* Following the official SDK pattern where each session gets its own server instance
|
|
4874
|
+
* @internal Exposed for telemetry purposes
|
|
3689
4875
|
*/
|
|
3690
|
-
|
|
4876
|
+
registrations = {
|
|
3691
4877
|
tools: /* @__PURE__ */ new Map(),
|
|
3692
4878
|
prompts: /* @__PURE__ */ new Map(),
|
|
3693
4879
|
resources: /* @__PURE__ */ new Map(),
|
|
@@ -3749,7 +4935,7 @@ var MCPServerClass = class {
|
|
|
3749
4935
|
return createHonoProxy(this, this.app);
|
|
3750
4936
|
}
|
|
3751
4937
|
/**
|
|
3752
|
-
* Wrap registration methods to capture
|
|
4938
|
+
* Wrap registration methods to capture registrations following official SDK pattern.
|
|
3753
4939
|
* Each session will get a fresh server instance with all registrations replayed.
|
|
3754
4940
|
*/
|
|
3755
4941
|
wrapRegistrationMethods() {
|
|
@@ -3801,7 +4987,7 @@ var MCPServerClass = class {
|
|
|
3801
4987
|
}), "actualCallback");
|
|
3802
4988
|
}
|
|
3803
4989
|
if (actualCallback) {
|
|
3804
|
-
self.
|
|
4990
|
+
self.registrations.tools.set(toolDefinition.name, {
|
|
3805
4991
|
config: toolDefinition,
|
|
3806
4992
|
handler: actualCallback
|
|
3807
4993
|
});
|
|
@@ -3811,7 +4997,7 @@ var MCPServerClass = class {
|
|
|
3811
4997
|
this.prompt = ((promptDefinition, callback) => {
|
|
3812
4998
|
const actualCallback = callback || promptDefinition.cb;
|
|
3813
4999
|
if (actualCallback) {
|
|
3814
|
-
self.
|
|
5000
|
+
self.registrations.prompts.set(promptDefinition.name, {
|
|
3815
5001
|
config: promptDefinition,
|
|
3816
5002
|
handler: actualCallback
|
|
3817
5003
|
});
|
|
@@ -3826,7 +5012,7 @@ var MCPServerClass = class {
|
|
|
3826
5012
|
const actualCallback = callback || resourceDefinition.readCallback;
|
|
3827
5013
|
if (actualCallback) {
|
|
3828
5014
|
const resourceKey = `${resourceDefinition.name}:${resourceDefinition.uri}`;
|
|
3829
|
-
self.
|
|
5015
|
+
self.registrations.resources.set(resourceKey, {
|
|
3830
5016
|
config: resourceDefinition,
|
|
3831
5017
|
handler: actualCallback
|
|
3832
5018
|
});
|
|
@@ -3836,13 +5022,10 @@ var MCPServerClass = class {
|
|
|
3836
5022
|
this.resourceTemplate = ((templateDefinition, callback) => {
|
|
3837
5023
|
const actualCallback = callback || templateDefinition.readCallback;
|
|
3838
5024
|
if (actualCallback) {
|
|
3839
|
-
self.
|
|
3840
|
-
templateDefinition
|
|
3841
|
-
|
|
3842
|
-
|
|
3843
|
-
handler: actualCallback
|
|
3844
|
-
}
|
|
3845
|
-
);
|
|
5025
|
+
self.registrations.resourceTemplates.set(templateDefinition.name, {
|
|
5026
|
+
config: templateDefinition,
|
|
5027
|
+
handler: actualCallback
|
|
5028
|
+
});
|
|
3846
5029
|
}
|
|
3847
5030
|
return originalResourceTemplate.call(
|
|
3848
5031
|
self,
|
|
@@ -3867,8 +5050,8 @@ var MCPServerClass = class {
|
|
|
3867
5050
|
}
|
|
3868
5051
|
}
|
|
3869
5052
|
);
|
|
3870
|
-
for (const [name,
|
|
3871
|
-
const { config, handler: actualCallback } =
|
|
5053
|
+
for (const [name, registration] of this.registrations.tools) {
|
|
5054
|
+
const { config, handler: actualCallback } = registration;
|
|
3872
5055
|
let inputSchema;
|
|
3873
5056
|
if (config.schema) {
|
|
3874
5057
|
inputSchema = this.convertZodSchemaToParams(config.schema);
|
|
@@ -3934,10 +5117,26 @@ var MCPServerClass = class {
|
|
|
3934
5117
|
}
|
|
3935
5118
|
return await actualCallback(params);
|
|
3936
5119
|
}, "executeCallback");
|
|
3937
|
-
|
|
3938
|
-
|
|
5120
|
+
const startTime = Date.now();
|
|
5121
|
+
let success = true;
|
|
5122
|
+
let errorType = null;
|
|
5123
|
+
try {
|
|
5124
|
+
const result = requestContext ? await runWithContext(requestContext, executeCallback) : await executeCallback();
|
|
5125
|
+
return result;
|
|
5126
|
+
} catch (err) {
|
|
5127
|
+
success = false;
|
|
5128
|
+
errorType = err instanceof Error ? err.name : "unknown_error";
|
|
5129
|
+
throw err;
|
|
5130
|
+
} finally {
|
|
5131
|
+
const executionTimeMs = Date.now() - startTime;
|
|
5132
|
+
Telemetry.getInstance().trackServerToolCall({
|
|
5133
|
+
toolName: name,
|
|
5134
|
+
lengthInputArgument: JSON.stringify(params).length,
|
|
5135
|
+
success,
|
|
5136
|
+
errorType,
|
|
5137
|
+
executionTimeMs
|
|
5138
|
+
}).catch((e) => console.debug(`Failed to track tool call: ${e}`));
|
|
3939
5139
|
}
|
|
3940
|
-
return await executeCallback();
|
|
3941
5140
|
}, "wrappedHandler");
|
|
3942
5141
|
newServer.registerTool(
|
|
3943
5142
|
name,
|
|
@@ -3951,8 +5150,8 @@ var MCPServerClass = class {
|
|
|
3951
5150
|
wrappedHandler
|
|
3952
5151
|
);
|
|
3953
5152
|
}
|
|
3954
|
-
for (const [name,
|
|
3955
|
-
const { config, handler } =
|
|
5153
|
+
for (const [name, registration] of this.registrations.prompts) {
|
|
5154
|
+
const { config, handler } = registration;
|
|
3956
5155
|
let argsSchema;
|
|
3957
5156
|
if (config.schema) {
|
|
3958
5157
|
argsSchema = this.convertZodSchemaToParams(config.schema);
|
|
@@ -3962,12 +5161,27 @@ var MCPServerClass = class {
|
|
|
3962
5161
|
argsSchema = void 0;
|
|
3963
5162
|
}
|
|
3964
5163
|
const wrappedHandler = /* @__PURE__ */ __name(async (params, extra) => {
|
|
3965
|
-
|
|
3966
|
-
|
|
3967
|
-
|
|
5164
|
+
let success = true;
|
|
5165
|
+
let errorType = null;
|
|
5166
|
+
try {
|
|
5167
|
+
const result = await handler(params, extra);
|
|
5168
|
+
if ("messages" in result && Array.isArray(result.messages)) {
|
|
5169
|
+
return result;
|
|
5170
|
+
}
|
|
5171
|
+
const { convertToolResultToPromptResult: convertToolResultToPromptResult2 } = await Promise.resolve().then(() => (init_conversion2(), conversion_exports2));
|
|
5172
|
+
return convertToolResultToPromptResult2(result);
|
|
5173
|
+
} catch (err) {
|
|
5174
|
+
success = false;
|
|
5175
|
+
errorType = err instanceof Error ? err.name : "unknown_error";
|
|
5176
|
+
throw err;
|
|
5177
|
+
} finally {
|
|
5178
|
+
Telemetry.getInstance().trackServerPromptCall({
|
|
5179
|
+
name,
|
|
5180
|
+
description: config.description ?? null,
|
|
5181
|
+
success,
|
|
5182
|
+
errorType
|
|
5183
|
+
}).catch((e) => console.debug(`Failed to track prompt call: ${e}`));
|
|
3968
5184
|
}
|
|
3969
|
-
const { convertToolResultToPromptResult: convertToolResultToPromptResult2 } = await Promise.resolve().then(() => (init_conversion2(), conversion_exports2));
|
|
3970
|
-
return convertToolResultToPromptResult2(result);
|
|
3971
5185
|
}, "wrappedHandler");
|
|
3972
5186
|
newServer.registerPrompt(
|
|
3973
5187
|
name,
|
|
@@ -3979,15 +5193,42 @@ var MCPServerClass = class {
|
|
|
3979
5193
|
wrappedHandler
|
|
3980
5194
|
);
|
|
3981
5195
|
}
|
|
3982
|
-
for (const [_key,
|
|
3983
|
-
const { config, handler } =
|
|
5196
|
+
for (const [_key, registration] of this.registrations.resources) {
|
|
5197
|
+
const { config, handler } = registration;
|
|
3984
5198
|
const wrappedHandler = /* @__PURE__ */ __name(async (extra) => {
|
|
3985
|
-
|
|
3986
|
-
|
|
3987
|
-
|
|
5199
|
+
let success = true;
|
|
5200
|
+
let errorType = null;
|
|
5201
|
+
let contents = [];
|
|
5202
|
+
try {
|
|
5203
|
+
const result = await handler(extra);
|
|
5204
|
+
if ("contents" in result && Array.isArray(result.contents)) {
|
|
5205
|
+
contents = result.contents;
|
|
5206
|
+
return result;
|
|
5207
|
+
}
|
|
5208
|
+
const { convertToolResultToResourceResult: convertToolResultToResourceResult2 } = await Promise.resolve().then(() => (init_conversion(), conversion_exports));
|
|
5209
|
+
const converted = convertToolResultToResourceResult2(
|
|
5210
|
+
config.uri,
|
|
5211
|
+
result
|
|
5212
|
+
);
|
|
5213
|
+
contents = converted.contents || [];
|
|
5214
|
+
return converted;
|
|
5215
|
+
} catch (err) {
|
|
5216
|
+
success = false;
|
|
5217
|
+
errorType = err instanceof Error ? err.name : "unknown_error";
|
|
5218
|
+
throw err;
|
|
5219
|
+
} finally {
|
|
5220
|
+
Telemetry.getInstance().trackServerResourceCall({
|
|
5221
|
+
name: config.name,
|
|
5222
|
+
description: config.description ?? null,
|
|
5223
|
+
contents: contents.map((c) => ({
|
|
5224
|
+
mime_type: c.mimeType ?? null,
|
|
5225
|
+
text: c.text ? `[text: ${c.text.length} chars]` : null,
|
|
5226
|
+
blob: c.blob ? `[blob: ${c.blob.length} bytes]` : null
|
|
5227
|
+
})),
|
|
5228
|
+
success,
|
|
5229
|
+
errorType
|
|
5230
|
+
}).catch((e) => console.debug(`Failed to track resource call: ${e}`));
|
|
3988
5231
|
}
|
|
3989
|
-
const { convertToolResultToResourceResult: convertToolResultToResourceResult2 } = await Promise.resolve().then(() => (init_conversion(), conversion_exports));
|
|
3990
|
-
return convertToolResultToResourceResult2(config.uri, result);
|
|
3991
5232
|
}, "wrappedHandler");
|
|
3992
5233
|
newServer.registerResource(
|
|
3993
5234
|
config.name,
|
|
@@ -4000,8 +5241,8 @@ var MCPServerClass = class {
|
|
|
4000
5241
|
wrappedHandler
|
|
4001
5242
|
);
|
|
4002
5243
|
}
|
|
4003
|
-
for (const [_name,
|
|
4004
|
-
const { config, handler } =
|
|
5244
|
+
for (const [_name, registration] of this.registrations.resourceTemplates) {
|
|
5245
|
+
const { config, handler } = registration;
|
|
4005
5246
|
const isFlatStructure = "uriTemplate" in config;
|
|
4006
5247
|
const uriTemplate = isFlatStructure ? config.uriTemplate : config.resourceTemplate.uriTemplate;
|
|
4007
5248
|
const mimeType = isFlatStructure ? config.mimeType : config.resourceTemplate.mimeType;
|
|
@@ -4028,16 +5269,42 @@ var MCPServerClass = class {
|
|
|
4028
5269
|
template,
|
|
4029
5270
|
metadata,
|
|
4030
5271
|
async (uri, extra) => {
|
|
4031
|
-
|
|
4032
|
-
|
|
4033
|
-
|
|
4034
|
-
|
|
5272
|
+
let success = true;
|
|
5273
|
+
let errorType = null;
|
|
5274
|
+
let contents = [];
|
|
5275
|
+
try {
|
|
5276
|
+
const params = this.parseTemplateUri(uriTemplate, uri.toString());
|
|
5277
|
+
const result = await handler(uri, params, extra);
|
|
5278
|
+
if ("contents" in result && Array.isArray(result.contents)) {
|
|
5279
|
+
contents = result.contents;
|
|
5280
|
+
return result;
|
|
5281
|
+
}
|
|
5282
|
+
const { convertToolResultToResourceResult: convertToolResultToResourceResult2 } = await Promise.resolve().then(() => (init_conversion(), conversion_exports));
|
|
5283
|
+
const converted = convertToolResultToResourceResult2(
|
|
5284
|
+
uri.toString(),
|
|
5285
|
+
result
|
|
5286
|
+
);
|
|
5287
|
+
contents = converted.contents || [];
|
|
5288
|
+
return converted;
|
|
5289
|
+
} catch (err) {
|
|
5290
|
+
success = false;
|
|
5291
|
+
errorType = err instanceof Error ? err.name : "unknown_error";
|
|
5292
|
+
throw err;
|
|
5293
|
+
} finally {
|
|
5294
|
+
Telemetry.getInstance().trackServerResourceCall({
|
|
5295
|
+
name: config.name,
|
|
5296
|
+
description: config.description ?? null,
|
|
5297
|
+
contents: contents.map((c) => ({
|
|
5298
|
+
mimeType: c.mimeType ?? null,
|
|
5299
|
+
text: c.text ? `[text: ${c.text.length} chars]` : null,
|
|
5300
|
+
blob: c.blob ? `[blob: ${c.blob.length} bytes]` : null
|
|
5301
|
+
})),
|
|
5302
|
+
success,
|
|
5303
|
+
errorType
|
|
5304
|
+
}).catch(
|
|
5305
|
+
(e) => console.debug(`Failed to track resource template call: ${e}`)
|
|
5306
|
+
);
|
|
4035
5307
|
}
|
|
4036
|
-
const { convertToolResultToResourceResult: convertToolResultToResourceResult2 } = await Promise.resolve().then(() => (init_conversion(), conversion_exports));
|
|
4037
|
-
return convertToolResultToResourceResult2(
|
|
4038
|
-
uri.toString(),
|
|
4039
|
-
result
|
|
4040
|
-
);
|
|
4041
5308
|
}
|
|
4042
5309
|
);
|
|
4043
5310
|
}
|
|
@@ -4237,10 +5504,14 @@ var MCPServerClass = class {
|
|
|
4237
5504
|
await this.mountMcp();
|
|
4238
5505
|
await this.mountInspector();
|
|
4239
5506
|
this.logRegisteredItems();
|
|
5507
|
+
this._trackServerRun("http");
|
|
4240
5508
|
await startServer(this.app, this.serverPort, this.serverHost, {
|
|
4241
5509
|
onDenoRequest: rewriteSupabaseRequest
|
|
4242
5510
|
});
|
|
4243
5511
|
}
|
|
5512
|
+
_trackServerRun(transport) {
|
|
5513
|
+
Telemetry.getInstance().trackServerRunFromServer(this, transport).catch((e) => console.debug(`Failed to track server run: ${e}`));
|
|
5514
|
+
}
|
|
4244
5515
|
/**
|
|
4245
5516
|
* Get the fetch handler for the server after mounting all endpoints
|
|
4246
5517
|
*
|
|
@@ -4294,6 +5565,8 @@ var MCPServerClass = class {
|
|
|
4294
5565
|
console.log("[MCP] Mounting inspector");
|
|
4295
5566
|
await this.mountInspector();
|
|
4296
5567
|
console.log("[MCP] Mounted inspector");
|
|
5568
|
+
const provider = options?.provider || "fetch";
|
|
5569
|
+
this._trackServerRun(provider);
|
|
4297
5570
|
const fetchHandler = this.app.fetch.bind(this.app);
|
|
4298
5571
|
if (options?.provider === "supabase") {
|
|
4299
5572
|
return async (req) => {
|
|
@@ -4363,6 +5636,7 @@ function createMCPServer(name, config = {}) {
|
|
|
4363
5636
|
__name(createMCPServer, "createMCPServer");
|
|
4364
5637
|
|
|
4365
5638
|
// src/server/index.ts
|
|
5639
|
+
init_version();
|
|
4366
5640
|
init_context_storage();
|
|
4367
5641
|
|
|
4368
5642
|
// src/server/oauth/providers/supabase.ts
|