@mastra/mcp 0.10.10 → 0.10.11
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/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +31 -0
- package/dist/client/client.d.ts.map +1 -1
- package/dist/index.cjs +26 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +26 -4
- package/dist/index.js.map +1 -1
- package/dist/server/server.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/client/client.ts +5 -7
- package/src/server/server.test.ts +286 -1
- package/src/server/server.ts +27 -6
package/dist/index.js
CHANGED
|
@@ -1537,9 +1537,24 @@ var MCPServer = class extends MCPServerBase {
|
|
|
1537
1537
|
this.logger.warn(`CallTool: Invalid tool arguments for '${request.params.name}'`, {
|
|
1538
1538
|
errors: validation.error
|
|
1539
1539
|
});
|
|
1540
|
+
let errorMessages = "Validation failed";
|
|
1541
|
+
if ("errors" in validation.error && Array.isArray(validation.error.errors)) {
|
|
1542
|
+
errorMessages = validation.error.errors.map((e) => `- ${e.path?.join(".") || "root"}: ${e.message}`).join("\n");
|
|
1543
|
+
} else if (validation.error instanceof Error) {
|
|
1544
|
+
errorMessages = validation.error.message;
|
|
1545
|
+
}
|
|
1540
1546
|
return {
|
|
1541
|
-
content: [
|
|
1547
|
+
content: [
|
|
1548
|
+
{
|
|
1549
|
+
type: "text",
|
|
1550
|
+
text: `Tool validation failed. Please fix the following errors and try again:
|
|
1551
|
+
${errorMessages}
|
|
1552
|
+
|
|
1553
|
+
Provided arguments: ${JSON.stringify(request.params.arguments, null, 2)}`
|
|
1554
|
+
}
|
|
1555
|
+
],
|
|
1542
1556
|
isError: true
|
|
1557
|
+
// Set to true so the LLM sees the error and can self-correct
|
|
1543
1558
|
};
|
|
1544
1559
|
}
|
|
1545
1560
|
if (!tool.execute) {
|
|
@@ -1554,7 +1569,7 @@ var MCPServer = class extends MCPServerBase {
|
|
|
1554
1569
|
return this.handleElicitationRequest(request2, serverInstance);
|
|
1555
1570
|
}
|
|
1556
1571
|
};
|
|
1557
|
-
const result = await tool.execute(validation?.value, {
|
|
1572
|
+
const result = await tool.execute(validation?.value ?? request.params.arguments ?? {}, {
|
|
1558
1573
|
messages: [],
|
|
1559
1574
|
toolCallId: "",
|
|
1560
1575
|
elicitation: sessionElicitation,
|
|
@@ -2492,11 +2507,18 @@ var MCPServer = class extends MCPServerBase {
|
|
|
2492
2507
|
if (tool.parameters instanceof z.ZodType && typeof tool.parameters.safeParse === "function") {
|
|
2493
2508
|
const validation = tool.parameters.safeParse(args ?? {});
|
|
2494
2509
|
if (!validation.success) {
|
|
2495
|
-
const errorMessages = validation.error.errors.map((e) =>
|
|
2510
|
+
const errorMessages = validation.error.errors.map((e) => `- ${e.path?.join(".") || "root"}: ${e.message}`).join("\n");
|
|
2496
2511
|
this.logger.warn(`ExecuteTool: Invalid tool arguments for '${toolId}': ${errorMessages}`, {
|
|
2497
2512
|
errors: validation.error.format()
|
|
2498
2513
|
});
|
|
2499
|
-
|
|
2514
|
+
return {
|
|
2515
|
+
error: true,
|
|
2516
|
+
message: `Tool validation failed. Please fix the following errors and try again:
|
|
2517
|
+
${errorMessages}
|
|
2518
|
+
|
|
2519
|
+
Provided arguments: ${JSON.stringify(args, null, 2)}`,
|
|
2520
|
+
validationErrors: validation.error.format()
|
|
2521
|
+
};
|
|
2500
2522
|
}
|
|
2501
2523
|
validatedArgs = validation.data;
|
|
2502
2524
|
} else {
|