Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <file>` 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.
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docs/mcpprobe-report.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"] },
Expand Down
1 change: 1 addition & 0 deletions src/McpProbe/Internal/MachineReadableOutput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 11 additions & 0 deletions src/McpProbe/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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<string!>? sizes = null, string? theme = null) -> void
McpProbe.Snapshots.IconContract.MimeType.get -> string?
McpProbe.Snapshots.IconContract.Sizes.get -> System.Collections.Generic.IReadOnlyList<string!>?
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
Expand All @@ -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.IconContract!>?
McpProbe.Snapshots.ToolContract.InputSchema.get -> System.Text.Json.JsonElement
McpProbe.Snapshots.ToolContract.Name.get -> string!
McpProbe.Snapshots.ToolContract.OutputSchema.get -> System.Text.Json.JsonElement?
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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!
Expand Down
125 changes: 125 additions & 0 deletions src/McpProbe/Snapshots/IconContract.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
using System.Collections.ObjectModel;

namespace McpProbe.Snapshots;

/// <summary>
/// One icon a tool declares in <c>tools/list</c>.
/// </summary>
public sealed class IconContract : IEquatable<IconContract>
{
/// <summary>Creates an icon contract.</summary>
/// <param name="source">The icon URI (<c>src</c>): an HTTP(S) URL or a <c>data:</c> URI.</param>
/// <param name="mimeType">Optional MIME type.</param>
/// <param name="sizes">Optional sizes such as <c>48x48</c> or <c>any</c>. An empty list is stored as unset.</param>
/// <param name="theme">Optional theme, <c>light</c> or <c>dark</c>.</param>
public IconContract(string source, string? mimeType = null, IReadOnlyList<string>? sizes = null, string? theme = null)
{
ArgumentException.ThrowIfNullOrEmpty(source);
Source = source;
MimeType = mimeType;
Sizes = CopySizes(sizes);
Theme = theme;
}

/// <summary>Gets the icon URI (<c>src</c>).</summary>
public string Source { get; }

/// <summary>Gets the MIME type, if any.</summary>
public string? MimeType { get; }

/// <summary>Gets the sizes, if any. Null when unset or empty.</summary>
public IReadOnlyList<string>? Sizes { get; }

/// <summary>Gets the theme, if any.</summary>
public string? Theme { get; }

/// <inheritdoc />
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);
}

/// <inheritdoc />
public override bool Equals(object? obj) => Equals(obj as IconContract);

/// <inheritdoc />
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<IconContract>? left, IReadOnlyList<IconContract>? 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<string>? CopySizes(IReadOnlyList<string>? sizes)
{
if (sizes is null || sizes.Count == 0)
{
return null;
}

return Array.AsReadOnly(sizes.ToArray());
}

private static bool SizesEqual(IReadOnlyList<string>? left, IReadOnlyList<string>? 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;
}
}
6 changes: 5 additions & 1 deletion src/McpProbe/Snapshots/ToolContract.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ namespace McpProbe.Snapshots;
/// </summary>
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<IconContract>? icons = null)
{
Name = name;
Title = title;
Description = description;
InputSchema = inputSchema;
OutputSchema = outputSchema;
Annotations = annotations;
Icons = icons is { Count: > 0 } ? icons : null;
}

/// <summary>Gets the tool name.</summary>
Expand All @@ -34,6 +35,9 @@ internal ToolContract(string name, string? title, string? description, JsonEleme

/// <summary>Gets the behavior hints, if any are set.</summary>
public ToolContractAnnotations? Annotations { get; }

/// <summary>Gets the icons, in server order, if the tool declares any.</summary>
public IReadOnlyList<IconContract>? Icons { get; }
}

/// <summary>
Expand Down
Loading
Loading