@mastra/mcp 1.17.3 → 1.18.0-alpha.1
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/client/configuration.d.ts +13 -21
- package/dist/client/configuration.d.ts.map +1 -1
- package/dist/docs/SKILL.md +2 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/docs/references/docs-auth-fga.md +1 -1
- package/dist/docs/references/docs-connections-connect-mcp-client.md +211 -0
- package/dist/docs/references/reference-tools-mcp-server.md +29 -1
- package/dist/index.cjs +1187 -178
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +1189 -181
- package/dist/index.js.map +1 -1
- package/dist/server/index.d.ts +1 -0
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/mastra-api-mcp-server.d.ts +32 -0
- package/dist/server/mastra-api-mcp-server.d.ts.map +1 -0
- package/dist/server/mastra-api-operations.generated.d.ts +364 -0
- package/dist/server/mastra-api-operations.generated.d.ts.map +1 -0
- package/dist/server/server.d.ts +15 -17
- package/dist/server/server.d.ts.map +1 -1
- package/package.json +9 -9
package/dist/index.cjs
CHANGED
|
@@ -9830,11 +9830,11 @@ var AiSdkSchemaWrapper = class {
|
|
|
9830
9830
|
* const jsonSchema = standardSchema['~standard'].jsonSchema.output({ target: 'draft-07' });
|
|
9831
9831
|
* ```
|
|
9832
9832
|
*/
|
|
9833
|
-
function toStandardSchema$
|
|
9833
|
+
function toStandardSchema$5(schema) {
|
|
9834
9834
|
return new AiSdkSchemaWrapper(schema);
|
|
9835
9835
|
}
|
|
9836
9836
|
//#endregion
|
|
9837
|
-
//#region ../schema-compat/dist/json-schema-
|
|
9837
|
+
//#region ../schema-compat/dist/json-schema-BKit3LVN.js
|
|
9838
9838
|
var require_code$1 = /* @__PURE__ */ __commonJSMin$1(((exports) => {
|
|
9839
9839
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9840
9840
|
exports.regexpCode = exports.getEsmExportName = exports.getProperty = exports.safeStringify = exports.stringify = exports.strConcat = exports.addCodeArg = exports.str = exports._ = exports.nil = exports._Code = exports.Name = exports.IDENTIFIER = exports._CodeOrName = void 0;
|
|
@@ -12440,11 +12440,27 @@ var require_utils = /* @__PURE__ */ __commonJSMin$1(((exports, module) => {
|
|
|
12440
12440
|
/** @type {(value: string) => boolean} */
|
|
12441
12441
|
const isIPv4 = RegExp.prototype.test.bind(/^(?:(?:25[0-5]|2[0-4]\d|1\d{2}|[1-9]\d|\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d{2}|[1-9]\d|\d)$/u);
|
|
12442
12442
|
/** @type {(value: string) => boolean} */
|
|
12443
|
+
const isPort = RegExp.prototype.test.bind(/^\d*$/u);
|
|
12444
|
+
/** @type {(value: string) => boolean} */
|
|
12443
12445
|
const isHexPair = RegExp.prototype.test.bind(/^[\da-f]{2}$/iu);
|
|
12444
12446
|
/** @type {(value: string) => boolean} */
|
|
12445
12447
|
const isUnreserved = RegExp.prototype.test.bind(/^[\da-z\-._~]$/iu);
|
|
12446
12448
|
/** @type {(value: string) => boolean} */
|
|
12447
|
-
const isPathCharacter = RegExp.prototype.test.bind(/^[
|
|
12449
|
+
const isPathCharacter = RegExp.prototype.test.bind(/^[A-Za-z0-9\-._~!$&'()*+,;=:@/]$/u);
|
|
12450
|
+
/** @type {(value: string) => boolean} */
|
|
12451
|
+
const isQueryFragmentCharacter = RegExp.prototype.test.bind(/^[A-Za-z0-9\-._~!$&'()*+,;=:@/?]$/u);
|
|
12452
|
+
/** @type {(value: string) => boolean} */
|
|
12453
|
+
const isUserinfoCharacter = RegExp.prototype.test.bind(/^[A-Za-z0-9\-._~!$&'()*+,;=:]$/u);
|
|
12454
|
+
const BYTE_HEX = new Array(256);
|
|
12455
|
+
{
|
|
12456
|
+
const HEX_DIGITS = "0123456789ABCDEF";
|
|
12457
|
+
for (let i = 0; i < 256; i++) BYTE_HEX[i] = "%" + HEX_DIGITS[i >> 4] + HEX_DIGITS[i & 15];
|
|
12458
|
+
}
|
|
12459
|
+
function percentEncodeNonAscii(cp) {
|
|
12460
|
+
if (cp < 2048) return BYTE_HEX[192 | cp >> 6] + BYTE_HEX[128 | cp & 63];
|
|
12461
|
+
if (cp < 65536) return BYTE_HEX[224 | cp >> 12] + BYTE_HEX[128 | cp >> 6 & 63] + BYTE_HEX[128 | cp & 63];
|
|
12462
|
+
return BYTE_HEX[240 | cp >> 18] + BYTE_HEX[128 | cp >> 12 & 63] + BYTE_HEX[128 | cp >> 6 & 63] + BYTE_HEX[128 | cp & 63];
|
|
12463
|
+
}
|
|
12448
12464
|
/**
|
|
12449
12465
|
* @param {Array<string>} input
|
|
12450
12466
|
* @returns {string}
|
|
@@ -12467,119 +12483,162 @@ var require_utils = /* @__PURE__ */ __commonJSMin$1(((exports, module) => {
|
|
|
12467
12483
|
}
|
|
12468
12484
|
return acc;
|
|
12469
12485
|
}
|
|
12470
|
-
/**
|
|
12471
|
-
|
|
12472
|
-
|
|
12473
|
-
|
|
12474
|
-
|
|
12475
|
-
|
|
12486
|
+
/** @type {(value: string) => boolean} */
|
|
12487
|
+
const isHextet = RegExp.prototype.test.bind(/^[\dA-Fa-f]{1,4}$/);
|
|
12488
|
+
/** @type {(value: string) => boolean} */
|
|
12489
|
+
const isIPvFuture = RegExp.prototype.test.bind(/^[vV][\dA-Fa-f]+\.[A-Za-z\d\-._~!$&'()*+,;=:]+$/);
|
|
12490
|
+
/** @type {(value: string) => boolean} */
|
|
12491
|
+
const isZoneCharacter = RegExp.prototype.test.bind(/^[A-Za-z\d\-._~]$/);
|
|
12476
12492
|
/**
|
|
12477
12493
|
* @param {string} value
|
|
12478
12494
|
* @returns {boolean}
|
|
12479
12495
|
*/
|
|
12480
12496
|
const nonSimpleDomain = RegExp.prototype.test.bind(/[^!"$&'()*+,\-.;=_`a-z{}~]/u);
|
|
12481
12497
|
/**
|
|
12482
|
-
* @param {
|
|
12498
|
+
* @param {string} zone
|
|
12483
12499
|
* @returns {boolean}
|
|
12484
12500
|
*/
|
|
12485
|
-
function
|
|
12486
|
-
|
|
12501
|
+
function isZoneIdentifier(zone) {
|
|
12502
|
+
if (zone.length === 0) return false;
|
|
12503
|
+
for (let i = 0; i < zone.length; i++) {
|
|
12504
|
+
if (isZoneCharacter(zone[i])) continue;
|
|
12505
|
+
if (zone[i] === "%" && i + 2 < zone.length && isHexPair(zone.slice(i + 1, i + 3))) {
|
|
12506
|
+
i += 2;
|
|
12507
|
+
continue;
|
|
12508
|
+
}
|
|
12509
|
+
return false;
|
|
12510
|
+
}
|
|
12487
12511
|
return true;
|
|
12488
12512
|
}
|
|
12489
12513
|
/**
|
|
12490
|
-
*
|
|
12491
|
-
*
|
|
12492
|
-
*
|
|
12493
|
-
* @
|
|
12514
|
+
* Compresses the longest run of zero hextets to "::" per RFC 5952. A run of a
|
|
12515
|
+
* single zero hextet is left uncompressed. On ties the leftmost run wins.
|
|
12516
|
+
*
|
|
12517
|
+
* @param {string[]} hextets
|
|
12518
|
+
* @returns {string}
|
|
12494
12519
|
*/
|
|
12495
|
-
function
|
|
12496
|
-
|
|
12497
|
-
|
|
12498
|
-
|
|
12499
|
-
|
|
12500
|
-
|
|
12501
|
-
|
|
12520
|
+
function compressIPv6ZeroRun(hextets) {
|
|
12521
|
+
let bestStart = -1;
|
|
12522
|
+
let bestLength = 0;
|
|
12523
|
+
let runStart = -1;
|
|
12524
|
+
let runLength = 0;
|
|
12525
|
+
for (let i = 0; i < hextets.length; i++) if (hextets[i] === "0") {
|
|
12526
|
+
if (runStart === -1) runStart = i;
|
|
12527
|
+
runLength++;
|
|
12528
|
+
if (runLength > bestLength) {
|
|
12529
|
+
bestLength = runLength;
|
|
12530
|
+
bestStart = runStart;
|
|
12502
12531
|
}
|
|
12503
|
-
|
|
12532
|
+
} else {
|
|
12533
|
+
runStart = -1;
|
|
12534
|
+
runLength = 0;
|
|
12504
12535
|
}
|
|
12505
|
-
return
|
|
12536
|
+
if (bestLength < 2) return hextets.join(":");
|
|
12537
|
+
const head = hextets.slice(0, bestStart).join(":");
|
|
12538
|
+
const tail = hextets.slice(bestStart + bestLength).join(":");
|
|
12539
|
+
return head + "::" + tail;
|
|
12506
12540
|
}
|
|
12507
12541
|
/**
|
|
12542
|
+
* Validates an IPv6 address against the alternatives in RFC 3986 section
|
|
12543
|
+
* 3.2.2 and returns the same address with leading hextet zeroes removed.
|
|
12544
|
+
* An embedded IPv4 address counts as two hextets and is only valid at the end.
|
|
12545
|
+
*
|
|
12508
12546
|
* @param {string} input
|
|
12509
|
-
* @returns {
|
|
12547
|
+
* @returns {string|undefined}
|
|
12510
12548
|
*/
|
|
12511
|
-
function
|
|
12512
|
-
|
|
12513
|
-
|
|
12514
|
-
|
|
12515
|
-
|
|
12516
|
-
|
|
12517
|
-
|
|
12518
|
-
|
|
12519
|
-
|
|
12520
|
-
|
|
12521
|
-
|
|
12522
|
-
let
|
|
12523
|
-
|
|
12524
|
-
|
|
12525
|
-
|
|
12526
|
-
|
|
12527
|
-
|
|
12528
|
-
if (cursor === ":") {
|
|
12529
|
-
if (endipv6Encountered === true) endIpv6 = true;
|
|
12530
|
-
if (!consume(buffer, address, output)) break;
|
|
12531
|
-
if (++tokenCount > 7) {
|
|
12532
|
-
output.error = true;
|
|
12533
|
-
break;
|
|
12534
|
-
}
|
|
12535
|
-
if (i > 0 && input[i - 1] === ":") endipv6Encountered = true;
|
|
12536
|
-
address.push(":");
|
|
12537
|
-
continue;
|
|
12538
|
-
} else if (cursor === "%") {
|
|
12539
|
-
if (!consume(buffer, address, output)) break;
|
|
12540
|
-
consume = consumeIsZone;
|
|
12541
|
-
} else {
|
|
12542
|
-
buffer.push(cursor);
|
|
12549
|
+
function normalizeIPv6Address(input) {
|
|
12550
|
+
const compression = input.indexOf("::");
|
|
12551
|
+
if (compression !== -1 && input.indexOf("::", compression + 1) !== -1) return void 0;
|
|
12552
|
+
const left = compression === -1 ? input.split(":") : input.slice(0, compression).split(":");
|
|
12553
|
+
const right = compression === -1 ? [] : input.slice(compression + 2).split(":");
|
|
12554
|
+
if (compression !== -1) {
|
|
12555
|
+
if (left.length === 1 && left[0] === "") left.length = 0;
|
|
12556
|
+
if (right.length === 1 && right[0] === "") right.length = 0;
|
|
12557
|
+
}
|
|
12558
|
+
const parts = left.concat(right);
|
|
12559
|
+
let hextetCount = 0;
|
|
12560
|
+
for (let i = 0; i < parts.length; i++) {
|
|
12561
|
+
const part = parts[i];
|
|
12562
|
+
if (part === "") return void 0;
|
|
12563
|
+
if (part.indexOf(".") !== -1) {
|
|
12564
|
+
if (i !== parts.length - 1 || compression !== -1 && right.length === 0 || !isIPv4(part)) return void 0;
|
|
12565
|
+
hextetCount += 2;
|
|
12543
12566
|
continue;
|
|
12544
12567
|
}
|
|
12568
|
+
if (!isHextet(part)) return void 0;
|
|
12569
|
+
parts[i] = parseInt(part, 16).toString(16);
|
|
12570
|
+
hextetCount++;
|
|
12545
12571
|
}
|
|
12546
|
-
if (
|
|
12547
|
-
|
|
12548
|
-
|
|
12549
|
-
|
|
12550
|
-
return
|
|
12572
|
+
if (compression === -1) {
|
|
12573
|
+
if (hextetCount !== 8) return void 0;
|
|
12574
|
+
return compressIPv6ZeroRun(parts);
|
|
12575
|
+
}
|
|
12576
|
+
if (hextetCount >= 8) return void 0;
|
|
12577
|
+
const expanded = parts.slice(0, left.length);
|
|
12578
|
+
for (let i = hextetCount; i < 8; i++) expanded.push("0");
|
|
12579
|
+
for (let i = left.length; i < parts.length; i++) expanded.push(parts[i]);
|
|
12580
|
+
return compressIPv6ZeroRun(expanded);
|
|
12551
12581
|
}
|
|
12552
12582
|
/**
|
|
12553
12583
|
* @typedef {Object} NormalizeIPv6Result
|
|
12554
12584
|
* @property {string} host - The normalized host.
|
|
12555
12585
|
* @property {string} [escapedHost] - The escaped host.
|
|
12556
12586
|
* @property {boolean} isIPV6 - Indicates if the host is an IPv6 address.
|
|
12587
|
+
* @property {boolean} [isIPVFuture] - Indicates if the host is an IPvFuture literal.
|
|
12588
|
+
* @property {boolean} [error] - Indicates if a bracketed IP literal is malformed.
|
|
12557
12589
|
*/
|
|
12558
12590
|
/**
|
|
12591
|
+
* Validates and normalizes a bracketed IP literal. Raw zone separators remain
|
|
12592
|
+
* accepted for backwards compatibility, while encoded separators and zone
|
|
12593
|
+
* contents follow RFC 6874.
|
|
12594
|
+
*
|
|
12559
12595
|
* @param {string} host
|
|
12560
12596
|
* @returns {NormalizeIPv6Result}
|
|
12561
12597
|
*/
|
|
12562
12598
|
function normalizeIPv6(host) {
|
|
12563
|
-
|
|
12599
|
+
const bracketed = host[0] === "[" && host[host.length - 1] === "]";
|
|
12600
|
+
if ((host[0] === "[" || host[host.length - 1] === "]") && !bracketed) return {
|
|
12564
12601
|
host,
|
|
12565
|
-
isIPV6: false
|
|
12602
|
+
isIPV6: false,
|
|
12603
|
+
error: true
|
|
12566
12604
|
};
|
|
12567
|
-
|
|
12568
|
-
if (
|
|
12569
|
-
|
|
12570
|
-
let escapedHost = ipv6.address;
|
|
12571
|
-
if (ipv6.zone) {
|
|
12572
|
-
newHost += "%" + ipv6.zone;
|
|
12573
|
-
escapedHost += "%25" + ipv6.zone;
|
|
12574
|
-
}
|
|
12605
|
+
let input = bracketed ? host.slice(1, -1) : host;
|
|
12606
|
+
if (bracketed && isIPvFuture(input)) {
|
|
12607
|
+
input = input.toLowerCase();
|
|
12575
12608
|
return {
|
|
12576
|
-
host:
|
|
12577
|
-
|
|
12578
|
-
|
|
12609
|
+
host: `[${input}]`,
|
|
12610
|
+
escapedHost: input,
|
|
12611
|
+
isIPV6: false,
|
|
12612
|
+
isIPVFuture: true
|
|
12613
|
+
};
|
|
12614
|
+
}
|
|
12615
|
+
if (findToken(input, ":") < 2) return {
|
|
12616
|
+
host,
|
|
12617
|
+
isIPV6: false,
|
|
12618
|
+
error: bracketed
|
|
12619
|
+
};
|
|
12620
|
+
let zoneIdentifier = "";
|
|
12621
|
+
const zoneSeparator = input.indexOf("%");
|
|
12622
|
+
if (zoneSeparator !== -1) {
|
|
12623
|
+
const separatorLength = input.slice(zoneSeparator, zoneSeparator + 3).toLowerCase() === "%25" ? 3 : 1;
|
|
12624
|
+
zoneIdentifier = input.slice(zoneSeparator + separatorLength);
|
|
12625
|
+
if (!isZoneIdentifier(zoneIdentifier)) return {
|
|
12626
|
+
host,
|
|
12627
|
+
isIPV6: false,
|
|
12628
|
+
error: true
|
|
12579
12629
|
};
|
|
12580
|
-
|
|
12630
|
+
input = input.slice(0, zoneSeparator);
|
|
12631
|
+
}
|
|
12632
|
+
const address = normalizeIPv6Address(input);
|
|
12633
|
+
if (address === void 0) return {
|
|
12581
12634
|
host,
|
|
12582
|
-
isIPV6: false
|
|
12635
|
+
isIPV6: false,
|
|
12636
|
+
error: true
|
|
12637
|
+
};
|
|
12638
|
+
return {
|
|
12639
|
+
host: address + (zoneIdentifier ? "%" + zoneIdentifier : ""),
|
|
12640
|
+
escapedHost: address + (zoneIdentifier ? "%25" + zoneIdentifier : ""),
|
|
12641
|
+
isIPV6: true
|
|
12583
12642
|
};
|
|
12584
12643
|
}
|
|
12585
12644
|
/**
|
|
@@ -12692,7 +12751,7 @@ var require_utils = /* @__PURE__ */ __commonJSMin$1(((exports, module) => {
|
|
|
12692
12751
|
}
|
|
12693
12752
|
/**
|
|
12694
12753
|
* Normalizes percent escapes and optionally decodes only unreserved ASCII bytes.
|
|
12695
|
-
* Reserved delimiters such as `%2F`
|
|
12754
|
+
* Reserved delimiters such as `%2F` stay escaped; `%2E` is unreserved.
|
|
12696
12755
|
*
|
|
12697
12756
|
* @param {string} input
|
|
12698
12757
|
* @param {boolean} [decodeUnreserved=false]
|
|
@@ -12728,7 +12787,8 @@ var require_utils = /* @__PURE__ */ __commonJSMin$1(((exports, module) => {
|
|
|
12728
12787
|
function normalizePathEncoding(input) {
|
|
12729
12788
|
let output = "";
|
|
12730
12789
|
for (let i = 0; i < input.length; i++) {
|
|
12731
|
-
|
|
12790
|
+
const ch = input[i];
|
|
12791
|
+
if (ch === "%" && i + 2 < input.length) {
|
|
12732
12792
|
const hex = input.slice(i + 1, i + 3);
|
|
12733
12793
|
if (isHexPair(hex)) {
|
|
12734
12794
|
const normalizedHex = hex.toUpperCase();
|
|
@@ -12739,8 +12799,168 @@ var require_utils = /* @__PURE__ */ __commonJSMin$1(((exports, module) => {
|
|
|
12739
12799
|
continue;
|
|
12740
12800
|
}
|
|
12741
12801
|
}
|
|
12742
|
-
if (isPathCharacter(
|
|
12743
|
-
else
|
|
12802
|
+
if (isPathCharacter(ch)) output += ch;
|
|
12803
|
+
else {
|
|
12804
|
+
const code = input.charCodeAt(i);
|
|
12805
|
+
if (code < 128) output += isEscapeSafe(code) ? ch : BYTE_HEX[code];
|
|
12806
|
+
else if (code < 55296 || code > 57343) output += percentEncodeNonAscii(code);
|
|
12807
|
+
else if (code <= 56319 && i + 1 < input.length) {
|
|
12808
|
+
const low = input.charCodeAt(i + 1);
|
|
12809
|
+
if (low >= 56320 && low <= 57343) {
|
|
12810
|
+
output += percentEncodeNonAscii(65536 + (code - 55296 << 10) + (low - 56320));
|
|
12811
|
+
i++;
|
|
12812
|
+
} else output += percentEncodeNonAscii(65533);
|
|
12813
|
+
} else output += percentEncodeNonAscii(65533);
|
|
12814
|
+
}
|
|
12815
|
+
}
|
|
12816
|
+
return output;
|
|
12817
|
+
}
|
|
12818
|
+
/**
|
|
12819
|
+
* Serializes a path without rewriting reserved data. Raw RFC 3986 path
|
|
12820
|
+
* characters remain literal, valid escapes are preserved and uppercased, and
|
|
12821
|
+
* everything else is UTF-8 percent-encoded. In a path-noscheme, a colon in the
|
|
12822
|
+
* first segment must be escaped so the result cannot be parsed as a scheme.
|
|
12823
|
+
*
|
|
12824
|
+
* @param {string} input
|
|
12825
|
+
* @param {boolean} [pathNoScheme=false]
|
|
12826
|
+
* @returns {string}
|
|
12827
|
+
*/
|
|
12828
|
+
function serializePathEncoding(input, pathNoScheme = false) {
|
|
12829
|
+
let output = "";
|
|
12830
|
+
let firstSegment = pathNoScheme && input[0] !== "/";
|
|
12831
|
+
for (let i = 0; i < input.length; i++) {
|
|
12832
|
+
const ch = input[i];
|
|
12833
|
+
if (ch === "%" && i + 2 < input.length) {
|
|
12834
|
+
const hex = input.slice(i + 1, i + 3);
|
|
12835
|
+
if (isHexPair(hex)) {
|
|
12836
|
+
output += "%" + hex.toUpperCase();
|
|
12837
|
+
i += 2;
|
|
12838
|
+
continue;
|
|
12839
|
+
}
|
|
12840
|
+
}
|
|
12841
|
+
if (ch === "/") firstSegment = false;
|
|
12842
|
+
if (isPathCharacter(ch) && (ch !== ":" || !firstSegment)) output += ch;
|
|
12843
|
+
else {
|
|
12844
|
+
const code = input.charCodeAt(i);
|
|
12845
|
+
if (code < 128) output += BYTE_HEX[code];
|
|
12846
|
+
else if (code < 55296 || code > 57343) output += percentEncodeNonAscii(code);
|
|
12847
|
+
else if (code <= 56319 && i + 1 < input.length) {
|
|
12848
|
+
const low = input.charCodeAt(i + 1);
|
|
12849
|
+
if (low >= 56320 && low <= 57343) {
|
|
12850
|
+
output += percentEncodeNonAscii(65536 + (code - 55296 << 10) + (low - 56320));
|
|
12851
|
+
i++;
|
|
12852
|
+
} else output += percentEncodeNonAscii(65533);
|
|
12853
|
+
} else output += percentEncodeNonAscii(65533);
|
|
12854
|
+
}
|
|
12855
|
+
}
|
|
12856
|
+
return output;
|
|
12857
|
+
}
|
|
12858
|
+
/**
|
|
12859
|
+
* Percent-encodes a URI component using its RFC 3986 literal character set.
|
|
12860
|
+
* Existing valid escapes are preserved and normalized to uppercase hex.
|
|
12861
|
+
*
|
|
12862
|
+
* @param {string} input
|
|
12863
|
+
* @param {(value: string) => boolean} isAllowed
|
|
12864
|
+
* @returns {string}
|
|
12865
|
+
*/
|
|
12866
|
+
function encodeComponent(input, isAllowed) {
|
|
12867
|
+
let output = "";
|
|
12868
|
+
for (let i = 0; i < input.length; i++) {
|
|
12869
|
+
const ch = input[i];
|
|
12870
|
+
if (ch === "%" && i + 2 < input.length) {
|
|
12871
|
+
const hex = input.slice(i + 1, i + 3);
|
|
12872
|
+
if (isHexPair(hex)) {
|
|
12873
|
+
output += "%" + hex.toUpperCase();
|
|
12874
|
+
i += 2;
|
|
12875
|
+
continue;
|
|
12876
|
+
}
|
|
12877
|
+
}
|
|
12878
|
+
if (isAllowed(ch)) output += ch;
|
|
12879
|
+
else {
|
|
12880
|
+
const code = input.charCodeAt(i);
|
|
12881
|
+
if (code < 128) output += BYTE_HEX[code];
|
|
12882
|
+
else if (code < 55296 || code > 57343) output += percentEncodeNonAscii(code);
|
|
12883
|
+
else if (code <= 56319 && i + 1 < input.length) {
|
|
12884
|
+
const low = input.charCodeAt(i + 1);
|
|
12885
|
+
if (low >= 56320 && low <= 57343) {
|
|
12886
|
+
output += percentEncodeNonAscii(65536 + (code - 55296 << 10) + (low - 56320));
|
|
12887
|
+
i++;
|
|
12888
|
+
} else output += percentEncodeNonAscii(65533);
|
|
12889
|
+
} else output += percentEncodeNonAscii(65533);
|
|
12890
|
+
}
|
|
12891
|
+
}
|
|
12892
|
+
return output;
|
|
12893
|
+
}
|
|
12894
|
+
/**
|
|
12895
|
+
* Encodes userinfo while preserving its RFC 3986 §3.2.1 literal characters.
|
|
12896
|
+
* In particular, authority delimiters such as `@`, `/`, `?`, and `#` are data.
|
|
12897
|
+
*
|
|
12898
|
+
* @param {string} input
|
|
12899
|
+
* @returns {string}
|
|
12900
|
+
*/
|
|
12901
|
+
function encodeUserinfo(input) {
|
|
12902
|
+
return encodeComponent(input, isUserinfoCharacter);
|
|
12903
|
+
}
|
|
12904
|
+
/**
|
|
12905
|
+
* Encodes query data using the RFC 3986 §3.4 grammar. A literal `#` must be
|
|
12906
|
+
* escaped because it would otherwise begin the fragment component.
|
|
12907
|
+
*
|
|
12908
|
+
* @param {string} input
|
|
12909
|
+
* @returns {string}
|
|
12910
|
+
*/
|
|
12911
|
+
function encodeQuery(input) {
|
|
12912
|
+
return encodeComponent(input, isQueryFragmentCharacter);
|
|
12913
|
+
}
|
|
12914
|
+
/**
|
|
12915
|
+
* Encodes fragment data using the RFC 3986 §3.5 grammar.
|
|
12916
|
+
*
|
|
12917
|
+
* @param {string} input
|
|
12918
|
+
* @returns {string}
|
|
12919
|
+
*/
|
|
12920
|
+
function encodeFragment(input) {
|
|
12921
|
+
return encodeComponent(input, isQueryFragmentCharacter);
|
|
12922
|
+
}
|
|
12923
|
+
function isEscapeSafe(cp) {
|
|
12924
|
+
return cp >= 48 && cp <= 57 || cp >= 65 && cp <= 90 || cp >= 97 && cp <= 122 || cp === 42 || cp === 43 || cp === 45 || cp === 46 || cp === 47 || cp === 64 || cp === 95;
|
|
12925
|
+
}
|
|
12926
|
+
/**
|
|
12927
|
+
* Normalizes the percent-encoding of a query or fragment component.
|
|
12928
|
+
*
|
|
12929
|
+
* Like `normalizePathEncoding`, but uses the query/fragment character set
|
|
12930
|
+
* (which additionally allows `?`) and decodes `.` since it has no dot-segment
|
|
12931
|
+
* meaning outside of a path.
|
|
12932
|
+
*
|
|
12933
|
+
* @param {string} input
|
|
12934
|
+
* @returns {string}
|
|
12935
|
+
*/
|
|
12936
|
+
function normalizeQueryFragmentEncoding(input) {
|
|
12937
|
+
let output = "";
|
|
12938
|
+
for (let i = 0; i < input.length; i++) {
|
|
12939
|
+
const ch = input[i];
|
|
12940
|
+
if (ch === "%" && i + 2 < input.length) {
|
|
12941
|
+
const hex = input.slice(i + 1, i + 3);
|
|
12942
|
+
if (isHexPair(hex)) {
|
|
12943
|
+
const normalizedHex = hex.toUpperCase();
|
|
12944
|
+
const decoded = String.fromCharCode(parseInt(normalizedHex, 16));
|
|
12945
|
+
if (isUnreserved(decoded)) output += decoded;
|
|
12946
|
+
else output += "%" + normalizedHex;
|
|
12947
|
+
i += 2;
|
|
12948
|
+
continue;
|
|
12949
|
+
}
|
|
12950
|
+
}
|
|
12951
|
+
if (isQueryFragmentCharacter(ch)) output += ch;
|
|
12952
|
+
else {
|
|
12953
|
+
const code = input.charCodeAt(i);
|
|
12954
|
+
if (code < 128) output += isEscapeSafe(code) ? ch : BYTE_HEX[code];
|
|
12955
|
+
else if (code < 55296 || code > 57343) output += percentEncodeNonAscii(code);
|
|
12956
|
+
else if (code <= 56319 && i + 1 < input.length) {
|
|
12957
|
+
const low = input.charCodeAt(i + 1);
|
|
12958
|
+
if (low >= 56320 && low <= 57343) {
|
|
12959
|
+
output += percentEncodeNonAscii(65536 + (code - 55296 << 10) + (low - 56320));
|
|
12960
|
+
i++;
|
|
12961
|
+
} else output += percentEncodeNonAscii(65533);
|
|
12962
|
+
} else output += percentEncodeNonAscii(65533);
|
|
12963
|
+
}
|
|
12744
12964
|
}
|
|
12745
12965
|
return output;
|
|
12746
12966
|
}
|
|
@@ -12772,21 +12992,27 @@ var require_utils = /* @__PURE__ */ __commonJSMin$1(((exports, module) => {
|
|
|
12772
12992
|
function recomposeAuthority(component) {
|
|
12773
12993
|
const uriTokens = [];
|
|
12774
12994
|
if (component.userinfo !== void 0) {
|
|
12775
|
-
uriTokens.push(component.userinfo);
|
|
12995
|
+
uriTokens.push(encodeUserinfo(component.userinfo));
|
|
12776
12996
|
uriTokens.push("@");
|
|
12777
12997
|
}
|
|
12778
12998
|
if (component.host !== void 0) {
|
|
12779
|
-
let host =
|
|
12999
|
+
let host = component.host;
|
|
12780
13000
|
if (!isIPv4(host)) {
|
|
12781
|
-
|
|
12782
|
-
if (ipV6res.isIPV6
|
|
13001
|
+
let ipV6res = normalizeIPv6(host);
|
|
13002
|
+
if (ipV6res.isIPV6 !== true && ipV6res.isIPVFuture !== true) {
|
|
13003
|
+
host = normalizePercentEncoding(host, true);
|
|
13004
|
+
ipV6res = normalizeIPv6(host);
|
|
13005
|
+
}
|
|
13006
|
+
if (ipV6res.isIPV6 === true || ipV6res.isIPVFuture === true) host = `[${ipV6res.escapedHost}]`;
|
|
12783
13007
|
else host = reescapeHostDelimiters(host, false);
|
|
12784
13008
|
}
|
|
12785
13009
|
uriTokens.push(host);
|
|
12786
13010
|
}
|
|
12787
13011
|
if (typeof component.port === "number" || typeof component.port === "string") {
|
|
13012
|
+
const port = String(component.port);
|
|
13013
|
+
if (!isPort(port)) throw new TypeError("URI port is malformed.");
|
|
12788
13014
|
uriTokens.push(":");
|
|
12789
|
-
uriTokens.push(
|
|
13015
|
+
uriTokens.push(port);
|
|
12790
13016
|
}
|
|
12791
13017
|
return uriTokens.length ? uriTokens.join("") : void 0;
|
|
12792
13018
|
}
|
|
@@ -12796,6 +13022,11 @@ var require_utils = /* @__PURE__ */ __commonJSMin$1(((exports, module) => {
|
|
|
12796
13022
|
reescapeHostDelimiters,
|
|
12797
13023
|
normalizePercentEncoding,
|
|
12798
13024
|
normalizePathEncoding,
|
|
13025
|
+
serializePathEncoding,
|
|
13026
|
+
normalizeQueryFragmentEncoding,
|
|
13027
|
+
encodeUserinfo,
|
|
13028
|
+
encodeQuery,
|
|
13029
|
+
encodeFragment,
|
|
12799
13030
|
escapePreservingEscapes,
|
|
12800
13031
|
removeDotSegments,
|
|
12801
13032
|
isIPv4,
|
|
@@ -12806,7 +13037,7 @@ var require_utils = /* @__PURE__ */ __commonJSMin$1(((exports, module) => {
|
|
|
12806
13037
|
}));
|
|
12807
13038
|
var require_schemes = /* @__PURE__ */ __commonJSMin$1(((exports, module) => {
|
|
12808
13039
|
const { isUUID } = require_utils();
|
|
12809
|
-
const URN_REG =
|
|
13040
|
+
const URN_REG = /^([\da-z][\d\-a-z]{0,31}):((?:[\w!$'()*+,\-./:;=@]|%[\da-f]{2})+)$/iu;
|
|
12810
13041
|
const supportedSchemeNames = [
|
|
12811
13042
|
"http",
|
|
12812
13043
|
"https",
|
|
@@ -12877,9 +13108,10 @@ var require_schemes = /* @__PURE__ */ __commonJSMin$1(((exports, module) => {
|
|
|
12877
13108
|
wsComponent.secure = void 0;
|
|
12878
13109
|
}
|
|
12879
13110
|
if (wsComponent.resourceName) {
|
|
12880
|
-
const
|
|
13111
|
+
const queryIndex = wsComponent.resourceName.indexOf("?");
|
|
13112
|
+
const path = queryIndex === -1 ? wsComponent.resourceName : wsComponent.resourceName.slice(0, queryIndex);
|
|
12881
13113
|
wsComponent.path = path && path !== "/" ? path : void 0;
|
|
12882
|
-
wsComponent.query =
|
|
13114
|
+
wsComponent.query = queryIndex === -1 ? void 0 : wsComponent.resourceName.slice(queryIndex + 1);
|
|
12883
13115
|
wsComponent.resourceName = void 0;
|
|
12884
13116
|
}
|
|
12885
13117
|
wsComponent.fragment = void 0;
|
|
@@ -12892,7 +13124,7 @@ var require_schemes = /* @__PURE__ */ __commonJSMin$1(((exports, module) => {
|
|
|
12892
13124
|
return urnComponent;
|
|
12893
13125
|
}
|
|
12894
13126
|
const matches = urnComponent.path.match(URN_REG);
|
|
12895
|
-
if (matches) {
|
|
13127
|
+
if (matches && matches[0] === urnComponent.path) {
|
|
12896
13128
|
const scheme = options.scheme || urnComponent.scheme || "urn";
|
|
12897
13129
|
urnComponent.nid = matches[1].toLowerCase();
|
|
12898
13130
|
urnComponent.nss = matches[2];
|
|
@@ -12986,8 +13218,19 @@ var require_schemes = /* @__PURE__ */ __commonJSMin$1(((exports, module) => {
|
|
|
12986
13218
|
};
|
|
12987
13219
|
}));
|
|
12988
13220
|
var require_fast_uri = /* @__PURE__ */ __commonJSMin$1(((exports, module) => {
|
|
12989
|
-
const { normalizeIPv6, removeDotSegments, recomposeAuthority, normalizePercentEncoding, normalizePathEncoding,
|
|
13221
|
+
const { normalizeIPv6, removeDotSegments, recomposeAuthority, normalizePercentEncoding, normalizePathEncoding, serializePathEncoding, normalizeQueryFragmentEncoding, encodeQuery, encodeFragment, reescapeHostDelimiters, isIPv4, nonSimpleDomain } = require_utils();
|
|
12990
13222
|
const { SCHEMES, getSchemeHandler } = require_schemes();
|
|
13223
|
+
const VALID_SCHEME = /^[A-Za-z][A-Za-z0-9+.-]*$/u;
|
|
13224
|
+
const MALFORMED_SCHEME_ERROR = "URI scheme is malformed.";
|
|
13225
|
+
/**
|
|
13226
|
+
* @param {string} scheme
|
|
13227
|
+
* @returns {string}
|
|
13228
|
+
*/
|
|
13229
|
+
function decodeValidScheme(scheme) {
|
|
13230
|
+
const decodedScheme = unescape(String(scheme));
|
|
13231
|
+
if (!VALID_SCHEME.test(decodedScheme)) throw new TypeError(MALFORMED_SCHEME_ERROR);
|
|
13232
|
+
return decodedScheme;
|
|
13233
|
+
}
|
|
12991
13234
|
/**
|
|
12992
13235
|
* @template {import('./types/index').URIComponent|string} T
|
|
12993
13236
|
* @param {T} uri
|
|
@@ -13007,10 +13250,16 @@ var require_fast_uri = /* @__PURE__ */ __commonJSMin$1(((exports, module) => {
|
|
|
13007
13250
|
*/
|
|
13008
13251
|
function resolve(baseURI, relativeURI, options) {
|
|
13009
13252
|
const schemelessOptions = options ? Object.assign({ scheme: "null" }, options) : { scheme: "null" };
|
|
13010
|
-
const { parsed: baseParsed, malformedAuthorityOrPort: baseMalformed } = parseWithStatus(baseURI, schemelessOptions);
|
|
13011
|
-
const { parsed: relativeParsed, malformedAuthorityOrPort: relativeMalformed } = parseWithStatus(relativeURI, schemelessOptions);
|
|
13012
|
-
if (baseMalformed || relativeMalformed) throw new Error(baseParsed.error || relativeParsed.error || "URI is malformed.");
|
|
13253
|
+
const { parsed: baseParsed, malformedAuthorityOrPort: baseMalformed, malformedPercentEncoding: baseMalformedPercentEncoding, malformedSchemeSpecific: baseMalformedSchemeSpecific, malformedHost: baseMalformedHost, malformedScheme: baseMalformedScheme } = parseWithStatus(baseURI, schemelessOptions);
|
|
13254
|
+
const { parsed: relativeParsed, malformedAuthorityOrPort: relativeMalformed, malformedPercentEncoding: relativeMalformedPercentEncoding, malformedSchemeSpecific: relativeMalformedSchemeSpecific, malformedHost: relativeMalformedHost, malformedScheme: relativeMalformedScheme } = parseWithStatus(relativeURI, schemelessOptions);
|
|
13255
|
+
if (baseMalformed || relativeMalformed || baseMalformedPercentEncoding || relativeMalformedPercentEncoding || baseMalformedSchemeSpecific || relativeMalformedSchemeSpecific || baseMalformedHost || relativeMalformedHost || baseMalformedScheme || relativeMalformedScheme) throw new Error(baseParsed.error || relativeParsed.error || "URI is malformed.");
|
|
13013
13256
|
const resolved = resolveComponent(baseParsed, relativeParsed, schemelessOptions, true);
|
|
13257
|
+
const resolvedSchemeHandler = getSchemeHandler(options && options.scheme || resolved.scheme);
|
|
13258
|
+
const resolvedHost = resolved.host;
|
|
13259
|
+
const resolvedHostIsIP = resolvedHost !== void 0 && resolvedHost !== "" && (isIPv4(resolvedHost) || normalizeIPv6(resolvedHost).isIPV6);
|
|
13260
|
+
canonicalizeHost(resolved, options || {}, resolvedSchemeHandler, resolvedHostIsIP);
|
|
13261
|
+
const encodedASCIIHost = resolvedHost && resolvedHost.indexOf("%") !== -1 && !/\P{ASCII}/u.test(resolvedHost);
|
|
13262
|
+
if (resolved.error && !encodedASCIIHost) throw new Error(resolved.error);
|
|
13014
13263
|
schemelessOptions.skipEscape = true;
|
|
13015
13264
|
return serialize(resolved, schemelessOptions);
|
|
13016
13265
|
}
|
|
@@ -13076,7 +13325,7 @@ var require_fast_uri = /* @__PURE__ */ __commonJSMin$1(((exports, module) => {
|
|
|
13076
13325
|
function equal(uriA, uriB, options) {
|
|
13077
13326
|
const normalizedA = normalizeComparableURI(uriA, options);
|
|
13078
13327
|
const normalizedB = normalizeComparableURI(uriB, options);
|
|
13079
|
-
return normalizedA !== void 0 && normalizedB !== void 0 && normalizedA
|
|
13328
|
+
return normalizedA !== void 0 && normalizedB !== void 0 && normalizedA === normalizedB;
|
|
13080
13329
|
}
|
|
13081
13330
|
/**
|
|
13082
13331
|
* @param {Readonly<import('./types/index').URIComponent>} cmpts
|
|
@@ -13102,13 +13351,17 @@ var require_fast_uri = /* @__PURE__ */ __commonJSMin$1(((exports, module) => {
|
|
|
13102
13351
|
};
|
|
13103
13352
|
const options = Object.assign({}, opts);
|
|
13104
13353
|
const uriTokens = [];
|
|
13354
|
+
if (component.scheme) component.scheme = decodeValidScheme(component.scheme);
|
|
13105
13355
|
const schemeHandler = getSchemeHandler(options.scheme || component.scheme);
|
|
13106
13356
|
if (schemeHandler && schemeHandler.serialize) schemeHandler.serialize(component, options);
|
|
13107
|
-
|
|
13108
|
-
|
|
13109
|
-
|
|
13110
|
-
|
|
13111
|
-
if (options.reference !== "suffix" && component.scheme)
|
|
13357
|
+
const hasAuthority = component.userinfo !== void 0 || component.host !== void 0 || component.port !== void 0;
|
|
13358
|
+
const pathNoScheme = !options.skipEscape && component.scheme === void 0 && !hasAuthority;
|
|
13359
|
+
if (component.path !== void 0) if (!options.skipEscape) component.path = serializePathEncoding(component.path, pathNoScheme);
|
|
13360
|
+
else component.path = normalizePercentEncoding(component.path);
|
|
13361
|
+
if (options.reference !== "suffix" && component.scheme) {
|
|
13362
|
+
component.scheme = decodeValidScheme(component.scheme);
|
|
13363
|
+
uriTokens.push(component.scheme, ":");
|
|
13364
|
+
}
|
|
13112
13365
|
const authority = recomposeAuthority(component);
|
|
13113
13366
|
if (authority !== void 0) {
|
|
13114
13367
|
if (options.reference !== "suffix") uriTokens.push("//");
|
|
@@ -13118,11 +13371,12 @@ var require_fast_uri = /* @__PURE__ */ __commonJSMin$1(((exports, module) => {
|
|
|
13118
13371
|
if (component.path !== void 0) {
|
|
13119
13372
|
let s = component.path;
|
|
13120
13373
|
if (!options.absolutePath && (!schemeHandler || !schemeHandler.absolutePath)) s = removeDotSegments(s);
|
|
13374
|
+
if (pathNoScheme) s = serializePathEncoding(s, true);
|
|
13121
13375
|
if (authority === void 0 && s[0] === "/" && s[1] === "/") s = "/%2F" + s.slice(2);
|
|
13122
13376
|
uriTokens.push(s);
|
|
13123
13377
|
}
|
|
13124
|
-
if (component.query !== void 0) uriTokens.push("?", component.query);
|
|
13125
|
-
if (component.fragment !== void 0) uriTokens.push("#", component.fragment);
|
|
13378
|
+
if (component.query !== void 0) uriTokens.push("?", encodeQuery(component.query));
|
|
13379
|
+
if (component.fragment !== void 0) uriTokens.push("#", encodeFragment(component.fragment));
|
|
13126
13380
|
return uriTokens.join("");
|
|
13127
13381
|
}
|
|
13128
13382
|
const URI_PARSE = /^(?:([^#/:?]+):)?(?:\/\/((?:([^#/?@]*)@)?(\[[^#/?\]]+\]|[^#/:?]*)(?::(\d*))?))?([^#?]*)(?:\?([^#]*))?(?:#((?:.|[\n\r])*))?/u;
|
|
@@ -13138,9 +13392,61 @@ var require_fast_uri = /* @__PURE__ */ __commonJSMin$1(((exports, module) => {
|
|
|
13138
13392
|
if (typeof parsed.port === "number" && (parsed.port < 0 || parsed.port > 65535)) return "URI port is malformed.";
|
|
13139
13393
|
}
|
|
13140
13394
|
/**
|
|
13395
|
+
* Checks percent syntax without decoding the represented octets. RFC 3986
|
|
13396
|
+
* percent-encoding is byte-oriented, so sequences such as `%FF` are valid even
|
|
13397
|
+
* though they are not independently valid UTF-8.
|
|
13398
|
+
*
|
|
13399
|
+
* @param {string|undefined} component
|
|
13400
|
+
* @returns {boolean}
|
|
13401
|
+
*/
|
|
13402
|
+
function hasMalformedPercentEncoding(component) {
|
|
13403
|
+
if (component === void 0) return false;
|
|
13404
|
+
let percent = component.indexOf("%");
|
|
13405
|
+
while (percent !== -1) {
|
|
13406
|
+
if (percent + 2 >= component.length || !/^[\da-f]{2}$/iu.test(component.slice(percent + 1, percent + 3))) return true;
|
|
13407
|
+
percent = component.indexOf("%", percent + 3);
|
|
13408
|
+
}
|
|
13409
|
+
return false;
|
|
13410
|
+
}
|
|
13411
|
+
/**
|
|
13412
|
+
* Whether the host is a bracketed IP literal (RFC 3986 `IP-literal`).
|
|
13413
|
+
* An unterminated `[` is not a literal, so it must still be validated as a
|
|
13414
|
+
* reg-name instead of being waved through as an IP.
|
|
13415
|
+
*
|
|
13416
|
+
* @param {string} host
|
|
13417
|
+
* @returns {boolean}
|
|
13418
|
+
*/
|
|
13419
|
+
function isIPLiteral(host) {
|
|
13420
|
+
return host[0] === "[" && host[host.length - 1] === "]";
|
|
13421
|
+
}
|
|
13422
|
+
/**
|
|
13423
|
+
* @param {RegExpMatchArray} matches
|
|
13424
|
+
* @returns {boolean}
|
|
13425
|
+
*/
|
|
13426
|
+
function hasMalformedComponentPercentEncoding(matches) {
|
|
13427
|
+
const host = matches[4];
|
|
13428
|
+
return hasMalformedPercentEncoding(matches[3]) || host !== void 0 && !isIPLiteral(host) && hasMalformedPercentEncoding(host) || hasMalformedPercentEncoding(matches[6]) || hasMalformedPercentEncoding(matches[7]) || hasMalformedPercentEncoding(matches[8]);
|
|
13429
|
+
}
|
|
13430
|
+
/**
|
|
13431
|
+
* @param {import('./types/index').URIComponent} parsed
|
|
13432
|
+
* @param {import('./types/index').Options} options
|
|
13433
|
+
* @param {{ domainHost?: boolean, unicodeSupport?: boolean }|undefined} schemeHandler
|
|
13434
|
+
* @param {boolean} isIP
|
|
13435
|
+
* @returns {boolean} whether host conversion failed
|
|
13436
|
+
*/
|
|
13437
|
+
function canonicalizeHost(parsed, options, schemeHandler, isIP) {
|
|
13438
|
+
if (!options.unicodeSupport && (!schemeHandler || !schemeHandler.unicodeSupport) && parsed.host && !isIPLiteral(parsed.host) && (options.domainHost || schemeHandler && schemeHandler.domainHost) && isIP === false && nonSimpleDomain(parsed.host)) try {
|
|
13439
|
+
parsed.host = new URL("http://" + parsed.host).hostname;
|
|
13440
|
+
} catch (e) {
|
|
13441
|
+
parsed.error = parsed.error || "Host's domain name can not be converted to ASCII: " + e;
|
|
13442
|
+
return true;
|
|
13443
|
+
}
|
|
13444
|
+
return false;
|
|
13445
|
+
}
|
|
13446
|
+
/**
|
|
13141
13447
|
* @param {string} uri
|
|
13142
13448
|
* @param {import('./types/index').Options} [opts]
|
|
13143
|
-
* @returns {{ parsed: import('./types/index').URIComponent, malformedAuthorityOrPort: boolean }}
|
|
13449
|
+
* @returns {{ parsed: import('./types/index').URIComponent, malformedAuthorityOrPort: boolean, malformedPercentEncoding: boolean, malformedSchemeSpecific: boolean, malformedHost: boolean, malformedScheme: boolean }}
|
|
13144
13450
|
*/
|
|
13145
13451
|
function parseWithStatus(uri, opts) {
|
|
13146
13452
|
const options = Object.assign({}, opts);
|
|
@@ -13155,6 +13461,11 @@ var require_fast_uri = /* @__PURE__ */ __commonJSMin$1(((exports, module) => {
|
|
|
13155
13461
|
fragment: void 0
|
|
13156
13462
|
};
|
|
13157
13463
|
let malformedAuthorityOrPort = false;
|
|
13464
|
+
let malformedPercentEncoding = false;
|
|
13465
|
+
let malformedSchemeSpecific = false;
|
|
13466
|
+
let malformedHost = false;
|
|
13467
|
+
let malformedIPLiteral = false;
|
|
13468
|
+
let malformedScheme = false;
|
|
13158
13469
|
let isIP = false;
|
|
13159
13470
|
if (options.reference === "suffix") if (options.scheme) uri = options.scheme + ":" + uri;
|
|
13160
13471
|
else uri = "//" + uri;
|
|
@@ -13186,6 +13497,16 @@ var require_fast_uri = /* @__PURE__ */ __commonJSMin$1(((exports, module) => {
|
|
|
13186
13497
|
parsed.path = matches[6] || "";
|
|
13187
13498
|
parsed.query = matches[7];
|
|
13188
13499
|
parsed.fragment = matches[8];
|
|
13500
|
+
if (parsed.scheme !== void 0) {
|
|
13501
|
+
const decodedScheme = unescape(parsed.scheme);
|
|
13502
|
+
if (VALID_SCHEME.test(decodedScheme)) parsed.scheme = decodedScheme.toLowerCase();
|
|
13503
|
+
else {
|
|
13504
|
+
parsed.error = parsed.error || MALFORMED_SCHEME_ERROR;
|
|
13505
|
+
malformedScheme = true;
|
|
13506
|
+
}
|
|
13507
|
+
}
|
|
13508
|
+
malformedPercentEncoding = hasMalformedComponentPercentEncoding(matches);
|
|
13509
|
+
if (malformedPercentEncoding) parsed.error = parsed.error || "URI contains malformed percent-encoding.";
|
|
13189
13510
|
if (isNaN(parsed.port)) parsed.port = matches[5];
|
|
13190
13511
|
const parseError = getParseError(parsed, matches);
|
|
13191
13512
|
if (parseError !== void 0) {
|
|
@@ -13193,9 +13514,16 @@ var require_fast_uri = /* @__PURE__ */ __commonJSMin$1(((exports, module) => {
|
|
|
13193
13514
|
malformedAuthorityOrPort = true;
|
|
13194
13515
|
}
|
|
13195
13516
|
if (parsed.host) if (isIPv4(parsed.host) === false) {
|
|
13517
|
+
const bracketedIPLiteral = isIPLiteral(parsed.host);
|
|
13518
|
+
const hasIPLiteralBracket = parsed.host.indexOf("[") !== -1 || parsed.host.indexOf("]") !== -1;
|
|
13196
13519
|
const ipv6result = normalizeIPv6(parsed.host);
|
|
13197
|
-
|
|
13198
|
-
|
|
13520
|
+
isIP = ipv6result.isIPV6 || ipv6result.isIPVFuture === true;
|
|
13521
|
+
malformedIPLiteral = hasIPLiteralBracket && (!bracketedIPLiteral || ipv6result.error === true);
|
|
13522
|
+
parsed.host = isIP ? ipv6result.host : ipv6result.host.toLowerCase();
|
|
13523
|
+
if (malformedIPLiteral) {
|
|
13524
|
+
parsed.error = parsed.error || "URI host is malformed.";
|
|
13525
|
+
malformedAuthorityOrPort = true;
|
|
13526
|
+
}
|
|
13199
13527
|
} else isIP = true;
|
|
13200
13528
|
if (parsed.scheme === void 0 && parsed.userinfo === void 0 && parsed.host === void 0 && parsed.port === void 0 && parsed.query === void 0 && !parsed.path) parsed.reference = "same-document";
|
|
13201
13529
|
else if (parsed.scheme === void 0) parsed.reference = "relative";
|
|
@@ -13203,30 +13531,30 @@ var require_fast_uri = /* @__PURE__ */ __commonJSMin$1(((exports, module) => {
|
|
|
13203
13531
|
else parsed.reference = "uri";
|
|
13204
13532
|
if (options.reference && options.reference !== "suffix" && options.reference !== parsed.reference) parsed.error = parsed.error || "URI is not a " + options.reference + " reference.";
|
|
13205
13533
|
const schemeHandler = getSchemeHandler(options.scheme || parsed.scheme);
|
|
13206
|
-
if (!
|
|
13207
|
-
if (parsed.host && (options.domainHost || schemeHandler && schemeHandler.domainHost) && isIP === false && nonSimpleDomain(parsed.host)) try {
|
|
13208
|
-
parsed.host = new URL("http://" + parsed.host).hostname;
|
|
13209
|
-
} catch (e) {
|
|
13210
|
-
parsed.error = parsed.error || "Host's domain name can not be converted to ASCII: " + e;
|
|
13211
|
-
}
|
|
13212
|
-
}
|
|
13534
|
+
if (!malformedIPLiteral) malformedHost = canonicalizeHost(parsed, options, schemeHandler, isIP);
|
|
13213
13535
|
if (!schemeHandler || schemeHandler && !schemeHandler.skipNormalize) {
|
|
13214
13536
|
if (uri.indexOf("%") !== -1) {
|
|
13215
|
-
if (parsed.
|
|
13216
|
-
|
|
13537
|
+
if (parsed.host !== void 0 && !malformedIPLiteral) {
|
|
13538
|
+
const host = isIP ? parsed.host : normalizePercentEncoding(parsed.host, true);
|
|
13539
|
+
parsed.host = reescapeHostDelimiters(host, isIP);
|
|
13540
|
+
}
|
|
13217
13541
|
}
|
|
13218
13542
|
if (parsed.path) parsed.path = normalizePathEncoding(parsed.path);
|
|
13219
|
-
if (parsed.
|
|
13220
|
-
|
|
13221
|
-
|
|
13222
|
-
|
|
13223
|
-
|
|
13543
|
+
if (parsed.query) parsed.query = normalizeQueryFragmentEncoding(parsed.query);
|
|
13544
|
+
if (parsed.fragment) parsed.fragment = normalizeQueryFragmentEncoding(parsed.fragment);
|
|
13545
|
+
}
|
|
13546
|
+
if (schemeHandler && schemeHandler.parse) {
|
|
13547
|
+
schemeHandler.parse(parsed, options);
|
|
13548
|
+
if (schemeHandler === SCHEMES.urn && parsed.nid === void 0) malformedSchemeSpecific = true;
|
|
13224
13549
|
}
|
|
13225
|
-
if (schemeHandler && schemeHandler.parse) schemeHandler.parse(parsed, options);
|
|
13226
13550
|
} else parsed.error = parsed.error || "URI can not be parsed.";
|
|
13227
13551
|
return {
|
|
13228
13552
|
parsed,
|
|
13229
|
-
malformedAuthorityOrPort
|
|
13553
|
+
malformedAuthorityOrPort,
|
|
13554
|
+
malformedPercentEncoding,
|
|
13555
|
+
malformedSchemeSpecific,
|
|
13556
|
+
malformedHost,
|
|
13557
|
+
malformedScheme
|
|
13230
13558
|
};
|
|
13231
13559
|
}
|
|
13232
13560
|
/**
|
|
@@ -13248,13 +13576,17 @@ var require_fast_uri = /* @__PURE__ */ __commonJSMin$1(((exports, module) => {
|
|
|
13248
13576
|
/**
|
|
13249
13577
|
* @param {string} uri
|
|
13250
13578
|
* @param {import('./types/index').Options} [opts]
|
|
13251
|
-
* @returns {{ normalized: string, malformedAuthorityOrPort: boolean }}
|
|
13579
|
+
* @returns {{ normalized: string, malformedAuthorityOrPort: boolean, malformedPercentEncoding: boolean, malformedSchemeSpecific: boolean, malformedHost: boolean, malformedScheme: boolean }}
|
|
13252
13580
|
*/
|
|
13253
13581
|
function normalizeStringWithStatus(uri, opts) {
|
|
13254
|
-
const { parsed, malformedAuthorityOrPort } = parseWithStatus(uri, opts);
|
|
13582
|
+
const { parsed, malformedAuthorityOrPort, malformedPercentEncoding, malformedSchemeSpecific, malformedHost, malformedScheme } = parseWithStatus(uri, opts);
|
|
13255
13583
|
return {
|
|
13256
|
-
normalized: malformedAuthorityOrPort ? uri : serialize(parsed, opts),
|
|
13257
|
-
malformedAuthorityOrPort
|
|
13584
|
+
normalized: malformedAuthorityOrPort || malformedPercentEncoding || malformedSchemeSpecific || malformedHost || malformedScheme ? uri : serialize(parsed, opts),
|
|
13585
|
+
malformedAuthorityOrPort,
|
|
13586
|
+
malformedPercentEncoding,
|
|
13587
|
+
malformedSchemeSpecific,
|
|
13588
|
+
malformedHost,
|
|
13589
|
+
malformedScheme
|
|
13258
13590
|
};
|
|
13259
13591
|
}
|
|
13260
13592
|
/**
|
|
@@ -13263,11 +13595,15 @@ var require_fast_uri = /* @__PURE__ */ __commonJSMin$1(((exports, module) => {
|
|
|
13263
13595
|
* @returns {string|undefined}
|
|
13264
13596
|
*/
|
|
13265
13597
|
function normalizeComparableURI(uri, opts) {
|
|
13266
|
-
if (typeof uri
|
|
13267
|
-
|
|
13268
|
-
|
|
13598
|
+
if (typeof uri !== "string" && typeof uri !== "object") return;
|
|
13599
|
+
let value;
|
|
13600
|
+
try {
|
|
13601
|
+
value = typeof uri === "string" ? uri : serialize(uri, opts);
|
|
13602
|
+
} catch {
|
|
13603
|
+
return;
|
|
13269
13604
|
}
|
|
13270
|
-
|
|
13605
|
+
const { normalized, malformedAuthorityOrPort, malformedPercentEncoding, malformedSchemeSpecific, malformedHost, malformedScheme } = normalizeStringWithStatus(value, opts);
|
|
13606
|
+
return malformedAuthorityOrPort || malformedPercentEncoding || malformedSchemeSpecific || malformedHost || malformedScheme ? void 0 : normalized;
|
|
13271
13607
|
}
|
|
13272
13608
|
const fastUri = {
|
|
13273
13609
|
SCHEMES,
|
|
@@ -16443,7 +16779,7 @@ var JsonSchemaWrapper = class {
|
|
|
16443
16779
|
* const jsonSchema = standardSchema['~standard'].jsonSchema.output({ target: 'draft-07' });
|
|
16444
16780
|
* ```
|
|
16445
16781
|
*/
|
|
16446
|
-
function toStandardSchema$
|
|
16782
|
+
function toStandardSchema$4(schema, options) {
|
|
16447
16783
|
return new JsonSchemaWrapper(schema, options);
|
|
16448
16784
|
}
|
|
16449
16785
|
//#endregion
|
|
@@ -16519,7 +16855,7 @@ function convertToJsonSchema$1(zodSchema, options) {
|
|
|
16519
16855
|
* const jsonSchema = standardSchema['~standard'].jsonSchema.output({ target: 'draft-07' });
|
|
16520
16856
|
* ```
|
|
16521
16857
|
*/
|
|
16522
|
-
function toStandardSchema$
|
|
16858
|
+
function toStandardSchema$3(zodSchema) {
|
|
16523
16859
|
const wrapper = Object.create(zodSchema);
|
|
16524
16860
|
const existingStandard = zodSchema["~standard"];
|
|
16525
16861
|
const jsonSchemaConverter = {
|
|
@@ -16542,7 +16878,7 @@ function toStandardSchema$2(zodSchema) {
|
|
|
16542
16878
|
return wrapper;
|
|
16543
16879
|
}
|
|
16544
16880
|
//#endregion
|
|
16545
|
-
//#region ../schema-compat/dist/schema-
|
|
16881
|
+
//#region ../schema-compat/dist/schema-D_ikovK6.js
|
|
16546
16882
|
/**
|
|
16547
16883
|
* Supported JSON Schema targets for z.toJSONSchema().
|
|
16548
16884
|
* Works with both real Zod v4 and Zod 3.25's v4 compat layer.
|
|
@@ -16671,18 +17007,18 @@ function isZodV3(schema) {
|
|
|
16671
17007
|
}
|
|
16672
17008
|
return schema instanceof v3_default.ZodType;
|
|
16673
17009
|
}
|
|
16674
|
-
function toStandardSchema(schema) {
|
|
17010
|
+
function toStandardSchema$2(schema) {
|
|
16675
17011
|
if (isZodV4(schema)) patchRecordSchemas(schema);
|
|
16676
17012
|
if (isStandardSchemaWithJSON$2(schema)) return schema;
|
|
16677
17013
|
if (isZodV4(schema)) return toStandardSchema$1(schema, {
|
|
16678
17014
|
unrepresentable: JSON_SCHEMA_LIBRARY_OPTIONS.unrepresentable,
|
|
16679
17015
|
override: JSON_SCHEMA_LIBRARY_OPTIONS.override
|
|
16680
17016
|
});
|
|
16681
|
-
if (isZodV3(schema)) return toStandardSchema$
|
|
16682
|
-
if (isVercelSchema(schema)) return toStandardSchema$
|
|
17017
|
+
if (isZodV3(schema)) return toStandardSchema$3(schema);
|
|
17018
|
+
if (isVercelSchema(schema)) return toStandardSchema$5(schema);
|
|
16683
17019
|
if (schema === null || typeof schema !== "object" && typeof schema !== "function") throw new Error(`Unsupported schema type: ${typeof schema}`);
|
|
16684
17020
|
if (typeof schema === "function") throw new Error(`Unsupported schema type: function (schema libraries should implement StandardSchemaWithJSON)`);
|
|
16685
|
-
return toStandardSchema$
|
|
17021
|
+
return toStandardSchema$4(schema);
|
|
16686
17022
|
}
|
|
16687
17023
|
/**
|
|
16688
17024
|
* Type guard to check if a value implements the StandardSchemaV1 interface.
|
|
@@ -22080,7 +22416,7 @@ var InternalMastraMCPClient = class extends _mastra_core_base.MastraBase {
|
|
|
22080
22416
|
convertOutputSchema(outputSchema) {
|
|
22081
22417
|
if (!outputSchema) return outputSchema;
|
|
22082
22418
|
return { "~standard": {
|
|
22083
|
-
...toStandardSchema("jsonSchema" in outputSchema ? outputSchema.jsonSchema : outputSchema)["~standard"],
|
|
22419
|
+
...toStandardSchema$2("jsonSchema" in outputSchema ? outputSchema.jsonSchema : outputSchema)["~standard"],
|
|
22084
22420
|
validate: (value) => ({ value })
|
|
22085
22421
|
} };
|
|
22086
22422
|
}
|
|
@@ -22201,7 +22537,7 @@ var InternalMastraMCPClient = class extends _mastra_core_base.MastraBase {
|
|
|
22201
22537
|
...annotations ? { annotations } : {}
|
|
22202
22538
|
} } : {};
|
|
22203
22539
|
const rawOutputSchema = tool.outputSchema ? "jsonSchema" in tool.outputSchema ? tool.outputSchema.jsonSchema : tool.outputSchema : void 0;
|
|
22204
|
-
const outputValidator = rawOutputSchema ? toStandardSchema(rawOutputSchema) : void 0;
|
|
22540
|
+
const outputValidator = rawOutputSchema ? toStandardSchema$2(rawOutputSchema) : void 0;
|
|
22205
22541
|
const mastraTool = (0, _mastra_core_tools.createTool)({
|
|
22206
22542
|
id: `${this.name}_${tool.name}`,
|
|
22207
22543
|
description: tool.description || "",
|
|
@@ -22948,38 +23284,30 @@ function isLoopbackHostname(hostname) {
|
|
|
22948
23284
|
return hostname === "localhost" || hostname === "[::1]" || hostname === "::1" || LOOPBACK_IPV4.test(hostname);
|
|
22949
23285
|
}
|
|
22950
23286
|
/**
|
|
22951
|
-
*
|
|
23287
|
+
* Manages Model Context Protocol (MCP) server connections and tool namespacing,
|
|
23288
|
+
* with access to tools, resources, prompts, and elicitation.
|
|
22952
23289
|
*
|
|
22953
|
-
*
|
|
22954
|
-
* resources, prompts, and elicitation across all configured servers.
|
|
23290
|
+
* Configure authentication when required by your servers.
|
|
22955
23291
|
*
|
|
22956
23292
|
* @example
|
|
23293
|
+
* `yourServerUrl` is a URL for a running MCP server's HTTP endpoint.
|
|
22957
23294
|
* ```typescript
|
|
22958
23295
|
* import { MCPClient } from '@mastra/mcp';
|
|
22959
|
-
* import { Agent } from '@mastra/core/agent';
|
|
22960
23296
|
*
|
|
22961
23297
|
* const mcp = new MCPClient({
|
|
22962
23298
|
* servers: {
|
|
22963
|
-
*
|
|
22964
|
-
* url: new URL('http://localhost:8080/sse'),
|
|
22965
|
-
* },
|
|
22966
|
-
* stockPrice: {
|
|
22967
|
-
* command: 'npx',
|
|
22968
|
-
* args: ['tsx', 'stock-price.ts'],
|
|
22969
|
-
* env: { API_KEY: 'your-api-key' },
|
|
22970
|
-
* },
|
|
23299
|
+
* remote: { url: yourServerUrl },
|
|
22971
23300
|
* },
|
|
22972
|
-
* timeout: 30000,
|
|
22973
|
-
* });
|
|
22974
|
-
*
|
|
22975
|
-
* const agent = new Agent({
|
|
22976
|
-
* id: 'multi-tool-agent',
|
|
22977
|
-
* name: 'Multi-tool Agent',
|
|
22978
|
-
* instructions: 'You have access to multiple tools.',
|
|
22979
|
-
* model: 'openai/gpt-4o',
|
|
22980
|
-
* tools: await mcp.listTools(),
|
|
22981
23301
|
* });
|
|
22982
23302
|
* ```
|
|
23303
|
+
*
|
|
23304
|
+
* @see For documentation bundled with your installed package, locate
|
|
23305
|
+
* `@mastra/mcp/package.json` with your project's resolver or package-manager
|
|
23306
|
+
* tooling, then read `dist/docs/SKILL.md` from that package root and follow its
|
|
23307
|
+
* reference links. Use package-manager tools for virtual or archived packages.
|
|
23308
|
+
*
|
|
23309
|
+
* @see [MCP client documentation](https://mastra.ai/reference/tools/mcp-client)
|
|
23310
|
+
* if packaged docs are unavailable.
|
|
22983
23311
|
*/
|
|
22984
23312
|
var MCPClient = class extends _mastra_core_base.MastraBase {
|
|
22985
23313
|
serverConfigs = {};
|
|
@@ -24386,7 +24714,7 @@ var streamSSE = (c, cb, onError) => {
|
|
|
24386
24714
|
return c.newResponse(stream.responseReadable);
|
|
24387
24715
|
};
|
|
24388
24716
|
//#endregion
|
|
24389
|
-
//#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/hono-mcp-server-sse-transport/0.0.7/
|
|
24717
|
+
//#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/hono-mcp-server-sse-transport/0.0.7/64266f0b1652040acd07ff3bd56a63a27af87510caf8cd4ce871013cbd451c67/node_modules/hono-mcp-server-sse-transport/build/sse.js
|
|
24390
24718
|
const MAXIMUM_MESSAGE_SIZE = 4 * 1024 * 1024;
|
|
24391
24719
|
var SSETransport = class {
|
|
24392
24720
|
messageUrl;
|
|
@@ -24899,32 +25227,30 @@ const ACCEPTED_MODERN_ERA_HTTP_OPTION_KEYS = /* @__PURE__ */ new Set([
|
|
|
24899
25227
|
"sessionIdGenerator"
|
|
24900
25228
|
]);
|
|
24901
25229
|
/**
|
|
24902
|
-
*
|
|
24903
|
-
*
|
|
24904
|
-
*
|
|
24905
|
-
* Mastra capabilities. It supports both stdio (subprocess) and SSE (HTTP) MCP transports.
|
|
25230
|
+
* Exposes Mastra tools, agents, and workflows to Model Context Protocol (MCP) clients.
|
|
25231
|
+
* Supports stdio, SSE, and Streamable HTTP transports; start or mount a transport
|
|
25232
|
+
* to accept client connections.
|
|
24906
25233
|
*
|
|
24907
25234
|
* @example
|
|
25235
|
+
* `yourTool` is a tool you have already configured.
|
|
24908
25236
|
* ```typescript
|
|
24909
25237
|
* import { MCPServer } from '@mastra/mcp';
|
|
24910
|
-
* import { createTool } from '@mastra/core/tools';
|
|
24911
|
-
* import { z } from 'zod';
|
|
24912
|
-
*
|
|
24913
|
-
* const weatherTool = createTool({
|
|
24914
|
-
* id: 'getWeather',
|
|
24915
|
-
* description: 'Gets the current weather for a location.',
|
|
24916
|
-
* inputSchema: z.object({ location: z.string() }),
|
|
24917
|
-
* execute: async (inputData) => `Weather in ${inputData.location} is sunny.`,
|
|
24918
|
-
* });
|
|
24919
25238
|
*
|
|
24920
25239
|
* const server = new MCPServer({
|
|
24921
|
-
*
|
|
25240
|
+
* id: 'my-server',
|
|
25241
|
+
* name: 'My Server',
|
|
24922
25242
|
* version: '1.0.0',
|
|
24923
|
-
* tools: {
|
|
25243
|
+
* tools: { yourTool },
|
|
24924
25244
|
* });
|
|
24925
|
-
*
|
|
24926
|
-
* await server.startStdio();
|
|
24927
25245
|
* ```
|
|
25246
|
+
*
|
|
25247
|
+
* @see For documentation bundled with your installed package, locate
|
|
25248
|
+
* `@mastra/mcp/package.json` with your project's resolver or package-manager
|
|
25249
|
+
* tooling, then read `dist/docs/SKILL.md` from that package root and follow its
|
|
25250
|
+
* reference links. Use package-manager tools for virtual or archived packages.
|
|
25251
|
+
*
|
|
25252
|
+
* @see [MCP server documentation](https://mastra.ai/reference/tools/mcp-server)
|
|
25253
|
+
* if packaged docs are unavailable.
|
|
24928
25254
|
*/
|
|
24929
25255
|
var MCPServer = class extends _mastra_core_mcp.MCPServerBase {
|
|
24930
25256
|
server;
|
|
@@ -27073,6 +27399,688 @@ var MCPServer = class extends _mastra_core_mcp.MCPServerBase {
|
|
|
27073
27399
|
}
|
|
27074
27400
|
};
|
|
27075
27401
|
//#endregion
|
|
27402
|
+
//#region src/server/mastra-api-operations.generated.ts
|
|
27403
|
+
const MASTRA_API_OPERATIONS = [
|
|
27404
|
+
{
|
|
27405
|
+
name: "agent_list",
|
|
27406
|
+
description: "List available agents",
|
|
27407
|
+
method: "GET",
|
|
27408
|
+
path: "/agents",
|
|
27409
|
+
destructive: false
|
|
27410
|
+
},
|
|
27411
|
+
{
|
|
27412
|
+
name: "agent_get",
|
|
27413
|
+
description: "Get agent details",
|
|
27414
|
+
method: "GET",
|
|
27415
|
+
path: "/agents/:agentId",
|
|
27416
|
+
destructive: false
|
|
27417
|
+
},
|
|
27418
|
+
{
|
|
27419
|
+
name: "agent_run",
|
|
27420
|
+
description: "Run an agent with JSON input",
|
|
27421
|
+
method: "POST",
|
|
27422
|
+
path: "/agents/:agentId/generate",
|
|
27423
|
+
destructive: true
|
|
27424
|
+
},
|
|
27425
|
+
{
|
|
27426
|
+
name: "workflow_list",
|
|
27427
|
+
description: "List available workflows",
|
|
27428
|
+
method: "GET",
|
|
27429
|
+
path: "/workflows",
|
|
27430
|
+
destructive: false
|
|
27431
|
+
},
|
|
27432
|
+
{
|
|
27433
|
+
name: "workflow_get",
|
|
27434
|
+
description: "Get workflow details",
|
|
27435
|
+
method: "GET",
|
|
27436
|
+
path: "/workflows/:workflowId",
|
|
27437
|
+
destructive: false
|
|
27438
|
+
},
|
|
27439
|
+
{
|
|
27440
|
+
name: "workflow_run_start",
|
|
27441
|
+
description: "Start a workflow run",
|
|
27442
|
+
method: "POST",
|
|
27443
|
+
path: "/workflows/:workflowId/start-async",
|
|
27444
|
+
destructive: true
|
|
27445
|
+
},
|
|
27446
|
+
{
|
|
27447
|
+
name: "workflow_run_list",
|
|
27448
|
+
description: "List workflow runs",
|
|
27449
|
+
method: "GET",
|
|
27450
|
+
path: "/workflows/:workflowId/runs",
|
|
27451
|
+
destructive: false
|
|
27452
|
+
},
|
|
27453
|
+
{
|
|
27454
|
+
name: "workflow_run_get",
|
|
27455
|
+
description: "Get workflow run details",
|
|
27456
|
+
method: "GET",
|
|
27457
|
+
path: "/workflows/:workflowId/runs/:runId",
|
|
27458
|
+
destructive: false
|
|
27459
|
+
},
|
|
27460
|
+
{
|
|
27461
|
+
name: "workflow_run_resume",
|
|
27462
|
+
description: "Resume a suspended workflow run",
|
|
27463
|
+
method: "POST",
|
|
27464
|
+
path: "/workflows/:workflowId/resume-async",
|
|
27465
|
+
destructive: true
|
|
27466
|
+
},
|
|
27467
|
+
{
|
|
27468
|
+
name: "workflow_run_cancel",
|
|
27469
|
+
description: "Cancel a workflow run",
|
|
27470
|
+
method: "POST",
|
|
27471
|
+
path: "/workflows/:workflowId/runs/:runId/cancel",
|
|
27472
|
+
destructive: true
|
|
27473
|
+
},
|
|
27474
|
+
{
|
|
27475
|
+
name: "tool_list",
|
|
27476
|
+
description: "List available tools",
|
|
27477
|
+
method: "GET",
|
|
27478
|
+
path: "/tools",
|
|
27479
|
+
destructive: false
|
|
27480
|
+
},
|
|
27481
|
+
{
|
|
27482
|
+
name: "tool_get",
|
|
27483
|
+
description: "Get tool details and input schema",
|
|
27484
|
+
method: "GET",
|
|
27485
|
+
path: "/tools/:toolId",
|
|
27486
|
+
destructive: false
|
|
27487
|
+
},
|
|
27488
|
+
{
|
|
27489
|
+
name: "tool_execute",
|
|
27490
|
+
description: "Execute a tool with JSON input",
|
|
27491
|
+
method: "POST",
|
|
27492
|
+
path: "/tools/:toolId/execute",
|
|
27493
|
+
destructive: true
|
|
27494
|
+
},
|
|
27495
|
+
{
|
|
27496
|
+
name: "mcp_list",
|
|
27497
|
+
description: "List MCP servers",
|
|
27498
|
+
method: "GET",
|
|
27499
|
+
path: "/mcp/v0/servers",
|
|
27500
|
+
destructive: false
|
|
27501
|
+
},
|
|
27502
|
+
{
|
|
27503
|
+
name: "mcp_get",
|
|
27504
|
+
description: "Get MCP server details",
|
|
27505
|
+
method: "GET",
|
|
27506
|
+
path: "/mcp/v0/servers/:id",
|
|
27507
|
+
destructive: false
|
|
27508
|
+
},
|
|
27509
|
+
{
|
|
27510
|
+
name: "mcp_tool_list",
|
|
27511
|
+
description: "List tools for an MCP server",
|
|
27512
|
+
method: "GET",
|
|
27513
|
+
path: "/mcp/:serverId/tools",
|
|
27514
|
+
destructive: false
|
|
27515
|
+
},
|
|
27516
|
+
{
|
|
27517
|
+
name: "mcp_tool_get",
|
|
27518
|
+
description: "Get MCP tool details",
|
|
27519
|
+
method: "GET",
|
|
27520
|
+
path: "/mcp/:serverId/tools/:toolId",
|
|
27521
|
+
destructive: false
|
|
27522
|
+
},
|
|
27523
|
+
{
|
|
27524
|
+
name: "mcp_tool_execute",
|
|
27525
|
+
description: "Execute an MCP tool with JSON input",
|
|
27526
|
+
method: "POST",
|
|
27527
|
+
path: "/mcp/:serverId/tools/:toolId/execute",
|
|
27528
|
+
destructive: true
|
|
27529
|
+
},
|
|
27530
|
+
{
|
|
27531
|
+
name: "thread_list",
|
|
27532
|
+
description: "List memory threads",
|
|
27533
|
+
method: "GET",
|
|
27534
|
+
path: "/memory/threads",
|
|
27535
|
+
destructive: false
|
|
27536
|
+
},
|
|
27537
|
+
{
|
|
27538
|
+
name: "thread_get",
|
|
27539
|
+
description: "Get thread details",
|
|
27540
|
+
method: "GET",
|
|
27541
|
+
path: "/memory/threads/:threadId",
|
|
27542
|
+
destructive: false
|
|
27543
|
+
},
|
|
27544
|
+
{
|
|
27545
|
+
name: "thread_create",
|
|
27546
|
+
description: "Create a memory thread",
|
|
27547
|
+
method: "POST",
|
|
27548
|
+
path: "/memory/threads",
|
|
27549
|
+
destructive: true
|
|
27550
|
+
},
|
|
27551
|
+
{
|
|
27552
|
+
name: "thread_update",
|
|
27553
|
+
description: "Update a memory thread",
|
|
27554
|
+
method: "PATCH",
|
|
27555
|
+
path: "/memory/threads/:threadId",
|
|
27556
|
+
destructive: true
|
|
27557
|
+
},
|
|
27558
|
+
{
|
|
27559
|
+
name: "thread_delete",
|
|
27560
|
+
description: "Delete a memory thread",
|
|
27561
|
+
method: "DELETE",
|
|
27562
|
+
path: "/memory/threads/:threadId",
|
|
27563
|
+
destructive: true
|
|
27564
|
+
},
|
|
27565
|
+
{
|
|
27566
|
+
name: "thread_messages",
|
|
27567
|
+
description: "List messages in a memory thread",
|
|
27568
|
+
method: "GET",
|
|
27569
|
+
path: "/memory/threads/:threadId/messages",
|
|
27570
|
+
destructive: false
|
|
27571
|
+
},
|
|
27572
|
+
{
|
|
27573
|
+
name: "memory_search",
|
|
27574
|
+
description: "Search long-term memory",
|
|
27575
|
+
method: "GET",
|
|
27576
|
+
path: "/memory/search",
|
|
27577
|
+
destructive: false
|
|
27578
|
+
},
|
|
27579
|
+
{
|
|
27580
|
+
name: "memory_current_get",
|
|
27581
|
+
description: "Get current working memory",
|
|
27582
|
+
method: "GET",
|
|
27583
|
+
path: "/memory/threads/:threadId/working-memory",
|
|
27584
|
+
destructive: false
|
|
27585
|
+
},
|
|
27586
|
+
{
|
|
27587
|
+
name: "memory_current_update",
|
|
27588
|
+
description: "Update current working memory",
|
|
27589
|
+
method: "POST",
|
|
27590
|
+
path: "/memory/threads/:threadId/working-memory",
|
|
27591
|
+
destructive: true
|
|
27592
|
+
},
|
|
27593
|
+
{
|
|
27594
|
+
name: "memory_status",
|
|
27595
|
+
description: "Get memory system status",
|
|
27596
|
+
method: "GET",
|
|
27597
|
+
path: "/memory/status",
|
|
27598
|
+
destructive: false
|
|
27599
|
+
},
|
|
27600
|
+
{
|
|
27601
|
+
name: "trace_list",
|
|
27602
|
+
description: "List observability traces",
|
|
27603
|
+
method: "GET",
|
|
27604
|
+
path: "/observability/traces/light",
|
|
27605
|
+
verbosePath: "/observability/traces",
|
|
27606
|
+
destructive: false
|
|
27607
|
+
},
|
|
27608
|
+
{
|
|
27609
|
+
name: "trace_get",
|
|
27610
|
+
description: "Get trace details",
|
|
27611
|
+
method: "GET",
|
|
27612
|
+
path: "/observability/traces/:traceId/light",
|
|
27613
|
+
verbosePath: "/observability/traces/:traceId",
|
|
27614
|
+
destructive: false
|
|
27615
|
+
},
|
|
27616
|
+
{
|
|
27617
|
+
name: "trace_span",
|
|
27618
|
+
description: "Get a trace span",
|
|
27619
|
+
method: "GET",
|
|
27620
|
+
path: "/observability/traces/:traceId/spans/:spanId",
|
|
27621
|
+
destructive: false
|
|
27622
|
+
},
|
|
27623
|
+
{
|
|
27624
|
+
name: "log_list",
|
|
27625
|
+
description: "List runtime logs",
|
|
27626
|
+
method: "GET",
|
|
27627
|
+
path: "/observability/logs",
|
|
27628
|
+
destructive: false
|
|
27629
|
+
},
|
|
27630
|
+
{
|
|
27631
|
+
name: "metric_aggregate",
|
|
27632
|
+
description: "Get an aggregate metric value",
|
|
27633
|
+
method: "POST",
|
|
27634
|
+
path: "/observability/metrics/aggregate",
|
|
27635
|
+
destructive: true
|
|
27636
|
+
},
|
|
27637
|
+
{
|
|
27638
|
+
name: "metric_breakdown",
|
|
27639
|
+
description: "Get metric values grouped by a label or field",
|
|
27640
|
+
method: "POST",
|
|
27641
|
+
path: "/observability/metrics/breakdown",
|
|
27642
|
+
destructive: true
|
|
27643
|
+
},
|
|
27644
|
+
{
|
|
27645
|
+
name: "metric_timeseries",
|
|
27646
|
+
description: "Get metric values over time",
|
|
27647
|
+
method: "POST",
|
|
27648
|
+
path: "/observability/metrics/timeseries",
|
|
27649
|
+
destructive: true
|
|
27650
|
+
},
|
|
27651
|
+
{
|
|
27652
|
+
name: "metric_percentiles",
|
|
27653
|
+
description: "Get metric percentile values over time",
|
|
27654
|
+
method: "POST",
|
|
27655
|
+
path: "/observability/metrics/percentiles",
|
|
27656
|
+
destructive: true
|
|
27657
|
+
},
|
|
27658
|
+
{
|
|
27659
|
+
name: "metric_names",
|
|
27660
|
+
description: "List discovered metric names",
|
|
27661
|
+
method: "GET",
|
|
27662
|
+
path: "/observability/discovery/metric-names",
|
|
27663
|
+
destructive: false
|
|
27664
|
+
},
|
|
27665
|
+
{
|
|
27666
|
+
name: "metric_label_keys",
|
|
27667
|
+
description: "List label keys for a metric",
|
|
27668
|
+
method: "GET",
|
|
27669
|
+
path: "/observability/discovery/metric-label-keys",
|
|
27670
|
+
destructive: false
|
|
27671
|
+
},
|
|
27672
|
+
{
|
|
27673
|
+
name: "metric_label_values",
|
|
27674
|
+
description: "List label values for a metric label key",
|
|
27675
|
+
method: "GET",
|
|
27676
|
+
path: "/observability/discovery/metric-label-values",
|
|
27677
|
+
destructive: false
|
|
27678
|
+
},
|
|
27679
|
+
{
|
|
27680
|
+
name: "score_create",
|
|
27681
|
+
description: "Create a score",
|
|
27682
|
+
method: "POST",
|
|
27683
|
+
path: "/observability/scores",
|
|
27684
|
+
destructive: true
|
|
27685
|
+
},
|
|
27686
|
+
{
|
|
27687
|
+
name: "score_list",
|
|
27688
|
+
description: "List scores",
|
|
27689
|
+
method: "GET",
|
|
27690
|
+
path: "/observability/scores",
|
|
27691
|
+
destructive: false
|
|
27692
|
+
},
|
|
27693
|
+
{
|
|
27694
|
+
name: "score_get",
|
|
27695
|
+
description: "Get score details",
|
|
27696
|
+
method: "GET",
|
|
27697
|
+
path: "/observability/scores/:scoreId",
|
|
27698
|
+
destructive: false
|
|
27699
|
+
},
|
|
27700
|
+
{
|
|
27701
|
+
name: "dataset_list",
|
|
27702
|
+
description: "List datasets",
|
|
27703
|
+
method: "GET",
|
|
27704
|
+
path: "/datasets",
|
|
27705
|
+
destructive: false
|
|
27706
|
+
},
|
|
27707
|
+
{
|
|
27708
|
+
name: "dataset_get",
|
|
27709
|
+
description: "Get dataset details",
|
|
27710
|
+
method: "GET",
|
|
27711
|
+
path: "/datasets/:datasetId",
|
|
27712
|
+
destructive: false
|
|
27713
|
+
},
|
|
27714
|
+
{
|
|
27715
|
+
name: "dataset_create",
|
|
27716
|
+
description: "Create a dataset",
|
|
27717
|
+
method: "POST",
|
|
27718
|
+
path: "/datasets",
|
|
27719
|
+
destructive: true
|
|
27720
|
+
},
|
|
27721
|
+
{
|
|
27722
|
+
name: "dataset_items",
|
|
27723
|
+
description: "List dataset items",
|
|
27724
|
+
method: "GET",
|
|
27725
|
+
path: "/datasets/:datasetId/items",
|
|
27726
|
+
destructive: false
|
|
27727
|
+
},
|
|
27728
|
+
{
|
|
27729
|
+
name: "experiment_list",
|
|
27730
|
+
description: "List dataset experiments",
|
|
27731
|
+
method: "GET",
|
|
27732
|
+
path: "/datasets/:datasetId/experiments",
|
|
27733
|
+
destructive: false
|
|
27734
|
+
},
|
|
27735
|
+
{
|
|
27736
|
+
name: "experiment_get",
|
|
27737
|
+
description: "Get experiment details",
|
|
27738
|
+
method: "GET",
|
|
27739
|
+
path: "/datasets/:datasetId/experiments/:experimentId",
|
|
27740
|
+
destructive: false
|
|
27741
|
+
},
|
|
27742
|
+
{
|
|
27743
|
+
name: "experiment_run",
|
|
27744
|
+
description: "Run a dataset experiment",
|
|
27745
|
+
method: "POST",
|
|
27746
|
+
path: "/datasets/:datasetId/experiments",
|
|
27747
|
+
destructive: true
|
|
27748
|
+
},
|
|
27749
|
+
{
|
|
27750
|
+
name: "experiment_results",
|
|
27751
|
+
description: "List experiment results",
|
|
27752
|
+
method: "GET",
|
|
27753
|
+
path: "/datasets/:datasetId/experiments/:experimentId/results",
|
|
27754
|
+
destructive: false
|
|
27755
|
+
},
|
|
27756
|
+
{
|
|
27757
|
+
name: "learning_entities",
|
|
27758
|
+
description: "List entities with Trace Intelligence output",
|
|
27759
|
+
method: "GET",
|
|
27760
|
+
path: "/learning/entities",
|
|
27761
|
+
destructive: false
|
|
27762
|
+
},
|
|
27763
|
+
{
|
|
27764
|
+
name: "learning_snapshots",
|
|
27765
|
+
description: "List analysis snapshots for an entity and ordered trace signals",
|
|
27766
|
+
method: "GET",
|
|
27767
|
+
path: "/learning/entities/:entityId/theme-snapshots",
|
|
27768
|
+
destructive: false
|
|
27769
|
+
},
|
|
27770
|
+
{
|
|
27771
|
+
name: "learning_flow",
|
|
27772
|
+
description: "Get the cross-signal theme flow for one snapshot",
|
|
27773
|
+
method: "GET",
|
|
27774
|
+
path: "/learning/entities/:entityId/theme-flow",
|
|
27775
|
+
destructive: false
|
|
27776
|
+
},
|
|
27777
|
+
{
|
|
27778
|
+
name: "learning_paths",
|
|
27779
|
+
description: "Get per-trace theme assignments for one snapshot",
|
|
27780
|
+
method: "GET",
|
|
27781
|
+
path: "/learning/entities/:entityId/theme-paths",
|
|
27782
|
+
destructive: false
|
|
27783
|
+
},
|
|
27784
|
+
{
|
|
27785
|
+
name: "learning_theme_list",
|
|
27786
|
+
description: "List themes for one trace signal in one snapshot",
|
|
27787
|
+
method: "GET",
|
|
27788
|
+
path: "/learning/entities/:entityId/themes",
|
|
27789
|
+
destructive: false
|
|
27790
|
+
},
|
|
27791
|
+
{
|
|
27792
|
+
name: "learning_theme_get",
|
|
27793
|
+
description: "Get one theme in one snapshot",
|
|
27794
|
+
method: "GET",
|
|
27795
|
+
path: "/learning/entities/:entityId/themes/:themeId",
|
|
27796
|
+
destructive: false
|
|
27797
|
+
},
|
|
27798
|
+
{
|
|
27799
|
+
name: "learning_theme_examples",
|
|
27800
|
+
description: "List trace examples for one theme in one snapshot",
|
|
27801
|
+
method: "GET",
|
|
27802
|
+
path: "/learning/entities/:entityId/themes/:themeId/examples",
|
|
27803
|
+
destructive: false
|
|
27804
|
+
},
|
|
27805
|
+
{
|
|
27806
|
+
name: "learning_theme_history",
|
|
27807
|
+
description: "Get lifecycle history for one durable theme",
|
|
27808
|
+
method: "GET",
|
|
27809
|
+
path: "/learning/entities/:entityId/themes/:themeId/history",
|
|
27810
|
+
destructive: false
|
|
27811
|
+
},
|
|
27812
|
+
{
|
|
27813
|
+
name: "learning_noise_get",
|
|
27814
|
+
description: "Get the noise bucket for one trace signal in one snapshot",
|
|
27815
|
+
method: "GET",
|
|
27816
|
+
path: "/learning/entities/:entityId/noise",
|
|
27817
|
+
destructive: false
|
|
27818
|
+
},
|
|
27819
|
+
{
|
|
27820
|
+
name: "learning_noise_examples",
|
|
27821
|
+
description: "List trace examples for the noise bucket in one snapshot",
|
|
27822
|
+
method: "GET",
|
|
27823
|
+
path: "/learning/entities/:entityId/noise/examples",
|
|
27824
|
+
destructive: false
|
|
27825
|
+
}
|
|
27826
|
+
];
|
|
27827
|
+
//#endregion
|
|
27828
|
+
//#region src/server/mastra-api-mcp-server.ts
|
|
27829
|
+
var MastraApiRequester = class {
|
|
27830
|
+
options;
|
|
27831
|
+
constructor(options) {
|
|
27832
|
+
this.options = options;
|
|
27833
|
+
}
|
|
27834
|
+
async getSchemaManifest() {
|
|
27835
|
+
const value = await this.request({
|
|
27836
|
+
method: "GET",
|
|
27837
|
+
path: "/system/api-schema",
|
|
27838
|
+
pathParamSchema: void 0,
|
|
27839
|
+
queryParamSchema: void 0,
|
|
27840
|
+
bodySchema: void 0
|
|
27841
|
+
}, {});
|
|
27842
|
+
if (!isRecord(value) || value.version !== 1 || !Array.isArray(value.routes)) throw new Error("The Mastra server returned an invalid API schema manifest. Confirm that the target server supports GET /api/system/api-schema.");
|
|
27843
|
+
const routes = value.routes.filter(isApiSchemaRoute);
|
|
27844
|
+
if (routes.length !== value.routes.length) throw new Error("The Mastra server API schema manifest contains an invalid route definition.");
|
|
27845
|
+
return routes;
|
|
27846
|
+
}
|
|
27847
|
+
async request(route, input, authInfo, requestSignal) {
|
|
27848
|
+
const pathParams = schemaPropertyNames(route.pathParamSchema);
|
|
27849
|
+
const queryParams = new Set(schemaPropertyNames(route.queryParamSchema));
|
|
27850
|
+
const bodyParams = new Set(schemaPropertyNames(route.bodySchema));
|
|
27851
|
+
const remainingInput = { ...input };
|
|
27852
|
+
let path = route.path;
|
|
27853
|
+
for (const name of pathParams) {
|
|
27854
|
+
path = path.replace(`:${name}`, encodeURIComponent(remainingInput[name]));
|
|
27855
|
+
delete remainingInput[name];
|
|
27856
|
+
}
|
|
27857
|
+
const url = new URL(joinUrl(this.options.baseUrl, this.options.apiPrefix, path));
|
|
27858
|
+
const body = {};
|
|
27859
|
+
for (const [name, value] of Object.entries(remainingInput)) {
|
|
27860
|
+
if (value === void 0) continue;
|
|
27861
|
+
if (route.method === "GET" || queryParams.has(name) && !bodyParams.has(name)) {
|
|
27862
|
+
if (value === null) continue;
|
|
27863
|
+
url.searchParams.set(name, typeof value === "object" ? JSON.stringify(value) : String(value));
|
|
27864
|
+
} else body[name] = value;
|
|
27865
|
+
}
|
|
27866
|
+
const headers = new Headers(this.options.headers);
|
|
27867
|
+
headers.set("accept", "application/json");
|
|
27868
|
+
const callerToken = getAuthToken(authInfo);
|
|
27869
|
+
if (callerToken) headers.set("authorization", `Bearer ${callerToken}`);
|
|
27870
|
+
const controller = new AbortController();
|
|
27871
|
+
const timeout = setTimeout(() => controller.abort(/* @__PURE__ */ new Error("request timed out")), this.options.timeoutMs);
|
|
27872
|
+
const abortRequest = () => controller.abort(requestSignal?.reason);
|
|
27873
|
+
if (requestSignal?.aborted) abortRequest();
|
|
27874
|
+
else requestSignal?.addEventListener("abort", abortRequest, { once: true });
|
|
27875
|
+
try {
|
|
27876
|
+
const hasBody = route.method !== "GET" && route.bodySchema !== void 0;
|
|
27877
|
+
if (hasBody) headers.set("content-type", "application/json");
|
|
27878
|
+
const response = await this.options.fetch(url, {
|
|
27879
|
+
method: route.method,
|
|
27880
|
+
headers,
|
|
27881
|
+
signal: controller.signal,
|
|
27882
|
+
...hasBody ? { body: JSON.stringify(body) } : {}
|
|
27883
|
+
});
|
|
27884
|
+
const responseBody = await readResponseBody(response);
|
|
27885
|
+
if (!response.ok) {
|
|
27886
|
+
const detail = getErrorDetail(responseBody);
|
|
27887
|
+
throw new Error(`Mastra API request ${route.method} ${route.path} failed with status ${response.status}${detail ? `: ${detail}` : "."}`);
|
|
27888
|
+
}
|
|
27889
|
+
return responseBody;
|
|
27890
|
+
} catch (error) {
|
|
27891
|
+
if (controller.signal.aborted) {
|
|
27892
|
+
if (requestSignal?.aborted) throw new Error(`Mastra API request ${route.method} ${route.path} was canceled.`, { cause: error });
|
|
27893
|
+
throw new Error(`Mastra API request ${route.method} ${route.path} timed out after ${this.options.timeoutMs}ms.`, { cause: error });
|
|
27894
|
+
}
|
|
27895
|
+
if (error instanceof Error && error.message.startsWith("Mastra API request ")) throw error;
|
|
27896
|
+
throw new Error(`Could not reach the Mastra server at ${this.options.baseUrl}. Check the server URL and network access.`, { cause: error });
|
|
27897
|
+
} finally {
|
|
27898
|
+
clearTimeout(timeout);
|
|
27899
|
+
requestSignal?.removeEventListener("abort", abortRequest);
|
|
27900
|
+
}
|
|
27901
|
+
}
|
|
27902
|
+
};
|
|
27903
|
+
/**
|
|
27904
|
+
* An MCP server that exposes the Mastra API CLI operations from a remote Mastra server.
|
|
27905
|
+
*
|
|
27906
|
+
* The factory reads the target server's schema manifest, registers the CLI operations
|
|
27907
|
+
* supported by that server, and uses the route schemas as MCP tool input schemas.
|
|
27908
|
+
*/
|
|
27909
|
+
var MastraApiMCPServer = class MastraApiMCPServer extends MCPServer {
|
|
27910
|
+
constructor(options, tools) {
|
|
27911
|
+
super({
|
|
27912
|
+
id: options.id ?? "mastra-api",
|
|
27913
|
+
name: options.name ?? "Mastra Server",
|
|
27914
|
+
version: options.version ?? "1.0.0",
|
|
27915
|
+
description: "Inspect and operate a Mastra server.",
|
|
27916
|
+
instructions: "Inspect resources before using them. Pass tool input inside the data field for tool_execute and mcp_tool_execute. Ask for confirmation before calling a tool marked as destructive.",
|
|
27917
|
+
protocolVersion: "2026-07-28",
|
|
27918
|
+
tools
|
|
27919
|
+
});
|
|
27920
|
+
}
|
|
27921
|
+
/** Creates a stateless MCP server for the target Mastra server. */
|
|
27922
|
+
static async create(options) {
|
|
27923
|
+
const requester = new MastraApiRequester(normalizeOptions(options));
|
|
27924
|
+
const tools = createApiTools(await requester.getSchemaManifest(), requester);
|
|
27925
|
+
if (Object.keys(tools).length === 0) throw new Error("The target Mastra server does not support any of the MCP server operations.");
|
|
27926
|
+
return new MastraApiMCPServer(options, tools);
|
|
27927
|
+
}
|
|
27928
|
+
};
|
|
27929
|
+
function createApiTools(routes, requester) {
|
|
27930
|
+
const tools = {};
|
|
27931
|
+
for (const operation of MASTRA_API_OPERATIONS) {
|
|
27932
|
+
const primaryRoute = routes.find((candidate) => candidate.method === operation.method && candidate.path === operation.path);
|
|
27933
|
+
const verboseRoute = "verbosePath" in operation ? routes.find((candidate) => candidate.method === operation.method && candidate.path === operation.verbosePath) : void 0;
|
|
27934
|
+
const route = primaryRoute ?? verboseRoute;
|
|
27935
|
+
if (!route) continue;
|
|
27936
|
+
const readOnly = operation.method === "GET";
|
|
27937
|
+
tools[operation.name] = (0, _mastra_core_tools.createTool)({
|
|
27938
|
+
id: operation.name,
|
|
27939
|
+
description: operation.description,
|
|
27940
|
+
inputSchema: (0, _mastra_core_schema.toStandardSchema)(mergeInputSchemas(route, primaryRoute !== void 0 && verboseRoute !== void 0)),
|
|
27941
|
+
mcp: { annotations: {
|
|
27942
|
+
title: operation.description,
|
|
27943
|
+
readOnlyHint: readOnly,
|
|
27944
|
+
destructiveHint: operation.destructive,
|
|
27945
|
+
idempotentHint: readOnly || operation.method === "DELETE",
|
|
27946
|
+
openWorldHint: true
|
|
27947
|
+
} },
|
|
27948
|
+
execute: async (input, context) => {
|
|
27949
|
+
let requestInput = input;
|
|
27950
|
+
let selectedRoute = route;
|
|
27951
|
+
if (primaryRoute && verboseRoute) {
|
|
27952
|
+
const { verbose, ...inputWithoutVerbose } = input;
|
|
27953
|
+
requestInput = inputWithoutVerbose;
|
|
27954
|
+
if (verbose === true) selectedRoute = verboseRoute;
|
|
27955
|
+
}
|
|
27956
|
+
return requester.request(selectedRoute, requestInput, context.mcp?.extra.authInfo ?? getRequestAuthInfo(context.requestContext), context.abortSignal ?? context.mcp?.extra.signal);
|
|
27957
|
+
}
|
|
27958
|
+
});
|
|
27959
|
+
}
|
|
27960
|
+
return tools;
|
|
27961
|
+
}
|
|
27962
|
+
function normalizeOptions(options) {
|
|
27963
|
+
let url;
|
|
27964
|
+
try {
|
|
27965
|
+
url = new URL(options.url);
|
|
27966
|
+
} catch (error) {
|
|
27967
|
+
throw new Error("The Mastra server URL must be a valid absolute URL.", { cause: error });
|
|
27968
|
+
}
|
|
27969
|
+
if (url.protocol !== "http:" && url.protocol !== "https:") throw new Error("The Mastra server URL must use HTTP or HTTPS.");
|
|
27970
|
+
if (url.username || url.password) throw new Error("The Mastra server URL cannot contain credentials. Use the headers option for authentication.");
|
|
27971
|
+
if (url.search || url.hash) throw new Error("The Mastra server URL cannot contain a query string or fragment.");
|
|
27972
|
+
const apiPrefix = normalizeApiPrefix(options.apiPrefix ?? "/api");
|
|
27973
|
+
const timeoutMs = options.timeoutMs ?? 12e4;
|
|
27974
|
+
if (!Number.isSafeInteger(timeoutMs) || timeoutMs <= 0) throw new Error("The request timeout must be a positive integer in milliseconds.");
|
|
27975
|
+
return {
|
|
27976
|
+
baseUrl: url.toString().replace(/\/$/, ""),
|
|
27977
|
+
apiPrefix,
|
|
27978
|
+
headers: { ...options.headers },
|
|
27979
|
+
timeoutMs,
|
|
27980
|
+
fetch: options.fetch ?? globalThis.fetch
|
|
27981
|
+
};
|
|
27982
|
+
}
|
|
27983
|
+
function normalizeApiPrefix(value) {
|
|
27984
|
+
if (value.includes("..") || value.includes("?") || value.includes("#")) throw new Error("The Mastra API prefix cannot contain \"..\", a query string, or a fragment.");
|
|
27985
|
+
let start = 0;
|
|
27986
|
+
let end = value.length;
|
|
27987
|
+
while (start < end && value[start] === "/") start++;
|
|
27988
|
+
while (end > start && value[end - 1] === "/") end--;
|
|
27989
|
+
return start === end ? "" : `/${value.slice(start, end)}`;
|
|
27990
|
+
}
|
|
27991
|
+
function joinUrl(baseUrl, apiPrefix, path) {
|
|
27992
|
+
const normalizedPath = path.startsWith("/") ? path : `/${path}`;
|
|
27993
|
+
if (!apiPrefix || baseUrl.endsWith(apiPrefix)) return `${baseUrl}${normalizedPath}`;
|
|
27994
|
+
return `${baseUrl}${apiPrefix}${normalizedPath}`;
|
|
27995
|
+
}
|
|
27996
|
+
function mergeInputSchemas(route, supportsVerbose = false) {
|
|
27997
|
+
const definitions = {};
|
|
27998
|
+
const schemas = [
|
|
27999
|
+
"pathParamSchema",
|
|
28000
|
+
"queryParamSchema",
|
|
28001
|
+
"bodySchema"
|
|
28002
|
+
].flatMap((key) => {
|
|
28003
|
+
const source = route[key];
|
|
28004
|
+
if (!isRecord(source)) return [];
|
|
28005
|
+
const schema = relocateSchemaReferences(source, `#/definitions/${key}`);
|
|
28006
|
+
definitions[key] = schema;
|
|
28007
|
+
return [schema];
|
|
28008
|
+
});
|
|
28009
|
+
const properties = {};
|
|
28010
|
+
const pathParams = new Set(schemaPropertyNames(route.pathParamSchema));
|
|
28011
|
+
const required = new Set(pathParams);
|
|
28012
|
+
let allowsAdditionalProperties = false;
|
|
28013
|
+
for (const schema of schemas) {
|
|
28014
|
+
if (isRecord(schema.properties)) for (const [name, property] of Object.entries(schema.properties)) properties[name] = pathParams.has(name) && Object.hasOwn(properties, name) ? { allOf: [properties[name], property] } : property;
|
|
28015
|
+
if (Array.isArray(schema.required)) {
|
|
28016
|
+
for (const name of schema.required) if (typeof name === "string") required.add(name);
|
|
28017
|
+
}
|
|
28018
|
+
if (schema.additionalProperties === true || isRecord(schema.additionalProperties)) allowsAdditionalProperties = true;
|
|
28019
|
+
}
|
|
28020
|
+
if (supportsVerbose) properties.verbose = {
|
|
28021
|
+
type: "boolean",
|
|
28022
|
+
description: "Return the full response instead of the lightweight response.",
|
|
28023
|
+
default: false
|
|
28024
|
+
};
|
|
28025
|
+
for (const name of pathParams) properties[name] = {
|
|
28026
|
+
type: "string",
|
|
28027
|
+
minLength: 1,
|
|
28028
|
+
allOf: [properties[name]]
|
|
28029
|
+
};
|
|
28030
|
+
return {
|
|
28031
|
+
type: "object",
|
|
28032
|
+
properties,
|
|
28033
|
+
required: [...required],
|
|
28034
|
+
additionalProperties: allowsAdditionalProperties,
|
|
28035
|
+
definitions
|
|
28036
|
+
};
|
|
28037
|
+
}
|
|
28038
|
+
function relocateSchemaReferences(value, root) {
|
|
28039
|
+
if (Array.isArray(value)) return value.map((item) => relocateSchemaReferences(item, root));
|
|
28040
|
+
if (!isRecord(value)) return value;
|
|
28041
|
+
return Object.fromEntries(Object.entries(value).map(([key, child]) => [key, key === "$ref" && typeof child === "string" && (child === "#" || child.startsWith("#/")) ? `${root}${child.slice(1)}` : relocateSchemaReferences(child, root)]));
|
|
28042
|
+
}
|
|
28043
|
+
function schemaPropertyNames(schema) {
|
|
28044
|
+
return isRecord(schema?.properties) ? Object.keys(schema.properties) : [];
|
|
28045
|
+
}
|
|
28046
|
+
function isApiSchemaRoute(value) {
|
|
28047
|
+
if (!isRecord(value) || typeof value.method !== "string" || typeof value.path !== "string") return false;
|
|
28048
|
+
return [
|
|
28049
|
+
"pathParamSchema",
|
|
28050
|
+
"queryParamSchema",
|
|
28051
|
+
"bodySchema"
|
|
28052
|
+
].every((key) => value[key] === void 0 || isRecord(value[key]));
|
|
28053
|
+
}
|
|
28054
|
+
function isRecord(value) {
|
|
28055
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
28056
|
+
}
|
|
28057
|
+
function getAuthToken(authInfo) {
|
|
28058
|
+
if (!isRecord(authInfo)) return void 0;
|
|
28059
|
+
return typeof authInfo.token === "string" && authInfo.token.length > 0 ? authInfo.token : void 0;
|
|
28060
|
+
}
|
|
28061
|
+
function getRequestAuthInfo(requestContext) {
|
|
28062
|
+
const authInfo = requestContext?.get("authInfo");
|
|
28063
|
+
if (authInfo !== void 0) return authInfo;
|
|
28064
|
+
const token = requestContext?.get(_mastra_core_request_context.MASTRA_AUTH_TOKEN_KEY);
|
|
28065
|
+
return typeof token === "string" && token.length > 0 ? { token } : void 0;
|
|
28066
|
+
}
|
|
28067
|
+
async function readResponseBody(response) {
|
|
28068
|
+
const text = await response.text();
|
|
28069
|
+
if (!text) return null;
|
|
28070
|
+
try {
|
|
28071
|
+
return JSON.parse(text);
|
|
28072
|
+
} catch {
|
|
28073
|
+
return text;
|
|
28074
|
+
}
|
|
28075
|
+
}
|
|
28076
|
+
function getErrorDetail(body) {
|
|
28077
|
+
if (typeof body === "string") return body.slice(0, 500);
|
|
28078
|
+
if (!isRecord(body)) return void 0;
|
|
28079
|
+
const error = isRecord(body.error) ? body.error : body;
|
|
28080
|
+
if (typeof error.message === "string") return error.message.slice(0, 500);
|
|
28081
|
+
return JSON.stringify(body).slice(0, 500);
|
|
28082
|
+
}
|
|
28083
|
+
//#endregion
|
|
27076
28084
|
//#region src/server/oauth-middleware.ts
|
|
27077
28085
|
/**
|
|
27078
28086
|
* Creates an OAuth middleware function for protecting MCP server endpoints.
|
|
@@ -27327,6 +28335,7 @@ exports.MCPOAuthClientProvider = MCPOAuthClientProvider;
|
|
|
27327
28335
|
exports.MCPServer = MCPServer;
|
|
27328
28336
|
exports.MCP_CALL_TOOL_CONTENT = MCP_CALL_TOOL_CONTENT;
|
|
27329
28337
|
exports.MCP_CALL_TOOL_META = MCP_CALL_TOOL_META;
|
|
28338
|
+
exports.MastraApiMCPServer = MastraApiMCPServer;
|
|
27330
28339
|
Object.defineProperty(exports, "UnauthorizedError", {
|
|
27331
28340
|
enumerable: true,
|
|
27332
28341
|
get: function() {
|