-
Notifications
You must be signed in to change notification settings - Fork 546
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
Merged
+982
−8
Merged
Implement SEP-973: Icons and metadata support for Implementations, Resources, Tools, and Prompts #802
Changes from 4 commits
Commits
Show all changes
24 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 9e4eba3
Simplify Icons property documentation as suggested in code review
Copilot 8a6f6fd
Rename Icon.Src property to Icon.Source for more .NET-y naming
Copilot 2e077dc
Add icon support to McpServerTool infrastructure and attributes
Copilot 6de63f5
Cleanup
MackinnonBuck 4bcbe1c
Refactor icon tests to use Delegate overload instead of MethodInfo pa…
Copilot a25abde
Change Icon.Sizes property from string to IList<string> per spec update
Copilot ae081ca
Add icon support to Prompts and Resources (CreateOptions and Attributes)
Copilot f37de15
Add client-server integration tests for Icons and WebsiteUrl
Copilot 8e423fd
Fix nullability warnings
MackinnonBuck 803e326
Revert "Add client-server integration tests for Icons and WebsiteUrl"
MackinnonBuck 38b4032
More nullability fixes
MackinnonBuck 0cd7f87
Add more tests
MackinnonBuck facca54
Address code review feedback: add Theme property, fix docs, improve t…
Copilot bb762b2
Update Icon tests to exercise Theme property
Copilot 608cf0d
Add Theme property assertions to client-server integration tests
Copilot c2a3252
Fix nullability
jozkee 45dd79a
Merge branch 'main' into copilot/fix-753
jozkee 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,104 @@ | ||
| # SEP-973 Implementation Examples | ||
|
|
||
| This document shows example JSON output that would be generated by the C# implementation of SEP-973. | ||
|
|
||
| ## Icon Object | ||
| ```json | ||
| { | ||
| "src": "https://example.com/icon.png", | ||
| "mimeType": "image/png", | ||
| "sizes": "48x48" | ||
| } | ||
| ``` | ||
|
|
||
| ## Implementation with Icons and Website URL | ||
| ```json | ||
| { | ||
| "name": "test-server", | ||
| "title": "Test MCP Server", | ||
| "version": "1.0.0", | ||
| "icons": [ | ||
| { | ||
| "src": "https://example.com/icon.png", | ||
| "mimeType": "image/png", | ||
| "sizes": "48x48" | ||
| }, | ||
| { | ||
| "src": "https://example.com/icon.svg", | ||
| "mimeType": "image/svg+xml", | ||
| "sizes": "any" | ||
| } | ||
| ], | ||
| "websiteUrl": "https://example.com" | ||
| } | ||
| ``` | ||
|
|
||
| ## Tool with Icon | ||
| ```json | ||
| { | ||
| "name": "get_weather", | ||
| "title": "Get Weather", | ||
| "description": "Get current weather information", | ||
| "inputSchema": { | ||
| "type": "object" | ||
| }, | ||
| "icons": [ | ||
| { | ||
| "src": "https://example.com/weather.png", | ||
| "mimeType": "image/png", | ||
| "sizes": "48x48" | ||
| } | ||
| ] | ||
| } | ||
| ``` | ||
|
|
||
| ## Resource with Icon | ||
| ```json | ||
| { | ||
| "name": "document.pdf", | ||
| "title": "Important Document", | ||
| "uri": "file:///path/to/document.pdf", | ||
| "description": "An important document", | ||
| "mimeType": "application/pdf", | ||
| "icons": [ | ||
| { | ||
| "src": "https://example.com/pdf-icon.png", | ||
| "mimeType": "image/png", | ||
| "sizes": "32x32" | ||
| } | ||
| ] | ||
| } | ||
| ``` | ||
|
|
||
| ## Prompt with Icon | ||
| ```json | ||
| { | ||
| "name": "code_review", | ||
| "title": "Code Review Prompt", | ||
| "description": "Review the provided code", | ||
| "icons": [ | ||
| { | ||
| "src": "https://example.com/review-icon.svg", | ||
| "mimeType": "image/svg+xml", | ||
| "sizes": "any" | ||
| } | ||
| ] | ||
| } | ||
| ``` | ||
|
|
||
| ## Key Features Implemented | ||
|
|
||
| 1. **Icon Class**: Core class for representing icons with required `src` and optional `mimeType` and `sizes` properties | ||
| 2. **Multiple Icon Support**: All classes support arrays of icons for different sizes/formats | ||
| 3. **Backward Compatibility**: All new properties are optional | ||
| 4. **Proper JSON Serialization**: Uses `JsonPropertyName` attributes for correct JSON field names | ||
| 5. **Security Documentation**: Includes security considerations as specified in SEP-973 | ||
| 6. **MIME Type Support**: Documents required (PNG, JPEG) and recommended (SVG, WebP) formats | ||
|
|
||
| ## Implementation Details | ||
|
|
||
| - All new properties use `IList<Icon>?` for consistency with existing collection patterns | ||
| - JSON property names match the specification exactly | ||
| - Optional properties serialize as `null` when not set, which is omitted from JSON | ||
| - Comprehensive XML documentation follows existing codebase patterns | ||
| - Tests cover serialization, deserialization, and edge cases | ||
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,84 @@ | ||
| # SEP-973 Implementation Summary | ||
|
|
||
| This document summarizes the implementation of SEP-973 in the C# MCP SDK. | ||
|
|
||
| ## What Was Implemented | ||
MackinnonBuck marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ### 1. Icon Class (`src/ModelContextProtocol.Core/Protocol/Icon.cs`) | ||
| - **Purpose**: Represents an icon for visual identification | ||
| - **Properties**: | ||
| - `Src` (required string): URI pointing to icon resource | ||
| - `MimeType` (optional string): MIME type override | ||
| - `Sizes` (optional string): Size specification (e.g., "48x48", "any") | ||
| - **JSON Property Names**: `src`, `mimeType`, `sizes` | ||
| - **Features**: Uses `init` accessors for immutability, comprehensive XML documentation | ||
|
|
||
| ### 2. Implementation Class Updates (`src/ModelContextProtocol.Core/Protocol/Implementation.cs`) | ||
| - **Added Properties**: | ||
| - `Icons` (optional `IList<Icon>?`): Array of icons for the implementation | ||
| - `WebsiteUrl` (optional string): URL to implementation website/documentation | ||
| - **JSON Property Names**: `icons`, `websiteUrl` | ||
|
|
||
| ### 3. Resource Class Updates (`src/ModelContextProtocol.Core/Protocol/Resource.cs`) | ||
| - **Added Properties**: | ||
| - `Icons` (optional `IList<Icon>?`): Array of icons for the resource | ||
| - **JSON Property Names**: `icons` | ||
|
|
||
| ### 4. Tool Class Updates (`src/ModelContextProtocol.Core/Protocol/Tool.cs`) | ||
| - **Added Properties**: | ||
| - `Icons` (optional `IList<Icon>?`): Array of icons for the tool | ||
| - **JSON Property Names**: `icons` | ||
|
|
||
| ### 5. Prompt Class Updates (`src/ModelContextProtocol.Core/Protocol/Prompt.cs`) | ||
| - **Added Properties**: | ||
| - `Icons` (optional `IList<Icon>?`): Array of icons for the prompt | ||
| - **JSON Property Names**: `icons` | ||
|
|
||
| ## Test Coverage | ||
|
|
||
| Created comprehensive test files: | ||
| 1. **IconTests.cs**: Tests Icon serialization, deserialization, and property validation | ||
| 2. **ImplementationTests.cs**: Tests Implementation with icons and websiteUrl | ||
| 3. **ToolIconTests.cs**: Tests Tool with icon support | ||
| 4. **ResourceAndPromptIconTests.cs**: Tests Resource and Prompt with icon support | ||
|
|
||
| ## Compliance with SEP-973 | ||
|
|
||
| ✅ **Icon Support**: Implements the Icon interface with all required and optional properties | ||
| ✅ **Implementation Metadata**: Adds icons and websiteUrl to Implementation class | ||
| ✅ **Resource Icons**: Adds icon support to Resource class | ||
| ✅ **Tool Icons**: Adds icon support to Tool class | ||
| ✅ **Prompt Icons**: Adds icon support to Prompt class | ||
| ✅ **Backward Compatibility**: All new fields are optional | ||
| ✅ **JSON Serialization**: Proper JsonPropertyName attributes | ||
| ✅ **Documentation**: Comprehensive XML docs with security considerations | ||
| ✅ **MIME Type Guidelines**: Documents required PNG/JPEG and recommended SVG/WebP support | ||
|
|
||
| ## Security Considerations | ||
|
|
||
| The implementation includes documentation about: | ||
| - URI validation and trusted domain requirements | ||
| - SVG security precautions (executable content) | ||
| - Resource exhaustion protection | ||
| - MIME type validation | ||
|
|
||
| ## Usage Examples | ||
|
|
||
| The implementation enables usage like: | ||
|
|
||
| ```csharp | ||
| var implementation = new Implementation | ||
| { | ||
| Name = "my-server", | ||
| Version = "1.0.0", | ||
| Icons = new List<Icon> | ||
| { | ||
| new() { Src = "https://example.com/icon.png", MimeType = "image/png", Sizes = "48x48" } | ||
| }, | ||
| WebsiteUrl = "https://example.com" | ||
| }; | ||
| ``` | ||
|
|
||
| ## Next Steps | ||
|
|
||
| The implementation is complete and ready for use. When .NET 9 SDK becomes available in the build environment, the code should compile correctly and all tests should pass. | ||
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; } | ||
MackinnonBuck marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| /// <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; } | ||
MackinnonBuck marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
jozkee marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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
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.