@@ -761,6 +761,75 @@ describe("McpdClient", () => {
761761 expect ( prefixedFilter ) . toHaveLength ( 1 ) ;
762762 expect ( prefixedFilter [ 0 ] ?. name ) . toBe ( "test__my__special__tool" ) ;
763763 } ) ;
764+
765+ it ( "should prefer prefixed format when filter is ambiguous" , async ( ) => {
766+ mockFetch . mockResolvedValueOnce ( {
767+ ok : true ,
768+ json : async ( ) => [ "my" , "other" ] ,
769+ } ) ;
770+
771+ mockFetch . mockResolvedValueOnce ( {
772+ ok : true ,
773+ json : async ( ) => ( {
774+ servers : [
775+ {
776+ name : "my" ,
777+ status : "ok" ,
778+ latency : "1ms" ,
779+ lastChecked : "2025-10-07T15:00:00Z" ,
780+ lastSuccessful : "2025-10-07T15:00:00Z" ,
781+ } ,
782+ {
783+ name : "other" ,
784+ status : "ok" ,
785+ latency : "1ms" ,
786+ lastChecked : "2025-10-07T15:00:00Z" ,
787+ lastSuccessful : "2025-10-07T15:00:00Z" ,
788+ } ,
789+ ] ,
790+ } ) ,
791+ } ) ;
792+
793+ mockFetch . mockResolvedValueOnce ( {
794+ ok : true ,
795+ json : async ( ) => ( {
796+ tools : [
797+ {
798+ name : "special__tool" ,
799+ description : "Tool from 'my' server" ,
800+ inputSchema : { type : "object" , properties : { } } ,
801+ } ,
802+ ] ,
803+ } ) ,
804+ } ) ;
805+
806+ mockFetch . mockResolvedValueOnce ( {
807+ ok : true ,
808+ json : async ( ) => ( {
809+ tools : [
810+ {
811+ name : "my__special__tool" ,
812+ description : "Tool from 'other' server" ,
813+ inputSchema : { type : "object" , properties : { } } ,
814+ } ,
815+ ] ,
816+ } ) ,
817+ } ) ;
818+
819+ const tools = await client . getAgentTools ( {
820+ tools : [ "my__special__tool" ] ,
821+ } ) ;
822+
823+ expect ( tools ) . toHaveLength ( 2 ) ;
824+
825+ const prefixedMatch = tools . find ( ( t ) => t . _serverName === "my" ) ;
826+ expect ( prefixedMatch ?. _toolName ) . toBe ( "special__tool" ) ;
827+ expect ( prefixedMatch ?. name ) . toBe ( "my__special__tool" ) ;
828+
829+ const rawMatch = tools . find ( ( t ) => t . _serverName === "other" ) ;
830+ expect ( rawMatch ?. _toolName ) . toBe ( "my__special__tool" ) ;
831+ expect ( rawMatch ?. name ) . toBe ( "other__my__special__tool" ) ;
832+ } ) ;
764833 } ) ;
765834
766835 describe ( "clearAgentToolsCache()" , ( ) => {
0 commit comments