From 36332c8961c1451a502deb3a575cf79262fd026f Mon Sep 17 00:00:00 2001 From: Lior Shmueli <48066416+ShmueLior@users.noreply.github.com> Date: Sat, 28 Nov 2026 10:20:11 +0200 Subject: [PATCH 1/2] Add options-first snapshot overloads and fix the README quickstart --- CHANGELOG.md | 5 + README.md | 44 ++++++-- src/McpProbe/McpProbeHost.cs | 18 ++++ src/McpProbe/PublicAPI.Unshipped.txt | 3 + src/McpProbe/Snapshots/ToolSnapshot.cs | 32 ++++++ tests/McpProbe.Tests/ToolSnapshotTests.cs | 125 +++++++++++++++++++--- 6 files changed, 203 insertions(+), 24 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f460219..e7d8a18 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,11 @@ All notable changes to this project are documented here. The format is based on - `LintReport.ToHtml()` and `ToolSurfaceDiff.ToHtml()`: a self-contained HTML page (inline CSS, no scripts) with a banner, a summary and, when there are findings or changes, a table. Server text is sanitized and HTML-encoded. - `mcpprobe lint --report ` and `mcpprobe diff --report ` also write that page. Stdout and exit codes are unchanged. The file is written on exit 0 and 1, not on a usage or connection error (exit 2). - GitHub Action and Azure Pipelines template inputs `strict`, `transport`, and `report`. All three are off by default, so existing workflows keep the same CLI invocation. `report` is a directory (`lint.html` and `diff.html`); the job summary is unchanged, and artifact upload is left to the workflow (`actions/upload-artifact` / `PublishPipelineArtifact@1`). `report` requires a CLI that has `--report`; the wrapper fails fast if the installed tool does not. +- Options-first overloads for `McpProbeHost.VerifyToolSnapshotAsync`, `ToolSnapshot.Verify` and `ToolSnapshot.VerifyAsync`, so `VerifyToolSnapshotAsync(new SnapshotOptions { ... })` compiles. The existing path-first signatures are unchanged. A call that names only `options:` is now ambiguous; pass the snapshot path, or pass the options positionally to use the new overload. + +### Fixed + +- The README Quickstart now includes a short `WeatherTools` type (with `UseStructuredContent`) and the missing usings, so it compiles and runs as written. The snapshot example shows a real `VerifyToolSnapshotAsync` call with `Log`. Notes were added for `*.received.json` in `.gitignore` and for the CLI's net8.0/net10.0 runtime and `DOTNET_ROOT`. ### Changed diff --git a/README.md b/README.md index fe62a04..7d6c407 100644 --- a/README.md +++ b/README.md @@ -28,17 +28,34 @@ dotnet add package McpProbe --prerelease using McpProbe; using McpProbe.Assertions; using Microsoft.Extensions.DependencyInjection; // WithTools() +using ModelContextProtocol.Server; +using System.ComponentModel; -[Fact] -public async Task Forecast_works() +[McpServerToolType] +public sealed class WeatherTools +{ + [McpServerTool(Name = "get_forecast", UseStructuredContent = true)] + [Description("Gets a daily weather forecast for a city.")] + public static Forecast GetForecast( + [Description("City name, for example 'Paris'.")] string city) + => new Forecast(city, "Sunny"); +} + +public sealed record Forecast(string City, string Summary); + +public class WeatherServerTests { - await using var probe = await McpProbeHost.StartAsync(mcp => mcp.WithTools()); + [Fact] + public async Task Forecast_works() + { + await using var probe = await McpProbeHost.StartAsync(mcp => mcp.WithTools()); - var tools = await probe.Client.ListToolsAsync(); - McpAssert.That(tools).ContainsTool("get_forecast").HasParameter("city", type: "string", required: true); + var tools = await probe.Client.ListToolsAsync(); + McpAssert.That(tools).ContainsTool("get_forecast").HasParameter("city", type: "string", required: true); - var result = await probe.Client.CallToolAsync("get_forecast", new Dictionary { ["city"] = "Paris" }); - McpAssert.That(result).Succeeded().HasStructuredValue("city", "Paris"); + var result = await probe.Client.CallToolAsync("get_forecast", new Dictionary { ["city"] = "Paris" }); + McpAssert.That(result).Succeeded().HasStructuredValue("city", "Paris"); + } } ``` @@ -61,10 +78,15 @@ McpAssert.That(resources).ContainsResource("weather://cities").HasMimeType("text ## Snapshot workflow ```csharp +using McpProbe.Snapshots; + [Fact] -public Task Tool_surface_matches_snapshot() => probe.VerifyToolSnapshotAsync(); +public Task Tool_surface_matches_snapshot() => + probe.VerifyToolSnapshotAsync(new SnapshotOptions { Log = output.WriteLine }); ``` +`output.WriteLine` is xUnit's `ITestOutputHelper`. To use the default file name with no options, call `VerifyToolSnapshotAsync()`. + 1. The first run writes `mcp-tools.json` next to the test file and fails, so you look at it. Commit it. 2. Later runs compare the live tool surface with the file: - **Breaking changes fail the test**: removed tool, removed parameter, newly required parameter, narrowed type or enum, tighter input constraints (`minimum`, `maxLength`, `minItems`, `multipleOf`, a new or changed `pattern` or `format`, a new `const`, `uniqueItems: true` or `additionalProperties: false`, ...), and removed or narrowed output fields. A removed parameter that looks renamed gets a hint. @@ -72,7 +94,7 @@ public Task Tool_surface_matches_snapshot() => probe.VerifyToolSnapshotAsync(); - Local `$ref`s (`#/$defs/...`, `#/definitions/...`, and the `#/properties/...` refs the C# SDK emits for recursive types) are followed, so a change inside a referenced schema is classified like an inline one. - Schema-valued `additionalProperties` (and `unevaluatedProperties`, `additionalItems`, `unevaluatedItems`) are compared like nested schemas, at paths such as `input.meta[additionalProperties]`. - Schema keywords McpProbe doesn't classify yet (such as `allOf`, `anyOf` or `oneOf`) are reported as non-breaking, marked "review by hand". -3. On a failure, the current surface is written to `mcp-tools.received.json`. To accept the change, run with `MCPPROBE_UPDATE_SNAPSHOTS=1` (or set `SnapshotOptions.Update`), review the diff in git, and commit. +3. On a failure, the current surface is written to `mcp-tools.received.json`. Add `*.received.json` to your `.gitignore` so those files aren't committed. To accept the change, run with `MCPPROBE_UPDATE_SNAPSHOTS=1` (or set `SnapshotOptions.Update`), review the diff in git, and commit. On CI (`CI` or `TF_BUILD` set), a missing snapshot is not created: the test fails. Set `SnapshotOptions.FailOnNonBreakingChanges` to fail on every change. @@ -92,6 +114,8 @@ Non-breaking: ## Lint rules ```csharp +using McpProbe.Linting; + var report = await probe.LintToolsAsync(); report.ThrowIfFailed(); // fails on warnings and errors by default @@ -136,6 +160,8 @@ mcpprobe lint --http https://localhost:5001/mcp --header "Authorization: Bea mcpprobe lint --http http://localhost:5000/sse --transport sse --header "Authorization: Bearer $TOKEN" ``` +The `mcpprobe` tool is packed for net8.0 and net10.0 (`RollForward=Major`), so a .NET 8 or .NET 10 runtime must be installed. An SDK is also needed if the `--stdio` command is `dotnet run`. If the apphost errors with "You must install .NET to run this application" even though `dotnet` works, set `DOTNET_ROOT` to that install's root (the directory that contains `dotnet` and the `shared` folder). + `--http` already tries Streamable HTTP and falls back to legacy SSE. Use `--transport streamable-http` or `--transport sse` to pin a mode (`auto` is the default). Legacy SSE servers usually listen at `/sse` (and `/message`), not at the Streamable HTTP path. If the server maps MCP at a prefix such as `/mcp` and enables legacy SSE, the C# SDK places those endpoints under the prefix (`/mcp/sse` and `/mcp/message`). There is no WebSocket transport. Exit codes: `0` passed, `1` check failed (breaking change or lint findings), `2` usage or connection error. The server's stderr is printed when it fails to start. `diff` and `lint` also take `--from-file ` to check a file without starting a server. Run `mcpprobe --help` for every option. diff --git a/src/McpProbe/McpProbeHost.cs b/src/McpProbe/McpProbeHost.cs index 4a2cfea..635b857 100644 --- a/src/McpProbe/McpProbeHost.cs +++ b/src/McpProbe/McpProbeHost.cs @@ -159,6 +159,24 @@ public Task VerifyToolSnapshotAsync( [CallerFilePath] string callerFilePath = "") => ToolSnapshot.VerifyAsync(Client, snapshotPath, options, cancellationToken, callerFilePath); + /// + /// Checks the server's tool surface against a snapshot file, using the default file name. + /// See for the workflow. + /// + /// Snapshot options. + /// Cancels the request. + /// Filled in by the compiler. + /// The diff between the snapshot and the current surface. + /// The check failed. + public Task VerifyToolSnapshotAsync( + SnapshotOptions options, + CancellationToken cancellationToken = default, + [CallerFilePath] string callerFilePath = "") + { + ArgumentNullException.ThrowIfNull(options); + return VerifyToolSnapshotAsync(ToolSnapshot.DefaultFileName, options, cancellationToken, callerFilePath); + } + /// /// Lists the server's tools and lints them. /// diff --git a/src/McpProbe/PublicAPI.Unshipped.txt b/src/McpProbe/PublicAPI.Unshipped.txt index fdd0053..668e9fd 100644 --- a/src/McpProbe/PublicAPI.Unshipped.txt +++ b/src/McpProbe/PublicAPI.Unshipped.txt @@ -116,6 +116,7 @@ McpProbe.McpProbeHost.DisposeAsync() -> System.Threading.Tasks.ValueTask McpProbe.McpProbeHost.LintToolsAsync(McpProbe.Linting.LintOptions? options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task! McpProbe.McpProbeHost.Server.get -> ModelContextProtocol.Server.McpServer! McpProbe.McpProbeHost.Services.get -> System.IServiceProvider! +McpProbe.McpProbeHost.VerifyToolSnapshotAsync(McpProbe.Snapshots.SnapshotOptions! options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken), string! callerFilePath = "") -> System.Threading.Tasks.Task! McpProbe.McpProbeHost.VerifyToolSnapshotAsync(string! snapshotPath = "mcp-tools.json", McpProbe.Snapshots.SnapshotOptions? options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken), string! callerFilePath = "") -> System.Threading.Tasks.Task! McpProbe.McpProbeHostOptions McpProbe.McpProbeHostOptions.ClientOptions.get -> ModelContextProtocol.Client.McpClientOptions? @@ -251,7 +252,9 @@ static McpProbe.McpProbeHost.StartAsync(System.Action bool static McpProbe.Snapshots.ToolContractAnnotations.operator ==(McpProbe.Snapshots.ToolContractAnnotations? left, McpProbe.Snapshots.ToolContractAnnotations? right) -> bool static McpProbe.Snapshots.ToolSnapshot.GetReceivedPath(string! snapshotPath) -> string! +static McpProbe.Snapshots.ToolSnapshot.Verify(McpProbe.Snapshots.ToolSurface! current, McpProbe.Snapshots.SnapshotOptions! options, string! callerFilePath = "") -> McpProbe.Snapshots.ToolSurfaceDiff! static McpProbe.Snapshots.ToolSnapshot.Verify(McpProbe.Snapshots.ToolSurface! current, string! snapshotPath = "mcp-tools.json", McpProbe.Snapshots.SnapshotOptions? options = null, string! callerFilePath = "") -> McpProbe.Snapshots.ToolSurfaceDiff! +static McpProbe.Snapshots.ToolSnapshot.VerifyAsync(ModelContextProtocol.Client.McpClient! client, McpProbe.Snapshots.SnapshotOptions! options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken), string! callerFilePath = "") -> System.Threading.Tasks.Task! static McpProbe.Snapshots.ToolSnapshot.VerifyAsync(ModelContextProtocol.Client.McpClient! client, string! snapshotPath = "mcp-tools.json", McpProbe.Snapshots.SnapshotOptions? options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken), string! callerFilePath = "") -> System.Threading.Tasks.Task! static McpProbe.Snapshots.ToolSurface.CaptureAsync(ModelContextProtocol.Client.McpClient! client, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task! static McpProbe.Snapshots.ToolSurface.FromClientTools(System.Collections.Generic.IEnumerable! tools) -> McpProbe.Snapshots.ToolSurface! diff --git a/src/McpProbe/Snapshots/ToolSnapshot.cs b/src/McpProbe/Snapshots/ToolSnapshot.cs index 416ca87..bee22d2 100644 --- a/src/McpProbe/Snapshots/ToolSnapshot.cs +++ b/src/McpProbe/Snapshots/ToolSnapshot.cs @@ -39,6 +39,23 @@ public static async Task VerifyAsync( return VerifyResolved(surface, ResolvePath(snapshotPath, options, callerFilePath), options ?? new SnapshotOptions()); } + /// Captures the client's tool surface and checks it against the default snapshot file. + /// A connected client. + /// Snapshot options. + /// Cancels the request. + /// Filled in by the compiler. + /// The diff between the snapshot and the current surface. + /// The check failed. + public static Task VerifyAsync( + McpClient client, + SnapshotOptions options, + CancellationToken cancellationToken = default, + [CallerFilePath] string callerFilePath = "") + { + ArgumentNullException.ThrowIfNull(options); + return VerifyAsync(client, DefaultFileName, options, cancellationToken, callerFilePath); + } + /// Checks a captured surface against a snapshot file. /// The current surface. /// The snapshot path. Relative paths resolve against or the calling source file's directory. @@ -56,6 +73,21 @@ public static ToolSurfaceDiff Verify( return VerifyResolved(current, ResolvePath(snapshotPath, options, callerFilePath), options ?? new SnapshotOptions()); } + /// Checks a captured surface against the default snapshot file. + /// The current surface. + /// Snapshot options. + /// Filled in by the compiler. + /// The diff between the snapshot and the current surface. + /// The check failed. + public static ToolSurfaceDiff Verify( + ToolSurface current, + SnapshotOptions options, + [CallerFilePath] string callerFilePath = "") + { + ArgumentNullException.ThrowIfNull(options); + return Verify(current, DefaultFileName, options, callerFilePath); + } + /// Gets the path of the file written next to a snapshot when the check fails. /// The snapshot path. /// The .received.json path. diff --git a/tests/McpProbe.Tests/ToolSnapshotTests.cs b/tests/McpProbe.Tests/ToolSnapshotTests.cs index a090d00..9aa2198 100644 --- a/tests/McpProbe.Tests/ToolSnapshotTests.cs +++ b/tests/McpProbe.Tests/ToolSnapshotTests.cs @@ -1,3 +1,4 @@ +using System.Runtime.CompilerServices; using McpProbe.Snapshots; using McpProbe.Tests.TestSupport; using WeatherServer; @@ -28,20 +29,20 @@ private SnapshotOptions Local(Action? configure = null) [Fact] public void MissingSnapshot_IsWrittenAndFailsOnce() { - var error = Assert.Throws(() => ToolSnapshot.Verify(Baseline, options: Local())); + var error = Assert.Throws(() => ToolSnapshot.Verify(Baseline, ToolSnapshot.DefaultFileName, Local())); Assert.Contains("No tool snapshot existed, so one was written", error.Message, StringComparison.Ordinal); Assert.Equal(_dir.File(ToolSnapshot.DefaultFileName), error.SnapshotPath); Assert.Equal(Baseline.ToJson(), File.ReadAllText(_dir.File(ToolSnapshot.DefaultFileName))); // Second run passes. - Assert.False(ToolSnapshot.Verify(Baseline, options: Local()).HasChanges); + Assert.False(ToolSnapshot.Verify(Baseline, ToolSnapshot.DefaultFileName, Local()).HasChanges); } [Fact] public void MissingSnapshot_OnCi_FailsWithoutWritingIt() { - var error = Assert.Throws(() => ToolSnapshot.Verify(Baseline, options: Local(o => o.CreateMissing = false))); + var error = Assert.Throws(() => ToolSnapshot.Verify(Baseline, ToolSnapshot.DefaultFileName, Local(o => o.CreateMissing = false))); Assert.Contains("Tool snapshot not found", error.Message, StringComparison.Ordinal); Assert.False(File.Exists(_dir.File("mcp-tools.json"))); @@ -54,7 +55,7 @@ public void MatchingSnapshot_PassesAndCleansUpReceivedFile() WriteBaseline(); File.WriteAllText(_dir.File("mcp-tools.received.json"), "stale"); - var diff = ToolSnapshot.Verify(Baseline, options: Local()); + var diff = ToolSnapshot.Verify(Baseline, ToolSnapshot.DefaultFileName, Local()); Assert.False(diff.HasChanges); Assert.False(File.Exists(_dir.File("mcp-tools.received.json"))); @@ -66,7 +67,7 @@ public void BreakingChange_FailsWithDiffAndWritesReceivedFile() WriteBaseline(); var current = Surface(Tool("get_forecast", """{"type":"object","properties":{"location":{"type":"string"}},"required":["location"]}""")); - var error = Assert.Throws(() => ToolSnapshot.Verify(current, options: Local())); + var error = Assert.Throws(() => ToolSnapshot.Verify(current, ToolSnapshot.DefaultFileName, Local())); Assert.Contains("has breaking changes", error.Message, StringComparison.Ordinal); Assert.Contains("- get_alerts: Tool was removed.", error.Message, StringComparison.Ordinal); @@ -84,7 +85,7 @@ public void NonBreakingChange_PassesAndIsLogged() var current = Surface(Tool("get_forecast", CityRequired), Tool("get_alerts"), Tool("get_radar")); var logs = new List(); - var diff = ToolSnapshot.Verify(current, options: Local(o => o.Log = logs.Add)); + var diff = ToolSnapshot.Verify(current, ToolSnapshot.DefaultFileName, Local(o => o.Log = logs.Add)); Assert.True(diff.HasChanges); Assert.False(diff.HasBreakingChanges); @@ -99,7 +100,7 @@ public void NonBreakingChange_FailsWhenConfigured() WriteBaseline(); var current = Surface(Tool("get_forecast", CityRequired), Tool("get_alerts"), Tool("get_radar")); - var error = Assert.Throws(() => ToolSnapshot.Verify(current, options: Local(o => o.FailOnNonBreakingChanges = true))); + var error = Assert.Throws(() => ToolSnapshot.Verify(current, ToolSnapshot.DefaultFileName, Local(o => o.FailOnNonBreakingChanges = true))); Assert.Contains("The tool surface changed", error.Message, StringComparison.Ordinal); } @@ -110,17 +111,17 @@ public void UpdateMode_RewritesTheSnapshotAndPasses() WriteBaseline(); var current = Surface(Tool("only_tool")); - var diff = ToolSnapshot.Verify(current, options: Local(o => o.Update = true)); + var diff = ToolSnapshot.Verify(current, ToolSnapshot.DefaultFileName, Local(o => o.Update = true)); Assert.True(diff.HasBreakingChanges); Assert.Equal(current.ToJson(), File.ReadAllText(_dir.File("mcp-tools.json"))); - Assert.False(ToolSnapshot.Verify(current, options: Local()).HasChanges); + Assert.False(ToolSnapshot.Verify(current, ToolSnapshot.DefaultFileName, Local()).HasChanges); } [Fact] public void UpdateMode_CreatesMissingSnapshotWithoutFailing() { - var diff = ToolSnapshot.Verify(Baseline, options: Local(o => { o.Update = true; o.CreateMissing = false; })); + var diff = ToolSnapshot.Verify(Baseline, ToolSnapshot.DefaultFileName, Local(o => { o.Update = true; o.CreateMissing = false; })); Assert.False(diff.HasChanges); Assert.True(File.Exists(_dir.File("mcp-tools.json"))); @@ -131,10 +132,10 @@ public void CorruptSnapshot_FailsClearly_AndUpdateRepairsIt() { File.WriteAllText(_dir.File("mcp-tools.json"), "{ not json"); - var error = Assert.Throws(() => ToolSnapshot.Verify(Baseline, options: Local())); + var error = Assert.Throws(() => ToolSnapshot.Verify(Baseline, ToolSnapshot.DefaultFileName, Local())); Assert.Contains("could not be read", error.Message, StringComparison.Ordinal); - ToolSnapshot.Verify(Baseline, options: Local(o => o.Update = true)); + ToolSnapshot.Verify(Baseline, ToolSnapshot.DefaultFileName, Local(o => o.Update = true)); Assert.Equal(Baseline.ToJson(), File.ReadAllText(_dir.File("mcp-tools.json"))); } @@ -143,7 +144,7 @@ public void ReformattedButEquivalentSnapshot_Passes() { File.WriteAllText(_dir.File("mcp-tools.json"), Baseline.ToJson().Replace("\n", "\r\n", StringComparison.Ordinal).Replace(" ", " ", StringComparison.Ordinal)); - Assert.False(ToolSnapshot.Verify(Baseline, options: Local()).HasChanges); + Assert.False(ToolSnapshot.Verify(Baseline, ToolSnapshot.DefaultFileName, Local()).HasChanges); } [Fact] @@ -194,12 +195,106 @@ public async Task EndToEnd_WithInMemoryHost() { await using var probe = await McpProbeHost.StartAsync(mcp => mcp.WithWeatherFeatures(), TestContext.Current.CancellationToken); - await Assert.ThrowsAsync(() => probe.VerifyToolSnapshotAsync(options: Local(), cancellationToken: TestContext.Current.CancellationToken)); - var diff = await probe.VerifyToolSnapshotAsync(options: Local(), cancellationToken: TestContext.Current.CancellationToken); + await Assert.ThrowsAsync(() => probe.VerifyToolSnapshotAsync(ToolSnapshot.DefaultFileName, Local(), TestContext.Current.CancellationToken)); + var diff = await probe.VerifyToolSnapshotAsync(ToolSnapshot.DefaultFileName, Local(), TestContext.Current.CancellationToken); Assert.False(diff.HasChanges); Assert.Contains("\"get_forecast\"", File.ReadAllText(_dir.File("mcp-tools.json")), StringComparison.Ordinal); } + + [Fact] + public async Task OptionsFirst_HostVerify_UsesDefaultFileNameAndHonorsOptions() + { + await using var probe = await McpProbeHost.StartAsync(mcp => mcp.WithWeatherFeatures(), TestContext.Current.CancellationToken); + + var error = await Assert.ThrowsAsync(() => + probe.VerifyToolSnapshotAsync(Local(), TestContext.Current.CancellationToken)); + + Assert.Equal(_dir.File(ToolSnapshot.DefaultFileName), error.SnapshotPath); + Assert.True(File.Exists(_dir.File(ToolSnapshot.DefaultFileName))); + Assert.Contains("\"get_forecast\"", File.ReadAllText(_dir.File(ToolSnapshot.DefaultFileName)), StringComparison.Ordinal); + } + + [Fact] + public async Task OptionsFirst_HostVerify_ResolvesPathFromTestFileNotHostSource() + { + var expected = ToolSnapshot.ResolvePath(ToolSnapshot.DefaultFileName, options: null, callerFilePath: ThisFile()); + var received = ToolSnapshot.GetReceivedPath(expected); + try + { + await using var probe = await McpProbeHost.StartAsync(mcp => mcp.WithWeatherFeatures(), TestContext.Current.CancellationToken); + var options = new SnapshotOptions { Update = false, CreateMissing = false }; + + var error = await Assert.ThrowsAsync(() => + probe.VerifyToolSnapshotAsync(options, TestContext.Current.CancellationToken)); + + Assert.Equal(expected, error.SnapshotPath); + Assert.DoesNotContain("McpProbeHost.cs", error.SnapshotPath, StringComparison.Ordinal); + Assert.Contains(Path.Combine("tests", "McpProbe.Tests"), error.SnapshotPath, StringComparison.Ordinal); + } + finally + { + if (File.Exists(expected)) + { + File.Delete(expected); + } + + if (File.Exists(received)) + { + File.Delete(received); + } + } + } + + [Fact] + public void OptionsFirst_Verify_UsesDefaultFileNameAndHonorsOptions() + { + var error = Assert.Throws(() => ToolSnapshot.Verify(Baseline, Local())); + + Assert.Equal(_dir.File(ToolSnapshot.DefaultFileName), error.SnapshotPath); + Assert.Equal(Baseline.ToJson(), File.ReadAllText(_dir.File(ToolSnapshot.DefaultFileName))); + } + + [Fact] + public async Task OptionsFirst_VerifyAsync_UsesDefaultFileNameAndHonorsOptions() + { + await using var probe = await McpProbeHost.StartAsync(mcp => mcp.WithWeatherFeatures(), TestContext.Current.CancellationToken); + + var error = await Assert.ThrowsAsync(() => + ToolSnapshot.VerifyAsync(probe.Client, Local(), TestContext.Current.CancellationToken)); + + Assert.Equal(_dir.File(ToolSnapshot.DefaultFileName), error.SnapshotPath); + Assert.True(File.Exists(_dir.File(ToolSnapshot.DefaultFileName))); + } + + [Fact] + public void OptionsFirst_Verify_NullOptions_Throws() + { + var ex = Assert.Throws(() => ToolSnapshot.Verify(Baseline, (SnapshotOptions)null!)); + Assert.Equal("options", ex.ParamName); + } + + [Fact] + public async Task OptionsFirst_VerifyAsync_NullOptions_Throws() + { + await using var probe = await McpProbeHost.StartAsync(mcp => mcp.WithWeatherFeatures(), TestContext.Current.CancellationToken); + + var ex = await Assert.ThrowsAsync(() => + ToolSnapshot.VerifyAsync(probe.Client, (SnapshotOptions)null!, TestContext.Current.CancellationToken)); + Assert.Equal("options", ex.ParamName); + } + + [Fact] + public async Task OptionsFirst_HostVerify_NullOptions_Throws() + { + await using var probe = await McpProbeHost.StartAsync(mcp => mcp.WithWeatherFeatures(), TestContext.Current.CancellationToken); + + var ex = await Assert.ThrowsAsync(() => + probe.VerifyToolSnapshotAsync((SnapshotOptions)null!, TestContext.Current.CancellationToken)); + Assert.Equal("options", ex.ParamName); + } + + private static string ThisFile([CallerFilePath] string path = "") => path; } [CollectionDefinition(nameof(EnvironmentVariableTests), DisableParallelization = true)] From 43039fb49fe79ad193216e2deaa354859aa0d881 Mon Sep 17 00:00:00 2001 From: Lior Shmueli <48066416+ShmueLior@users.noreply.github.com> Date: Sat, 28 Nov 2026 10:27:00 +0200 Subject: [PATCH 2/2] Name the options-first snapshot parameter snapshotOptions Keep existing options: named calls binding to the path-first overloads so 0.2 and 0.3 callers do not get CS0121. --- CHANGELOG.md | 2 +- src/McpProbe/McpProbeHost.cs | 8 +- src/McpProbe/PublicAPI.Unshipped.txt | 6 +- src/McpProbe/Snapshots/ToolSnapshot.cs | 16 +-- tests/McpProbe.Tests/ToolSnapshotTests.cs | 158 +++++++++++++++++++--- 5 files changed, 156 insertions(+), 34 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e7d8a18..69ec247 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,7 @@ All notable changes to this project are documented here. The format is based on - `LintReport.ToHtml()` and `ToolSurfaceDiff.ToHtml()`: a self-contained HTML page (inline CSS, no scripts) with a banner, a summary and, when there are findings or changes, a table. Server text is sanitized and HTML-encoded. - `mcpprobe lint --report ` and `mcpprobe diff --report ` also write that page. Stdout and exit codes are unchanged. The file is written on exit 0 and 1, not on a usage or connection error (exit 2). - GitHub Action and Azure Pipelines template inputs `strict`, `transport`, and `report`. All three are off by default, so existing workflows keep the same CLI invocation. `report` is a directory (`lint.html` and `diff.html`); the job summary is unchanged, and artifact upload is left to the workflow (`actions/upload-artifact` / `PublishPipelineArtifact@1`). `report` requires a CLI that has `--report`; the wrapper fails fast if the installed tool does not. -- Options-first overloads for `McpProbeHost.VerifyToolSnapshotAsync`, `ToolSnapshot.Verify` and `ToolSnapshot.VerifyAsync`, so `VerifyToolSnapshotAsync(new SnapshotOptions { ... })` compiles. The existing path-first signatures are unchanged. A call that names only `options:` is now ambiguous; pass the snapshot path, or pass the options positionally to use the new overload. +- Options-first overloads for `McpProbeHost.VerifyToolSnapshotAsync`, `ToolSnapshot.Verify` and `ToolSnapshot.VerifyAsync`, so `VerifyToolSnapshotAsync(new SnapshotOptions { ... })` compiles. The existing path-first signatures are unchanged. The new overloads name their options parameter `snapshotOptions`, so a call that names only `options:` still binds to the path-first overload. ### Fixed diff --git a/src/McpProbe/McpProbeHost.cs b/src/McpProbe/McpProbeHost.cs index 635b857..f89baf0 100644 --- a/src/McpProbe/McpProbeHost.cs +++ b/src/McpProbe/McpProbeHost.cs @@ -163,18 +163,18 @@ public Task VerifyToolSnapshotAsync( /// Checks the server's tool surface against a snapshot file, using the default file name. /// See for the workflow. /// - /// Snapshot options. + /// Snapshot options. /// Cancels the request. /// Filled in by the compiler. /// The diff between the snapshot and the current surface. /// The check failed. public Task VerifyToolSnapshotAsync( - SnapshotOptions options, + SnapshotOptions snapshotOptions, CancellationToken cancellationToken = default, [CallerFilePath] string callerFilePath = "") { - ArgumentNullException.ThrowIfNull(options); - return VerifyToolSnapshotAsync(ToolSnapshot.DefaultFileName, options, cancellationToken, callerFilePath); + ArgumentNullException.ThrowIfNull(snapshotOptions); + return VerifyToolSnapshotAsync(ToolSnapshot.DefaultFileName, snapshotOptions, cancellationToken, callerFilePath); } /// diff --git a/src/McpProbe/PublicAPI.Unshipped.txt b/src/McpProbe/PublicAPI.Unshipped.txt index 668e9fd..7c63e03 100644 --- a/src/McpProbe/PublicAPI.Unshipped.txt +++ b/src/McpProbe/PublicAPI.Unshipped.txt @@ -116,7 +116,7 @@ McpProbe.McpProbeHost.DisposeAsync() -> System.Threading.Tasks.ValueTask McpProbe.McpProbeHost.LintToolsAsync(McpProbe.Linting.LintOptions? options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task! McpProbe.McpProbeHost.Server.get -> ModelContextProtocol.Server.McpServer! McpProbe.McpProbeHost.Services.get -> System.IServiceProvider! -McpProbe.McpProbeHost.VerifyToolSnapshotAsync(McpProbe.Snapshots.SnapshotOptions! options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken), string! callerFilePath = "") -> System.Threading.Tasks.Task! +McpProbe.McpProbeHost.VerifyToolSnapshotAsync(McpProbe.Snapshots.SnapshotOptions! snapshotOptions, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken), string! callerFilePath = "") -> System.Threading.Tasks.Task! McpProbe.McpProbeHost.VerifyToolSnapshotAsync(string! snapshotPath = "mcp-tools.json", McpProbe.Snapshots.SnapshotOptions? options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken), string! callerFilePath = "") -> System.Threading.Tasks.Task! McpProbe.McpProbeHostOptions McpProbe.McpProbeHostOptions.ClientOptions.get -> ModelContextProtocol.Client.McpClientOptions? @@ -252,9 +252,9 @@ static McpProbe.McpProbeHost.StartAsync(System.Action bool static McpProbe.Snapshots.ToolContractAnnotations.operator ==(McpProbe.Snapshots.ToolContractAnnotations? left, McpProbe.Snapshots.ToolContractAnnotations? right) -> bool static McpProbe.Snapshots.ToolSnapshot.GetReceivedPath(string! snapshotPath) -> string! -static McpProbe.Snapshots.ToolSnapshot.Verify(McpProbe.Snapshots.ToolSurface! current, McpProbe.Snapshots.SnapshotOptions! options, string! callerFilePath = "") -> McpProbe.Snapshots.ToolSurfaceDiff! +static McpProbe.Snapshots.ToolSnapshot.Verify(McpProbe.Snapshots.ToolSurface! current, McpProbe.Snapshots.SnapshotOptions! snapshotOptions, string! callerFilePath = "") -> McpProbe.Snapshots.ToolSurfaceDiff! static McpProbe.Snapshots.ToolSnapshot.Verify(McpProbe.Snapshots.ToolSurface! current, string! snapshotPath = "mcp-tools.json", McpProbe.Snapshots.SnapshotOptions? options = null, string! callerFilePath = "") -> McpProbe.Snapshots.ToolSurfaceDiff! -static McpProbe.Snapshots.ToolSnapshot.VerifyAsync(ModelContextProtocol.Client.McpClient! client, McpProbe.Snapshots.SnapshotOptions! options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken), string! callerFilePath = "") -> System.Threading.Tasks.Task! +static McpProbe.Snapshots.ToolSnapshot.VerifyAsync(ModelContextProtocol.Client.McpClient! client, McpProbe.Snapshots.SnapshotOptions! snapshotOptions, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken), string! callerFilePath = "") -> System.Threading.Tasks.Task! static McpProbe.Snapshots.ToolSnapshot.VerifyAsync(ModelContextProtocol.Client.McpClient! client, string! snapshotPath = "mcp-tools.json", McpProbe.Snapshots.SnapshotOptions? options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken), string! callerFilePath = "") -> System.Threading.Tasks.Task! static McpProbe.Snapshots.ToolSurface.CaptureAsync(ModelContextProtocol.Client.McpClient! client, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task! static McpProbe.Snapshots.ToolSurface.FromClientTools(System.Collections.Generic.IEnumerable! tools) -> McpProbe.Snapshots.ToolSurface! diff --git a/src/McpProbe/Snapshots/ToolSnapshot.cs b/src/McpProbe/Snapshots/ToolSnapshot.cs index bee22d2..e000c56 100644 --- a/src/McpProbe/Snapshots/ToolSnapshot.cs +++ b/src/McpProbe/Snapshots/ToolSnapshot.cs @@ -41,19 +41,19 @@ public static async Task VerifyAsync( /// Captures the client's tool surface and checks it against the default snapshot file. /// A connected client. - /// Snapshot options. + /// Snapshot options. /// Cancels the request. /// Filled in by the compiler. /// The diff between the snapshot and the current surface. /// The check failed. public static Task VerifyAsync( McpClient client, - SnapshotOptions options, + SnapshotOptions snapshotOptions, CancellationToken cancellationToken = default, [CallerFilePath] string callerFilePath = "") { - ArgumentNullException.ThrowIfNull(options); - return VerifyAsync(client, DefaultFileName, options, cancellationToken, callerFilePath); + ArgumentNullException.ThrowIfNull(snapshotOptions); + return VerifyAsync(client, DefaultFileName, snapshotOptions, cancellationToken, callerFilePath); } /// Checks a captured surface against a snapshot file. @@ -75,17 +75,17 @@ public static ToolSurfaceDiff Verify( /// Checks a captured surface against the default snapshot file. /// The current surface. - /// Snapshot options. + /// Snapshot options. /// Filled in by the compiler. /// The diff between the snapshot and the current surface. /// The check failed. public static ToolSurfaceDiff Verify( ToolSurface current, - SnapshotOptions options, + SnapshotOptions snapshotOptions, [CallerFilePath] string callerFilePath = "") { - ArgumentNullException.ThrowIfNull(options); - return Verify(current, DefaultFileName, options, callerFilePath); + ArgumentNullException.ThrowIfNull(snapshotOptions); + return Verify(current, DefaultFileName, snapshotOptions, callerFilePath); } /// Gets the path of the file written next to a snapshot when the check fails. diff --git a/tests/McpProbe.Tests/ToolSnapshotTests.cs b/tests/McpProbe.Tests/ToolSnapshotTests.cs index 9aa2198..55d4368 100644 --- a/tests/McpProbe.Tests/ToolSnapshotTests.cs +++ b/tests/McpProbe.Tests/ToolSnapshotTests.cs @@ -1,6 +1,7 @@ using System.Runtime.CompilerServices; using McpProbe.Snapshots; using McpProbe.Tests.TestSupport; +using ModelContextProtocol.Client; using WeatherServer; using static McpProbe.Tests.TestSupport.SchemaTools; @@ -29,20 +30,20 @@ private SnapshotOptions Local(Action? configure = null) [Fact] public void MissingSnapshot_IsWrittenAndFailsOnce() { - var error = Assert.Throws(() => ToolSnapshot.Verify(Baseline, ToolSnapshot.DefaultFileName, Local())); + var error = Assert.Throws(() => ToolSnapshot.Verify(Baseline, options: Local())); Assert.Contains("No tool snapshot existed, so one was written", error.Message, StringComparison.Ordinal); Assert.Equal(_dir.File(ToolSnapshot.DefaultFileName), error.SnapshotPath); Assert.Equal(Baseline.ToJson(), File.ReadAllText(_dir.File(ToolSnapshot.DefaultFileName))); // Second run passes. - Assert.False(ToolSnapshot.Verify(Baseline, ToolSnapshot.DefaultFileName, Local()).HasChanges); + Assert.False(ToolSnapshot.Verify(Baseline, options: Local()).HasChanges); } [Fact] public void MissingSnapshot_OnCi_FailsWithoutWritingIt() { - var error = Assert.Throws(() => ToolSnapshot.Verify(Baseline, ToolSnapshot.DefaultFileName, Local(o => o.CreateMissing = false))); + var error = Assert.Throws(() => ToolSnapshot.Verify(Baseline, options: Local(o => o.CreateMissing = false))); Assert.Contains("Tool snapshot not found", error.Message, StringComparison.Ordinal); Assert.False(File.Exists(_dir.File("mcp-tools.json"))); @@ -55,7 +56,7 @@ public void MatchingSnapshot_PassesAndCleansUpReceivedFile() WriteBaseline(); File.WriteAllText(_dir.File("mcp-tools.received.json"), "stale"); - var diff = ToolSnapshot.Verify(Baseline, ToolSnapshot.DefaultFileName, Local()); + var diff = ToolSnapshot.Verify(Baseline, options: Local()); Assert.False(diff.HasChanges); Assert.False(File.Exists(_dir.File("mcp-tools.received.json"))); @@ -67,7 +68,7 @@ public void BreakingChange_FailsWithDiffAndWritesReceivedFile() WriteBaseline(); var current = Surface(Tool("get_forecast", """{"type":"object","properties":{"location":{"type":"string"}},"required":["location"]}""")); - var error = Assert.Throws(() => ToolSnapshot.Verify(current, ToolSnapshot.DefaultFileName, Local())); + var error = Assert.Throws(() => ToolSnapshot.Verify(current, options: Local())); Assert.Contains("has breaking changes", error.Message, StringComparison.Ordinal); Assert.Contains("- get_alerts: Tool was removed.", error.Message, StringComparison.Ordinal); @@ -85,7 +86,7 @@ public void NonBreakingChange_PassesAndIsLogged() var current = Surface(Tool("get_forecast", CityRequired), Tool("get_alerts"), Tool("get_radar")); var logs = new List(); - var diff = ToolSnapshot.Verify(current, ToolSnapshot.DefaultFileName, Local(o => o.Log = logs.Add)); + var diff = ToolSnapshot.Verify(current, options: Local(o => o.Log = logs.Add)); Assert.True(diff.HasChanges); Assert.False(diff.HasBreakingChanges); @@ -100,7 +101,7 @@ public void NonBreakingChange_FailsWhenConfigured() WriteBaseline(); var current = Surface(Tool("get_forecast", CityRequired), Tool("get_alerts"), Tool("get_radar")); - var error = Assert.Throws(() => ToolSnapshot.Verify(current, ToolSnapshot.DefaultFileName, Local(o => o.FailOnNonBreakingChanges = true))); + var error = Assert.Throws(() => ToolSnapshot.Verify(current, options: Local(o => o.FailOnNonBreakingChanges = true))); Assert.Contains("The tool surface changed", error.Message, StringComparison.Ordinal); } @@ -111,17 +112,17 @@ public void UpdateMode_RewritesTheSnapshotAndPasses() WriteBaseline(); var current = Surface(Tool("only_tool")); - var diff = ToolSnapshot.Verify(current, ToolSnapshot.DefaultFileName, Local(o => o.Update = true)); + var diff = ToolSnapshot.Verify(current, options: Local(o => o.Update = true)); Assert.True(diff.HasBreakingChanges); Assert.Equal(current.ToJson(), File.ReadAllText(_dir.File("mcp-tools.json"))); - Assert.False(ToolSnapshot.Verify(current, ToolSnapshot.DefaultFileName, Local()).HasChanges); + Assert.False(ToolSnapshot.Verify(current, options: Local()).HasChanges); } [Fact] public void UpdateMode_CreatesMissingSnapshotWithoutFailing() { - var diff = ToolSnapshot.Verify(Baseline, ToolSnapshot.DefaultFileName, Local(o => { o.Update = true; o.CreateMissing = false; })); + var diff = ToolSnapshot.Verify(Baseline, options: Local(o => { o.Update = true; o.CreateMissing = false; })); Assert.False(diff.HasChanges); Assert.True(File.Exists(_dir.File("mcp-tools.json"))); @@ -132,10 +133,10 @@ public void CorruptSnapshot_FailsClearly_AndUpdateRepairsIt() { File.WriteAllText(_dir.File("mcp-tools.json"), "{ not json"); - var error = Assert.Throws(() => ToolSnapshot.Verify(Baseline, ToolSnapshot.DefaultFileName, Local())); + var error = Assert.Throws(() => ToolSnapshot.Verify(Baseline, options: Local())); Assert.Contains("could not be read", error.Message, StringComparison.Ordinal); - ToolSnapshot.Verify(Baseline, ToolSnapshot.DefaultFileName, Local(o => o.Update = true)); + ToolSnapshot.Verify(Baseline, options: Local(o => o.Update = true)); Assert.Equal(Baseline.ToJson(), File.ReadAllText(_dir.File("mcp-tools.json"))); } @@ -144,7 +145,7 @@ public void ReformattedButEquivalentSnapshot_Passes() { File.WriteAllText(_dir.File("mcp-tools.json"), Baseline.ToJson().Replace("\n", "\r\n", StringComparison.Ordinal).Replace(" ", " ", StringComparison.Ordinal)); - Assert.False(ToolSnapshot.Verify(Baseline, ToolSnapshot.DefaultFileName, Local()).HasChanges); + Assert.False(ToolSnapshot.Verify(Baseline, options: Local()).HasChanges); } [Fact] @@ -195,8 +196,8 @@ public async Task EndToEnd_WithInMemoryHost() { await using var probe = await McpProbeHost.StartAsync(mcp => mcp.WithWeatherFeatures(), TestContext.Current.CancellationToken); - await Assert.ThrowsAsync(() => probe.VerifyToolSnapshotAsync(ToolSnapshot.DefaultFileName, Local(), TestContext.Current.CancellationToken)); - var diff = await probe.VerifyToolSnapshotAsync(ToolSnapshot.DefaultFileName, Local(), TestContext.Current.CancellationToken); + await Assert.ThrowsAsync(() => probe.VerifyToolSnapshotAsync(options: Local(), cancellationToken: TestContext.Current.CancellationToken)); + var diff = await probe.VerifyToolSnapshotAsync(options: Local(), cancellationToken: TestContext.Current.CancellationToken); Assert.False(diff.HasChanges); Assert.Contains("\"get_forecast\"", File.ReadAllText(_dir.File("mcp-tools.json")), StringComparison.Ordinal); @@ -271,7 +272,7 @@ public async Task OptionsFirst_VerifyAsync_UsesDefaultFileNameAndHonorsOptions() public void OptionsFirst_Verify_NullOptions_Throws() { var ex = Assert.Throws(() => ToolSnapshot.Verify(Baseline, (SnapshotOptions)null!)); - Assert.Equal("options", ex.ParamName); + Assert.Equal("snapshotOptions", ex.ParamName); } [Fact] @@ -281,7 +282,7 @@ public async Task OptionsFirst_VerifyAsync_NullOptions_Throws() var ex = await Assert.ThrowsAsync(() => ToolSnapshot.VerifyAsync(probe.Client, (SnapshotOptions)null!, TestContext.Current.CancellationToken)); - Assert.Equal("options", ex.ParamName); + Assert.Equal("snapshotOptions", ex.ParamName); } [Fact] @@ -291,7 +292,128 @@ public async Task OptionsFirst_HostVerify_NullOptions_Throws() var ex = await Assert.ThrowsAsync(() => probe.VerifyToolSnapshotAsync((SnapshotOptions)null!, TestContext.Current.CancellationToken)); - Assert.Equal("options", ex.ParamName); + Assert.Equal("snapshotOptions", ex.ParamName); + } + + [Fact] + public void NamedOptions_Verify_UsesDefaultFileNameAndHonorsOptions() + { + var error = Assert.Throws(() => ToolSnapshot.Verify(Baseline, options: Local())); + + Assert.Equal(_dir.File(ToolSnapshot.DefaultFileName), error.SnapshotPath); + Assert.Equal(Baseline.ToJson(), File.ReadAllText(_dir.File(ToolSnapshot.DefaultFileName))); + } + + [Fact] + public async Task NamedOptions_VerifyAsync_UsesDefaultFileNameAndHonorsOptions() + { + await using var probe = await McpProbeHost.StartAsync(mcp => mcp.WithWeatherFeatures(), TestContext.Current.CancellationToken); + + var error = await Assert.ThrowsAsync(() => + ToolSnapshot.VerifyAsync(probe.Client, options: Local(), cancellationToken: TestContext.Current.CancellationToken)); + + Assert.Equal(_dir.File(ToolSnapshot.DefaultFileName), error.SnapshotPath); + Assert.True(File.Exists(_dir.File(ToolSnapshot.DefaultFileName))); + } + + [Fact] + public async Task NamedOptions_HostVerify_UsesDefaultFileNameAndHonorsOptions() + { + await using var probe = await McpProbeHost.StartAsync(mcp => mcp.WithWeatherFeatures(), TestContext.Current.CancellationToken); + + var error = await Assert.ThrowsAsync(() => + probe.VerifyToolSnapshotAsync(options: Local(), cancellationToken: TestContext.Current.CancellationToken)); + + Assert.Equal(_dir.File(ToolSnapshot.DefaultFileName), error.SnapshotPath); + Assert.True(File.Exists(_dir.File(ToolSnapshot.DefaultFileName))); + Assert.Contains("\"get_forecast\"", File.ReadAllText(_dir.File(ToolSnapshot.DefaultFileName)), StringComparison.Ordinal); + } + + [Fact] + public async Task NamedOptions_HostVerify_ResolvesPathFromTestFile() + { + var expected = ToolSnapshot.ResolvePath(ToolSnapshot.DefaultFileName, options: null, callerFilePath: ThisFile()); + var received = ToolSnapshot.GetReceivedPath(expected); + try + { + await using var probe = await McpProbeHost.StartAsync(mcp => mcp.WithWeatherFeatures(), TestContext.Current.CancellationToken); + var options = new SnapshotOptions { Update = false, CreateMissing = false }; + + var error = await Assert.ThrowsAsync(() => + probe.VerifyToolSnapshotAsync(options: options, cancellationToken: TestContext.Current.CancellationToken)); + + Assert.Equal(expected, error.SnapshotPath); + Assert.DoesNotContain("McpProbeHost.cs", error.SnapshotPath, StringComparison.Ordinal); + Assert.Contains(Path.Combine("tests", "McpProbe.Tests"), error.SnapshotPath, StringComparison.Ordinal); + } + finally + { + if (File.Exists(expected)) + { + File.Delete(expected); + } + + if (File.Exists(received)) + { + File.Delete(received); + } + } + } + + [Fact] + public void OverloadResolution_CallShapes_Compile() + { + // The body of CompileOverloadResolutionMatrix is the compile matrix: if any shape is + // CS0121 or binds to the wrong parameter type, this test project does not build. + Assert.NotNull((Action)CompileOverloadResolutionMatrix); + } + + private static void CompileOverloadResolutionMatrix( + McpProbeHost probe, + McpClient client, + ToolSurface surface, + SnapshotOptions snapshotOptions, + CancellationToken cancellationToken) + { + // Named options: only, the 0.2/0.3 workaround. Must bind to the path-first overloads. + _ = probe.VerifyToolSnapshotAsync(options: snapshotOptions); + _ = probe.VerifyToolSnapshotAsync(options: snapshotOptions, cancellationToken: cancellationToken); + _ = ToolSnapshot.Verify(surface, options: snapshotOptions); + _ = ToolSnapshot.VerifyAsync(client, options: snapshotOptions); + _ = ToolSnapshot.VerifyAsync(client, options: snapshotOptions, cancellationToken: cancellationToken); + + // Positional options. Must bind to the options-first overloads. + _ = probe.VerifyToolSnapshotAsync(snapshotOptions); + _ = probe.VerifyToolSnapshotAsync(snapshotOptions, cancellationToken); + _ = ToolSnapshot.Verify(surface, snapshotOptions); + _ = ToolSnapshot.VerifyAsync(client, snapshotOptions); + _ = ToolSnapshot.VerifyAsync(client, snapshotOptions, cancellationToken); + + // Path only. + _ = probe.VerifyToolSnapshotAsync("custom.json"); + _ = ToolSnapshot.Verify(surface, "custom.json"); + _ = ToolSnapshot.VerifyAsync(client, "custom.json"); + + // No-arg (default path, default options). + _ = probe.VerifyToolSnapshotAsync(); + _ = ToolSnapshot.Verify(surface); + _ = ToolSnapshot.VerifyAsync(client); + + // cancellationToken: only, as used by samples/WeatherServer.Tests. + _ = probe.VerifyToolSnapshotAsync(cancellationToken: cancellationToken); + _ = ToolSnapshot.VerifyAsync(client, cancellationToken: cancellationToken); + + // Path plus options, positional and named. + _ = probe.VerifyToolSnapshotAsync("custom.json", snapshotOptions); + _ = ToolSnapshot.Verify(surface, "custom.json", snapshotOptions); + _ = ToolSnapshot.VerifyAsync(client, "custom.json", snapshotOptions); + _ = probe.VerifyToolSnapshotAsync("custom.json", options: snapshotOptions); + _ = ToolSnapshot.Verify(surface, snapshotPath: "custom.json", options: snapshotOptions); + + // Explicit name of the new parameter. + _ = probe.VerifyToolSnapshotAsync(snapshotOptions: snapshotOptions); + _ = ToolSnapshot.Verify(surface, snapshotOptions: snapshotOptions); + _ = ToolSnapshot.VerifyAsync(client, snapshotOptions: snapshotOptions); } private static string ThisFile([CallerFilePath] string path = "") => path;