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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <file>` and `mcpprobe diff --report <file>` 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. The new overloads name their options parameter `snapshotOptions`, so a call that names only `options:` still binds to the path-first 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

Expand Down
44 changes: 35 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,34 @@ dotnet add package McpProbe --prerelease
using McpProbe;
using McpProbe.Assertions;
using Microsoft.Extensions.DependencyInjection; // WithTools<T>()
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<WeatherTools>());
[Fact]
public async Task Forecast_works()
{
await using var probe = await McpProbeHost.StartAsync(mcp => mcp.WithTools<WeatherTools>());

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<string, object?> { ["city"] = "Paris" });
McpAssert.That(result).Succeeded().HasStructuredValue("city", "Paris");
var result = await probe.Client.CallToolAsync("get_forecast", new Dictionary<string, object?> { ["city"] = "Paris" });
McpAssert.That(result).Succeeded().HasStructuredValue("city", "Paris");
}
}
```

Expand All @@ -61,18 +78,23 @@ 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.
- **Non-breaking changes pass**: added tools, optional parameters, descriptions, annotations, widened types, looser input constraints. They are in the returned `ToolSurfaceDiff`, and `SnapshotOptions.Log` gets a report (for example `Log = output.WriteLine` with xUnit's `ITestOutputHelper`).
- 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.

Expand All @@ -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

Expand Down Expand Up @@ -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 <snapshot>` to check a file without starting a server. Run `mcpprobe <command> --help` for every option.
Expand Down
18 changes: 18 additions & 0 deletions src/McpProbe/McpProbeHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,24 @@ public Task<ToolSurfaceDiff> VerifyToolSnapshotAsync(
[CallerFilePath] string callerFilePath = "") =>
ToolSnapshot.VerifyAsync(Client, snapshotPath, options, cancellationToken, callerFilePath);

/// <summary>
/// Checks the server's tool surface against a snapshot file, using the default file name.
/// See <see cref="ToolSnapshot"/> for the workflow.
/// </summary>
/// <param name="snapshotOptions">Snapshot options.</param>
/// <param name="cancellationToken">Cancels the request.</param>
/// <param name="callerFilePath">Filled in by the compiler.</param>
/// <returns>The diff between the snapshot and the current surface.</returns>
/// <exception cref="McpProbeSnapshotException">The check failed.</exception>
public Task<ToolSurfaceDiff> VerifyToolSnapshotAsync(
SnapshotOptions snapshotOptions,
CancellationToken cancellationToken = default,
[CallerFilePath] string callerFilePath = "")
{
ArgumentNullException.ThrowIfNull(snapshotOptions);
return VerifyToolSnapshotAsync(ToolSnapshot.DefaultFileName, snapshotOptions, cancellationToken, callerFilePath);
}

/// <summary>
/// Lists the server's tools and lints them.
/// </summary>
Expand Down
3 changes: 3 additions & 0 deletions src/McpProbe/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.Linting.LintReport!>!
McpProbe.McpProbeHost.Server.get -> ModelContextProtocol.Server.McpServer!
McpProbe.McpProbeHost.Services.get -> System.IServiceProvider!
McpProbe.McpProbeHost.VerifyToolSnapshotAsync(McpProbe.Snapshots.SnapshotOptions! snapshotOptions, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken), string! callerFilePath = "") -> System.Threading.Tasks.Task<McpProbe.Snapshots.ToolSurfaceDiff!>!
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.Snapshots.ToolSurfaceDiff!>!
McpProbe.McpProbeHostOptions
McpProbe.McpProbeHostOptions.ClientOptions.get -> ModelContextProtocol.Client.McpClientOptions?
Expand Down Expand Up @@ -251,7 +252,9 @@ static McpProbe.McpProbeHost.StartAsync(System.Action<Microsoft.Extensions.Depen
static McpProbe.Snapshots.ToolContractAnnotations.operator !=(McpProbe.Snapshots.ToolContractAnnotations? left, McpProbe.Snapshots.ToolContractAnnotations? right) -> 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! 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! snapshotOptions, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken), string! callerFilePath = "") -> System.Threading.Tasks.Task<McpProbe.Snapshots.ToolSurfaceDiff!>!
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<McpProbe.Snapshots.ToolSurfaceDiff!>!
static McpProbe.Snapshots.ToolSurface.CaptureAsync(ModelContextProtocol.Client.McpClient! client, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task<McpProbe.Snapshots.ToolSurface!>!
static McpProbe.Snapshots.ToolSurface.FromClientTools(System.Collections.Generic.IEnumerable<ModelContextProtocol.Client.McpClientTool!>! tools) -> McpProbe.Snapshots.ToolSurface!
Expand Down
32 changes: 32 additions & 0 deletions src/McpProbe/Snapshots/ToolSnapshot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,23 @@ public static async Task<ToolSurfaceDiff> VerifyAsync(
return VerifyResolved(surface, ResolvePath(snapshotPath, options, callerFilePath), options ?? new SnapshotOptions());
}

/// <summary>Captures the client's tool surface and checks it against the default snapshot file.</summary>
/// <param name="client">A connected client.</param>
/// <param name="snapshotOptions">Snapshot options.</param>
/// <param name="cancellationToken">Cancels the request.</param>
/// <param name="callerFilePath">Filled in by the compiler.</param>
/// <returns>The diff between the snapshot and the current surface.</returns>
/// <exception cref="McpProbeSnapshotException">The check failed.</exception>
public static Task<ToolSurfaceDiff> VerifyAsync(
McpClient client,
SnapshotOptions snapshotOptions,
CancellationToken cancellationToken = default,
[CallerFilePath] string callerFilePath = "")
{
ArgumentNullException.ThrowIfNull(snapshotOptions);
return VerifyAsync(client, DefaultFileName, snapshotOptions, cancellationToken, callerFilePath);
}

/// <summary>Checks a captured surface against a snapshot file.</summary>
/// <param name="current">The current surface.</param>
/// <param name="snapshotPath">The snapshot path. Relative paths resolve against <see cref="SnapshotOptions.Directory"/> or the calling source file's directory.</param>
Expand All @@ -56,6 +73,21 @@ public static ToolSurfaceDiff Verify(
return VerifyResolved(current, ResolvePath(snapshotPath, options, callerFilePath), options ?? new SnapshotOptions());
}

/// <summary>Checks a captured surface against the default snapshot file.</summary>
/// <param name="current">The current surface.</param>
/// <param name="snapshotOptions">Snapshot options.</param>
/// <param name="callerFilePath">Filled in by the compiler.</param>
/// <returns>The diff between the snapshot and the current surface.</returns>
/// <exception cref="McpProbeSnapshotException">The check failed.</exception>
public static ToolSurfaceDiff Verify(
ToolSurface current,
SnapshotOptions snapshotOptions,
[CallerFilePath] string callerFilePath = "")
{
ArgumentNullException.ThrowIfNull(snapshotOptions);
return Verify(current, DefaultFileName, snapshotOptions, callerFilePath);
}

/// <summary>Gets the path of the file written next to a snapshot when the check fails.</summary>
/// <param name="snapshotPath">The snapshot path.</param>
/// <returns>The <c>.received.json</c> path.</returns>
Expand Down
Loading
Loading