Skip to content

Commit 4bcbe1c

Browse files
Refactor icon tests to use Delegate overload instead of MethodInfo pattern
Co-authored-by: MackinnonBuck <[email protected]>
1 parent 6de63f5 commit 4bcbe1c

File tree

1 file changed

+3
-21
lines changed

1 file changed

+3
-21
lines changed

tests/ModelContextProtocol.Tests/Server/McpServerToolTests.cs

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -705,10 +705,7 @@ public void SupportsIconsInCreateOptions()
705705
[Fact]
706706
public void SupportsIconSourceInAttribute()
707707
{
708-
MethodInfo? method = typeof(IconTestClass).GetMethod(nameof(IconTestClass.ToolWithIconSource));
709-
Assert.NotNull(method);
710-
711-
McpServerTool tool = McpServerTool.Create(method, new IconTestClass());
708+
McpServerTool tool = McpServerTool.Create([McpServerTool(IconSource = "https://example.com/tool-icon.png")] () => "result");
712709

713710
Assert.NotNull(tool.ProtocolTool.Icons);
714711
Assert.Single(tool.ProtocolTool.Icons);
@@ -720,15 +717,12 @@ public void SupportsIconSourceInAttribute()
720717
[Fact]
721718
public void CreateOptionsIconsOverrideAttributeIconSource()
722719
{
723-
MethodInfo? method = typeof(IconTestClass).GetMethod(nameof(IconTestClass.ToolWithIconSource));
724-
Assert.NotNull(method);
725-
726720
var optionsIcons = new List<Icon>
727721
{
728722
new() { Source = "https://example.com/override-icon.svg", MimeType = "image/svg+xml" }
729723
};
730724

731-
McpServerTool tool = McpServerTool.Create(method, new IconTestClass(), new McpServerToolCreateOptions
725+
McpServerTool tool = McpServerTool.Create([McpServerTool(IconSource = "https://example.com/tool-icon.png")] () => "result", new McpServerToolCreateOptions
732726
{
733727
Icons = optionsIcons
734728
});
@@ -742,23 +736,11 @@ public void CreateOptionsIconsOverrideAttributeIconSource()
742736
[Fact]
743737
public void SupportsToolWithoutIcons()
744738
{
745-
MethodInfo? method = typeof(IconTestClass).GetMethod(nameof(IconTestClass.ToolWithoutIcon));
746-
Assert.NotNull(method);
747-
748-
McpServerTool tool = McpServerTool.Create(method, new IconTestClass());
739+
McpServerTool tool = McpServerTool.Create([McpServerTool] () => "result");
749740

750741
Assert.Null(tool.ProtocolTool.Icons);
751742
}
752743

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-
762744
[JsonSourceGenerationOptions(PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase)]
763745
[JsonSerializable(typeof(DisposableToolType))]
764746
[JsonSerializable(typeof(AsyncDisposableToolType))]

0 commit comments

Comments
 (0)