@mastra/mcp 1.17.2 → 1.17.3-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.
Files changed (34) hide show
  1. package/LICENSE.md +6 -4
  2. package/dist/client/actions/elicitation.d.ts.map +1 -1
  3. package/dist/client/actions/progress.d.ts.map +1 -1
  4. package/dist/client/actions/prompt.d.ts.map +1 -1
  5. package/dist/client/actions/resource.d.ts +21 -21
  6. package/dist/client/actions/resource.d.ts.map +1 -1
  7. package/dist/client/client.d.ts +6 -2
  8. package/dist/client/client.d.ts.map +1 -1
  9. package/dist/client/configuration.d.ts +51 -51
  10. package/dist/client/configuration.d.ts.map +1 -1
  11. package/dist/client/oauth-provider.d.ts.map +1 -1
  12. package/dist/client/server-proxy.d.ts.map +1 -1
  13. package/dist/docs/SKILL.md +8 -8
  14. package/dist/docs/assets/SOURCE_MAP.json +1 -1
  15. package/dist/docs/references/docs-auth-fga.md +18 -16
  16. package/dist/docs/references/docs-connections-mcp.md +3 -1
  17. package/dist/docs/references/docs-connections-overview.md +2 -0
  18. package/dist/docs/references/reference-editor-tools.md +2 -0
  19. package/dist/docs/references/reference-migrations-upgrade-to-v1-mcp.md +2 -0
  20. package/dist/docs/references/reference-tools-mcp-client.md +4 -2
  21. package/dist/docs/references/reference-tools-mcp-server.md +2 -0
  22. package/dist/index.cjs +30 -16
  23. package/dist/index.cjs.map +1 -1
  24. package/dist/index.js +31 -17
  25. package/dist/index.js.map +1 -1
  26. package/dist/server/__tests__/mock-extra.d.ts.map +1 -1
  27. package/dist/server/mrtrElicitation.d.ts.map +1 -1
  28. package/dist/server/oauth-middleware.d.ts.map +1 -1
  29. package/dist/server/promptActions.d.ts.map +1 -1
  30. package/dist/server/resourceActions.d.ts.map +1 -1
  31. package/dist/server/server.d.ts.map +1 -1
  32. package/dist/server/toolActions.d.ts.map +1 -1
  33. package/package.json +12 -13
  34. package/CHANGELOG.md +0 -5453
package/dist/index.js CHANGED
@@ -2,7 +2,7 @@ import { createRequire } from "module";
2
2
  import { AsyncLocalStorage } from "async_hooks";
3
3
  import { MastraBase } from "@mastra/core/base";
4
4
  import { ErrorCategory, ErrorDomain, MastraError } from "@mastra/core/error";
5
- import { createTool, isValidationError } from "@mastra/core/tools";
5
+ import { createTool, isValidationError, validateToolOutput } from "@mastra/core/tools";
6
6
  import { Client, DEFAULT_REQUEST_TIMEOUT_MSEC, ProtocolErrorCode, SSEClientTransport, SdkHttpError, StreamableHTTPClientTransport, UnauthorizedError, auth, buildDiscoveryUrls, discoverAuthorizationServerMetadata, discoverOAuthMetadata, discoverOAuthProtectedResourceMetadata, exchangeAuthorization, extractResourceMetadataUrl, parseErrorResponse, refreshAuthorization, registerClient, selectResourceURL, startAuthorization } from "@modelcontextprotocol/client";
7
7
  import { StdioClientTransport, getDefaultEnvironment } from "@modelcontextprotocol/client/stdio";
8
8
  import { asyncExitHook, gracefulExit } from "exit-hook";
@@ -17418,7 +17418,7 @@ let customAlphabet = (alphabet, defaultSize = 21) => {
17418
17418
  return (size = defaultSize) => {
17419
17419
  let id = "";
17420
17420
  let i = size | 0;
17421
- while (i--) id += alphabet[Math.random() * alphabet.length | 0];
17421
+ while (i-- > 0) id += alphabet[Math.random() * alphabet.length | 0];
17422
17422
  return id;
17423
17423
  };
17424
17424
  };
@@ -22049,8 +22049,12 @@ var InternalMastraMCPClient = class extends MastraBase {
22049
22049
  return "jsonSchema" in inputSchema ? inputSchema.jsonSchema : inputSchema;
22050
22050
  }
22051
22051
  /**
22052
- * Wraps the output schema with a validator that always succeeds. The MCP client validates
22053
- * structuredContent via AJV; the JSON schema is surfaced here for documentation only.
22052
+ * Wraps the output schema with a validator that always succeeds. The tool's execute wrapper
22053
+ * returns the full CallToolResult envelope when there is no structuredContent (and for
22054
+ * in-band errors with `onToolError: 'return'`), which would never match the advertised
22055
+ * outputSchema — so enforcement happens inside the execute wrapper, scoped to the
22056
+ * structuredContent path (see buildToolFromListEntry). The JSON schema is surfaced here
22057
+ * for documentation.
22054
22058
  */
22055
22059
  convertOutputSchema(outputSchema) {
22056
22060
  if (!outputSchema) return outputSchema;
@@ -22175,6 +22179,8 @@ var InternalMastraMCPClient = class extends MastraBase {
22175
22179
  ...toolMeta ? { _meta: toolMeta } : {},
22176
22180
  ...annotations ? { annotations } : {}
22177
22181
  } } : {};
22182
+ const rawOutputSchema = tool.outputSchema ? "jsonSchema" in tool.outputSchema ? tool.outputSchema.jsonSchema : tool.outputSchema : void 0;
22183
+ const outputValidator = rawOutputSchema ? toStandardSchema(rawOutputSchema) : void 0;
22178
22184
  const mastraTool = createTool({
22179
22185
  id: `${this.name}_${tool.name}`,
22180
22186
  description: tool.description || "",
@@ -22229,7 +22235,16 @@ var InternalMastraMCPClient = class extends MastraBase {
22229
22235
  });
22230
22236
  }
22231
22237
  this.log("debug", `Tool executed successfully: ${tool.name}`);
22232
- if (res.structuredContent !== void 0) return attachMcpCallToolContent(res.structuredContent, res.content, res._meta ? this.stampServerIdInMeta(res._meta) : void 0);
22238
+ if (res.structuredContent !== void 0) {
22239
+ if (!res.isError && outputValidator) {
22240
+ const validation = validateToolOutput(outputValidator, res.structuredContent, tool.name);
22241
+ if (validation.error) {
22242
+ this.log("debug", `Tool output failed schema validation: ${tool.name}`, { message: validation.error.message });
22243
+ return validation.error;
22244
+ }
22245
+ }
22246
+ return attachMcpCallToolContent(res.structuredContent, res.content, res._meta ? this.stampServerIdInMeta(res._meta) : void 0);
22247
+ }
22233
22248
  return res;
22234
22249
  };
22235
22250
  const failedTransport = this.transport;
@@ -24185,7 +24200,7 @@ onListChanged: async (serverName, handler) => {
24185
24200
  }
24186
24201
  };
24187
24202
  //#endregion
24188
- //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/hono/4.12.30/1b2e4fcdfb5fc9f7f51bffc1540f859608c39e01fb7d73d8ab30d60a680eaffc/node_modules/hono/dist/utils/stream.js
24203
+ //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/hono/4.12.34/86d7f25c35c79da0f9cccb7fef43100dfeaf7989a3b5712a780063b91be3ae59/node_modules/hono/dist/utils/stream.js
24189
24204
  var StreamingApi = class {
24190
24205
  writer;
24191
24206
  encoder;
@@ -24258,7 +24273,7 @@ var StreamingApi = class {
24258
24273
  }
24259
24274
  };
24260
24275
  //#endregion
24261
- //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/hono/4.12.30/1b2e4fcdfb5fc9f7f51bffc1540f859608c39e01fb7d73d8ab30d60a680eaffc/node_modules/hono/dist/helper/streaming/utils.js
24276
+ //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/hono/4.12.34/86d7f25c35c79da0f9cccb7fef43100dfeaf7989a3b5712a780063b91be3ae59/node_modules/hono/dist/helper/streaming/utils.js
24262
24277
  var isOldBunVersion = () => {
24263
24278
  const version = typeof Bun !== "undefined" ? Bun.version : void 0;
24264
24279
  if (version === void 0) return false;
@@ -24267,7 +24282,7 @@ var isOldBunVersion = () => {
24267
24282
  return result;
24268
24283
  };
24269
24284
  //#endregion
24270
- //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/hono/4.12.30/1b2e4fcdfb5fc9f7f51bffc1540f859608c39e01fb7d73d8ab30d60a680eaffc/node_modules/hono/dist/utils/html.js
24285
+ //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/hono/4.12.34/86d7f25c35c79da0f9cccb7fef43100dfeaf7989a3b5712a780063b91be3ae59/node_modules/hono/dist/utils/html.js
24271
24286
  var HtmlEscapedCallbackPhase = {
24272
24287
  Stringify: 1,
24273
24288
  BeforeStream: 2,
@@ -24297,7 +24312,7 @@ var resolveCallback = async (str, phase, preserveCallbacks, context, buffer) =>
24297
24312
  else return resStr;
24298
24313
  };
24299
24314
  //#endregion
24300
- //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/hono/4.12.30/1b2e4fcdfb5fc9f7f51bffc1540f859608c39e01fb7d73d8ab30d60a680eaffc/node_modules/hono/dist/helper/streaming/sse.js
24315
+ //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/hono/4.12.34/86d7f25c35c79da0f9cccb7fef43100dfeaf7989a3b5712a780063b91be3ae59/node_modules/hono/dist/helper/streaming/sse.js
24301
24316
  var SSEStreamingApi = class extends StreamingApi {
24302
24317
  constructor(writable, readable) {
24303
24318
  super(writable, readable);
@@ -24306,16 +24321,15 @@ var SSEStreamingApi = class extends StreamingApi {
24306
24321
  const dataLines = (await resolveCallback(message.data, HtmlEscapedCallbackPhase.Stringify, false, {})).split(/\r\n|\r|\n/).map((line) => {
24307
24322
  return `data: ${line}`;
24308
24323
  }).join("\n");
24309
- for (const key of [
24310
- "event",
24311
- "id",
24312
- "retry"
24313
- ]) if (message[key] && /[\r\n]/.test(message[key])) throw new Error(`${key} must not contain "\\r" or "\\n"`);
24324
+ for (const key of ["event", "id"]) {
24325
+ const value = message[key];
24326
+ if (value && /[\r\n]/.test(value)) throw new Error(`${key} must not contain "\\r" or "\\n"`);
24327
+ }
24314
24328
  const sseData = [
24315
24329
  message.event && `event: ${message.event}`,
24316
24330
  dataLines,
24317
- message.id && `id: ${message.id}`,
24318
- message.retry && `retry: ${message.retry}`
24331
+ message.id !== void 0 && `id: ${message.id}`,
24332
+ message.retry !== void 0 && `retry: ${message.retry}`
24319
24333
  ].filter(Boolean).join("\n") + "\n\n";
24320
24334
  await this.write(sseData);
24321
24335
  }
@@ -24351,7 +24365,7 @@ var streamSSE = (c, cb, onError) => {
24351
24365
  return c.newResponse(stream.responseReadable);
24352
24366
  };
24353
24367
  //#endregion
24354
- //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/hono-mcp-server-sse-transport/0.0.7/d5ae5a23aa2b79db7055621f11a7cbc8d27f7caba1eeb308ab2cf5bcb1a8e5b8/node_modules/hono-mcp-server-sse-transport/build/sse.js
24368
+ //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/hono-mcp-server-sse-transport/0.0.7/2a63beb8624fb1bf3c7a3ca090a15654580e3b90bf86b236de2fea1561bf2a49/node_modules/hono-mcp-server-sse-transport/build/sse.js
24355
24369
  const MAXIMUM_MESSAGE_SIZE = 4 * 1024 * 1024;
24356
24370
  var SSETransport = class {
24357
24371
  messageUrl;