544
expect(strictProvider['strict']).toBe(true);
545
});
546
547
- it('should use removeNonRequiredProperties when strict mode is enabled', () => {
547
+ it('should keep optional properties as required-nullable when strict mode is enabled', () => {
548
const strictProvider = new MastraProvider({ strict: true });
549
550
const toolWithOptionalProps: Tool = {
567
568
strictProvider.wrapTool(toolWithOptionalProps, mockExecuteToolFn);
569
570
- // In strict mode, only required properties should be passed to jsonSchemaToZodSchema
571
- // The removeNonRequiredProperties function should have been called and filtered the schema
570
+ // In strict mode every property is required and closed; optional ones
571
+ // stay available and accept null instead of being dropped.
572
expect(createTool).toHaveBeenCalledWith({
573
id: toolWithOptionalProps.slug,
574
description: toolWithOptionalProps.description,
581
type: 'string',
582
description: 'Required field',
583
},
584
+ optional_field: {
585
+ type: ['string', 'null'],
586
+ description: 'Optional field',
587
+ },
588
},
585
- required: ['required_field'],
589
+ required: ['required_field', 'optional_field'],
590
additionalProperties: false,
591
},
592
},
595
});
596
});
597
598
+ it('keeps the original schema for tools strict mode cannot express', () => {
599
+ const strictProvider = new MastraProvider({ strict: true });
600
+ const toolWithMap: Tool = {
601
+ ...mockTool,
602
+ inputParameters: {
603
+ type: 'object',
604
+ properties: {
605
+ headers: { type: 'object', additionalProperties: { type: 'string' } },
606
+ name: { type: 'string' },
607
+ },
608
+ required: ['headers'],
609
+ },
610
+ };
611
+
612
+ strictProvider.wrapTool(toolWithMap, mockExecuteToolFn);
613
+
614
+ expect(createTool).toHaveBeenCalledWith(
615
+ expect.objectContaining({
616
+ inputSchema: { type: 'mock-zod-schema', originalSchema: toolWithMap.inputParameters },
617
+ })
618
+ );
619
+ });
620
+
621
+ it('omits null arguments the tool schema rejects before executing under strict mode', async () => {
622
+ const strictProvider = new MastraProvider({ strict: true });
623
+ const wrapped = strictProvider.wrapTool(
624
+ {
625
+ ...mockTool,
626
+ inputParameters: {
627
+ type: 'object',
628
+ properties: {
629
+ cfg: {
630
+ type: 'object',
631
+ properties: { url: { type: 'string' }, note: { type: 'string' } },
632
+ required: ['url'],
633
+ },
634
+ clearable: { type: ['string', 'null'] },
635
+ },
636
+ required: ['cfg'],
637
+ },
638
+ },
639
+ mockExecuteToolFn
640
+ ) as unknown as { execute: (input: unknown, context: unknown) => Promise<unknown> };
641
+
642
+ await wrapped.execute({ cfg: { url: 'u', note: null }, clearable: null }, {});
643
+
644
+ expect(mockExecuteToolFn).toHaveBeenCalledWith(mockTool.slug, {
645
+ cfg: { url: 'u' },
646
+ clearable: null,
647
+ });
648
+ });
649
+
650
it('should use all properties when strict mode is disabled', () => {
651
const nonStrictProvider = new MastraProvider({ strict: false });
652