@@ -238,21 +238,37 @@ describe('normalizeFunction', () => {
238238 func : ( ) => null
239239 }
240240 ] ) ( 'should normalize the config, $description' , ( { func } ) => {
241- const out = normalizeFunction ( func ) ;
241+ const updatedFunc = func ;
242+
243+ ( updatedFunc as any ) . toolName = 'loremIpsum' ;
244+
245+ const out = normalizeFunction ( updatedFunc ) ;
242246 const updated = ( out ?. original as any ) ?.( ) ;
243247
244248 if ( updated ?. [ 1 ] ?. inputSchema && isZodSchema ( updated [ 1 ] . inputSchema ) ) {
245249 updated [ 1 ] . inputSchema = 'isZod = true' ;
246250 }
247251
252+ expect ( out ?. type ) . toBe ( 'creator' ) ;
248253 expect ( updated ) . toMatchSnapshot ( ) ;
249254 } ) ;
250255
256+ it ( 'should be an invalid creator if the toolName is missing' , ( ) => {
257+ const func = ( ) => [ 'loremIpsum ' , { description : 'lorem ipsum' , inputSchema : z . any ( ) } , async ( ) => { } ] ;
258+
259+ const updated = normalizeFunction ( func ) ;
260+
261+ expect ( updated ?. type ) . toBe ( 'invalid' ) ;
262+ expect ( updated ?. error ) . toMatch ( / m i s s i n g .* t o o l n a m e / i) ;
263+ } ) ;
264+
251265 it ( 'should throw a predictable error on unwrap if the function errors' , ( ) => {
252266 const func = ( ) => {
253267 throw new Error ( 'Function error' ) ;
254268 } ;
255269
270+ ( func as any ) . toolName = 'loremIpsum' ;
271+
256272 const updated = normalizeFunction ( func ) ;
257273
258274 expect ( ( ) => ( updated ?. value as any ) ?.( ) ) . toThrow ( 'Tool failed to load:' ) ;
@@ -468,13 +484,31 @@ describe('normalizeTools', () => {
468484 it . each ( [
469485 {
470486 description : 'a creator' ,
471- config : ( ) => [ 'loremIpsum' , { description : 'lorem ipsum' , inputSchema : { type : 'object' , properties : { } } } , ( ) => { } ]
487+ config : ( ( ) => {
488+ const testing = ( ) => [ 'loremIpsum' , { description : 'lorem ipsum' , inputSchema : { type : 'object' , properties : { } } } , ( ) => { } ] ;
489+
490+ ( testing as any ) . toolName = 'loremIpsum' ;
491+
492+ return testing ;
493+ } ) ( )
472494 } ,
473495 {
474496 description : 'array of creators' ,
475497 config : [
476- ( ) => [ 'loremIpsum' , { description : 'lorem ipsum' , inputSchema : { type : 'object' , properties : { } } } , ( ) => { } ] ,
477- ( ) => [ 'dolorSit' , { description : 'dolor sit' , inputSchema : { type : 'object' , properties : { } } } , ( ) => { } ]
498+ ( ( ) => {
499+ const testing = ( ) => [ 'loremIpsum' , { description : 'lorem ipsum' , inputSchema : { type : 'object' , properties : { } } } , ( ) => { } ] ;
500+
501+ ( testing as any ) . toolName = 'loremIpsum' ;
502+
503+ return testing ;
504+ } ) ( ) ,
505+ ( ( ) => {
506+ const testing = ( ) => [ 'dolorSit' , { description : 'dolor sit' , inputSchema : { type : 'object' , properties : { } } } , ( ) => { } ] ;
507+
508+ ( testing as any ) . toolName = 'dolorSit' ;
509+
510+ return testing ;
511+ } ) ( )
478512 ]
479513 } ,
480514 {
@@ -487,7 +521,13 @@ describe('normalizeTools', () => {
487521 '@scope/pkg' ,
488522 { name : 'ametDolor' , description : 'amet dolor' , inputSchema : { type : 'object' , properties : { } } , handler : ( ) => { } } ,
489523 [ 'loremIpsum' , { description : 'lorem ipsum' , inputSchema : { type : 'object' , properties : { } } } , ( ) => { } ] ,
490- ( ) => [ 'dolorSit' , { description : 'dolor sit' , inputSchema : { type : 'object' , properties : { } } } , ( ) => { } ]
524+ ( ( ) => {
525+ const testing = ( ) => [ 'dolorSit' , { description : 'dolor sit' , inputSchema : { type : 'object' , properties : { } } } , ( ) => { } ] ;
526+
527+ ( testing as any ) . toolName = 'dolorSit' ;
528+
529+ return testing ;
530+ } ) ( )
491531 ]
492532 } ,
493533 {
@@ -570,13 +610,31 @@ describe('createMcpTool', () => {
570610 it . each ( [
571611 {
572612 description : 'a creator' ,
573- config : ( ) => [ 'loremIpsum' , { description : 'lorem ipsum' , inputSchema : { type : 'object' , properties : { } } } , ( ) => { } ]
613+ config : ( ( ) => {
614+ const testing = ( ) => [ 'loremIpsum' , { description : 'lorem ipsum' , inputSchema : { type : 'object' , properties : { } } } , ( ) => { } ] ;
615+
616+ ( testing as any ) . toolName = 'loremIpsum' ;
617+
618+ return testing ;
619+ } ) ( )
574620 } ,
575621 {
576622 description : 'array of creators' ,
577623 config : [
578- ( ) => [ 'loremIpsum' , { description : 'lorem ipsum' , inputSchema : { type : 'object' , properties : { } } } , ( ) => { } ] ,
579- ( ) => [ 'dolorSit' , { description : 'dolor sit' , inputSchema : { type : 'object' , properties : { } } } , ( ) => { } ]
624+ ( ( ) => {
625+ const testing = ( ) => [ 'loremIpsum' , { description : 'lorem ipsum' , inputSchema : { type : 'object' , properties : { } } } , ( ) => { } ] ;
626+
627+ ( testing as any ) . toolName = 'loremIpsum' ;
628+
629+ return testing ;
630+ } ) ( ) ,
631+ ( ( ) => {
632+ const testing = ( ) => [ 'dolorSit' , { description : 'dolor sit' , inputSchema : { type : 'object' , properties : { } } } , ( ) => { } ] ;
633+
634+ ( testing as any ) . toolName = 'dolorSit' ;
635+
636+ return testing ;
637+ } ) ( )
580638 ]
581639 } ,
582640 {
@@ -589,7 +647,13 @@ describe('createMcpTool', () => {
589647 '@scope/pkg' ,
590648 { name : 'ametDolor' , description : 'amet dolor' , inputSchema : { type : 'object' , properties : { } } , handler : ( ) => { } } ,
591649 [ 'loremIpsum' , { description : 'lorem ipsum' , inputSchema : { type : 'object' , properties : { } } } , ( ) => { } ] ,
592- ( ) => [ 'dolorSit' , { description : 'dolor sit' , inputSchema : { type : 'object' , properties : { } } } , ( ) => { } ]
650+ ( ( ) => {
651+ const testing = ( ) => [ 'dolorSit' , { description : 'dolor sit' , inputSchema : { type : 'object' , properties : { } } } , ( ) => { } ] ;
652+
653+ ( testing as any ) . toolName = 'dolorSit' ;
654+
655+ return testing ;
656+ } ) ( )
593657 ]
594658 } ,
595659 {
0 commit comments