Add MCP Apps extension support (typed metadata, attribute, and helpers) (#1484)

This commit is contained in:
Copilot 2026-06-17 13:28:47 -07:00 • committed by GitHub
commit f93df7e172
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -0,0 +1,25 @@
using ModelContextProtocol.Extensions.Apps;
using ModelContextProtocol.Server;
using System.ComponentModel;
using System.Text.Json;
using System.Text.Json.Serialization;
[McpServerResourceType]
public sealed class WeatherResources
{
private static readonly string UiDir = Path.Combine(AppContext.BaseDirectory, "ui");
[McpServerResource(UriTemplate = "ui://weather-app/forecast", Name = "weather-forecast-ui", MimeType = McpApps.HtmlMimeType)]
[McpMeta("ui", """{"csp":{"connectDomains":["https://api.weather.gov"]},"prefersBorder":true}""")]
[Description("Interactive weather forecast UI with city picker")]
public static string GetWeatherForecastUi() => File.ReadAllText(Path.Combine(UiDir, "weather-forecast.html"));
[McpServerResource(UriTemplate = "data://weather-app/us-cities", Name = "us-cities", MimeType = "application/json")]
[Description("List of supported US cities for weather forecasts")]
public static string GetUsCities()
{
var options = new JsonSerializerOptions { Converters = { new JsonStringEnumConverter<UsCity>() } };
var cities = Enum.GetValues<UsCity>().Select(c => JsonSerializer.Serialize(c, options).Trim('"')).Order().ToList();
return JsonSerializer.Serialize(cities);
}
}