@@ -678,6 +678,87 @@ Instance JSON document does not match the specified schema.
678
678
679
679
record Person ( string Name , int Age ) ;
680
680
681
+ [ Fact ]
682
+ public void SupportsIconsInCreateOptions ( )
683
+ {
684
+ var icons = new List < Icon >
685
+ {
686
+ new ( ) { Source = "https://example.com/icon.png" , MimeType = "image/png" , Sizes = "48x48" } ,
687
+ new ( ) { Source = "https://example.com/icon.svg" , MimeType = "image/svg+xml" , Sizes = "any" }
688
+ } ;
689
+
690
+ McpServerTool tool = McpServerTool . Create ( ( ) => "test" , new McpServerToolCreateOptions
691
+ {
692
+ Icons = icons
693
+ } ) ;
694
+
695
+ Assert . NotNull ( tool . ProtocolTool . Icons ) ;
696
+ Assert . Equal ( 2 , tool . ProtocolTool . Icons . Count ) ;
697
+ Assert . Equal ( "https://example.com/icon.png" , tool . ProtocolTool . Icons [ 0 ] . Source ) ;
698
+ Assert . Equal ( "image/png" , tool . ProtocolTool . Icons [ 0 ] . MimeType ) ;
699
+ Assert . Equal ( "48x48" , tool . ProtocolTool . Icons [ 0 ] . Sizes ) ;
700
+ Assert . Equal ( "https://example.com/icon.svg" , tool . ProtocolTool . Icons [ 1 ] . Source ) ;
701
+ Assert . Equal ( "image/svg+xml" , tool . ProtocolTool . Icons [ 1 ] . MimeType ) ;
702
+ Assert . Equal ( "any" , tool . ProtocolTool . Icons [ 1 ] . Sizes ) ;
703
+ }
704
+
705
+ [ Fact ]
706
+ public void SupportsIconSourceInAttribute ( )
707
+ {
708
+ MethodInfo ? method = typeof ( IconTestClass ) . GetMethod ( nameof ( IconTestClass . ToolWithIconSource ) ) ;
709
+ Assert . NotNull ( method ) ;
710
+
711
+ McpServerTool tool = McpServerTool . Create ( method , new IconTestClass ( ) ) ;
712
+
713
+ Assert . NotNull ( tool . ProtocolTool . Icons ) ;
714
+ Assert . Single ( tool . ProtocolTool . Icons ) ;
715
+ Assert . Equal ( "https://example.com/tool-icon.png" , tool . ProtocolTool . Icons [ 0 ] . Source ) ;
716
+ Assert . Null ( tool . ProtocolTool . Icons [ 0 ] . MimeType ) ;
717
+ Assert . Null ( tool . ProtocolTool . Icons [ 0 ] . Sizes ) ;
718
+ }
719
+
720
+ [ Fact ]
721
+ public void CreateOptionsIconsOverrideAttributeIconSource ( )
722
+ {
723
+ MethodInfo ? method = typeof ( IconTestClass ) . GetMethod ( nameof ( IconTestClass . ToolWithIconSource ) ) ;
724
+ Assert . NotNull ( method ) ;
725
+
726
+ var optionsIcons = new List < Icon >
727
+ {
728
+ new ( ) { Source = "https://example.com/override-icon.svg" , MimeType = "image/svg+xml" }
729
+ } ;
730
+
731
+ McpServerTool tool = McpServerTool . Create ( method , new IconTestClass ( ) , new McpServerToolCreateOptions
732
+ {
733
+ Icons = optionsIcons
734
+ } ) ;
735
+
736
+ Assert . NotNull ( tool . ProtocolTool . Icons ) ;
737
+ Assert . Single ( tool . ProtocolTool . Icons ) ;
738
+ Assert . Equal ( "https://example.com/override-icon.svg" , tool . ProtocolTool . Icons [ 0 ] . Source ) ;
739
+ Assert . Equal ( "image/svg+xml" , tool . ProtocolTool . Icons [ 0 ] . MimeType ) ;
740
+ }
741
+
742
+ [ Fact ]
743
+ public void SupportsToolWithoutIcons ( )
744
+ {
745
+ MethodInfo ? method = typeof ( IconTestClass ) . GetMethod ( nameof ( IconTestClass . ToolWithoutIcon ) ) ;
746
+ Assert . NotNull ( method ) ;
747
+
748
+ McpServerTool tool = McpServerTool . Create ( method , new IconTestClass ( ) ) ;
749
+
750
+ Assert . Null ( tool . ProtocolTool . Icons ) ;
751
+ }
752
+
753
+ private class IconTestClass
754
+ {
755
+ [ McpServerTool ( IconSource = "https://example.com/tool-icon.png" ) ]
756
+ public string ToolWithIconSource ( ) => "result" ;
757
+
758
+ [ McpServerTool ]
759
+ public string ToolWithoutIcon ( ) => "result" ;
760
+ }
761
+
681
762
[ JsonSourceGenerationOptions ( PropertyNamingPolicy = JsonKnownNamingPolicy . CamelCase ) ]
682
763
[ JsonSerializable ( typeof ( DisposableToolType ) ) ]
683
764
[ JsonSerializable ( typeof ( AsyncDisposableToolType ) ) ]
0 commit comments