From fa3b6c0246c7265229fa2aa5d74f623cca2f9e41 Mon Sep 17 00:00:00 2001 From: Lior Shmueli <48066416+ShmueLior@users.noreply.github.com> Date: Fri, 4 Dec 2026 08:56:33 +0200 Subject: [PATCH 1/3] Store tool icons in the tool surface snapshot Keep formatVersion 1 and omit icons when a tool has none, so existing snapshot files stay the same. Icon changes are non-breaking. --- CHANGELOG.md | 1 + README.md | 3 + src/McpProbe/PublicAPI.Unshipped.txt | 11 + src/McpProbe/Snapshots/IconContract.cs | 125 +++++++++++ src/McpProbe/Snapshots/ToolContract.cs | 6 +- src/McpProbe/Snapshots/ToolSurface.cs | 143 +++++++++++- src/McpProbe/Snapshots/ToolSurfaceChange.cs | 3 + src/McpProbe/Snapshots/ToolSurfaceComparer.cs | 63 +++++- tests/McpProbe.Tests/ToolSurfaceIconsTests.cs | 204 ++++++++++++++++++ 9 files changed, 554 insertions(+), 5 deletions(-) create mode 100644 src/McpProbe/Snapshots/IconContract.cs create mode 100644 tests/McpProbe.Tests/ToolSurfaceIconsTests.cs diff --git a/CHANGELOG.md b/CHANGELOG.md index 2551d15..c271f85 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ All notable changes to this project are documented here. The format is based on ### Added +- Tool snapshots store each tool's `icons` (`src`, and optional `mimeType`, `sizes` and `theme`) when the server declares them. The field is omitted when there are no icons, and `formatVersion` stays 1, so existing snapshot files stay the same. A change to icons is `IconsChanged` and non-breaking. `data:` icon URIs are stored as declared. - `--format text|json|sarif` on `lint` and `diff` picks the stdout format. `json` is the McpProbe report format (format 1, see `docs/mcpprobe-report.schema.json`), `sarif` is SARIF 2.1.0. The default is still `text`. - `--sarif ` on `lint` and `diff` also writes a SARIF 2.1.0 file, like `--report`. In SARIF, each result points at the baseline or `--from-file` snapshot (default `mcp-tools.json`) and has a stable fingerprint for GitHub code scanning. - `LintReport.ToJson()` and `ToSarif()`, and `ToolSurfaceDiff.ToJson()` and `ToSarif()` in the library. diff --git a/README.md b/README.md index f367ec6..0130294 100644 --- a/README.md +++ b/README.md @@ -458,11 +458,14 @@ If you cannot reference the GitHub repo, install the tool and run the same comma Tools are sorted by name and JSON keys are sorted, so diffs stay small. Comparison is semantic: formatting and line endings don't matter. +A tool's `icons` are stored when the server declares them, and omitted when there are none, so an existing snapshot without icons stays the same. Icon changes are non-breaking. A `data:` icon is stored as declared, so a large embedded icon makes the snapshot large. + ## Limitations - Only local `$ref`s are followed. Remote refs, `$anchor`/`$id` refs and `$dynamicRef` are compared as plain keywords, and so is `$defs` when such a ref is present. - `allOf`, `anyOf` and `oneOf` aren't walked; changes inside them are reported as unclassified keyword changes. - Two different `pattern`s or `format`s can't be compared, so any change to one counts as breaking. +- Snapshots cover the tool surface, including icons. They do not include prompts, resources, resource templates, `_meta`, or the Tasks `execution` field, so a change there is not reported by `diff`. - The test suite in this repo uses xUnit v3. The quickstart was also run once by hand with NUnit 4, MSTest 4 and TUnit 1.87 against the packed library; those checks aren't part of CI yet. ## Contributing diff --git a/src/McpProbe/PublicAPI.Unshipped.txt b/src/McpProbe/PublicAPI.Unshipped.txt index 0b1b063..7d793df 100644 --- a/src/McpProbe/PublicAPI.Unshipped.txt +++ b/src/McpProbe/PublicAPI.Unshipped.txt @@ -170,6 +170,13 @@ McpProbe.McpProbeHostOptions.McpProbeHostOptions() -> void McpProbe.Snapshots.ChangeSeverity McpProbe.Snapshots.ChangeSeverity.Breaking = 1 -> McpProbe.Snapshots.ChangeSeverity McpProbe.Snapshots.ChangeSeverity.NonBreaking = 0 -> McpProbe.Snapshots.ChangeSeverity +McpProbe.Snapshots.IconContract +McpProbe.Snapshots.IconContract.Equals(McpProbe.Snapshots.IconContract? other) -> bool +McpProbe.Snapshots.IconContract.IconContract(string! source, string? mimeType = null, System.Collections.Generic.IReadOnlyList? sizes = null, string? theme = null) -> void +McpProbe.Snapshots.IconContract.MimeType.get -> string? +McpProbe.Snapshots.IconContract.Sizes.get -> System.Collections.Generic.IReadOnlyList? +McpProbe.Snapshots.IconContract.Source.get -> string! +McpProbe.Snapshots.IconContract.Theme.get -> string? McpProbe.Snapshots.McpProbeSnapshotException McpProbe.Snapshots.McpProbeSnapshotException.Diff.get -> McpProbe.Snapshots.ToolSurfaceDiff? McpProbe.Snapshots.McpProbeSnapshotException.McpProbeSnapshotException() -> void @@ -191,6 +198,7 @@ McpProbe.Snapshots.SnapshotOptions.Update.set -> void McpProbe.Snapshots.ToolContract McpProbe.Snapshots.ToolContract.Annotations.get -> McpProbe.Snapshots.ToolContractAnnotations? McpProbe.Snapshots.ToolContract.Description.get -> string? +McpProbe.Snapshots.ToolContract.Icons.get -> System.Collections.Generic.IReadOnlyList? McpProbe.Snapshots.ToolContract.InputSchema.get -> System.Text.Json.JsonElement McpProbe.Snapshots.ToolContract.Name.get -> string! McpProbe.Snapshots.ToolContract.OutputSchema.get -> System.Text.Json.JsonElement? @@ -238,6 +246,7 @@ McpProbe.Snapshots.ToolSurfaceChangeKind.BecameOptional = 8 -> McpProbe.Snapshot McpProbe.Snapshots.ToolSurfaceChangeKind.BecameRequired = 7 -> McpProbe.Snapshots.ToolSurfaceChangeKind McpProbe.Snapshots.ToolSurfaceChangeKind.ConstraintChanged = 14 -> McpProbe.Snapshots.ToolSurfaceChangeKind McpProbe.Snapshots.ToolSurfaceChangeKind.DescriptionChanged = 3 -> McpProbe.Snapshots.ToolSurfaceChangeKind +McpProbe.Snapshots.ToolSurfaceChangeKind.IconsChanged = 15 -> McpProbe.Snapshots.ToolSurfaceChangeKind McpProbe.Snapshots.ToolSurfaceChangeKind.EnumChanged = 10 -> McpProbe.Snapshots.ToolSurfaceChangeKind McpProbe.Snapshots.ToolSurfaceChangeKind.KeywordChanged = 13 -> McpProbe.Snapshots.ToolSurfaceChangeKind McpProbe.Snapshots.ToolSurfaceChangeKind.OutputSchemaAdded = 11 -> McpProbe.Snapshots.ToolSurfaceChangeKind @@ -276,6 +285,8 @@ override McpProbe.Linting.LintRule.ToString() -> string! override McpProbe.Linting.LintSuppression.Equals(object? obj) -> bool override McpProbe.Linting.LintSuppression.GetHashCode() -> int override McpProbe.Linting.LintSuppression.ToString() -> string! +override McpProbe.Snapshots.IconContract.Equals(object? obj) -> bool +override McpProbe.Snapshots.IconContract.GetHashCode() -> int override McpProbe.Snapshots.ToolContractAnnotations.Equals(object? obj) -> bool override McpProbe.Snapshots.ToolContractAnnotations.GetHashCode() -> int override McpProbe.Snapshots.ToolContractAnnotations.ToString() -> string! diff --git a/src/McpProbe/Snapshots/IconContract.cs b/src/McpProbe/Snapshots/IconContract.cs new file mode 100644 index 0000000..6c9441b --- /dev/null +++ b/src/McpProbe/Snapshots/IconContract.cs @@ -0,0 +1,125 @@ +using System.Collections.ObjectModel; + +namespace McpProbe.Snapshots; + +/// +/// One icon a tool declares in tools/list. +/// +public sealed class IconContract : IEquatable +{ + /// Creates an icon contract. + /// The icon URI (src): an HTTP(S) URL or a data: URI. + /// Optional MIME type. + /// Optional sizes such as 48x48 or any. An empty list is stored as unset. + /// Optional theme, light or dark. + public IconContract(string source, string? mimeType = null, IReadOnlyList? sizes = null, string? theme = null) + { + ArgumentNullException.ThrowIfNull(source); + Source = source; + MimeType = mimeType; + Sizes = CopySizes(sizes); + Theme = theme; + } + + /// Gets the icon URI (src). + public string Source { get; } + + /// Gets the MIME type, if any. + public string? MimeType { get; } + + /// Gets the sizes, if any. Null when unset or empty. + public IReadOnlyList? Sizes { get; } + + /// Gets the theme, if any. + public string? Theme { get; } + + /// + public bool Equals(IconContract? other) + { + if (other is null) + { + return false; + } + + if (ReferenceEquals(this, other)) + { + return true; + } + + return string.Equals(Source, other.Source, StringComparison.Ordinal) && + string.Equals(MimeType, other.MimeType, StringComparison.Ordinal) && + string.Equals(Theme, other.Theme, StringComparison.Ordinal) && + SizesEqual(Sizes, other.Sizes); + } + + /// + public override bool Equals(object? obj) => Equals(obj as IconContract); + + /// + public override int GetHashCode() + { + var hash = new HashCode(); + hash.Add(Source, StringComparer.Ordinal); + hash.Add(MimeType, StringComparer.Ordinal); + hash.Add(Theme, StringComparer.Ordinal); + if (Sizes is not null) + { + foreach (var size in Sizes) + { + hash.Add(size, StringComparer.Ordinal); + } + } + + return hash.ToHashCode(); + } + + internal static bool ListsEqual(IReadOnlyList? left, IReadOnlyList? right) + { + var leftCount = left?.Count ?? 0; + var rightCount = right?.Count ?? 0; + if (leftCount != rightCount) + { + return false; + } + + for (var i = 0; i < leftCount; i++) + { + if (!left![i].Equals(right![i])) + { + return false; + } + } + + return true; + } + + private static ReadOnlyCollection? CopySizes(IReadOnlyList? sizes) + { + if (sizes is null || sizes.Count == 0) + { + return null; + } + + return Array.AsReadOnly(sizes.ToArray()); + } + + private static bool SizesEqual(IReadOnlyList? left, IReadOnlyList? right) + { + var leftCount = left?.Count ?? 0; + var rightCount = right?.Count ?? 0; + if (leftCount != rightCount) + { + return false; + } + + for (var i = 0; i < leftCount; i++) + { + if (!string.Equals(left![i], right![i], StringComparison.Ordinal)) + { + return false; + } + } + + return true; + } +} diff --git a/src/McpProbe/Snapshots/ToolContract.cs b/src/McpProbe/Snapshots/ToolContract.cs index bdd1cc5..5b0fa4f 100644 --- a/src/McpProbe/Snapshots/ToolContract.cs +++ b/src/McpProbe/Snapshots/ToolContract.cs @@ -7,7 +7,7 @@ namespace McpProbe.Snapshots; /// public sealed class ToolContract { - internal ToolContract(string name, string? title, string? description, JsonElement inputSchema, JsonElement? outputSchema, ToolContractAnnotations? annotations) + internal ToolContract(string name, string? title, string? description, JsonElement inputSchema, JsonElement? outputSchema, ToolContractAnnotations? annotations, IReadOnlyList? icons = null) { Name = name; Title = title; @@ -15,6 +15,7 @@ internal ToolContract(string name, string? title, string? description, JsonEleme InputSchema = inputSchema; OutputSchema = outputSchema; Annotations = annotations; + Icons = icons is { Count: > 0 } ? icons : null; } /// Gets the tool name. @@ -34,6 +35,9 @@ internal ToolContract(string name, string? title, string? description, JsonEleme /// Gets the behavior hints, if any are set. public ToolContractAnnotations? Annotations { get; } + + /// Gets the icons, in server order, if the tool declares any. + public IReadOnlyList? Icons { get; } } /// diff --git a/src/McpProbe/Snapshots/ToolSurface.cs b/src/McpProbe/Snapshots/ToolSurface.cs index 6791368..9a6658f 100644 --- a/src/McpProbe/Snapshots/ToolSurface.cs +++ b/src/McpProbe/Snapshots/ToolSurface.cs @@ -8,7 +8,7 @@ namespace McpProbe.Snapshots; /// -/// A server's tool surface: every tool's name, description, input schema, output schema and annotations. +/// A server's tool surface: every tool's name, description, input schema, output schema, annotations and icons. /// This is what gets written to a snapshot file and compared between versions. /// public sealed class ToolSurface @@ -49,7 +49,8 @@ public static ToolSurface FromTools(IEnumerable tools) tool.Description, CanonicalElement(tool.InputSchema) ?? EmptyObjectSchema(), tool.OutputSchema is { } output ? CanonicalElement(output) : null, - annotations)); + annotations, + CopyIcons(tool.Icons))); } return Create(contracts); @@ -129,7 +130,7 @@ public static ToolSurface Parse(string json) annotations = new ToolContractAnnotations(ReadBool(a, "readOnlyHint"), ReadBool(a, "destructiveHint"), ReadBool(a, "idempotentHint"), ReadBool(a, "openWorldHint")); } - contracts.Add(new ToolContract(name, JsonSchemaReader.GetString(tool, "title"), JsonSchemaReader.GetString(tool, "description"), input, output, annotations)); + contracts.Add(new ToolContract(name, JsonSchemaReader.GetString(tool, "title"), JsonSchemaReader.GetString(tool, "description"), input, output, annotations, ReadIcons(tool))); } try @@ -176,6 +177,11 @@ public string ToJson() node["annotations"] = annotations; } + if (tool.Icons is { Count: > 0 } icons) + { + node["icons"] = WriteIcons(icons); + } + tools.Add(node); } @@ -221,6 +227,137 @@ private static JsonElement EmptyObjectSchema() private static bool? ReadBool(JsonObject obj, string name) => obj[name] is JsonValue v && v.TryGetValue(out bool b) ? b : null; + private static List? CopyIcons(IList? icons) + { + if (icons is null || icons.Count == 0) + { + return null; + } + + var copied = new List(icons.Count); + foreach (var icon in icons) + { + if (icon is null) + { + continue; + } + + copied.Add(new IconContract(icon.Source ?? string.Empty, icon.MimeType, icon.Sizes?.ToArray(), icon.Theme)); + } + + return copied.Count == 0 ? null : copied; + } + + private static List? ReadIcons(JsonObject tool) + { + if (!tool.ContainsKey("icons")) + { + return null; + } + + if (tool["icons"] is not JsonArray array) + { + throw new FormatException("The 'icons' field of a tool must be an array."); + } + + if (array.Count == 0) + { + return null; + } + + var icons = new List(array.Count); + foreach (var item in array) + { + if (item is not JsonObject icon || JsonSchemaReader.GetString(icon, "src") is not { Length: > 0 } src) + { + throw new FormatException("Every icon in the snapshot needs a non-empty 'src'."); + } + + icons.Add(new IconContract(src, ReadOptionalString(icon, "mimeType"), ReadSizes(icon), ReadOptionalString(icon, "theme"))); + } + + return icons; + } + + private static string? ReadOptionalString(JsonObject obj, string name) + { + if (!obj.ContainsKey(name)) + { + return null; + } + + if (obj[name] is JsonValue value && value.TryGetValue(out string? text) && text is not null) + { + return text; + } + + throw new FormatException($"The icon '{name}' field must be a string."); + } + + private static List? ReadSizes(JsonObject icon) + { + if (!icon.ContainsKey("sizes")) + { + return null; + } + + if (icon["sizes"] is not JsonArray array) + { + throw new FormatException("The icon 'sizes' field must be an array of strings."); + } + + if (array.Count == 0) + { + return null; + } + + var sizes = new List(array.Count); + foreach (var item in array) + { + if (item is not JsonValue value || !value.TryGetValue(out string? size) || size is null) + { + throw new FormatException("The icon 'sizes' field must be an array of strings."); + } + + sizes.Add(size); + } + + return sizes; + } + + private static JsonArray WriteIcons(IReadOnlyList icons) + { + var array = new JsonArray(); + foreach (var icon in icons) + { + var node = new JsonObject { ["src"] = icon.Source }; + if (icon.MimeType is not null) + { + node["mimeType"] = icon.MimeType; + } + + if (icon.Sizes is { Count: > 0 } sizes) + { + var sizesNode = new JsonArray(); + foreach (var size in sizes) + { + sizesNode.Add(size); + } + + node["sizes"] = sizesNode; + } + + if (icon.Theme is not null) + { + node["theme"] = icon.Theme; + } + + array.Add(node); + } + + return array; + } + private static void AddBool(JsonObject obj, string name, bool? value) { if (value is { } b) diff --git a/src/McpProbe/Snapshots/ToolSurfaceChange.cs b/src/McpProbe/Snapshots/ToolSurfaceChange.cs index 809a7ba..e122592 100644 --- a/src/McpProbe/Snapshots/ToolSurfaceChange.cs +++ b/src/McpProbe/Snapshots/ToolSurfaceChange.cs @@ -62,6 +62,9 @@ public enum ToolSurfaceChangeKind /// uniqueItems, const or additionalProperties (and its siblings) changed. /// ConstraintChanged, + + /// A tool's icons changed. Presentation only, so this is non-breaking. + IconsChanged, } /// One difference between a baseline and a current tool surface. diff --git a/src/McpProbe/Snapshots/ToolSurfaceComparer.cs b/src/McpProbe/Snapshots/ToolSurfaceComparer.cs index 4fc9d6e..ecf9459 100644 --- a/src/McpProbe/Snapshots/ToolSurfaceComparer.cs +++ b/src/McpProbe/Snapshots/ToolSurfaceComparer.cs @@ -17,7 +17,7 @@ namespace McpProbe.Snapshots; /// a new enum value or a looser constraint. /// /// -/// Non-breaking: added tools, optional parameters and output properties, description, title and annotation changes, +/// Non-breaking: added tools, optional parameters and output properties, description, title, annotation and icon changes, /// widened input types and looser input constraints. Other JSON Schema keywords (allOf, anyOf, oneOf and so on) are /// reported as without being classified. /// @@ -108,6 +108,7 @@ private static void CompareTool(ToolContract old, ToolContract cur, List? wider, SortedSet? narrowe return narrower.All(t => wider.Contains(t) || (t == "integer" && wider.Contains("number"))); } + private static void CompareIcons(string tool, IReadOnlyList? old, IReadOnlyList? cur, List changes) + { + if (IconContract.ListsEqual(old, cur)) + { + return; + } + + changes.Add(new( + tool, + null, + ToolSurfaceChangeKind.IconsChanged, + ChangeSeverity.NonBreaking, + $"Icons changed from {FormatIcons(old)} to {FormatIcons(cur)}.")); + } + + private static string FormatIcons(IReadOnlyList? icons) + { + if (icons is null || icons.Count == 0) + { + return "(unset)"; + } + + var parts = new List(icons.Count); + foreach (var icon in icons) + { + var fields = new List { "src: '" + Printable.Truncate(DisplayIconSource(icon.Source), ChangedTextPreviewLength) + "'" }; + if (icon.MimeType is not null) + { + fields.Add("mimeType: '" + Printable.Truncate(icon.MimeType, ChangedTextPreviewLength) + "'"); + } + + if (icon.Sizes is { Count: > 0 }) + { + fields.Add("sizes: [" + string.Join(", ", icon.Sizes.Select(s => "'" + Printable.Truncate(s, ChangedTextPreviewLength) + "'")) + "]"); + } + + if (icon.Theme is not null) + { + fields.Add("theme: '" + Printable.Truncate(icon.Theme, ChangedTextPreviewLength) + "'"); + } + + parts.Add("{" + string.Join(", ", fields) + "}"); + } + + return "[" + string.Join(", ", parts) + "]"; + } + + private static string DisplayIconSource(string source) + { + if (!source.StartsWith("data:", StringComparison.OrdinalIgnoreCase)) + { + return source; + } + + var bytes = System.Text.Encoding.UTF8.GetByteCount(source); + var comma = source.IndexOf(','); + var prefix = comma < 0 ? "data:" : source[..(comma + 1)]; + return prefix + "..." + " (" + bytes.ToString(System.Globalization.CultureInfo.InvariantCulture) + " bytes)"; + } + // Each side is truncated on its own so a long "before" cannot hide the "after" in the message. private const int ChangedTextPreviewLength = 120; diff --git a/tests/McpProbe.Tests/ToolSurfaceIconsTests.cs b/tests/McpProbe.Tests/ToolSurfaceIconsTests.cs new file mode 100644 index 0000000..155ecff --- /dev/null +++ b/tests/McpProbe.Tests/ToolSurfaceIconsTests.cs @@ -0,0 +1,204 @@ +using McpProbe.Snapshots; +using ModelContextProtocol.Protocol; +using static McpProbe.Tests.TestSupport.SchemaTools; + +namespace McpProbe.Tests; + +public sealed class ToolSurfaceIconsTests +{ + [Fact] + public void ToJson_OmitsIconsWhenTheToolHasNone() + { + var json = Surface(Tool("plain")).ToJson(); + + Assert.DoesNotContain("icons", json, StringComparison.Ordinal); + Assert.Null(Assert.Single(Surface(Tool("plain")).Tools).Icons); + } + + [Fact] + public void ToJson_WritesIconsAfterAnnotationsInSpecFieldOrder() + { + var tool = Tool("weather"); + tool.Icons = + [ + new Icon + { + Source = "https://example.com/light.png", + MimeType = "image/png", + Sizes = ["48x48", "any"], + Theme = "light", + }, + ]; + + var json = Surface(tool).ToJson(); + + Assert.Contains( + """ + "icons": [ + { + "src": "https://example.com/light.png", + "mimeType": "image/png", + "sizes": [ + "48x48", + "any" + ], + "theme": "light" + } + ] + """.Replace("\r\n", "\n", StringComparison.Ordinal), + json, + StringComparison.Ordinal); + var annotationsAt = json.IndexOf("\"inputSchema\"", StringComparison.Ordinal); + var iconsAt = json.IndexOf("\"icons\"", StringComparison.Ordinal); + Assert.True(iconsAt > annotationsAt); + } + + [Fact] + public void Parse_RoundTripsIconsAndTreatsEmptyArrayAsNone() + { + var tool = Tool("weather"); + tool.Icons = + [ + new Icon { Source = "https://example.com/a.png", Theme = "dark" }, + new Icon { Source = "https://example.com/b.svg", MimeType = "image/svg+xml", Sizes = ["any"] }, + ]; + var surface = Surface(tool); + var parsed = ToolSurface.Parse(surface.ToJson()); + + Assert.Equal(surface.ToJson(), parsed.ToJson()); + Assert.False(ToolSurfaceComparer.Compare(surface, parsed).HasChanges); + var icons = Assert.Single(parsed.Tools).Icons; + Assert.NotNull(icons); + Assert.Equal(2, icons.Count); + Assert.Equal("dark", icons[0].Theme); + Assert.Equal(["any"], icons[1].Sizes); + + var empty = ToolSurface.Parse("""{"formatVersion":1,"tools":[{"name":"a","icons":[]}]}"""); + Assert.Null(Assert.Single(empty.Tools).Icons); + Assert.DoesNotContain("icons", empty.ToJson(), StringComparison.Ordinal); + } + + [Fact] + public void Parse_OldSnapshotWithoutIcons_MatchesAToolWithNoIcons() + { + var baseline = ToolSurface.Parse("""{"formatVersion":1,"tools":[{"name":"a","description":"A test tool that does something useful.","inputSchema":{"type":"object"}}]}"""); + var current = Surface(Tool("a")); + + Assert.False(ToolSurfaceComparer.Compare(baseline, current).HasChanges); + } + + [Theory] + [InlineData("""{"formatVersion":1,"tools":[{"name":"a","icons":{}}]}""", "must be an array")] + [InlineData("""{"formatVersion":1,"tools":[{"name":"a","icons":null}]}""", "must be an array")] + [InlineData("""{"formatVersion":1,"tools":[{"name":"a","icons":["x"]}]}""", "non-empty 'src'")] + [InlineData("""{"formatVersion":1,"tools":[{"name":"a","icons":[{}]}]}""", "non-empty 'src'")] + [InlineData("""{"formatVersion":1,"tools":[{"name":"a","icons":[{"src":""}]}]}""", "non-empty 'src'")] + [InlineData("""{"formatVersion":1,"tools":[{"name":"a","icons":[{"src":"https://example.com/a.png","mimeType":1}]}]}""", "mimeType")] + [InlineData("""{"formatVersion":1,"tools":[{"name":"a","icons":[{"src":"https://example.com/a.png","theme":false}]}]}""", "theme")] + [InlineData("""{"formatVersion":1,"tools":[{"name":"a","icons":[{"src":"https://example.com/a.png","sizes":"48x48"}]}]}""", "sizes")] + [InlineData("""{"formatVersion":1,"tools":[{"name":"a","icons":[{"src":"https://example.com/a.png","sizes":[1]}]}]}""", "sizes")] + public void Parse_RejectsInvalidIcons(string json, string expected) + { + var error = Assert.Throws(() => ToolSurface.Parse(json)); + Assert.Contains(expected, error.Message, StringComparison.Ordinal); + } + + [Fact] + public void Parse_IgnoresUnknownIconProperties() + { + var surface = ToolSurface.Parse("""{"formatVersion":1,"tools":[{"name":"a","icons":[{"src":"https://example.com/a.png","extra":true}]}]}"""); + + var icon = Assert.Single(Assert.Single(surface.Tools).Icons!); + Assert.Equal("https://example.com/a.png", icon.Source); + } + + [Fact] + public void IconAdded_IsNonBreaking_AndShowsBeforeAndAfter() + { + var old = Tool("t"); + var cur = Tool("t"); + cur.Icons = [new Icon { Source = "https://example.com/a.png", MimeType = "image/png" }]; + + var change = Assert.Single(Diff(old, cur).Changes); + + Assert.Equal(ToolSurfaceChangeKind.IconsChanged, change.Kind); + Assert.Equal(ChangeSeverity.NonBreaking, change.Severity); + Assert.Equal("Icons changed from (unset) to [{src: 'https://example.com/a.png', mimeType: 'image/png'}].", change.Message); + Assert.Null(change.Before); + Assert.Null(change.After); + Assert.False(Diff(old, cur).HasBreakingChanges); + } + + [Fact] + public void IconOrderChange_IsNonBreaking() + { + var old = Tool("t"); + old.Icons = + [ + new Icon { Source = "https://example.com/light.png", Theme = "light" }, + new Icon { Source = "https://example.com/dark.png", Theme = "dark" }, + ]; + var cur = Tool("t"); + cur.Icons = + [ + new Icon { Source = "https://example.com/dark.png", Theme = "dark" }, + new Icon { Source = "https://example.com/light.png", Theme = "light" }, + ]; + + var change = Assert.Single(Diff(old, cur).Changes); + Assert.Equal(ToolSurfaceChangeKind.IconsChanged, change.Kind); + Assert.Equal(ChangeSeverity.NonBreaking, change.Severity); + } + + [Fact] + public void EmptyIconsAndOmittedIcons_AreEqual() + { + var omitted = Tool("t"); + var empty = Tool("t"); + empty.Icons = []; + + Assert.False(Diff(omitted, empty).HasChanges); + } + + [Fact] + public void DataUriIcon_IsStoredInFull_AndRedactedInTheMessage() + { + var payload = Convert.ToBase64String(new byte[30]); + var src = "data:image/png;base64," + payload; + var tool = Tool("t"); + tool.Icons = [new Icon { Source = src }]; + + var json = Surface(tool).ToJson(); + Assert.Contains(payload, json, StringComparison.Ordinal); + + var change = Assert.Single(Diff(Tool("t"), tool).Changes); + Assert.DoesNotContain(payload, change.Message, StringComparison.Ordinal); + Assert.Contains("data:image/png;base64,... (", change.Message, StringComparison.Ordinal); + Assert.Contains(" bytes)", change.Message, StringComparison.Ordinal); + } + + [Fact] + public void IconChange_DoesNotFailUnlessNonBreakingChangesFailTheCheck() + { + var old = Tool("t"); + var cur = Tool("t"); + cur.Icons = [new Icon { Source = "https://example.com/a.png" }]; + var diff = Diff(old, cur); + + Assert.True(diff.HasChanges); + Assert.False(diff.HasBreakingChanges); + Assert.Equal(ToolSurfaceChangeKind.IconsChanged, Assert.Single(diff.Changes).Kind); + } + + [Fact] + public void IconRemoved_IsNonBreaking() + { + var old = Tool("t"); + old.Icons = [new Icon { Source = "https://example.com/a.png" }]; + var change = Assert.Single(Diff(old, Tool("t")).Changes); + + Assert.Equal(ToolSurfaceChangeKind.IconsChanged, change.Kind); + Assert.Equal(ChangeSeverity.NonBreaking, change.Severity); + Assert.Contains("to (unset)", change.Message, StringComparison.Ordinal); + } +} From 4b15db3b8d6ae0ce38fa2491a460e23579eee1c9 Mon Sep 17 00:00:00 2001 From: Lior Shmueli <48066416+ShmueLior@users.noreply.github.com> Date: Fri, 4 Dec 2026 09:15:59 +0200 Subject: [PATCH 2/3] Leave out icons without a src so a captured snapshot can be read back --- src/McpProbe/Snapshots/IconContract.cs | 2 +- src/McpProbe/Snapshots/ToolSurface.cs | 6 ++++-- tests/McpProbe.Tests/ToolSurfaceIconsTests.cs | 18 ++++++++++++++++++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/McpProbe/Snapshots/IconContract.cs b/src/McpProbe/Snapshots/IconContract.cs index 6c9441b..5c666a4 100644 --- a/src/McpProbe/Snapshots/IconContract.cs +++ b/src/McpProbe/Snapshots/IconContract.cs @@ -14,7 +14,7 @@ public sealed class IconContract : IEquatable /// Optional theme, light or dark. public IconContract(string source, string? mimeType = null, IReadOnlyList? sizes = null, string? theme = null) { - ArgumentNullException.ThrowIfNull(source); + ArgumentException.ThrowIfNullOrEmpty(source); Source = source; MimeType = mimeType; Sizes = CopySizes(sizes); diff --git a/src/McpProbe/Snapshots/ToolSurface.cs b/src/McpProbe/Snapshots/ToolSurface.cs index 9a6658f..70edb27 100644 --- a/src/McpProbe/Snapshots/ToolSurface.cs +++ b/src/McpProbe/Snapshots/ToolSurface.cs @@ -237,12 +237,14 @@ private static JsonElement EmptyObjectSchema() var copied = new List(icons.Count); foreach (var icon in icons) { - if (icon is null) + // The snapshot parser requires a non-empty 'src', so an icon without one is left out + // instead of writing a file that can't be read back. MCPP028 (icon lint) reports it. + if (icon is null || string.IsNullOrEmpty(icon.Source)) { continue; } - copied.Add(new IconContract(icon.Source ?? string.Empty, icon.MimeType, icon.Sizes?.ToArray(), icon.Theme)); + copied.Add(new IconContract(icon.Source, icon.MimeType, icon.Sizes?.ToArray(), icon.Theme)); } return copied.Count == 0 ? null : copied; diff --git a/tests/McpProbe.Tests/ToolSurfaceIconsTests.cs b/tests/McpProbe.Tests/ToolSurfaceIconsTests.cs index 155ecff..aa07a77 100644 --- a/tests/McpProbe.Tests/ToolSurfaceIconsTests.cs +++ b/tests/McpProbe.Tests/ToolSurfaceIconsTests.cs @@ -201,4 +201,22 @@ public void IconRemoved_IsNonBreaking() Assert.Equal(ChangeSeverity.NonBreaking, change.Severity); Assert.Contains("to (unset)", change.Message, StringComparison.Ordinal); } + + [Fact] + public void Capture_SkipsIconsWithoutSrc_SoTheSnapshotReadsBack() + { + var tool = Tool("weather"); + tool.Icons = [new Icon { Source = "" }, new Icon { Source = "https://example.com/a.png" }]; + + var json = Surface(tool).ToJson(); + var icon = Assert.Single(Assert.Single(ToolSurface.Parse(json).Tools).Icons!); + + Assert.Equal("https://example.com/a.png", icon.Source); + } + + [Fact] + public void IconContract_RejectsEmptySource() + { + Assert.Throws(() => new IconContract("")); + } } From df8df842337f72fee12335b5e5bde39561f41a83 Mon Sep 17 00:00:00 2001 From: Lior Shmueli <48066416+ShmueLior@users.noreply.github.com> Date: Fri, 4 Dec 2026 09:38:51 +0200 Subject: [PATCH 3/3] Add IconsChanged to the JSON and SARIF reports The report format already lists every tool-surface change kind. This adds icons-changed so an icon diff is valid JSON and has a SARIF rule. --- docs/mcpprobe-report.schema.json | 2 +- src/McpProbe/Internal/MachineReadableOutput.cs | 1 + tests/McpProbe.Tests/Goldens/diff.sarif | 16 ++++++++++++++++ .../McpProbe.Tests/MachineReadableOutputTests.cs | 12 ++++++++++++ 4 files changed, 30 insertions(+), 1 deletion(-) diff --git a/docs/mcpprobe-report.schema.json b/docs/mcpprobe-report.schema.json index 7fa8ce3..2e02c01 100644 --- a/docs/mcpprobe-report.schema.json +++ b/docs/mcpprobe-report.schema.json @@ -104,7 +104,7 @@ "enum": [ "tool-added", "tool-removed", "title-changed", "description-changed", "annotations-changed", "property-added", "property-removed", "became-required", "became-optional", "type-changed", - "enum-changed", "output-schema-added", "output-schema-removed", "keyword-changed", "constraint-changed" + "enum-changed", "output-schema-added", "output-schema-removed", "keyword-changed", "constraint-changed", "icons-changed" ] }, "severity": { "enum": ["breaking", "nonBreaking"] }, diff --git a/src/McpProbe/Internal/MachineReadableOutput.cs b/src/McpProbe/Internal/MachineReadableOutput.cs index c2bb045..fed09e1 100644 --- a/src/McpProbe/Internal/MachineReadableOutput.cs +++ b/src/McpProbe/Internal/MachineReadableOutput.cs @@ -48,6 +48,7 @@ private static readonly (ToolSurfaceChangeKind Kind, string Description)[] s_cha (ToolSurfaceChangeKind.OutputSchemaRemoved, "Output schema was removed"), (ToolSurfaceChangeKind.KeywordChanged, "Unclassified JSON Schema keyword changed"), (ToolSurfaceChangeKind.ConstraintChanged, "Schema constraint changed"), + (ToolSurfaceChangeKind.IconsChanged, "Tool icons changed"), ]; public static string LintJson(LintReport report, bool failed) diff --git a/tests/McpProbe.Tests/Goldens/diff.sarif b/tests/McpProbe.Tests/Goldens/diff.sarif index 084455f..a55323a 100644 --- a/tests/McpProbe.Tests/Goldens/diff.sarif +++ b/tests/McpProbe.Tests/Goldens/diff.sarif @@ -249,6 +249,22 @@ "tools" ] } + }, + { + "id": "icons-changed", + "name": "icons-changed", + "shortDescription": { + "text": "Tool icons changed" + }, + "defaultConfiguration": { + "level": "warning" + }, + "properties": { + "tags": [ + "mcp", + "tools" + ] + } } ] } diff --git a/tests/McpProbe.Tests/MachineReadableOutputTests.cs b/tests/McpProbe.Tests/MachineReadableOutputTests.cs index 1d1965a..81de908 100644 --- a/tests/McpProbe.Tests/MachineReadableOutputTests.cs +++ b/tests/McpProbe.Tests/MachineReadableOutputTests.cs @@ -316,4 +316,16 @@ public void ChangeKindIds_AreKebabCaseForEveryKind() Assert.All(ids, id => Assert.Matches("^[a-z]+(-[a-z]+)*$", id)); Assert.Contains("output-schema-removed", ids); } + + [Fact] + public void DiffJson_IconChange_IsIconsChanged() + { + var cur = Tool("t"); + cur.Icons = [new ModelContextProtocol.Protocol.Icon { Source = "https://example.com/a.png" }]; + var json = Diff(Tool("t"), cur).ToJson(); + + Assert.Contains("\"kind\": \"icons-changed\"", json, StringComparison.Ordinal); + AssertValid(Path.Combine(RepoRoot(), "docs", "mcpprobe-report.schema.json"), json); + } + }