@mastra/mcp 2.1.0-alpha.0 → 2.1.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/dist/client/client.d.ts.map +1 -1
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/index.cjs +107 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +107 -10
- package/dist/index.js.map +1 -1
- package/dist/server/server.d.ts +2 -1
- package/dist/server/server.d.ts.map +1 -1
- package/dist/shared/json-schema-dialect.d.ts +19 -0
- package/dist/shared/json-schema-dialect.d.ts.map +1 -0
- package/package.json +9 -9
package/dist/index.js
CHANGED
|
@@ -22216,6 +22216,90 @@ function trimStartOfStream() {
|
|
|
22216
22216
|
}
|
|
22217
22217
|
require_json_schema_traverse();
|
|
22218
22218
|
//#endregion
|
|
22219
|
+
//#region src/shared/json-schema-dialect.ts
|
|
22220
|
+
const JSON_SCHEMA_2020_12 = "https://json-schema.org/draft/2020-12/schema";
|
|
22221
|
+
const JSON_SCHEMA_2019_09 = /^https?:\/\/json-schema\.org\/draft\/2019-09\/schema#?$/;
|
|
22222
|
+
/** Keywords whose value is a subschema (`items` may also be an array of subschemas). */
|
|
22223
|
+
const SCHEMA_KEYWORDS = /* @__PURE__ */ new Set([
|
|
22224
|
+
"items",
|
|
22225
|
+
"additionalItems",
|
|
22226
|
+
"contains",
|
|
22227
|
+
"additionalProperties",
|
|
22228
|
+
"propertyNames",
|
|
22229
|
+
"unevaluatedItems",
|
|
22230
|
+
"unevaluatedProperties",
|
|
22231
|
+
"if",
|
|
22232
|
+
"then",
|
|
22233
|
+
"else",
|
|
22234
|
+
"not"
|
|
22235
|
+
]);
|
|
22236
|
+
/** Keywords whose value is an array of subschemas. */
|
|
22237
|
+
const SCHEMA_ARRAY_KEYWORDS = /* @__PURE__ */ new Set([
|
|
22238
|
+
"allOf",
|
|
22239
|
+
"anyOf",
|
|
22240
|
+
"oneOf"
|
|
22241
|
+
]);
|
|
22242
|
+
/** Keywords whose values map arbitrary names to subschemas. */
|
|
22243
|
+
const SCHEMA_MAP_KEYWORDS = /* @__PURE__ */ new Set([
|
|
22244
|
+
"properties",
|
|
22245
|
+
"patternProperties",
|
|
22246
|
+
"$defs",
|
|
22247
|
+
"definitions",
|
|
22248
|
+
"dependentSchemas"
|
|
22249
|
+
]);
|
|
22250
|
+
const MAX_JSON_SCHEMA_NODES = 1e4;
|
|
22251
|
+
var Unconvertible = class extends Error {};
|
|
22252
|
+
/**
|
|
22253
|
+
* Converts a 2019-09 schema (e.g. from zod v3) into 2020-12 form. Tuples are the
|
|
22254
|
+
* only structural difference handled: array-form `items` becomes `prefixItems`,
|
|
22255
|
+
* and `additionalItems` becomes `items`.
|
|
22256
|
+
*
|
|
22257
|
+
* Returns `undefined` when the schema does not declare 2019-09, or relies on
|
|
22258
|
+
* features this conversion cannot preserve (`$recursiveRef`/`$recursiveAnchor`,
|
|
22259
|
+
* `$ref` pointers into tuple members, embedded `$schema` declarations,
|
|
22260
|
+
* `unevaluatedItems`, `prefixItems`, or `contentSchema`), or exceeds the depth/node limits.
|
|
22261
|
+
* Callers should then keep the original.
|
|
22262
|
+
*/
|
|
22263
|
+
function toJsonSchema2020(schema) {
|
|
22264
|
+
if (!schema.$schema || !JSON_SCHEMA_2019_09.test(schema.$schema)) return void 0;
|
|
22265
|
+
try {
|
|
22266
|
+
return {
|
|
22267
|
+
...rewrite(schema, 0, { nodes: 0 }, true),
|
|
22268
|
+
$schema: JSON_SCHEMA_2020_12
|
|
22269
|
+
};
|
|
22270
|
+
} catch (error) {
|
|
22271
|
+
if (error instanceof Unconvertible) return void 0;
|
|
22272
|
+
throw error;
|
|
22273
|
+
}
|
|
22274
|
+
}
|
|
22275
|
+
function checkBudget(depth, budget) {
|
|
22276
|
+
if (depth > 128 || ++budget.nodes > 1e4) throw new Unconvertible();
|
|
22277
|
+
}
|
|
22278
|
+
/** Rewrites a value in a subschema position. Only known schema keywords are walked; everything else is copied as-is. */
|
|
22279
|
+
function rewrite(schema, depth, budget, isRoot = false) {
|
|
22280
|
+
if (!schema || typeof schema !== "object" || Array.isArray(schema)) return schema;
|
|
22281
|
+
checkBudget(depth, budget);
|
|
22282
|
+
const out = { ...schema };
|
|
22283
|
+
if (!isRoot && "$schema" in out) throw new Unconvertible();
|
|
22284
|
+
if ("$recursiveRef" in out || "$recursiveAnchor" in out) throw new Unconvertible();
|
|
22285
|
+
if ("unevaluatedItems" in out || "prefixItems" in out || "contentSchema" in out) throw new Unconvertible();
|
|
22286
|
+
if (typeof out.$ref === "string" && /\/(items\/\d+|additionalItems)(\/|$)/.test(out.$ref)) throw new Unconvertible();
|
|
22287
|
+
for (const [key, child] of Object.entries(out)) if (SCHEMA_KEYWORDS.has(key)) out[key] = Array.isArray(child) ? (checkBudget(depth + 1, budget), child.map((item) => rewrite(item, depth + 2, budget))) : rewrite(child, depth + 1, budget);
|
|
22288
|
+
else if (SCHEMA_ARRAY_KEYWORDS.has(key) && Array.isArray(child)) {
|
|
22289
|
+
checkBudget(depth + 1, budget);
|
|
22290
|
+
out[key] = child.map((item) => rewrite(item, depth + 2, budget));
|
|
22291
|
+
} else if (SCHEMA_MAP_KEYWORDS.has(key) && child && typeof child === "object" && !Array.isArray(child)) {
|
|
22292
|
+
checkBudget(depth + 1, budget);
|
|
22293
|
+
out[key] = Object.fromEntries(Object.entries(child).map(([name, sub]) => [name, rewrite(sub, depth + 2, budget)]));
|
|
22294
|
+
}
|
|
22295
|
+
if (!Array.isArray(out.items)) return out;
|
|
22296
|
+
out.prefixItems = out.items;
|
|
22297
|
+
if ("additionalItems" in out) out.items = out.additionalItems;
|
|
22298
|
+
else delete out.items;
|
|
22299
|
+
delete out.additionalItems;
|
|
22300
|
+
return out;
|
|
22301
|
+
}
|
|
22302
|
+
//#endregion
|
|
22219
22303
|
//#region src/shared/mastra-tool-meta.ts
|
|
22220
22304
|
const MASTRA_META_KEY = "mastra";
|
|
22221
22305
|
const STRICT_META_KEY = "strict";
|
|
@@ -22870,9 +22954,6 @@ async function fetchFollowingAllowedRedirects(fetchImpl, url, init, allowedHosts
|
|
|
22870
22954
|
//#endregion
|
|
22871
22955
|
//#region src/client/client.ts
|
|
22872
22956
|
const DEFAULT_SERVER_CONNECT_TIMEOUT_MSEC = 3e3;
|
|
22873
|
-
const JSON_SCHEMA_2020_12 = "https://json-schema.org/draft/2020-12/schema";
|
|
22874
|
-
const MAX_JSON_SCHEMA_DEPTH = 128;
|
|
22875
|
-
const MAX_JSON_SCHEMA_NODES = 1e4;
|
|
22876
22957
|
/**
|
|
22877
22958
|
* Bounds the work a validator can be asked to do for an untrusted tool catalogue.
|
|
22878
22959
|
* Only schema-bearing keywords are walked, so deeply nested annotation data such as
|
|
@@ -22919,8 +23000,8 @@ function getJsonSchemaComplexityError(schema) {
|
|
|
22919
23000
|
if (value === null || typeof value !== "object" || Array.isArray(value) || seen.has(value)) continue;
|
|
22920
23001
|
seen.add(value);
|
|
22921
23002
|
nodes += 1;
|
|
22922
|
-
if (depth >
|
|
22923
|
-
if (nodes >
|
|
23003
|
+
if (depth > 128) return `JSON Schema exceeds the maximum depth of 128`;
|
|
23004
|
+
if (nodes > 1e4) return `JSON Schema exceeds the maximum node count of ${MAX_JSON_SCHEMA_NODES}`;
|
|
22924
23005
|
const record = value;
|
|
22925
23006
|
for (const keyword of schemaMapKeywords) {
|
|
22926
23007
|
const schemas = record[keyword];
|
|
@@ -22942,12 +23023,24 @@ function getJsonSchemaComplexityError(schema) {
|
|
|
22942
23023
|
});
|
|
22943
23024
|
}
|
|
22944
23025
|
}
|
|
22945
|
-
|
|
23026
|
+
const SUPPORTED_DIALECTS = /* @__PURE__ */ new Set([
|
|
23027
|
+
JSON_SCHEMA_2020_12,
|
|
23028
|
+
`${JSON_SCHEMA_2020_12}#`,
|
|
23029
|
+
"http://json-schema.org/draft-07/schema",
|
|
23030
|
+
"http://json-schema.org/draft-07/schema#"
|
|
23031
|
+
]);
|
|
23032
|
+
/**
|
|
23033
|
+
* MCP 2026-07-28 schemas default to JSON Schema 2020-12 when they declare no dialect.
|
|
23034
|
+
* 2019-09 schemas (e.g. from zod v3 servers) are converted to 2020-12 when that can be done
|
|
23035
|
+
* faithfully, so tool calls are not rejected before they run.
|
|
23036
|
+
*/
|
|
22946
23037
|
function withDefaultDialect(schema) {
|
|
22947
|
-
|
|
23038
|
+
if (!schema.$schema) return {
|
|
22948
23039
|
...schema,
|
|
22949
23040
|
$schema: JSON_SCHEMA_2020_12
|
|
22950
23041
|
};
|
|
23042
|
+
if (SUPPORTED_DIALECTS.has(schema.$schema)) return schema;
|
|
23043
|
+
return toJsonSchema2020(schema) ?? schema;
|
|
22951
23044
|
}
|
|
22952
23045
|
const DEFAULT_INSTRUCTIONS_MAX_LENGTH = 512;
|
|
22953
23046
|
const DEFAULT_SERVER_LOG_LEVEL = "info";
|
|
@@ -26291,14 +26384,18 @@ var MCPServer = class extends MCPServerBase {
|
|
|
26291
26384
|
/**
|
|
26292
26385
|
* Converts a tool schema to JSON Schema 2020-12, the dialect MCP 2026-07-28
|
|
26293
26386
|
* assumes when none is declared. The dialect declaration is kept so validators
|
|
26294
|
-
* that dispatch on `$schema` pick the same draft on both sides.
|
|
26387
|
+
* that dispatch on `$schema` pick the same draft on both sides. Some vendors
|
|
26388
|
+
* (e.g. zod v3) emit 2019-09 for this target, so it is rewritten to 2020-12.
|
|
26295
26389
|
*/
|
|
26296
26390
|
jsonSchema(schema, options) {
|
|
26297
26391
|
if (!schema) return void 0;
|
|
26298
|
-
|
|
26392
|
+
if (!isStandardSchemaWithJSON(schema)) return schema.jsonSchema ?? schema;
|
|
26393
|
+
const converted = standardSchemaToJSONSchema(schema, {
|
|
26299
26394
|
...options,
|
|
26300
26395
|
target: "draft-2020-12"
|
|
26301
|
-
})
|
|
26396
|
+
});
|
|
26397
|
+
if (!converted.$schema || converted.$schema === "https://json-schema.org/draft/2020-12/schema") return converted;
|
|
26398
|
+
return toJsonSchema2020(converted) ?? converted;
|
|
26302
26399
|
}
|
|
26303
26400
|
addTools(tools) {
|
|
26304
26401
|
const converted = this.convertTools(tools);
|