Skip to content

Commit ca3fbdc

Browse files
authored
[MCP] Updated icon theme description and added validation (#8996)
1 parent 3098c7c commit ca3fbdc

File tree

4 files changed

+68
-3
lines changed

4 files changed

+68
-3
lines changed

src/HotChocolate/Adapters/src/Adapters.Mcp.Core/Properties/McpAdapterResources.Designer.cs

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/HotChocolate/Adapters/src/Adapters.Mcp.Core/Properties/McpAdapterResources.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@
4545
<data name="OperationToolIcon_InvalidIconSourceScheme" xml:space="preserve">
4646
<value>The icon source URI must use the HTTP, HTTPS, or data scheme.</value>
4747
</data>
48+
<data name="OperationToolIcon_InvalidIconTheme" xml:space="preserve">
49+
<value>The icon theme must be 'light' or 'dark'.</value>
50+
</data>
4851
<data name="ReadResourceHandler_ResourceNotFound" xml:space="preserve">
4952
<value>Resource not found.</value>
5053
</data>

src/HotChocolate/Adapters/src/Adapters.Mcp.Core/Storage/OperationToolIcon.cs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,24 @@ public IList<string>? Sizes
8484
}
8585

8686
/// <summary>
87-
/// The optional theme for this icon. Can be "light", "dark", or a custom theme identifier. Used
88-
/// to specify which UI theme the icon is designed for.
87+
/// The optional theme for this icon. Can be "light" or "dark". Used to specify which UI theme
88+
/// the icon is designed for.
8989
/// </summary>
90-
public string? Theme { get; init; }
90+
public string? Theme
91+
{
92+
get;
93+
init
94+
{
95+
if (value is not null and not "light" and not "dark")
96+
{
97+
throw new ArgumentException(
98+
OperationToolIcon_InvalidIconTheme,
99+
nameof(Theme));
100+
}
101+
102+
field = value;
103+
}
104+
}
91105

92106
[GeneratedRegex(@"^([0-9]+x[0-9]+|any)\z")]
93107
private static partial Regex IconSizeRegex();

src/HotChocolate/Adapters/test/Adapters.Mcp.Tests/Storage/OperationToolIconTests.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,4 +115,43 @@ public void OperationToolIcon_InvalidSizes_ThrowsArgumentException(params string
115115
+ "(Parameter 'Sizes')",
116116
exception.Message);
117117
}
118+
119+
[Theory]
120+
[InlineData(null)]
121+
[InlineData("light")]
122+
[InlineData("dark")]
123+
public void OperationToolIcon_ValidTheme_Succeeds(string? theme)
124+
{
125+
// arrange & act
126+
var exception =
127+
Record.Exception(
128+
() => new OperationToolIcon(new Uri("https://example.com/icon.png"))
129+
{
130+
Theme = theme
131+
});
132+
133+
// assert
134+
Assert.Null(exception);
135+
}
136+
137+
[Theory]
138+
[InlineData("blue")]
139+
[InlineData("LIGHT")]
140+
[InlineData("Dark")]
141+
public void OperationToolIcon_InvalidTheme_ThrowsArgumentException(string theme)
142+
{
143+
// arrange & act
144+
var exception =
145+
Record.Exception(
146+
() => new OperationToolIcon(new Uri("https://example.com/icon.png"))
147+
{
148+
Theme = theme
149+
});
150+
151+
// assert
152+
Assert.IsType<ArgumentException>(exception);
153+
Assert.Equal(
154+
"The icon theme must be 'light' or 'dark'. (Parameter 'Theme')",
155+
exception.Message);
156+
}
118157
}

0 commit comments

Comments
 (0)