@mastra/mcp 1.17.3-alpha.0 → 1.17.3-alpha.2
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/README.md +22 -8
- package/dist/client/client.d.ts +6 -2
- 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 +18 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +19 -4
- package/dist/index.js.map +1 -1
- package/package.json +7 -7
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";
|
|
@@ -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
|
|
22053
|
-
*
|
|
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)
|
|
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;
|