@mastra/mcp 1.3.0 → 1.3.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/CHANGELOG.md +22 -0
- package/dist/client/client.d.ts +1 -1
- 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 +20 -39
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +20 -39
- package/dist/index.js.map +1 -1
- package/dist/server/server.d.ts.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -409,6 +409,7 @@ var InternalMastraMCPClient = class extends MastraBase {
|
|
|
409
409
|
operationContextStore = new AsyncLocalStorage();
|
|
410
410
|
exitHookUnsubscribe;
|
|
411
411
|
sigTermHandler;
|
|
412
|
+
sigHupHandler;
|
|
412
413
|
_roots;
|
|
413
414
|
/** Provides access to resource operations (list, read, subscribe, etc.) */
|
|
414
415
|
resources;
|
|
@@ -667,6 +668,10 @@ var InternalMastraMCPClient = class extends MastraBase {
|
|
|
667
668
|
this.sigTermHandler = () => gracefulExit();
|
|
668
669
|
process.on("SIGTERM", this.sigTermHandler);
|
|
669
670
|
}
|
|
671
|
+
if (!this.sigHupHandler) {
|
|
672
|
+
this.sigHupHandler = () => gracefulExit();
|
|
673
|
+
process.on("SIGHUP", this.sigHupHandler);
|
|
674
|
+
}
|
|
670
675
|
this.log("debug", `Successfully connected to MCP server`);
|
|
671
676
|
return this.isConnected;
|
|
672
677
|
}
|
|
@@ -723,6 +728,10 @@ var InternalMastraMCPClient = class extends MastraBase {
|
|
|
723
728
|
process.off("SIGTERM", this.sigTermHandler);
|
|
724
729
|
this.sigTermHandler = void 0;
|
|
725
730
|
}
|
|
731
|
+
if (this.sigHupHandler) {
|
|
732
|
+
process.off("SIGHUP", this.sigHupHandler);
|
|
733
|
+
this.sigHupHandler = void 0;
|
|
734
|
+
}
|
|
726
735
|
}
|
|
727
736
|
}
|
|
728
737
|
/**
|
|
@@ -887,34 +896,6 @@ var InternalMastraMCPClient = class extends MastraBase {
|
|
|
887
896
|
});
|
|
888
897
|
}
|
|
889
898
|
}
|
|
890
|
-
async convertOutputSchema(outputSchema) {
|
|
891
|
-
if (!outputSchema) return;
|
|
892
|
-
try {
|
|
893
|
-
await $RefParser.dereference(outputSchema);
|
|
894
|
-
return "jsonSchema" in outputSchema ? outputSchema.jsonSchema : outputSchema;
|
|
895
|
-
} catch (error) {
|
|
896
|
-
let errorDetails;
|
|
897
|
-
if (error instanceof Error) {
|
|
898
|
-
errorDetails = error.stack;
|
|
899
|
-
} else {
|
|
900
|
-
try {
|
|
901
|
-
errorDetails = JSON.stringify(error);
|
|
902
|
-
} catch {
|
|
903
|
-
errorDetails = String(error);
|
|
904
|
-
}
|
|
905
|
-
}
|
|
906
|
-
this.log("error", "Failed to dereference JSON schema", {
|
|
907
|
-
error: errorDetails,
|
|
908
|
-
originalJsonSchema: outputSchema
|
|
909
|
-
});
|
|
910
|
-
throw new MastraError({
|
|
911
|
-
id: "MCP_TOOL_OUTPUT_SCHEMA_CONVERSION_FAILED",
|
|
912
|
-
domain: ErrorDomain.MCP,
|
|
913
|
-
category: ErrorCategory.USER,
|
|
914
|
-
details: { error: errorDetails ?? "Unknown error" }
|
|
915
|
-
});
|
|
916
|
-
}
|
|
917
|
-
}
|
|
918
899
|
async tools() {
|
|
919
900
|
this.log("debug", `Requesting tools from MCP server`);
|
|
920
901
|
const { tools } = await this.client.listTools({}, { timeout: this.timeout });
|
|
@@ -926,7 +907,10 @@ var InternalMastraMCPClient = class extends MastraBase {
|
|
|
926
907
|
id: `${this.name}_${tool.name}`,
|
|
927
908
|
description: tool.description || "",
|
|
928
909
|
inputSchema: await this.convertInputSchema(tool.inputSchema),
|
|
929
|
-
outputSchema
|
|
910
|
+
// Don't pass outputSchema to createTool — the MCP SDK's Client.callTool()
|
|
911
|
+
// already validates structuredContent against the tool's outputSchema using AJV.
|
|
912
|
+
// Passing it here causes Zod to strip unrecognized keys from the CallToolResult
|
|
913
|
+
// envelope, returning {} for tools without structuredContent.
|
|
930
914
|
mcpMetadata: {
|
|
931
915
|
serverName: this.name,
|
|
932
916
|
serverVersion: this.client.getServerVersion()?.version
|
|
@@ -953,16 +937,6 @@ var InternalMastraMCPClient = class extends MastraBase {
|
|
|
953
937
|
if (res.structuredContent !== void 0) {
|
|
954
938
|
return res.structuredContent;
|
|
955
939
|
}
|
|
956
|
-
if (tool.outputSchema && !res.isError) {
|
|
957
|
-
const content = res.content;
|
|
958
|
-
if (content && content.length === 1 && content[0].type === "text" && content[0].text !== void 0) {
|
|
959
|
-
try {
|
|
960
|
-
return JSON.parse(content[0].text);
|
|
961
|
-
} catch {
|
|
962
|
-
return content[0].text;
|
|
963
|
-
}
|
|
964
|
-
}
|
|
965
|
-
}
|
|
966
940
|
return res;
|
|
967
941
|
};
|
|
968
942
|
try {
|
|
@@ -2814,9 +2788,16 @@ Provided arguments: ${JSON.stringify(request.params.arguments, null, 2)}`
|
|
|
2814
2788
|
return this.handleElicitationRequest(request2, serverInstance, options);
|
|
2815
2789
|
}
|
|
2816
2790
|
};
|
|
2791
|
+
const proxiedContext = new RequestContext();
|
|
2792
|
+
if (extra) {
|
|
2793
|
+
Object.entries(extra).forEach(([key, value]) => {
|
|
2794
|
+
proxiedContext.set(key, value);
|
|
2795
|
+
});
|
|
2796
|
+
}
|
|
2817
2797
|
const mcpOptions = {
|
|
2818
2798
|
messages: [],
|
|
2819
2799
|
toolCallId: "",
|
|
2800
|
+
requestContext: proxiedContext,
|
|
2820
2801
|
// Pass MCP-specific context through the mcp property
|
|
2821
2802
|
mcp: {
|
|
2822
2803
|
elicitation: sessionElicitation,
|