@@ -487,7 +487,7 @@ describe("filterMcpToolsForMode", () => {
487487 it ( "should return original tools when modelInfo is undefined" , ( ) => {
488488 const tools = new Set ( [ "read_file" , "write_to_file" , "apply_diff" ] )
489489 const result = applyModelToolCustomization ( tools , codeMode , undefined )
490- expect ( result ) . toEqual ( tools )
490+ expect ( result . allowedTools ) . toEqual ( tools )
491491 } )
492492
493493 it ( "should exclude tools specified in excludedTools" , ( ) => {
@@ -498,9 +498,9 @@ describe("filterMcpToolsForMode", () => {
498498 excludedTools : [ "apply_diff" ] ,
499499 }
500500 const result = applyModelToolCustomization ( tools , codeMode , modelInfo )
501- expect ( result . has ( "read_file" ) ) . toBe ( true )
502- expect ( result . has ( "write_to_file" ) ) . toBe ( true )
503- expect ( result . has ( "apply_diff" ) ) . toBe ( false )
501+ expect ( result . allowedTools . has ( "read_file" ) ) . toBe ( true )
502+ expect ( result . allowedTools . has ( "write_to_file" ) ) . toBe ( true )
503+ expect ( result . allowedTools . has ( "apply_diff" ) ) . toBe ( false )
504504 } )
505505
506506 it ( "should exclude multiple tools" , ( ) => {
@@ -511,10 +511,10 @@ describe("filterMcpToolsForMode", () => {
511511 excludedTools : [ "apply_diff" , "write_to_file" ] ,
512512 }
513513 const result = applyModelToolCustomization ( tools , codeMode , modelInfo )
514- expect ( result . has ( "read_file" ) ) . toBe ( true )
515- expect ( result . has ( "execute_command" ) ) . toBe ( true )
516- expect ( result . has ( "write_to_file" ) ) . toBe ( false )
517- expect ( result . has ( "apply_diff" ) ) . toBe ( false )
514+ expect ( result . allowedTools . has ( "read_file" ) ) . toBe ( true )
515+ expect ( result . allowedTools . has ( "execute_command" ) ) . toBe ( true )
516+ expect ( result . allowedTools . has ( "write_to_file" ) ) . toBe ( false )
517+ expect ( result . allowedTools . has ( "apply_diff" ) ) . toBe ( false )
518518 } )
519519
520520 it ( "should include tools only if they belong to allowed groups" , ( ) => {
@@ -525,9 +525,9 @@ describe("filterMcpToolsForMode", () => {
525525 includedTools : [ "write_to_file" , "apply_diff" ] , // Both in edit group
526526 }
527527 const result = applyModelToolCustomization ( tools , codeMode , modelInfo )
528- expect ( result . has ( "read_file" ) ) . toBe ( true )
529- expect ( result . has ( "write_to_file" ) ) . toBe ( true )
530- expect ( result . has ( "apply_diff" ) ) . toBe ( true )
528+ expect ( result . allowedTools . has ( "read_file" ) ) . toBe ( true )
529+ expect ( result . allowedTools . has ( "write_to_file" ) ) . toBe ( true )
530+ expect ( result . allowedTools . has ( "apply_diff" ) ) . toBe ( true )
531531 } )
532532
533533 it ( "should NOT include tools from groups not allowed by mode" , ( ) => {
@@ -539,9 +539,9 @@ describe("filterMcpToolsForMode", () => {
539539 }
540540 // Architect mode doesn't have edit group
541541 const result = applyModelToolCustomization ( tools , architectMode , modelInfo )
542- expect ( result . has ( "read_file" ) ) . toBe ( true )
543- expect ( result . has ( "write_to_file" ) ) . toBe ( false ) // Not in allowed groups
544- expect ( result . has ( "apply_diff" ) ) . toBe ( false ) // Not in allowed groups
542+ expect ( result . allowedTools . has ( "read_file" ) ) . toBe ( true )
543+ expect ( result . allowedTools . has ( "write_to_file" ) ) . toBe ( false ) // Not in allowed groups
544+ expect ( result . allowedTools . has ( "apply_diff" ) ) . toBe ( false ) // Not in allowed groups
545545 } )
546546
547547 it ( "should apply both exclude and include operations" , ( ) => {
@@ -553,10 +553,10 @@ describe("filterMcpToolsForMode", () => {
553553 includedTools : [ "search_and_replace" ] , // Another edit tool (customTool)
554554 }
555555 const result = applyModelToolCustomization ( tools , codeMode , modelInfo )
556- expect ( result . has ( "read_file" ) ) . toBe ( true )
557- expect ( result . has ( "write_to_file" ) ) . toBe ( true )
558- expect ( result . has ( "apply_diff" ) ) . toBe ( false ) // Excluded
559- expect ( result . has ( "search_and_replace" ) ) . toBe ( true ) // Included
556+ expect ( result . allowedTools . has ( "read_file" ) ) . toBe ( true )
557+ expect ( result . allowedTools . has ( "write_to_file" ) ) . toBe ( true )
558+ expect ( result . allowedTools . has ( "apply_diff" ) ) . toBe ( false ) // Excluded
559+ expect ( result . allowedTools . has ( "search_and_replace" ) ) . toBe ( true ) // Included
560560 } )
561561
562562 it ( "should handle empty excludedTools and includedTools arrays" , ( ) => {
@@ -568,7 +568,7 @@ describe("filterMcpToolsForMode", () => {
568568 includedTools : [ ] ,
569569 }
570570 const result = applyModelToolCustomization ( tools , codeMode , modelInfo )
571- expect ( result ) . toEqual ( tools )
571+ expect ( result . allowedTools ) . toEqual ( tools )
572572 } )
573573
574574 it ( "should ignore excluded tools that are not in the original set" , ( ) => {
@@ -579,9 +579,9 @@ describe("filterMcpToolsForMode", () => {
579579 excludedTools : [ "apply_diff" , "nonexistent_tool" ] ,
580580 }
581581 const result = applyModelToolCustomization ( tools , codeMode , modelInfo )
582- expect ( result . has ( "read_file" ) ) . toBe ( true )
583- expect ( result . has ( "write_to_file" ) ) . toBe ( true )
584- expect ( result . size ) . toBe ( 2 )
582+ expect ( result . allowedTools . has ( "read_file" ) ) . toBe ( true )
583+ expect ( result . allowedTools . has ( "write_to_file" ) ) . toBe ( true )
584+ expect ( result . allowedTools . size ) . toBe ( 2 )
585585 } )
586586
587587 it ( "should NOT include customTools by default" , ( ) => {
@@ -594,8 +594,8 @@ describe("filterMcpToolsForMode", () => {
594594 }
595595 const result = applyModelToolCustomization ( tools , codeMode , modelInfo )
596596 // customTools should not be in the result unless explicitly included
597- expect ( result . has ( "read_file" ) ) . toBe ( true )
598- expect ( result . has ( "write_to_file" ) ) . toBe ( true )
597+ expect ( result . allowedTools . has ( "read_file" ) ) . toBe ( true )
598+ expect ( result . allowedTools . has ( "write_to_file" ) ) . toBe ( true )
599599 } )
600600
601601 it ( "should NOT include tools that are not in any TOOL_GROUPS" , ( ) => {
@@ -606,8 +606,8 @@ describe("filterMcpToolsForMode", () => {
606606 includedTools : [ "my_custom_tool" ] , // Not in any tool group
607607 }
608608 const result = applyModelToolCustomization ( tools , codeMode , modelInfo )
609- expect ( result . has ( "read_file" ) ) . toBe ( true )
610- expect ( result . has ( "my_custom_tool" ) ) . toBe ( false )
609+ expect ( result . allowedTools . has ( "read_file" ) ) . toBe ( true )
610+ expect ( result . allowedTools . has ( "my_custom_tool" ) ) . toBe ( false )
611611 } )
612612
613613 it ( "should NOT include undefined tools even with allowed groups" , ( ) => {
@@ -619,8 +619,8 @@ describe("filterMcpToolsForMode", () => {
619619 }
620620 // Even though architect mode has read group, undefined tools are not added
621621 const result = applyModelToolCustomization ( tools , architectMode , modelInfo )
622- expect ( result . has ( "read_file" ) ) . toBe ( true )
623- expect ( result . has ( "custom_edit_tool" ) ) . toBe ( false )
622+ expect ( result . allowedTools . has ( "read_file" ) ) . toBe ( true )
623+ expect ( result . allowedTools . has ( "custom_edit_tool" ) ) . toBe ( false )
624624 } )
625625
626626 describe ( "with customTools defined in TOOL_GROUPS" , ( ) => {
@@ -647,9 +647,9 @@ describe("filterMcpToolsForMode", () => {
647647 includedTools : [ "special_edit_tool" ] , // customTool from edit group
648648 }
649649 const result = applyModelToolCustomization ( tools , codeMode , modelInfo )
650- expect ( result . has ( "read_file" ) ) . toBe ( true )
651- expect ( result . has ( "write_to_file" ) ) . toBe ( true )
652- expect ( result . has ( "special_edit_tool" ) ) . toBe ( true ) // customTool should be included
650+ expect ( result . allowedTools . has ( "read_file" ) ) . toBe ( true )
651+ expect ( result . allowedTools . has ( "write_to_file" ) ) . toBe ( true )
652+ expect ( result . allowedTools . has ( "special_edit_tool" ) ) . toBe ( true ) // customTool should be included
653653 } )
654654
655655 it ( "should NOT include customTools when not specified in includedTools" , ( ) => {
@@ -660,9 +660,9 @@ describe("filterMcpToolsForMode", () => {
660660 // No includedTools specified
661661 }
662662 const result = applyModelToolCustomization ( tools , codeMode , modelInfo )
663- expect ( result . has ( "read_file" ) ) . toBe ( true )
664- expect ( result . has ( "write_to_file" ) ) . toBe ( true )
665- expect ( result . has ( "special_edit_tool" ) ) . toBe ( false ) // customTool should NOT be included by default
663+ expect ( result . allowedTools . has ( "read_file" ) ) . toBe ( true )
664+ expect ( result . allowedTools . has ( "write_to_file" ) ) . toBe ( true )
665+ expect ( result . allowedTools . has ( "special_edit_tool" ) ) . toBe ( false ) // customTool should NOT be included by default
666666 } )
667667
668668 it ( "should NOT include customTools from groups not allowed by mode" , ( ) => {
@@ -674,8 +674,8 @@ describe("filterMcpToolsForMode", () => {
674674 }
675675 // Architect mode doesn't have edit group
676676 const result = applyModelToolCustomization ( tools , architectMode , modelInfo )
677- expect ( result . has ( "read_file" ) ) . toBe ( true )
678- expect ( result . has ( "special_edit_tool" ) ) . toBe ( false ) // customTool should NOT be included
677+ expect ( result . allowedTools . has ( "read_file" ) ) . toBe ( true )
678+ expect ( result . allowedTools . has ( "special_edit_tool" ) ) . toBe ( false ) // customTool should NOT be included
679679 } )
680680 } )
681681 } )
@@ -822,5 +822,31 @@ describe("filterMcpToolsForMode", () => {
822822 expect ( toolNames ) . toContain ( "search_and_replace" ) // Included
823823 expect ( toolNames ) . not . toContain ( "apply_diff" ) // Excluded
824824 } )
825+
826+ it ( "should rename tools to alias names when model includes aliases" , ( ) => {
827+ const codeMode : ModeConfig = {
828+ slug : "code" ,
829+ name : "Code" ,
830+ roleDefinition : "Test" ,
831+ groups : [ "read" , "edit" , "browser" , "command" , "mcp" ] as const ,
832+ }
833+
834+ const modelInfo : ModelInfo = {
835+ contextWindow : 100000 ,
836+ supportsPromptCache : false ,
837+ includedTools : [ "edit_file" , "write_file" ] ,
838+ }
839+
840+ const filtered = filterNativeToolsForMode ( mockNativeTools , "code" , [ codeMode ] , { } , undefined , {
841+ modelInfo,
842+ } )
843+
844+ const toolNames = filtered . map ( ( t ) => ( "function" in t ? t . function . name : "" ) )
845+
846+ expect ( toolNames ) . toContain ( "edit_file" )
847+ expect ( toolNames ) . toContain ( "write_file" )
848+ expect ( toolNames ) . not . toContain ( "apply_diff" )
849+ expect ( toolNames ) . not . toContain ( "write_to_file" )
850+ } )
825851 } )
826852} )
0 commit comments