@mastra/mcp 0.10.6-alpha.0 → 0.10.6-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/.turbo/turbo-build.log +7 -7
- package/CHANGELOG.md +13 -0
- package/dist/index.cjs +17 -10
- package/dist/index.js +16 -10
- package/package.json +3 -2
- package/src/client/client.ts +12 -10
- package/src/server/server.test.ts +2 -4
- package/src/server/server.ts +11 -4
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
|
|
2
|
-
> @mastra/mcp@0.10.6-alpha.
|
|
2
|
+
> @mastra/mcp@0.10.6-alpha.1 build /home/runner/work/mastra/mastra/packages/mcp
|
|
3
3
|
> tsup src/index.ts --format esm,cjs --experimental-dts --clean --treeshake=smallest --splitting
|
|
4
4
|
|
|
5
5
|
[34mCLI[39m Building entry: src/index.ts
|
|
6
6
|
[34mCLI[39m Using tsconfig: tsconfig.json
|
|
7
7
|
[34mCLI[39m tsup v8.5.0
|
|
8
8
|
[34mTSC[39m Build start
|
|
9
|
-
[32mTSC[39m ⚡️ Build success in
|
|
9
|
+
[32mTSC[39m ⚡️ Build success in 17864ms
|
|
10
10
|
[34mDTS[39m Build start
|
|
11
11
|
[34mCLI[39m Target: es2022
|
|
12
12
|
Analysis will use the bundled TypeScript version 5.8.3
|
|
13
13
|
[36mWriting package typings: /home/runner/work/mastra/mastra/packages/mcp/dist/_tsup-dts-rollup.d.ts[39m
|
|
14
14
|
Analysis will use the bundled TypeScript version 5.8.3
|
|
15
15
|
[36mWriting package typings: /home/runner/work/mastra/mastra/packages/mcp/dist/_tsup-dts-rollup.d.cts[39m
|
|
16
|
-
[32mDTS[39m ⚡️ Build success in
|
|
16
|
+
[32mDTS[39m ⚡️ Build success in 29258ms
|
|
17
17
|
[34mCLI[39m Cleaning output folder
|
|
18
18
|
[34mESM[39m Build start
|
|
19
19
|
[34mCJS[39m Build start
|
|
20
|
-
[
|
|
21
|
-
[
|
|
22
|
-
[
|
|
23
|
-
[
|
|
20
|
+
[32mESM[39m [1mdist/index.js [22m[32m88.94 KB[39m
|
|
21
|
+
[32mESM[39m ⚡️ Build success in 2045ms
|
|
22
|
+
[32mCJS[39m [1mdist/index.cjs [22m[32m89.72 KB[39m
|
|
23
|
+
[32mCJS[39m ⚡️ Build success in 2045ms
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @mastra/mcp
|
|
2
2
|
|
|
3
|
+
## 0.10.6-alpha.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- c0ba5e2: Handle json schema with $defs and $ref property for MCP tool schemas.
|
|
8
|
+
- cb16baf: Fix MCP tool output schema type and return value
|
|
9
|
+
- Updated dependencies [c7bbf1e]
|
|
10
|
+
- Updated dependencies [8722d53]
|
|
11
|
+
- Updated dependencies [132027f]
|
|
12
|
+
- Updated dependencies [0c85311]
|
|
13
|
+
- Updated dependencies [cb16baf]
|
|
14
|
+
- @mastra/core@0.10.11-alpha.3
|
|
15
|
+
|
|
3
16
|
## 0.10.6-alpha.0
|
|
4
17
|
|
|
5
18
|
### Patch Changes
|
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var $RefParser = require('@apidevtools/json-schema-ref-parser');
|
|
3
4
|
var base = require('@mastra/core/base');
|
|
4
5
|
var error = require('@mastra/core/error');
|
|
5
6
|
var tools = require('@mastra/core/tools');
|
|
@@ -26,6 +27,7 @@ var streamableHttp_js = require('@modelcontextprotocol/sdk/server/streamableHttp
|
|
|
26
27
|
|
|
27
28
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
28
29
|
|
|
30
|
+
var $RefParser__default = /*#__PURE__*/_interopDefault($RefParser);
|
|
29
31
|
var equal__default = /*#__PURE__*/_interopDefault(equal);
|
|
30
32
|
|
|
31
33
|
// src/client/client.ts
|
|
@@ -504,11 +506,12 @@ var InternalMastraMCPClient = class extends base.MastraBase {
|
|
|
504
506
|
return handler(request.params);
|
|
505
507
|
});
|
|
506
508
|
}
|
|
507
|
-
convertInputSchema(inputSchema) {
|
|
509
|
+
async convertInputSchema(inputSchema) {
|
|
508
510
|
if (utils.isZodType(inputSchema)) {
|
|
509
511
|
return inputSchema;
|
|
510
512
|
}
|
|
511
513
|
try {
|
|
514
|
+
await $RefParser__default.default.dereference(inputSchema);
|
|
512
515
|
return zodFromJsonSchema.convertJsonSchemaToZod(inputSchema);
|
|
513
516
|
} catch (error$1) {
|
|
514
517
|
let errorDetails;
|
|
@@ -533,12 +536,13 @@ var InternalMastraMCPClient = class extends base.MastraBase {
|
|
|
533
536
|
});
|
|
534
537
|
}
|
|
535
538
|
}
|
|
536
|
-
convertOutputSchema(outputSchema) {
|
|
539
|
+
async convertOutputSchema(outputSchema) {
|
|
537
540
|
if (!outputSchema) return;
|
|
538
541
|
if (utils.isZodType(outputSchema)) {
|
|
539
542
|
return outputSchema;
|
|
540
543
|
}
|
|
541
544
|
try {
|
|
545
|
+
await $RefParser__default.default.dereference(outputSchema);
|
|
542
546
|
return zodFromJsonSchema.convertJsonSchemaToZod(outputSchema);
|
|
543
547
|
} catch (error$1) {
|
|
544
548
|
let errorDetails;
|
|
@@ -567,14 +571,14 @@ var InternalMastraMCPClient = class extends base.MastraBase {
|
|
|
567
571
|
this.log("debug", `Requesting tools from MCP server`);
|
|
568
572
|
const { tools: tools$1 } = await this.client.listTools({ timeout: this.timeout });
|
|
569
573
|
const toolsRes = {};
|
|
570
|
-
tools$1
|
|
574
|
+
for (const tool of tools$1) {
|
|
571
575
|
this.log("debug", `Processing tool: ${tool.name}`);
|
|
572
576
|
try {
|
|
573
577
|
const mastraTool = tools.createTool({
|
|
574
578
|
id: `${this.name}_${tool.name}`,
|
|
575
579
|
description: tool.description || "",
|
|
576
|
-
inputSchema: this.convertInputSchema(tool.inputSchema),
|
|
577
|
-
outputSchema: this.convertOutputSchema(tool.outputSchema),
|
|
580
|
+
inputSchema: await this.convertInputSchema(tool.inputSchema),
|
|
581
|
+
outputSchema: await this.convertOutputSchema(tool.outputSchema),
|
|
578
582
|
execute: async ({ context, runtimeContext }) => {
|
|
579
583
|
const previousContext = this.currentOperationContext;
|
|
580
584
|
this.currentOperationContext = runtimeContext || null;
|
|
@@ -612,7 +616,7 @@ var InternalMastraMCPClient = class extends base.MastraBase {
|
|
|
612
616
|
mcpToolDefinition: tool
|
|
613
617
|
});
|
|
614
618
|
}
|
|
615
|
-
}
|
|
619
|
+
}
|
|
616
620
|
return toolsRes;
|
|
617
621
|
}
|
|
618
622
|
};
|
|
@@ -1567,10 +1571,13 @@ var MCPServer = class extends mcp.MCPServerBase {
|
|
|
1567
1571
|
this.logger.info(`Tool '${request.params.name}' executed successfully in ${duration}ms.`);
|
|
1568
1572
|
const response = { isError: false, content: [] };
|
|
1569
1573
|
if (tool.outputSchema) {
|
|
1570
|
-
|
|
1571
|
-
|
|
1574
|
+
let structuredContent;
|
|
1575
|
+
if (result && typeof result === "object" && "structuredContent" in result) {
|
|
1576
|
+
structuredContent = result.structuredContent;
|
|
1577
|
+
} else {
|
|
1578
|
+
structuredContent = result;
|
|
1572
1579
|
}
|
|
1573
|
-
const outputValidation = tool.outputSchema.validate?.(
|
|
1580
|
+
const outputValidation = tool.outputSchema.validate?.(structuredContent ?? {});
|
|
1574
1581
|
if (outputValidation && !outputValidation.success) {
|
|
1575
1582
|
this.logger.warn(`CallTool: Invalid structured content for '${request.params.name}'`, {
|
|
1576
1583
|
errors: outputValidation.error
|
|
@@ -1579,7 +1586,7 @@ var MCPServer = class extends mcp.MCPServerBase {
|
|
|
1579
1586
|
`Invalid structured content for tool ${request.params.name}: ${JSON.stringify(outputValidation.error)}`
|
|
1580
1587
|
);
|
|
1581
1588
|
}
|
|
1582
|
-
response.structuredContent =
|
|
1589
|
+
response.structuredContent = structuredContent;
|
|
1583
1590
|
}
|
|
1584
1591
|
if (response.structuredContent) {
|
|
1585
1592
|
response.content = [{ type: "text", text: JSON.stringify(response.structuredContent) }];
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import $RefParser from '@apidevtools/json-schema-ref-parser';
|
|
1
2
|
import { MastraBase } from '@mastra/core/base';
|
|
2
3
|
import { MastraError, ErrorCategory, ErrorDomain } from '@mastra/core/error';
|
|
3
4
|
import { createTool as createTool$1 } from '@mastra/core/tools';
|
|
@@ -498,11 +499,12 @@ var InternalMastraMCPClient = class extends MastraBase {
|
|
|
498
499
|
return handler(request.params);
|
|
499
500
|
});
|
|
500
501
|
}
|
|
501
|
-
convertInputSchema(inputSchema) {
|
|
502
|
+
async convertInputSchema(inputSchema) {
|
|
502
503
|
if (isZodType(inputSchema)) {
|
|
503
504
|
return inputSchema;
|
|
504
505
|
}
|
|
505
506
|
try {
|
|
507
|
+
await $RefParser.dereference(inputSchema);
|
|
506
508
|
return convertJsonSchemaToZod(inputSchema);
|
|
507
509
|
} catch (error) {
|
|
508
510
|
let errorDetails;
|
|
@@ -527,12 +529,13 @@ var InternalMastraMCPClient = class extends MastraBase {
|
|
|
527
529
|
});
|
|
528
530
|
}
|
|
529
531
|
}
|
|
530
|
-
convertOutputSchema(outputSchema) {
|
|
532
|
+
async convertOutputSchema(outputSchema) {
|
|
531
533
|
if (!outputSchema) return;
|
|
532
534
|
if (isZodType(outputSchema)) {
|
|
533
535
|
return outputSchema;
|
|
534
536
|
}
|
|
535
537
|
try {
|
|
538
|
+
await $RefParser.dereference(outputSchema);
|
|
536
539
|
return convertJsonSchemaToZod(outputSchema);
|
|
537
540
|
} catch (error) {
|
|
538
541
|
let errorDetails;
|
|
@@ -561,14 +564,14 @@ var InternalMastraMCPClient = class extends MastraBase {
|
|
|
561
564
|
this.log("debug", `Requesting tools from MCP server`);
|
|
562
565
|
const { tools } = await this.client.listTools({ timeout: this.timeout });
|
|
563
566
|
const toolsRes = {};
|
|
564
|
-
|
|
567
|
+
for (const tool of tools) {
|
|
565
568
|
this.log("debug", `Processing tool: ${tool.name}`);
|
|
566
569
|
try {
|
|
567
570
|
const mastraTool = createTool$1({
|
|
568
571
|
id: `${this.name}_${tool.name}`,
|
|
569
572
|
description: tool.description || "",
|
|
570
|
-
inputSchema: this.convertInputSchema(tool.inputSchema),
|
|
571
|
-
outputSchema: this.convertOutputSchema(tool.outputSchema),
|
|
573
|
+
inputSchema: await this.convertInputSchema(tool.inputSchema),
|
|
574
|
+
outputSchema: await this.convertOutputSchema(tool.outputSchema),
|
|
572
575
|
execute: async ({ context, runtimeContext }) => {
|
|
573
576
|
const previousContext = this.currentOperationContext;
|
|
574
577
|
this.currentOperationContext = runtimeContext || null;
|
|
@@ -606,7 +609,7 @@ var InternalMastraMCPClient = class extends MastraBase {
|
|
|
606
609
|
mcpToolDefinition: tool
|
|
607
610
|
});
|
|
608
611
|
}
|
|
609
|
-
}
|
|
612
|
+
}
|
|
610
613
|
return toolsRes;
|
|
611
614
|
}
|
|
612
615
|
};
|
|
@@ -1561,10 +1564,13 @@ var MCPServer = class extends MCPServerBase {
|
|
|
1561
1564
|
this.logger.info(`Tool '${request.params.name}' executed successfully in ${duration}ms.`);
|
|
1562
1565
|
const response = { isError: false, content: [] };
|
|
1563
1566
|
if (tool.outputSchema) {
|
|
1564
|
-
|
|
1565
|
-
|
|
1567
|
+
let structuredContent;
|
|
1568
|
+
if (result && typeof result === "object" && "structuredContent" in result) {
|
|
1569
|
+
structuredContent = result.structuredContent;
|
|
1570
|
+
} else {
|
|
1571
|
+
structuredContent = result;
|
|
1566
1572
|
}
|
|
1567
|
-
const outputValidation = tool.outputSchema.validate?.(
|
|
1573
|
+
const outputValidation = tool.outputSchema.validate?.(structuredContent ?? {});
|
|
1568
1574
|
if (outputValidation && !outputValidation.success) {
|
|
1569
1575
|
this.logger.warn(`CallTool: Invalid structured content for '${request.params.name}'`, {
|
|
1570
1576
|
errors: outputValidation.error
|
|
@@ -1573,7 +1579,7 @@ var MCPServer = class extends MCPServerBase {
|
|
|
1573
1579
|
`Invalid structured content for tool ${request.params.name}: ${JSON.stringify(outputValidation.error)}`
|
|
1574
1580
|
);
|
|
1575
1581
|
}
|
|
1576
|
-
response.structuredContent =
|
|
1582
|
+
response.structuredContent = structuredContent;
|
|
1577
1583
|
}
|
|
1578
1584
|
if (response.structuredContent) {
|
|
1579
1585
|
response.content = [{ type: "text", text: JSON.stringify(response.structuredContent) }];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/mcp",
|
|
3
|
-
"version": "0.10.6-alpha.
|
|
3
|
+
"version": "0.10.6-alpha.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
"author": "",
|
|
23
23
|
"license": "Elastic-2.0",
|
|
24
24
|
"dependencies": {
|
|
25
|
+
"@apidevtools/json-schema-ref-parser": "^14.1.0",
|
|
25
26
|
"@modelcontextprotocol/sdk": "^1.13.0",
|
|
26
27
|
"date-fns": "^4.1.0",
|
|
27
28
|
"exit-hook": "^4.0.0",
|
|
@@ -51,7 +52,7 @@
|
|
|
51
52
|
"zod": "^3.25.67",
|
|
52
53
|
"zod-to-json-schema": "^3.24.5",
|
|
53
54
|
"@internal/lint": "0.0.17",
|
|
54
|
-
"@mastra/core": "0.10.11-alpha.
|
|
55
|
+
"@mastra/core": "0.10.11-alpha.3"
|
|
55
56
|
},
|
|
56
57
|
"scripts": {
|
|
57
58
|
"build": "tsup src/index.ts --format esm,cjs --experimental-dts --clean --treeshake=smallest --splitting",
|
package/src/client/client.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import $RefParser from '@apidevtools/json-schema-ref-parser';
|
|
1
2
|
import { MastraBase } from '@mastra/core/base';
|
|
2
|
-
|
|
3
3
|
import type { RuntimeContext } from '@mastra/core/di';
|
|
4
4
|
import { ErrorCategory, ErrorDomain, MastraError } from '@mastra/core/error';
|
|
5
5
|
import { createTool } from '@mastra/core/tools';
|
|
@@ -468,15 +468,16 @@ export class InternalMastraMCPClient extends MastraBase {
|
|
|
468
468
|
return handler(request.params);
|
|
469
469
|
});
|
|
470
470
|
}
|
|
471
|
-
|
|
472
|
-
private convertInputSchema(
|
|
471
|
+
|
|
472
|
+
private async convertInputSchema(
|
|
473
473
|
inputSchema: Awaited<ReturnType<Client['listTools']>>['tools'][0]['inputSchema'] | JSONSchema,
|
|
474
|
-
): z.ZodType {
|
|
474
|
+
): Promise<z.ZodType> {
|
|
475
475
|
if (isZodType(inputSchema)) {
|
|
476
476
|
return inputSchema;
|
|
477
477
|
}
|
|
478
478
|
|
|
479
479
|
try {
|
|
480
|
+
await $RefParser.dereference(inputSchema)
|
|
480
481
|
return convertJsonSchemaToZod(inputSchema as JSONSchema);
|
|
481
482
|
} catch (error: unknown) {
|
|
482
483
|
let errorDetails: string | undefined;
|
|
@@ -504,15 +505,16 @@ export class InternalMastraMCPClient extends MastraBase {
|
|
|
504
505
|
}
|
|
505
506
|
}
|
|
506
507
|
|
|
507
|
-
private convertOutputSchema(
|
|
508
|
+
private async convertOutputSchema(
|
|
508
509
|
outputSchema: Awaited<ReturnType<Client['listTools']>>['tools'][0]['outputSchema'] | JSONSchema,
|
|
509
|
-
): z.ZodType | undefined {
|
|
510
|
+
): Promise<z.ZodType | undefined> {
|
|
510
511
|
if (!outputSchema) return
|
|
511
512
|
if (isZodType(outputSchema)) {
|
|
512
513
|
return outputSchema;
|
|
513
514
|
}
|
|
514
515
|
|
|
515
516
|
try {
|
|
517
|
+
await $RefParser.dereference(outputSchema)
|
|
516
518
|
return convertJsonSchemaToZod(outputSchema as JSONSchema);
|
|
517
519
|
} catch (error: unknown) {
|
|
518
520
|
let errorDetails: string | undefined;
|
|
@@ -544,14 +546,14 @@ export class InternalMastraMCPClient extends MastraBase {
|
|
|
544
546
|
this.log('debug', `Requesting tools from MCP server`);
|
|
545
547
|
const { tools } = await this.client.listTools({ timeout: this.timeout });
|
|
546
548
|
const toolsRes: Record<string, any> = {};
|
|
547
|
-
|
|
549
|
+
for (const tool of tools) {
|
|
548
550
|
this.log('debug', `Processing tool: ${tool.name}`);
|
|
549
551
|
try {
|
|
550
552
|
const mastraTool = createTool({
|
|
551
553
|
id: `${this.name}_${tool.name}`,
|
|
552
554
|
description: tool.description || '',
|
|
553
|
-
inputSchema: this.convertInputSchema(tool.inputSchema),
|
|
554
|
-
outputSchema: this.convertOutputSchema(tool.outputSchema),
|
|
555
|
+
inputSchema: await this.convertInputSchema(tool.inputSchema),
|
|
556
|
+
outputSchema: await this.convertOutputSchema(tool.outputSchema),
|
|
555
557
|
execute: async ({ context, runtimeContext }: { context: any; runtimeContext?: RuntimeContext | null }) => {
|
|
556
558
|
const previousContext = this.currentOperationContext;
|
|
557
559
|
this.currentOperationContext = runtimeContext || null; // Set current context
|
|
@@ -592,7 +594,7 @@ export class InternalMastraMCPClient extends MastraBase {
|
|
|
592
594
|
mcpToolDefinition: tool,
|
|
593
595
|
});
|
|
594
596
|
}
|
|
595
|
-
}
|
|
597
|
+
}
|
|
596
598
|
|
|
597
599
|
return toolsRes;
|
|
598
600
|
}
|
|
@@ -1789,10 +1789,8 @@ describe('MCPServer with Tool Output Schema', () => {
|
|
|
1789
1789
|
timestamp: z.string(),
|
|
1790
1790
|
}),
|
|
1791
1791
|
execute: async ({ input }: { input: string }) => ({
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
timestamp: mockDateISO,
|
|
1795
|
-
},
|
|
1792
|
+
processedInput: `processed: ${input}`,
|
|
1793
|
+
timestamp: mockDateISO,
|
|
1796
1794
|
}),
|
|
1797
1795
|
},
|
|
1798
1796
|
};
|
package/src/server/server.ts
CHANGED
|
@@ -282,10 +282,17 @@ export class MCPServer extends MCPServerBase {
|
|
|
282
282
|
const response: CallToolResult = { isError: false, content: [] };
|
|
283
283
|
|
|
284
284
|
if (tool.outputSchema) {
|
|
285
|
-
|
|
286
|
-
|
|
285
|
+
// Handle both cases: tools that return { structuredContent: ... } and tools that return the plain object
|
|
286
|
+
let structuredContent;
|
|
287
|
+
if (result && typeof result === 'object' && 'structuredContent' in result) {
|
|
288
|
+
// Tool returned { structuredContent: ... } format (MCP-aware tool)
|
|
289
|
+
structuredContent = result.structuredContent;
|
|
290
|
+
} else {
|
|
291
|
+
// Tool returned plain object, wrap it automatically for backward compatibility
|
|
292
|
+
structuredContent = result;
|
|
287
293
|
}
|
|
288
|
-
|
|
294
|
+
|
|
295
|
+
const outputValidation = tool.outputSchema.validate?.(structuredContent ?? {});
|
|
289
296
|
if (outputValidation && !outputValidation.success) {
|
|
290
297
|
this.logger.warn(`CallTool: Invalid structured content for '${request.params.name}'`, {
|
|
291
298
|
errors: outputValidation.error,
|
|
@@ -294,7 +301,7 @@ export class MCPServer extends MCPServerBase {
|
|
|
294
301
|
`Invalid structured content for tool ${request.params.name}: ${JSON.stringify(outputValidation.error)}`,
|
|
295
302
|
);
|
|
296
303
|
}
|
|
297
|
-
response.structuredContent =
|
|
304
|
+
response.structuredContent = structuredContent;
|
|
298
305
|
}
|
|
299
306
|
|
|
300
307
|
if (response.structuredContent) {
|