-
Notifications
You must be signed in to change notification settings - Fork 512
Implement SEP-973: Icons and metadata support for Implementations, Resources, Tools, and Prompts #802
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Copilot
wants to merge
7
commits into
main
Choose a base branch
from
copilot/fix-753
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+648
−0
Open
Implement SEP-973: Icons and metadata support for Implementations, Resources, Tools, and Prompts #802
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
941bc0e
Initial plan
Copilot 31ad1e4
Initial plan for SEP-973 implementation
Copilot 8b1b684
Implement SEP-973: Add Icon class and icon support to Implementation,…
Copilot 24517c2
Complete SEP-973 implementation with documentation and fix property c…
Copilot 6c42203
Address code review feedback: improve tests, remove docs, split test …
Copilot f666ff0
Fix tests to use S.T.J. source generator
MackinnonBuck 3ac0678
Styling fixes
MackinnonBuck File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
using System.Text.Json.Serialization; | ||
|
||
namespace ModelContextProtocol.Protocol; | ||
|
||
/// <summary> | ||
/// Represents an icon that can be used to visually identify an implementation, resource, tool, or prompt. | ||
/// </summary> | ||
/// <remarks> | ||
/// <para> | ||
/// Icons enhance user interfaces by providing visual context and improving the discoverability of available functionality. | ||
/// Each icon includes a source URI pointing to the icon resource, and optional MIME type and size information. | ||
/// </para> | ||
/// <para> | ||
/// Clients that support rendering icons MUST support at least the following MIME types: | ||
/// </para> | ||
/// <list type="bullet"> | ||
/// <item><description>image/png - PNG images (safe, universal compatibility)</description></item> | ||
/// <item><description>image/jpeg (and image/jpg) - JPEG images (safe, universal compatibility)</description></item> | ||
/// </list> | ||
/// <para> | ||
/// Clients that support rendering icons SHOULD also support: | ||
/// </para> | ||
/// <list type="bullet"> | ||
/// <item><description>image/svg+xml - SVG images (scalable but requires security precautions)</description></item> | ||
/// <item><description>image/webp - WebP images (modern, efficient format)</description></item> | ||
/// </list> | ||
/// <para> | ||
/// See the <see href="https://github.com/modelcontextprotocol/specification/blob/main/schema/">schema</see> for details. | ||
/// </para> | ||
/// </remarks> | ||
public sealed class Icon | ||
{ | ||
/// <summary> | ||
/// Gets or sets the URI pointing to the icon resource. | ||
/// </summary> | ||
/// <remarks> | ||
/// <para> | ||
/// This can be an HTTP/HTTPS URL pointing to an image file or a data URI with base64-encoded image data. | ||
/// </para> | ||
/// <para> | ||
/// Consumers SHOULD take steps to ensure URLs serving icons are from the same domain as the client/server | ||
/// or a trusted domain. | ||
/// </para> | ||
/// <para> | ||
/// Consumers SHOULD take appropriate precautions when consuming SVGs as they can contain executable JavaScript. | ||
/// </para> | ||
/// </remarks> | ||
[JsonPropertyName("src")] | ||
public required string Src { get; init; } | ||
|
||
/// <summary> | ||
/// Gets or sets the optional MIME type of the icon. | ||
/// </summary> | ||
/// <remarks> | ||
/// This can be used to override the server's MIME type if it's missing or generic. | ||
/// Common values include "image/png", "image/jpeg", "image/svg+xml", and "image/webp". | ||
/// </remarks> | ||
[JsonPropertyName("mimeType")] | ||
public string? MimeType { get; init; } | ||
|
||
/// <summary> | ||
/// Gets or sets the optional size specification for the icon. | ||
/// </summary> | ||
/// <remarks> | ||
/// <para> | ||
/// This can specify one or more sizes at which the icon file can be used. | ||
/// Examples include "48x48", "any" for scalable formats like SVG, or "48x48 96x96" for multiple sizes. | ||
/// </para> | ||
/// <para> | ||
/// If not provided, clients should assume that the icon can be used at any size. | ||
/// </para> | ||
/// </remarks> | ||
[JsonPropertyName("sizes")] | ||
public string? Sizes { get; init; } | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
using ModelContextProtocol.Protocol; | ||
using System.Text.Json; | ||
|
||
namespace ModelContextProtocol.Tests.Protocol; | ||
|
||
public static class IconTests | ||
{ | ||
[Fact] | ||
public static void Icon_SerializationRoundTrip_PreservesAllProperties() | ||
{ | ||
// Arrange | ||
var original = new Icon | ||
{ | ||
Src = "https://example.com/icon.png", | ||
MimeType = "image/png", | ||
Sizes = "48x48" | ||
}; | ||
|
||
// Act - Serialize to JSON | ||
string json = JsonSerializer.Serialize(original, McpJsonUtilities.DefaultOptions); | ||
|
||
// Act - Deserialize back from JSON | ||
var deserialized = JsonSerializer.Deserialize<Icon>(json, McpJsonUtilities.DefaultOptions); | ||
|
||
// Assert | ||
Assert.NotNull(deserialized); | ||
Assert.Equal(original.Src, deserialized.Src); | ||
Assert.Equal(original.MimeType, deserialized.MimeType); | ||
Assert.Equal(original.Sizes, deserialized.Sizes); | ||
} | ||
|
||
[Fact] | ||
public static void Icon_SerializationRoundTrip_WithOnlyRequiredProperties() | ||
{ | ||
// Arrange | ||
var original = new Icon | ||
{ | ||
Src = "data:image/svg+xml;base64,PHN2Zy4uLjwvc3ZnPg==" | ||
}; | ||
|
||
// Act - Serialize to JSON | ||
string json = JsonSerializer.Serialize(original, McpJsonUtilities.DefaultOptions); | ||
|
||
// Act - Deserialize back from JSON | ||
var deserialized = JsonSerializer.Deserialize<Icon>(json, McpJsonUtilities.DefaultOptions); | ||
|
||
// Assert | ||
Assert.NotNull(deserialized); | ||
Assert.Equal(original.Src, deserialized.Src); | ||
Assert.Equal(original.MimeType, deserialized.MimeType); | ||
Assert.Equal(original.Sizes, deserialized.Sizes); | ||
} | ||
|
||
[Fact] | ||
public static void Icon_HasCorrectJsonPropertyNames() | ||
{ | ||
var icon = new Icon | ||
{ | ||
Src = "https://example.com/icon.svg", | ||
MimeType = "image/svg+xml", | ||
Sizes = "any" | ||
}; | ||
|
||
string json = JsonSerializer.Serialize(icon, McpJsonUtilities.DefaultOptions); | ||
|
||
Assert.Contains("\"src\":", json); | ||
Assert.Contains("\"mimeType\":", json); | ||
Assert.Contains("\"sizes\":", json); | ||
} | ||
|
||
[Theory] | ||
[InlineData("""{}""")] | ||
[InlineData("""{"mimeType":"image/png"}""")] | ||
[InlineData("""{"sizes":"48x48"}""")] | ||
[InlineData("""{"mimeType":"image/png","sizes":"48x48"}""")] | ||
public static void Icon_DeserializationWithMissingSrc_ThrowsJsonException(string invalidJson) | ||
{ | ||
Assert.Throws<JsonException>(() => JsonSerializer.Deserialize<Icon>(invalidJson, McpJsonUtilities.DefaultOptions)); | ||
} | ||
|
||
[Theory] | ||
[InlineData("false")] | ||
[InlineData("true")] | ||
[InlineData("42")] | ||
[InlineData("[]")] | ||
public static void Icon_DeserializationWithInvalidJson_ThrowsJsonException(string invalidJson) | ||
{ | ||
Assert.Throws<JsonException>(() => JsonSerializer.Deserialize<Icon>(invalidJson, McpJsonUtilities.DefaultOptions)); | ||
} | ||
} |
105 changes: 105 additions & 0 deletions
105
tests/ModelContextProtocol.Tests/Protocol/ImplementationTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
using ModelContextProtocol.Protocol; | ||
using System.Text.Json; | ||
|
||
namespace ModelContextProtocol.Tests.Protocol; | ||
|
||
public static class ImplementationTests | ||
{ | ||
[Fact] | ||
public static void Implementation_SerializationRoundTrip_PreservesAllProperties() | ||
{ | ||
// Arrange | ||
var original = new Implementation | ||
{ | ||
Name = "test-server", | ||
Title = "Test MCP Server", | ||
Version = "1.0.0", | ||
Icons = | ||
[ | ||
new() { Src = "https://example.com/icon.png", MimeType = "image/png", Sizes = "48x48" }, | ||
new() { Src = "https://example.com/icon.svg", MimeType = "image/svg+xml", Sizes = "any" } | ||
], | ||
WebsiteUrl = "https://example.com" | ||
}; | ||
|
||
// Act - Serialize to JSON | ||
string json = JsonSerializer.Serialize(original, McpJsonUtilities.DefaultOptions); | ||
|
||
// Act - Deserialize back from JSON | ||
var deserialized = JsonSerializer.Deserialize<Implementation>(json, McpJsonUtilities.DefaultOptions); | ||
|
||
// Assert | ||
Assert.NotNull(deserialized); | ||
Assert.Equal(original.Name, deserialized.Name); | ||
Assert.Equal(original.Title, deserialized.Title); | ||
Assert.Equal(original.Version, deserialized.Version); | ||
Assert.Equal(original.WebsiteUrl, deserialized.WebsiteUrl); | ||
Assert.NotNull(deserialized.Icons); | ||
Assert.Equal(original.Icons.Count, deserialized.Icons.Count); | ||
|
||
for (int i = 0; i < original.Icons.Count; i++) | ||
{ | ||
Assert.Equal(original.Icons[i].Src, deserialized.Icons[i].Src); | ||
Assert.Equal(original.Icons[i].MimeType, deserialized.Icons[i].MimeType); | ||
Assert.Equal(original.Icons[i].Sizes, deserialized.Icons[i].Sizes); | ||
} | ||
} | ||
|
||
[Fact] | ||
public static void Implementation_SerializationRoundTrip_WithoutOptionalProperties() | ||
{ | ||
// Arrange | ||
var original = new Implementation | ||
{ | ||
Name = "simple-server", | ||
Version = "1.0.0" | ||
}; | ||
|
||
// Act - Serialize to JSON | ||
string json = JsonSerializer.Serialize(original, McpJsonUtilities.DefaultOptions); | ||
|
||
// Act - Deserialize back from JSON | ||
var deserialized = JsonSerializer.Deserialize<Implementation>(json, McpJsonUtilities.DefaultOptions); | ||
|
||
// Assert | ||
Assert.NotNull(deserialized); | ||
Assert.Equal(original.Name, deserialized.Name); | ||
Assert.Equal(original.Title, deserialized.Title); | ||
Assert.Equal(original.Version, deserialized.Version); | ||
Assert.Equal(original.Icons, deserialized.Icons); | ||
Assert.Equal(original.WebsiteUrl, deserialized.WebsiteUrl); | ||
} | ||
|
||
[Fact] | ||
public static void Implementation_HasCorrectJsonPropertyNames() | ||
{ | ||
var implementation = new Implementation | ||
{ | ||
Name = "test-server", | ||
Title = "Test Server", | ||
Version = "1.0.0", | ||
Icons = [new() { Src = "https://example.com/icon.png" }], | ||
WebsiteUrl = "https://example.com" | ||
}; | ||
|
||
string json = JsonSerializer.Serialize(implementation, McpJsonUtilities.DefaultOptions); | ||
|
||
Assert.Contains("\"name\":", json); | ||
Assert.Contains("\"title\":", json); | ||
Assert.Contains("\"version\":", json); | ||
Assert.Contains("\"icons\":", json); | ||
Assert.Contains("\"websiteUrl\":", json); | ||
} | ||
|
||
[Theory] | ||
[InlineData("""{}""")] | ||
[InlineData("""{"title":"Test Server"}""")] | ||
[InlineData("""{"name":"test-server"}""")] | ||
[InlineData("""{"version":"1.0.0"}""")] | ||
[InlineData("""{"title":"Test Server","version":"1.0.0"}""")] | ||
[InlineData("""{"name":"test-server","title":"Test Server"}""")] | ||
public static void Implementation_DeserializationWithMissingRequiredProperties_ThrowsJsonException(string invalidJson) | ||
{ | ||
Assert.Throws<JsonException>(() => JsonSerializer.Deserialize<Implementation>(invalidJson, McpJsonUtilities.DefaultOptions)); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.