Skip to content

Commit 4f7a3b3

Browse files
Fixing the toolProperties issue (#392)
* Fixing the toolProperties issue * Adding test
1 parent bfaf3bb commit 4f7a3b3

File tree

2 files changed

+51
-2
lines changed

2 files changed

+51
-2
lines changed

src/utils/toolProperties.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,8 @@ export function convertToolProperties(args: Args): McpToolProperty[] {
227227
propertyName,
228228
propertyType: property.propertyType,
229229
description: property.description || '', // Default to empty string if not provided
230-
isRequired: property.isRequired,
231-
isArray: property.isArray,
230+
isRequired: property.isRequired ?? true, // Default to true (required by default)
231+
isArray: property.isArray ?? false, // Default to false
232232
}));
233233
}
234234

test/toolArrayProperties.test.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,4 +174,53 @@ describe('isArray property support', () => {
174174
expect(doubleArrayProp?.isArray).to.equal(true);
175175
expect(doubleArrayProp?.isRequired).to.equal(false);
176176
});
177+
178+
it('convertToolProperties defaults undefined isRequired to true and isArray to false', () => {
179+
// Create a mock Args object with undefined optional properties
180+
const toolProps = {
181+
prop1: {
182+
propertyName: '',
183+
propertyType: 'string',
184+
description: 'Test property 1',
185+
isRequired: undefined,
186+
isArray: undefined,
187+
},
188+
prop2: {
189+
propertyName: '',
190+
propertyType: 'number',
191+
description: 'Test property 2',
192+
isRequired: false,
193+
isArray: true,
194+
},
195+
prop3: {
196+
propertyName: '',
197+
propertyType: 'boolean',
198+
description: 'Test property 3',
199+
isRequired: true,
200+
isArray: false,
201+
},
202+
};
203+
204+
const converted = convertToolProperties(toolProps as any);
205+
206+
expect(converted).to.have.lengthOf(3);
207+
208+
// prop1 with undefined should default to required=true, array=false
209+
const prop1 = converted.find((p) => p.propertyName === 'prop1');
210+
expect(prop1?.isRequired).to.equal(true);
211+
expect(prop1?.isArray).to.equal(false);
212+
expect(prop1?.propertyType).to.equal('string');
213+
214+
// prop2 with explicit false/true should be preserved
215+
const prop2 = converted.find((p) => p.propertyName === 'prop2');
216+
expect(prop2?.isRequired).to.equal(false);
217+
expect(prop2?.isArray).to.equal(true);
218+
expect(prop2?.propertyType).to.equal('number');
219+
220+
// prop3 with explicit true/false should be preserved
221+
const prop3 = converted.find((p) => p.propertyName === 'prop3');
222+
expect(prop3?.isRequired).to.equal(true);
223+
expect(prop3?.isArray).to.equal(false);
224+
expect(prop3?.propertyType).to.equal('boolean');
225+
});
177226
});

0 commit comments

Comments
 (0)