@mastra/mcp 2.8.0-alpha.2 → 2.9.0-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 +193 -2
- package/dist/docs/references/docs-connections-mcp.md +99 -0
- package/dist/docs/references/reference-tools-mcp-client.md +4 -0
- package/dist/index.cjs +202 -126
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +203 -127
- package/dist/index.js.map +1 -1
- package/dist/server/request.d.ts +3 -1
- package/dist/server/request.d.ts.map +1 -1
- package/dist/server/server.d.ts.map +1 -1
- package/dist/server/tasks/workflow-runs.d.ts +7 -0
- package/dist/server/tasks/workflow-runs.d.ts.map +1 -1
- package/package.json +10 -10
package/dist/index.cjs
CHANGED
|
@@ -56,101 +56,6 @@ let _mastra_core_signals = require("@mastra/core/signals");
|
|
|
56
56
|
// src/client/types.ts
|
|
57
57
|
/** The current protocol revision; the one `/mcp` servers speak. */
|
|
58
58
|
const MCP_CLIENT_PROTOCOL_VERSION = "2026-07-28";
|
|
59
|
-
// ../schema-compat/dist/json-schema-traverse-D0CId4oM.js
|
|
60
|
-
var __create$1 = Object.create;
|
|
61
|
-
var __defProp$2 = Object.defineProperty;
|
|
62
|
-
var __getOwnPropDesc$1 = Object.getOwnPropertyDescriptor;
|
|
63
|
-
var __getOwnPropNames$1 = Object.getOwnPropertyNames;
|
|
64
|
-
var __getProtoOf$1 = Object.getPrototypeOf;
|
|
65
|
-
var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
|
|
66
|
-
var __commonJSMin$1 = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod, mod.exports), cb = null), mod.exports);
|
|
67
|
-
var __copyProps$1 = (to, from, except, desc) => {
|
|
68
|
-
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames$1(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
69
|
-
key = keys[i];
|
|
70
|
-
if (!__hasOwnProp$1.call(to, key) && key !== except) __defProp$2(to, key, {
|
|
71
|
-
get: ((k) => from[k]).bind(null, key),
|
|
72
|
-
enumerable: !(desc = __getOwnPropDesc$1(from, key)) || desc.enumerable
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
return to;
|
|
76
|
-
};
|
|
77
|
-
var __toESM$1 = (mod, isNodeMode, target) => (target = mod != null ? __create$1(__getProtoOf$1(mod)) : {}, __copyProps$1(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp$1.call(mod, "default") ? __defProp$2(target, "default", {
|
|
78
|
-
value: mod,
|
|
79
|
-
enumerable: true
|
|
80
|
-
}) : target, mod));
|
|
81
|
-
var require_json_schema_traverse = /* @__PURE__ */ __commonJSMin$1(((exports, module) => {
|
|
82
|
-
var traverse = module.exports = function(schema, opts, cb) {
|
|
83
|
-
if (typeof opts == "function") {
|
|
84
|
-
cb = opts;
|
|
85
|
-
opts = {};
|
|
86
|
-
}
|
|
87
|
-
cb = opts.cb || cb;
|
|
88
|
-
var pre = typeof cb == "function" ? cb : cb.pre || function() {};
|
|
89
|
-
var post = cb.post || function() {};
|
|
90
|
-
_traverse(opts, pre, post, schema, "", schema);
|
|
91
|
-
};
|
|
92
|
-
traverse.keywords = {
|
|
93
|
-
additionalItems: true,
|
|
94
|
-
items: true,
|
|
95
|
-
contains: true,
|
|
96
|
-
additionalProperties: true,
|
|
97
|
-
propertyNames: true,
|
|
98
|
-
not: true,
|
|
99
|
-
if: true,
|
|
100
|
-
then: true,
|
|
101
|
-
else: true
|
|
102
|
-
};
|
|
103
|
-
traverse.arrayKeywords = {
|
|
104
|
-
items: true,
|
|
105
|
-
allOf: true,
|
|
106
|
-
anyOf: true,
|
|
107
|
-
oneOf: true
|
|
108
|
-
};
|
|
109
|
-
traverse.propsKeywords = {
|
|
110
|
-
$defs: true,
|
|
111
|
-
definitions: true,
|
|
112
|
-
properties: true,
|
|
113
|
-
patternProperties: true,
|
|
114
|
-
dependencies: true
|
|
115
|
-
};
|
|
116
|
-
traverse.skipKeywords = {
|
|
117
|
-
default: true,
|
|
118
|
-
enum: true,
|
|
119
|
-
const: true,
|
|
120
|
-
required: true,
|
|
121
|
-
maximum: true,
|
|
122
|
-
minimum: true,
|
|
123
|
-
exclusiveMaximum: true,
|
|
124
|
-
exclusiveMinimum: true,
|
|
125
|
-
multipleOf: true,
|
|
126
|
-
maxLength: true,
|
|
127
|
-
minLength: true,
|
|
128
|
-
pattern: true,
|
|
129
|
-
format: true,
|
|
130
|
-
maxItems: true,
|
|
131
|
-
minItems: true,
|
|
132
|
-
uniqueItems: true,
|
|
133
|
-
maxProperties: true,
|
|
134
|
-
minProperties: true
|
|
135
|
-
};
|
|
136
|
-
function _traverse(opts, pre, post, schema, jsonPtr, rootSchema, parentJsonPtr, parentKeyword, parentSchema, keyIndex) {
|
|
137
|
-
if (schema && typeof schema == "object" && !Array.isArray(schema)) {
|
|
138
|
-
pre(schema, jsonPtr, rootSchema, parentJsonPtr, parentKeyword, parentSchema, keyIndex);
|
|
139
|
-
for (var key in schema) {
|
|
140
|
-
var sch = schema[key];
|
|
141
|
-
if (Array.isArray(sch)) {
|
|
142
|
-
if (key in traverse.arrayKeywords) for (var i = 0; i < sch.length; i++) _traverse(opts, pre, post, sch[i], jsonPtr + "/" + key + "/" + i, rootSchema, jsonPtr, key, schema, i);
|
|
143
|
-
} else if (key in traverse.propsKeywords) {
|
|
144
|
-
if (sch && typeof sch == "object") for (var prop in sch) _traverse(opts, pre, post, sch[prop], jsonPtr + "/" + key + "/" + escapeJsonPtr(prop), rootSchema, jsonPtr, key, schema, prop);
|
|
145
|
-
} else if (key in traverse.keywords || opts.allKeys && !(key in traverse.skipKeywords)) _traverse(opts, pre, post, sch, jsonPtr + "/" + key, rootSchema, jsonPtr, key, schema);
|
|
146
|
-
}
|
|
147
|
-
post(schema, jsonPtr, rootSchema, parentJsonPtr, parentKeyword, parentSchema, keyIndex);
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
function escapeJsonPtr(str) {
|
|
151
|
-
return str.replace(/~/g, "~0").replace(/\//g, "~1");
|
|
152
|
-
}
|
|
153
|
-
}));
|
|
154
59
|
// ../schema-compat/dist/esm-BG70JlG8.js
|
|
155
60
|
const ignoreOverride$1 = Symbol("Let zodToJsonSchema decide on which parser to use");
|
|
156
61
|
const defaultOptions$1 = {
|
|
@@ -1356,6 +1261,101 @@ var AiSdkSchemaWrapper = class {
|
|
|
1356
1261
|
function toStandardSchema$2(schema) {
|
|
1357
1262
|
return new AiSdkSchemaWrapper(schema);
|
|
1358
1263
|
}
|
|
1264
|
+
// ../schema-compat/dist/json-schema-traverse-D0CId4oM.js
|
|
1265
|
+
var __create$1 = Object.create;
|
|
1266
|
+
var __defProp$2 = Object.defineProperty;
|
|
1267
|
+
var __getOwnPropDesc$1 = Object.getOwnPropertyDescriptor;
|
|
1268
|
+
var __getOwnPropNames$1 = Object.getOwnPropertyNames;
|
|
1269
|
+
var __getProtoOf$1 = Object.getPrototypeOf;
|
|
1270
|
+
var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
|
|
1271
|
+
var __commonJSMin$1 = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod, mod.exports), cb = null), mod.exports);
|
|
1272
|
+
var __copyProps$1 = (to, from, except, desc) => {
|
|
1273
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames$1(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
1274
|
+
key = keys[i];
|
|
1275
|
+
if (!__hasOwnProp$1.call(to, key) && key !== except) __defProp$2(to, key, {
|
|
1276
|
+
get: ((k) => from[k]).bind(null, key),
|
|
1277
|
+
enumerable: !(desc = __getOwnPropDesc$1(from, key)) || desc.enumerable
|
|
1278
|
+
});
|
|
1279
|
+
}
|
|
1280
|
+
return to;
|
|
1281
|
+
};
|
|
1282
|
+
var __toESM$1 = (mod, isNodeMode, target) => (target = mod != null ? __create$1(__getProtoOf$1(mod)) : {}, __copyProps$1(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp$1.call(mod, "default") ? __defProp$2(target, "default", {
|
|
1283
|
+
value: mod,
|
|
1284
|
+
enumerable: true
|
|
1285
|
+
}) : target, mod));
|
|
1286
|
+
var require_json_schema_traverse = /* @__PURE__ */ __commonJSMin$1(((exports, module) => {
|
|
1287
|
+
var traverse = module.exports = function(schema, opts, cb) {
|
|
1288
|
+
if (typeof opts == "function") {
|
|
1289
|
+
cb = opts;
|
|
1290
|
+
opts = {};
|
|
1291
|
+
}
|
|
1292
|
+
cb = opts.cb || cb;
|
|
1293
|
+
var pre = typeof cb == "function" ? cb : cb.pre || function() {};
|
|
1294
|
+
var post = cb.post || function() {};
|
|
1295
|
+
_traverse(opts, pre, post, schema, "", schema);
|
|
1296
|
+
};
|
|
1297
|
+
traverse.keywords = {
|
|
1298
|
+
additionalItems: true,
|
|
1299
|
+
items: true,
|
|
1300
|
+
contains: true,
|
|
1301
|
+
additionalProperties: true,
|
|
1302
|
+
propertyNames: true,
|
|
1303
|
+
not: true,
|
|
1304
|
+
if: true,
|
|
1305
|
+
then: true,
|
|
1306
|
+
else: true
|
|
1307
|
+
};
|
|
1308
|
+
traverse.arrayKeywords = {
|
|
1309
|
+
items: true,
|
|
1310
|
+
allOf: true,
|
|
1311
|
+
anyOf: true,
|
|
1312
|
+
oneOf: true
|
|
1313
|
+
};
|
|
1314
|
+
traverse.propsKeywords = {
|
|
1315
|
+
$defs: true,
|
|
1316
|
+
definitions: true,
|
|
1317
|
+
properties: true,
|
|
1318
|
+
patternProperties: true,
|
|
1319
|
+
dependencies: true
|
|
1320
|
+
};
|
|
1321
|
+
traverse.skipKeywords = {
|
|
1322
|
+
default: true,
|
|
1323
|
+
enum: true,
|
|
1324
|
+
const: true,
|
|
1325
|
+
required: true,
|
|
1326
|
+
maximum: true,
|
|
1327
|
+
minimum: true,
|
|
1328
|
+
exclusiveMaximum: true,
|
|
1329
|
+
exclusiveMinimum: true,
|
|
1330
|
+
multipleOf: true,
|
|
1331
|
+
maxLength: true,
|
|
1332
|
+
minLength: true,
|
|
1333
|
+
pattern: true,
|
|
1334
|
+
format: true,
|
|
1335
|
+
maxItems: true,
|
|
1336
|
+
minItems: true,
|
|
1337
|
+
uniqueItems: true,
|
|
1338
|
+
maxProperties: true,
|
|
1339
|
+
minProperties: true
|
|
1340
|
+
};
|
|
1341
|
+
function _traverse(opts, pre, post, schema, jsonPtr, rootSchema, parentJsonPtr, parentKeyword, parentSchema, keyIndex) {
|
|
1342
|
+
if (schema && typeof schema == "object" && !Array.isArray(schema)) {
|
|
1343
|
+
pre(schema, jsonPtr, rootSchema, parentJsonPtr, parentKeyword, parentSchema, keyIndex);
|
|
1344
|
+
for (var key in schema) {
|
|
1345
|
+
var sch = schema[key];
|
|
1346
|
+
if (Array.isArray(sch)) {
|
|
1347
|
+
if (key in traverse.arrayKeywords) for (var i = 0; i < sch.length; i++) _traverse(opts, pre, post, sch[i], jsonPtr + "/" + key + "/" + i, rootSchema, jsonPtr, key, schema, i);
|
|
1348
|
+
} else if (key in traverse.propsKeywords) {
|
|
1349
|
+
if (sch && typeof sch == "object") for (var prop in sch) _traverse(opts, pre, post, sch[prop], jsonPtr + "/" + key + "/" + escapeJsonPtr(prop), rootSchema, jsonPtr, key, schema, prop);
|
|
1350
|
+
} else if (key in traverse.keywords || opts.allKeys && !(key in traverse.skipKeywords)) _traverse(opts, pre, post, sch, jsonPtr + "/" + key, rootSchema, jsonPtr, key, schema);
|
|
1351
|
+
}
|
|
1352
|
+
post(schema, jsonPtr, rootSchema, parentJsonPtr, parentKeyword, parentSchema, keyIndex);
|
|
1353
|
+
}
|
|
1354
|
+
}
|
|
1355
|
+
function escapeJsonPtr(str) {
|
|
1356
|
+
return str.replace(/~/g, "~0").replace(/\//g, "~1");
|
|
1357
|
+
}
|
|
1358
|
+
}));
|
|
1359
1359
|
// ../schema-compat/dist/json-schema-BdCwqjfN.js
|
|
1360
1360
|
var require_code$1 = /* @__PURE__ */ __commonJSMin$1(((exports) => {
|
|
1361
1361
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -15977,6 +15977,50 @@ function runOutsideDatadogTraceScope(callback) {
|
|
|
15977
15977
|
if (!scope) return callback();
|
|
15978
15978
|
return scope.activate(null, callback);
|
|
15979
15979
|
}
|
|
15980
|
+
const LOGGABLE_ERROR_NAMES = /* @__PURE__ */ new Set([
|
|
15981
|
+
"Error",
|
|
15982
|
+
"TypeError",
|
|
15983
|
+
"RangeError",
|
|
15984
|
+
"SyntaxError",
|
|
15985
|
+
"AbortError",
|
|
15986
|
+
"TimeoutError",
|
|
15987
|
+
"McpError",
|
|
15988
|
+
"ProtocolError",
|
|
15989
|
+
"SdkError",
|
|
15990
|
+
"SdkHttpError",
|
|
15991
|
+
"SseError",
|
|
15992
|
+
"StreamableHTTPError",
|
|
15993
|
+
"UnauthorizedError",
|
|
15994
|
+
"OAuthError",
|
|
15995
|
+
"UnsupportedProtocolVersionError"
|
|
15996
|
+
]);
|
|
15997
|
+
const LOGGABLE_ERROR_CODES = /* @__PURE__ */ new Set([
|
|
15998
|
+
"ECONNRESET",
|
|
15999
|
+
"ECONNREFUSED",
|
|
16000
|
+
"ECONNABORTED",
|
|
16001
|
+
"ETIMEDOUT",
|
|
16002
|
+
"ENOTFOUND",
|
|
16003
|
+
"EPIPE",
|
|
16004
|
+
"EAI_AGAIN",
|
|
16005
|
+
"ABORT_ERR",
|
|
16006
|
+
"UND_ERR_SOCKET",
|
|
16007
|
+
"UND_ERR_CONNECT_TIMEOUT",
|
|
16008
|
+
"UND_ERR_HEADERS_TIMEOUT",
|
|
16009
|
+
"UND_ERR_BODY_TIMEOUT"
|
|
16010
|
+
]);
|
|
16011
|
+
/**
|
|
16012
|
+
* Names a tool-call failure for logs without its message: server error text can echo the submitted
|
|
16013
|
+
* arguments back (Issue #29318). The full error still reaches the caller.
|
|
16014
|
+
*/
|
|
16015
|
+
function errorKind(error) {
|
|
16016
|
+
if (error instanceof _mastra_core_error.MastraError) return error.id;
|
|
16017
|
+
if (error instanceof Error) {
|
|
16018
|
+
const name = LOGGABLE_ERROR_NAMES.has(error.name) ? error.name : "Error";
|
|
16019
|
+
const code = error.code;
|
|
16020
|
+
return typeof code === "number" || typeof code === "string" && LOGGABLE_ERROR_CODES.has(code) ? `${name} (${code})` : name;
|
|
16021
|
+
}
|
|
16022
|
+
return typeof error;
|
|
16023
|
+
}
|
|
15980
16024
|
/**
|
|
15981
16025
|
* Convert an MCP LoggingLevel to a logger method name that exists in our logger
|
|
15982
16026
|
*/
|
|
@@ -17123,10 +17167,7 @@ var InternalMastraMCPClient = class extends _mastra_core_base.MastraBase {
|
|
|
17123
17167
|
});
|
|
17124
17168
|
return res && finishToolCall(res);
|
|
17125
17169
|
}
|
|
17126
|
-
this.log("debug", `Executing tool: ${tool.name}`, {
|
|
17127
|
-
toolArgs: input,
|
|
17128
|
-
runId: context?.runId
|
|
17129
|
-
});
|
|
17170
|
+
this.log("debug", `Executing tool: ${tool.name}`, { runId: context?.runId });
|
|
17130
17171
|
const progressMeta = this.enableProgressTracking ? { progressToken: context?.runId || crypto.randomUUID() } : void 0;
|
|
17131
17172
|
const _meta = this.requestMeta({
|
|
17132
17173
|
...context?._meta,
|
|
@@ -17155,7 +17196,7 @@ var InternalMastraMCPClient = class extends _mastra_core_base.MastraBase {
|
|
|
17155
17196
|
const finishToolCall = async (res) => {
|
|
17156
17197
|
if (res.isError && this.onToolError === "throw") {
|
|
17157
17198
|
const errorText = extractToolErrorText(res.content);
|
|
17158
|
-
this.log("debug", `Tool reported an error: ${tool.name}
|
|
17199
|
+
this.log("debug", `Tool reported an error: ${tool.name}`);
|
|
17159
17200
|
throw new _mastra_core_error.MastraError({
|
|
17160
17201
|
id: "MCP_CLIENT_TOOL_EXECUTION_FAILED",
|
|
17161
17202
|
domain: _mastra_core_error.ErrorDomain.MCP,
|
|
@@ -17174,7 +17215,7 @@ var InternalMastraMCPClient = class extends _mastra_core_base.MastraBase {
|
|
|
17174
17215
|
const validationSchema = await getOutputValidationSchema();
|
|
17175
17216
|
const validation = (0, _mastra_core_tools.validateToolOutput)(validationSchema, res.structuredContent, tool.name);
|
|
17176
17217
|
if (validation.error) {
|
|
17177
|
-
this.log("debug", `Tool output failed schema validation: ${tool.name}`, {
|
|
17218
|
+
this.log("debug", `Tool output failed schema validation: ${tool.name}`, { issuePaths: (0, _mastra_core_tools.getValidationIssuePaths)(validation.error, validationSchema, "output") });
|
|
17178
17219
|
return validation.error;
|
|
17179
17220
|
}
|
|
17180
17221
|
}
|
|
@@ -17188,24 +17229,20 @@ var InternalMastraMCPClient = class extends _mastra_core_base.MastraBase {
|
|
|
17188
17229
|
return await executeToolCall();
|
|
17189
17230
|
} catch (e) {
|
|
17190
17231
|
if (!(e instanceof _mastra_core_error.MastraError && (e.id === "MCP_CLIENT_TOOL_EXECUTION_FAILED" || e.id.startsWith("MCP_CLIENT_TOOL_TASK_"))) && isReconnectableMCPError(e)) {
|
|
17191
|
-
this.log("debug", `Transport error detected for tool ${tool.name}, attempting reconnection...`, { error:
|
|
17232
|
+
this.log("debug", `Transport error detected for tool ${tool.name}, attempting reconnection...`, { error: errorKind(e) });
|
|
17192
17233
|
try {
|
|
17193
17234
|
await this.reconnectAfterTransportFailure(failedTransport, lifecycleGeneration);
|
|
17194
17235
|
this.log("debug", `Retrying tool ${tool.name} after reconnection...`);
|
|
17195
17236
|
return await executeToolCall();
|
|
17196
17237
|
} catch (reconnectError) {
|
|
17197
17238
|
this.log("error", `Reconnection or retry failed for tool ${tool.name}`, {
|
|
17198
|
-
originalError:
|
|
17199
|
-
reconnectError:
|
|
17200
|
-
toolArgs: input
|
|
17239
|
+
originalError: errorKind(e),
|
|
17240
|
+
reconnectError: errorKind(reconnectError)
|
|
17201
17241
|
});
|
|
17202
17242
|
throw reconnectError;
|
|
17203
17243
|
}
|
|
17204
17244
|
}
|
|
17205
|
-
this.log("error", `Error calling tool: ${tool.name}`, {
|
|
17206
|
-
error: e instanceof Error ? e.stack : JSON.stringify(e, null, 2),
|
|
17207
|
-
toolArgs: input
|
|
17208
|
-
});
|
|
17245
|
+
this.log("error", `Error calling tool: ${tool.name}`, { error: errorKind(e) });
|
|
17209
17246
|
throw e;
|
|
17210
17247
|
}
|
|
17211
17248
|
});
|
|
@@ -19007,7 +19044,7 @@ onListChanged: async (serverName, handler) => {
|
|
|
19007
19044
|
const errors = {};
|
|
19008
19045
|
const errorDetails = {};
|
|
19009
19046
|
const durations = {};
|
|
19010
|
-
const settled = await this.discoverAcrossServers((serverName) => this.getToolsForServer(serverName), {
|
|
19047
|
+
const settled = await this.discoverAcrossServers(async (serverName) => modelVisibleTools(await this.getToolsForServer(serverName)), {
|
|
19011
19048
|
errorId: "MCP_CLIENT_GET_TOOLS_FAILED",
|
|
19012
19049
|
logMessage: "Failed to list tools from server:"
|
|
19013
19050
|
}, options);
|
|
@@ -19062,7 +19099,7 @@ onListChanged: async (serverName, handler) => {
|
|
|
19062
19099
|
const errors = {};
|
|
19063
19100
|
const errorDetails = {};
|
|
19064
19101
|
const durations = {};
|
|
19065
|
-
const settled = await this.discoverAcrossServers((serverName) => this.getToolsForServer(serverName), {
|
|
19102
|
+
const settled = await this.discoverAcrossServers(async (serverName) => modelVisibleTools(await this.getToolsForServer(serverName)), {
|
|
19066
19103
|
errorId: "MCP_CLIENT_GET_TOOLSETS_FAILED",
|
|
19067
19104
|
logMessage: "Failed to list toolsets from server:"
|
|
19068
19105
|
}, options);
|
|
@@ -19126,7 +19163,7 @@ onListChanged: async (serverName, handler) => {
|
|
|
19126
19163
|
const errorDetails = {};
|
|
19127
19164
|
const durations = {};
|
|
19128
19165
|
const settled = await this.discoverAcrossServers(async (serverName) => {
|
|
19129
|
-
return (await this.getConnectedClientForServer(serverName)).toolDefinitions();
|
|
19166
|
+
return modelVisibleDefinitions(await (await this.getConnectedClientForServer(serverName)).toolDefinitions());
|
|
19130
19167
|
}, {
|
|
19131
19168
|
errorId: "MCP_CLIENT_GET_TOOL_DEFINITIONS_FAILED",
|
|
19132
19169
|
logMessage: "Failed to list tool definitions from server:"
|
|
@@ -19195,7 +19232,7 @@ onListChanged: async (serverName, handler) => {
|
|
|
19195
19232
|
this.logger.warn("Skipping cached MCP tool definitions for a server that is no longer configured", { serverName });
|
|
19196
19233
|
continue;
|
|
19197
19234
|
}
|
|
19198
|
-
for (const [toolName, definition] of Object.entries(definitions)) try {
|
|
19235
|
+
for (const [toolName, definition] of Object.entries(modelVisibleDefinitions(definitions))) try {
|
|
19199
19236
|
tools[`${serverName}_${toolName}`] = await this.toolFromDefinition({
|
|
19200
19237
|
serverName,
|
|
19201
19238
|
definition
|
|
@@ -19463,6 +19500,22 @@ onListChanged: async (serverName, handler) => {
|
|
|
19463
19500
|
return {};
|
|
19464
19501
|
}
|
|
19465
19502
|
};
|
|
19503
|
+
/**
|
|
19504
|
+
* Whether a tool may be handed to the model. MCP App servers mark helpers their app calls itself
|
|
19505
|
+
* with `_meta.ui.visibility` lacking `'model'`; per the MCP Apps spec, hosts must not give those
|
|
19506
|
+
* to the model. They stay callable by the app through the server.
|
|
19507
|
+
*/
|
|
19508
|
+
function isModelVisible(meta) {
|
|
19509
|
+
const ui = meta?.ui;
|
|
19510
|
+
const visibility = ui && typeof ui === "object" && "visibility" in ui ? ui.visibility : void 0;
|
|
19511
|
+
return !Array.isArray(visibility) || visibility.includes("model");
|
|
19512
|
+
}
|
|
19513
|
+
function modelVisibleTools(tools) {
|
|
19514
|
+
return Object.fromEntries(Object.entries(tools).filter(([, tool]) => isModelVisible(tool.mcp?._meta)));
|
|
19515
|
+
}
|
|
19516
|
+
function modelVisibleDefinitions(definitions) {
|
|
19517
|
+
return Object.fromEntries(Object.entries(definitions).filter(([, definition]) => isModelVisible(definition._meta)));
|
|
19518
|
+
}
|
|
19466
19519
|
// src/server/actions.ts
|
|
19467
19520
|
/** Runtime tool catalogue mutations. Every change is published to listening clients. */
|
|
19468
19521
|
var ServerToolActions = class {
|
|
@@ -19594,8 +19647,17 @@ function callerTrace(ctx) {
|
|
|
19594
19647
|
return callerTraceContext(meta?.traceparent, meta?.tracestate) ?? callerTraceContext(headers?.get("traceparent"), headers?.get("tracestate"));
|
|
19595
19648
|
}
|
|
19596
19649
|
/**
|
|
19650
|
+
* Where `@mastra/server` attaches, on `req.auth`, the request context its auth
|
|
19651
|
+
* resolved (user, permissions, roles, resource id, tenant, auth mode). A symbol
|
|
19652
|
+
* cannot come out of a token or JSON payload, so only server code can supply it.
|
|
19653
|
+
*/
|
|
19654
|
+
const MCP_TRUSTED_REQUEST_CONTEXT = Symbol.for("mastra.mcp.trustedRequestContext");
|
|
19655
|
+
const MASTRA_USER_KEY = "mastra__user";
|
|
19656
|
+
/**
|
|
19597
19657
|
* Builds the trusted application context for one request. Auth is re-derived from
|
|
19598
|
-
* the transport every time; nothing is carried between continuation rounds.
|
|
19658
|
+
* the transport every time; nothing is carried between continuation rounds. When
|
|
19659
|
+
* the request came through a Mastra server route, the values its auth resolved are
|
|
19660
|
+
* copied in, so tools are authorized the same way as that server's routes. The W3C
|
|
19599
19661
|
* trace fields sent by the client are exposed under `traceContext` as opaque
|
|
19600
19662
|
* strings for observability only; they are never consulted for authorization.
|
|
19601
19663
|
*/
|
|
@@ -19605,6 +19667,12 @@ async function toRequestContext(ctx, mapAuthInfoToUser) {
|
|
|
19605
19667
|
if (traceContext) requestContext.set("traceContext", traceContext);
|
|
19606
19668
|
const authInfo = ctx.http?.authInfo;
|
|
19607
19669
|
if (!authInfo) return requestContext;
|
|
19670
|
+
const trusted = authInfo[MCP_TRUSTED_REQUEST_CONTEXT];
|
|
19671
|
+
if (trusted && typeof trusted === "object") {
|
|
19672
|
+
for (const [key, value] of Object.entries(trusted)) requestContext.set(key, value);
|
|
19673
|
+
const trustedUser = trusted[MASTRA_USER_KEY];
|
|
19674
|
+
if (trustedUser) requestContext.set("user", trustedUser);
|
|
19675
|
+
}
|
|
19608
19676
|
requestContext.set("authInfo", authInfo);
|
|
19609
19677
|
const user = await mapAuthInfoToUser?.({
|
|
19610
19678
|
authInfo,
|
|
@@ -22807,6 +22875,17 @@ function toSummary(listing) {
|
|
|
22807
22875
|
function isWorkflowTaskContext(context) {
|
|
22808
22876
|
return context?.kind === "workflow" && typeof context.runId === "string" && typeof context.workflowKey === "string";
|
|
22809
22877
|
}
|
|
22878
|
+
/**
|
|
22879
|
+
* A run's result with its step results read: a storage v2 result's `steps` is a loader that reads
|
|
22880
|
+
* them from storage, so a view, and the text a tool answers with, gets them as for v1.
|
|
22881
|
+
*/
|
|
22882
|
+
async function withLoadedSteps(result) {
|
|
22883
|
+
const steps = result.steps;
|
|
22884
|
+
return typeof steps === "function" ? {
|
|
22885
|
+
...result,
|
|
22886
|
+
steps: await steps()
|
|
22887
|
+
} : result;
|
|
22888
|
+
}
|
|
22810
22889
|
/** Statuses a run never leaves. */
|
|
22811
22890
|
const FINAL_STATUSES = /* @__PURE__ */ new Set([
|
|
22812
22891
|
"success",
|
|
@@ -23076,11 +23155,11 @@ var MCPServer = class extends _mastra_core_mcp.MCPServerBase {
|
|
|
23076
23155
|
inputSchema: workflow.inputSchema,
|
|
23077
23156
|
mcp: { toolType: "workflow" },
|
|
23078
23157
|
execute: async (inputData, context) => {
|
|
23079
|
-
return (await workflow.createRun({ runId: context?.requestContext?.get("runId") })).start({
|
|
23158
|
+
return withLoadedSteps(await (await workflow.createRun({ runId: context?.requestContext?.get("runId") })).start({
|
|
23080
23159
|
inputData,
|
|
23081
23160
|
requestContext: context?.requestContext,
|
|
23082
23161
|
tracingContext: context?.tracingContext
|
|
23083
|
-
});
|
|
23162
|
+
}));
|
|
23084
23163
|
}
|
|
23085
23164
|
}));
|
|
23086
23165
|
}
|
|
@@ -23870,7 +23949,7 @@ var MCPServer = class extends _mastra_core_mcp.MCPServerBase {
|
|
|
23870
23949
|
if (!workflow) throw new Error(`Workflow '${workflowKey}' is not served`);
|
|
23871
23950
|
const input = (0, _mastra_core_tools.validateToolInput)(workflow.inputSchema, args, name);
|
|
23872
23951
|
if (input.error) {
|
|
23873
|
-
this.logger.warn(`Tool '${name}' rejected its input.`, {
|
|
23952
|
+
this.logger.warn(`Tool '${name}' rejected its input.`, { issuePaths: (0, _mastra_core_tools.getValidationIssuePaths)(input.error, workflow.inputSchema) });
|
|
23874
23953
|
return errorResult$1(input.error.message);
|
|
23875
23954
|
}
|
|
23876
23955
|
const context = {
|
|
@@ -23893,11 +23972,11 @@ var MCPServer = class extends _mastra_core_mcp.MCPServerBase {
|
|
|
23893
23972
|
};
|
|
23894
23973
|
const start = (runTracing) => {
|
|
23895
23974
|
const run = workflow.createRun({ runId: context.runId });
|
|
23896
|
-
const result = run.then((started) => started.start({
|
|
23975
|
+
const result = run.then(async (started) => withLoadedSteps(await started.start({
|
|
23897
23976
|
inputData: input.data,
|
|
23898
23977
|
requestContext,
|
|
23899
23978
|
tracingContext: runTracing
|
|
23900
|
-
}));
|
|
23979
|
+
})));
|
|
23901
23980
|
const cancel = () => void run.then((started) => started.cancel()).catch((error) => this.logger.warn("Could not cancel workflow run", {
|
|
23902
23981
|
tool: name,
|
|
23903
23982
|
error
|
|
@@ -24026,12 +24105,12 @@ var MCPServer = class extends _mastra_core_mcp.MCPServerBase {
|
|
|
24026
24105
|
error
|
|
24027
24106
|
})));
|
|
24028
24107
|
try {
|
|
24029
|
-
view = await run.resume({
|
|
24108
|
+
view = await withLoadedSteps(await run.resume({
|
|
24030
24109
|
step: answered.step,
|
|
24031
24110
|
resumeData: answer.content ?? {},
|
|
24032
24111
|
requestContext,
|
|
24033
24112
|
...span && { tracingContext: { currentSpan: span } }
|
|
24034
|
-
});
|
|
24113
|
+
}));
|
|
24035
24114
|
} catch (error) {
|
|
24036
24115
|
if (isResumeClaimLost(error)) return this.watchWorkflowRun(workflow, context, attempt.signal);
|
|
24037
24116
|
const now = await workflow.getWorkflowRunById(context.runId, { withNestedWorkflows: false });
|
|
@@ -24199,7 +24278,7 @@ var MCPServer = class extends _mastra_core_mcp.MCPServerBase {
|
|
|
24199
24278
|
}
|
|
24200
24279
|
toCallToolResult(name, tool, value) {
|
|
24201
24280
|
if ((0, _mastra_core_tools.isValidationError)(value)) {
|
|
24202
|
-
this.logger.warn(`Tool '${name}' rejected its input.`, {
|
|
24281
|
+
this.logger.warn(`Tool '${name}' rejected its input.`, { issuePaths: (0, _mastra_core_tools.getValidationIssuePaths)(value, tool.parameters) });
|
|
24203
24282
|
return errorResult$1(value.message);
|
|
24204
24283
|
}
|
|
24205
24284
|
const resourceUri = uiResourceUri(tool.mcp?._meta);
|
|
@@ -24644,10 +24723,7 @@ var MCPServer = class extends _mastra_core_mcp.MCPServerBase {
|
|
|
24644
24723
|
id: "MCP_SERVER_TOOL_EXECUTE_FAILED",
|
|
24645
24724
|
domain: _mastra_core_error.ErrorDomain.MCP,
|
|
24646
24725
|
category: _mastra_core_error.ErrorCategory.USER,
|
|
24647
|
-
details: {
|
|
24648
|
-
toolId,
|
|
24649
|
-
args: JSON.stringify(args)
|
|
24650
|
-
}
|
|
24726
|
+
details: { toolId }
|
|
24651
24727
|
}, error);
|
|
24652
24728
|
this.logger.trackException(mastraError);
|
|
24653
24729
|
throw mastraError;
|