@mastra/mcp 1.5.0 → 1.5.1-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/index.js CHANGED
@@ -1,7 +1,5 @@
1
1
  import { AsyncLocalStorage } from 'async_hooks';
2
- import $RefParser from '@apidevtools/json-schema-ref-parser';
3
2
  import { MastraBase } from '@mastra/core/base';
4
- import { MastraError, ErrorCategory, ErrorDomain } from '@mastra/core/error';
5
3
  import { createTool, isValidationError } from '@mastra/core/tools';
6
4
  import { Client } from '@modelcontextprotocol/sdk/client/index.js';
7
5
  import { SSEClientTransport } from '@modelcontextprotocol/sdk/client/sse.js';
@@ -10,6 +8,7 @@ import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/
10
8
  import { DEFAULT_REQUEST_TIMEOUT_MSEC } from '@modelcontextprotocol/sdk/shared/protocol.js';
11
9
  import { LoggingMessageNotificationSchema, ListRootsRequestSchema, ListResourcesResultSchema, ReadResourceResultSchema, EmptyResultSchema, ListResourceTemplatesResultSchema, ListPromptsResultSchema, GetPromptResultSchema, PromptListChangedNotificationSchema, ResourceUpdatedNotificationSchema, ResourceListChangedNotificationSchema, ElicitRequestSchema, ProgressNotificationSchema, ListToolsRequestSchema, CallToolRequestSchema, SetLevelRequestSchema, ListResourcesRequestSchema, ReadResourceRequestSchema, ListResourceTemplatesRequestSchema, SubscribeRequestSchema, UnsubscribeRequestSchema, ListPromptsRequestSchema, PromptSchema, GetPromptRequestSchema, CallToolResultSchema, ErrorCode, JSONRPCMessageSchema } from '@modelcontextprotocol/sdk/types.js';
12
10
  import { asyncExitHook, gracefulExit } from 'exit-hook';
11
+ import { MastraError, ErrorCategory, ErrorDomain } from '@mastra/core/error';
13
12
  import equal from 'fast-deep-equal';
14
13
  import { v5 } from 'uuid';
15
14
  import { randomUUID } from 'crypto';
@@ -25,6 +24,31 @@ export { UnauthorizedError, auth, buildDiscoveryUrls, discoverAuthorizationServe
25
24
 
26
25
  // src/client/client.ts
27
26
 
27
+ // src/shared/mastra-tool-meta.ts
28
+ var MASTRA_META_KEY = "mastra";
29
+ var STRICT_META_KEY = "strict";
30
+ function withMastraToolStrictMeta(meta, strict) {
31
+ if (strict == null) {
32
+ return meta;
33
+ }
34
+ const mastraMeta = meta?.[MASTRA_META_KEY] && typeof meta[MASTRA_META_KEY] === "object" ? meta[MASTRA_META_KEY] : void 0;
35
+ return {
36
+ ...meta ?? {},
37
+ [MASTRA_META_KEY]: {
38
+ ...mastraMeta ?? {},
39
+ [STRICT_META_KEY]: strict
40
+ }
41
+ };
42
+ }
43
+ function getMastraToolStrictMeta(meta) {
44
+ const mastraMeta = meta?.[MASTRA_META_KEY];
45
+ if (!mastraMeta || typeof mastraMeta !== "object") {
46
+ return void 0;
47
+ }
48
+ const strict = mastraMeta[STRICT_META_KEY];
49
+ return typeof strict === "boolean" ? strict : void 0;
50
+ }
51
+
28
52
  // src/client/actions/elicitation.ts
29
53
  var ElicitationClientActions = class {
30
54
  client;
@@ -868,31 +892,7 @@ var InternalMastraMCPClient = class extends MastraBase {
868
892
  });
869
893
  }
870
894
  async convertInputSchema(inputSchema) {
871
- try {
872
- await $RefParser.dereference(inputSchema);
873
- return "jsonSchema" in inputSchema ? inputSchema.jsonSchema : inputSchema;
874
- } catch (error) {
875
- let errorDetails;
876
- if (error instanceof Error) {
877
- errorDetails = error.stack;
878
- } else {
879
- try {
880
- errorDetails = JSON.stringify(error);
881
- } catch {
882
- errorDetails = String(error);
883
- }
884
- }
885
- this.log("error", "Failed to dereference JSON schema", {
886
- error: errorDetails,
887
- originalJsonSchema: inputSchema
888
- });
889
- throw new MastraError({
890
- id: "MCP_TOOL_INPUT_SCHEMA_CONVERSION_FAILED",
891
- domain: ErrorDomain.MCP,
892
- category: ErrorCategory.USER,
893
- details: { error: errorDetails ?? "Unknown error" }
894
- });
895
- }
895
+ return "jsonSchema" in inputSchema ? inputSchema.jsonSchema : inputSchema;
896
896
  }
897
897
  async tools() {
898
898
  this.log("debug", `Requesting tools from MCP server`);
@@ -917,6 +917,7 @@ var InternalMastraMCPClient = class extends MastraBase {
917
917
  id: `${this.name}_${tool.name}`,
918
918
  description: tool.description || "",
919
919
  inputSchema: await this.convertInputSchema(tool.inputSchema),
920
+ strict: getMastraToolStrictMeta(tool._meta),
920
921
  // Don't pass outputSchema to createTool — the MCP SDK's Client.callTool()
921
922
  // already validates structuredContent against the tool's outputSchema using AJV.
922
923
  // Passing it here causes Zod to strip unrecognized keys from the CallToolResult
@@ -2774,8 +2775,9 @@ var MCPServer = class extends MCPServerBase {
2774
2775
  if (tool.mcp?.annotations) {
2775
2776
  toolSpec.annotations = tool.mcp.annotations;
2776
2777
  }
2777
- if (tool.mcp?._meta) {
2778
- toolSpec._meta = tool.mcp._meta;
2778
+ const toolMeta = withMastraToolStrictMeta(tool.mcp?._meta, tool.strict);
2779
+ if (toolMeta) {
2780
+ toolSpec._meta = toolMeta;
2779
2781
  }
2780
2782
  return toolSpec;
2781
2783
  })
@@ -4053,7 +4055,8 @@ Provided arguments: ${JSON.stringify(request.params.arguments, null, 2)}`
4053
4055
  description: tool.description,
4054
4056
  inputSchema: this.convertSchema(tool.parameters),
4055
4057
  outputSchema: this.convertSchema(tool.parameters),
4056
- toolType: tool.mcp?.toolType
4058
+ toolType: tool.mcp?.toolType,
4059
+ _meta: withMastraToolStrictMeta(tool.mcp?._meta, tool.strict)
4057
4060
  }))
4058
4061
  };
4059
4062
  }
@@ -4087,7 +4090,8 @@ Provided arguments: ${JSON.stringify(request.params.arguments, null, 2)}`
4087
4090
  description: tool.description,
4088
4091
  inputSchema: this.convertSchema(tool.parameters),
4089
4092
  outputSchema: this.convertSchema(tool.outputSchema),
4090
- toolType: tool.mcp?.toolType
4093
+ toolType: tool.mcp?.toolType,
4094
+ _meta: withMastraToolStrictMeta(tool.mcp?._meta, tool.strict)
4091
4095
  };
4092
4096
  }
4093
4097
  /**