@mastra/mcp 1.6.0 → 1.6.1-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +9 -0
- package/dist/client/client.d.ts.map +1 -1
- package/dist/docs/SKILL.md +1 -2
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/docs/references/reference-tools-mcp-server.md +1 -3
- package/dist/index.cjs +58 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +57 -2
- package/dist/index.js.map +1 -1
- package/package.json +9 -9
- package/dist/docs/references/docs-mcp-publishing-mcp-server.md +0 -115
package/dist/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { AsyncLocalStorage } from 'async_hooks';
|
|
2
|
+
import { createRequire } from 'module';
|
|
2
3
|
import { MastraBase } from '@mastra/core/base';
|
|
3
4
|
import { createTool, isValidationError } from '@mastra/core/tools';
|
|
4
5
|
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
|
|
@@ -415,7 +416,57 @@ function isReconnectableMCPError(error) {
|
|
|
415
416
|
|
|
416
417
|
// src/client/client.ts
|
|
417
418
|
var DEFAULT_SERVER_CONNECT_TIMEOUT_MSEC = 3e3;
|
|
419
|
+
var require2 = createRequire(import.meta.url);
|
|
418
420
|
var SSE_FALLBACK_STATUS_CODES = [400, 404, 405];
|
|
421
|
+
var DATADOG_TRACER_TEST_SYMBOL = /* @__PURE__ */ Symbol.for("mastra.mcp.dd-trace-test-tracer");
|
|
422
|
+
function shouldDetachPersistentTransportRequest(init) {
|
|
423
|
+
return (init?.method ?? "GET").toUpperCase() === "GET";
|
|
424
|
+
}
|
|
425
|
+
function getDatadogScope() {
|
|
426
|
+
const testTracer = globalThis[DATADOG_TRACER_TEST_SYMBOL];
|
|
427
|
+
const tracer = testTracer ?? loadDatadogTracer();
|
|
428
|
+
if (typeof tracer?.scope === "function") {
|
|
429
|
+
return tracer.scope();
|
|
430
|
+
}
|
|
431
|
+
if (typeof tracer?.default?.scope === "function") {
|
|
432
|
+
return tracer.default.scope();
|
|
433
|
+
}
|
|
434
|
+
return null;
|
|
435
|
+
}
|
|
436
|
+
function loadDatadogTracer() {
|
|
437
|
+
if (!isDatadogTracerLikelyLoaded()) {
|
|
438
|
+
return null;
|
|
439
|
+
}
|
|
440
|
+
try {
|
|
441
|
+
return require2("dd-trace");
|
|
442
|
+
} catch {
|
|
443
|
+
return null;
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
function isDatadogTracerLikelyLoaded() {
|
|
447
|
+
if (globalThis[DATADOG_TRACER_TEST_SYMBOL]) {
|
|
448
|
+
return true;
|
|
449
|
+
}
|
|
450
|
+
if (process.execArgv.some((arg) => arg.includes("dd-trace"))) {
|
|
451
|
+
return true;
|
|
452
|
+
}
|
|
453
|
+
if (process.env.NODE_OPTIONS?.includes("dd-trace")) {
|
|
454
|
+
return true;
|
|
455
|
+
}
|
|
456
|
+
try {
|
|
457
|
+
const resolvedPath = require2.resolve("dd-trace");
|
|
458
|
+
return Boolean(require2.cache[resolvedPath]);
|
|
459
|
+
} catch {
|
|
460
|
+
return false;
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
function runOutsideDatadogTraceScope(callback) {
|
|
464
|
+
const scope = getDatadogScope();
|
|
465
|
+
if (!scope) {
|
|
466
|
+
return callback();
|
|
467
|
+
}
|
|
468
|
+
return scope.activate(null, callback);
|
|
469
|
+
}
|
|
419
470
|
function convertLogLevelToLoggerMethod(level) {
|
|
420
471
|
switch (level) {
|
|
421
472
|
case "debug":
|
|
@@ -610,7 +661,11 @@ var InternalMastraMCPClient = class extends MastraBase {
|
|
|
610
661
|
}
|
|
611
662
|
async connectHttp(url) {
|
|
612
663
|
const { requestInit, eventSourceInit, authProvider, connectTimeout, fetch: userFetch } = this.serverConfig;
|
|
613
|
-
const fetch2 =
|
|
664
|
+
const fetch2 = (requestUrl, init) => {
|
|
665
|
+
const requestContext = this.operationContextStore.getStore() ?? null;
|
|
666
|
+
const executeFetch = () => userFetch ? userFetch(requestUrl, init, requestContext) : globalThis.fetch(requestUrl, init);
|
|
667
|
+
return shouldDetachPersistentTransportRequest(init) ? runOutsideDatadogTraceScope(executeFetch) : executeFetch();
|
|
668
|
+
};
|
|
614
669
|
this.log("debug", `Attempting to connect to URL: ${url}`);
|
|
615
670
|
let shouldTrySSE = url.pathname.endsWith(`/sse`);
|
|
616
671
|
if (!shouldTrySSE) {
|
|
@@ -639,7 +694,7 @@ var InternalMastraMCPClient = class extends MastraBase {
|
|
|
639
694
|
if (shouldTrySSE) {
|
|
640
695
|
this.log("debug", "Falling back to deprecated HTTP+SSE transport...");
|
|
641
696
|
try {
|
|
642
|
-
const sseEventSourceInit =
|
|
697
|
+
const sseEventSourceInit = { ...eventSourceInit, fetch: fetch2 };
|
|
643
698
|
const sseTransport = new SSEClientTransport(url, {
|
|
644
699
|
requestInit,
|
|
645
700
|
eventSourceInit: sseEventSourceInit,
|