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 @@ -5,6 +5,11 @@ All notable changes to this project are documented here. The format is based on

## [Unreleased]

### Added

- `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).

## [0.3.0-preview] - 2026-11-28

### Added
Expand Down
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,27 @@ mcpprobe lint --http http://localhost:5000/sse --transport sse --header "Aut

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.

### HTML report

`lint` and `diff` take `--report <file>` to also write a self-contained HTML page (inline CSS, no scripts): a banner, a one-line summary and, when there are findings or changes, a table. It is not in 0.3.0-preview; it comes with the next release. The text report on stdout and the exit code do not change, the file is written whether the check passed or failed (exit `0` or `1`), and nothing is written on a usage or connection error (exit `2`). In code, use `LintReport.ToHtml()` and `ToolSurfaceDiff.ToHtml()`.

```bash
mcpprobe lint --stdio "dotnet run --project src/MyServer" --report mcp-lint.html
mcpprobe diff --stdio "dotnet run --project src/MyServer" --baseline mcp-tools.json --report mcp-diff.html
```

To keep the files from a CI run, upload them as an artifact. `if: always()` keeps the upload when the check fails:

```yaml
- uses: actions/upload-artifact@v4
if: always()
with:
name: mcpprobe-reports
path: |
mcp-lint.html
mcp-diff.html
```

### GitHub Actions

The `McpProbe tool surface check` Action installs the same `McpProbe.Cli` version as the tag you pin, then runs `diff` and `lint`. It needs `actions/setup-dotnet` (a .NET 8 or .NET 10 SDK) and your server already built. Reports go to the job summary. Pin an exact release tag that includes the Action (0.3.0-preview or later):
Expand Down
50 changes: 47 additions & 3 deletions src/McpProbe.Cli/CliApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,34 @@ private static Command BuildSnapshotCommand(TextWriter stdout, TextWriter stderr
return command;
}

private static Option<string?> BuildReportOption() => new("--report")
{
Description = "Also write a self-contained HTML report to this file. stdout and the exit code are unchanged.",
};

/// <summary>A blank <c>--report</c> is a usage error; checked before connecting so nothing is written.</summary>
private static string? ReportPath(ParseResult parse, Option<string?> report)
{
var value = parse.GetValue(report);
return value is null ? null : string.IsNullOrWhiteSpace(value) ? throw new ArgumentException("--report needs a file path.") : Path.GetFullPath(value);
}

/// <summary>Writes through a sibling temp file so a failure never leaves a partial report.</summary>
private static async Task WriteReportAsync(string path, string html, CancellationToken ct)
{
Directory.CreateDirectory(Path.GetDirectoryName(path)!);
var temp = $"{path}.{Guid.NewGuid():N}.tmp";
try
{
await File.WriteAllTextAsync(temp, html, ct).ConfigureAwait(false);
File.Move(temp, path, overwrite: true);
}
finally
{
File.Delete(temp);
}
}

private static Command BuildDiffCommand(TextWriter stdout, TextWriter stderr)
{
var server = new ServerOptions(allowFile: true);
Expand All @@ -83,12 +111,16 @@ private static Command BuildDiffCommand(TextWriter stdout, TextWriter stderr)
Description = "Also fail (exit 1) on non-breaking changes, so the snapshot is always kept up to date.",
};

var report = BuildReportOption();

var command = new Command("diff", "Compare a server's tool surface with a snapshot. Exits 1 on breaking changes.");
server.AddTo(command);
command.Options.Add(baseline);
command.Options.Add(failOnNonBreaking);
command.Options.Add(report);
command.SetAction((parse, ct) => RunGuardedAsync(stderr, async () =>
{
var reportPath = ReportPath(parse, report);
var baselinePath = Path.GetFullPath(parse.GetValue(baseline)!);
if (!File.Exists(baselinePath))
{
Expand All @@ -100,6 +132,10 @@ private static Command BuildDiffCommand(TextWriter stdout, TextWriter stderr)
var current = await server.CaptureAsync(parse, stderr, ct).ConfigureAwait(false);
var diff = ToolSurfaceComparer.Compare(expected, current);
await stdout.WriteLineAsync(diff.ToReport()).ConfigureAwait(false);
if (reportPath is not null)
{
await WriteReportAsync(reportPath, diff.ToHtml(), ct).ConfigureAwait(false);
}

if (diff.HasBreakingChanges || (diff.HasChanges && parse.GetValue(failOnNonBreaking)))
{
Expand Down Expand Up @@ -140,15 +176,18 @@ private static Command BuildLintCommand(TextWriter stdout, TextWriter stderr)
{
Description = "Also run schema-portability rules MCPP009-MCPP012. Those findings fail the command only when their severity is error.",
};
var report = BuildReportOption();
var command = new Command("lint", "Lint tool names, descriptions and parameters. Exits 1 on findings at or above --fail-on, or on a portability error when --strict is set.");
server.AddTo(command);
command.Options.Add(failOn);
command.Options.Add(minLength);
command.Options.Add(rules);
command.Options.Add(nested);
command.Options.Add(strict);
command.Options.Add(report);
command.SetAction((parse, ct) => RunGuardedAsync(stderr, async () =>
{
var reportPath = ReportPath(parse, report);
var options = new LintOptions
{
FailOn = ParseSeverity(parse.GetValue(failOn)!),
Expand All @@ -170,9 +209,14 @@ private static Command BuildLintCommand(TextWriter stdout, TextWriter stderr)
}

var surface = await server.CaptureAsync(parse, stderr, ct).ConfigureAwait(false);
var report = ToolLinter.Lint(surface, options);
await stdout.WriteLineAsync(report.ToReport()).ConfigureAwait(false);
return report.Failed ? ExitCodes.CheckFailed : ExitCodes.Success;
var lint = ToolLinter.Lint(surface, options);
await stdout.WriteLineAsync(lint.ToReport()).ConfigureAwait(false);
if (reportPath is not null)
{
await WriteReportAsync(reportPath, lint.ToHtml(), ct).ConfigureAwait(false);
}

return lint.Failed ? ExitCodes.CheckFailed : ExitCodes.Success;
}));
return command;
}
Expand Down
68 changes: 68 additions & 0 deletions src/McpProbe/Internal/HtmlReport.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
using System.Net;
using System.Text;

namespace McpProbe.Internal;

/// <summary>
/// Builds the self-contained HTML for lint and diff reports. Callers pass cells already run through
/// <see cref="Printable"/>; every cell, title and summary is HTML-encoded here, and only as element text.
/// </summary>
internal static class HtmlReport
{
private const string Css =
"body{font-family:system-ui,sans-serif;margin:2rem;background:#fff;color:#1f2328}" +
".banner{display:inline-block;padding:.25rem .75rem;border-radius:.25rem;font-weight:600;color:#fff}" +
".pass{background:#1a7f37}.fail{background:#cf222e}.note{background:#9a6700}" +
"table{border-collapse:collapse;margin-top:1rem}th,td{border:1px solid #d0d7de;padding:.35rem .6rem;text-align:left;vertical-align:top}" +
"th{background:#f6f8fa}td{overflow-wrap:anywhere}th:nth-child(1),th:nth-child(2),th:nth-child(6),td:nth-child(1),td:nth-child(2),td:nth-child(6){white-space:nowrap}.error td:first-child,.breaking td:first-child{color:#cf222e;font-weight:600}" +
".warning td:first-child,.non-breaking td:first-child{color:#9a6700;font-weight:600}";

/// <param name="title">The page title and heading.</param>
/// <param name="bannerClass">One of <c>pass</c>, <c>fail</c> or <c>note</c>; fixed values, never server text.</param>
/// <param name="banner">The banner text.</param>
/// <param name="summary">The one-line summary.</param>
/// <param name="headers">The table headers.</param>
/// <param name="rows">The rows: a fixed CSS class (never server text) and the cells.</param>
public static string Page(string title, string bannerClass, string banner, string summary, string[] headers, IEnumerable<(string RowClass, string[] Cells)> rows)
{
var sb = new StringBuilder("<!DOCTYPE html>\n<html lang=\"en\"><head><meta charset=\"utf-8\">");
sb.Append("<meta name=\"viewport\" content=\"width=device-width,initial-scale=1\">");
sb.Append("<title>").Append(Encode(title)).Append("</title><style>").Append(Css).Append("</style></head><body>\n");
sb.Append("<h1>").Append(Encode(title)).Append("</h1>\n");
sb.Append("<p><span class=\"banner ").Append(bannerClass).Append("\">").Append(Encode(banner)).Append("</span></p>\n");
sb.Append("<p>").Append(Encode(summary)).Append("</p>\n");

var any = false;
foreach (var (rowClass, cells) in rows)
{
if (!any)
{
any = true;
sb.Append("<table><thead><tr>");
foreach (var header in headers)
{
sb.Append("<th>").Append(Encode(header)).Append("</th>");
}

sb.Append("</tr></thead><tbody>\n");
}

sb.Append("<tr class=\"").Append(rowClass).Append("\">");
foreach (var cell in cells)
{
sb.Append("<td>").Append(Encode(cell)).Append("</td>");
}

sb.Append("</tr>\n");
}

if (any)
{
sb.Append("</tbody></table>\n");
}

return sb.Append("</body></html>\n").ToString();
}

private static string Encode(string value) => WebUtility.HtmlEncode(value);
}
32 changes: 30 additions & 2 deletions src/McpProbe/Linting/LintReport.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Globalization;
using System.Text;
using McpProbe.Internal;

namespace McpProbe.Linting;

Expand Down Expand Up @@ -45,8 +46,7 @@ public string ToReport()
}

var sb = new StringBuilder();
sb.Append(CultureInfo.InvariantCulture,
$"{Findings.Count} lint finding(s): {Count(LintSeverity.Error)} error, {Count(LintSeverity.Warning)} warning, {Count(LintSeverity.Info)} info.");
sb.Append(Summary());
foreach (var finding in Findings)
{
sb.Append('\n').Append(" ").Append(finding);
Expand All @@ -55,6 +55,31 @@ public string ToReport()
return sb.ToString();
}

/// <summary>
/// Formats the findings as a complete, self-contained HTML document: inline CSS, no scripts and no external assets.
/// Server-supplied text is already sanitized and HTML-encoded, so the result is safe to write to a file.
/// </summary>
/// <returns>The HTML document.</returns>
public string ToHtml()
{
var rows = Findings.Select(f => (RowClass: LintFinding.SeverityLabel(f.Severity), Cells: new[]
{
LintFinding.SeverityLabel(f.Severity),
f.RuleId,
Printable.Text(f.ToolName, 100),
f.ParameterName is null ? string.Empty : Printable.Text(f.ParameterName, 100),
Printable.Text(f.Message, 500),
Fails(f) ? "yes" : "no",
}));
return HtmlReport.Page(
"McpProbe lint report",
Failed ? "fail" : "pass",
Failed ? "Failed" : "Passed",
Findings.Count == 0 ? "No lint findings." : $"{Summary()} Fails on: {LintFinding.SeverityLabel(FailOn)}.",
["Severity", "Rule", "Tool", "Path", "Message", "Fails the run"],
rows);
}

/// <summary>Throws when <see cref="Failed"/> is <see langword="true"/>.</summary>
/// <exception cref="McpProbeAssertionException">A finding failed the run (see <see cref="Failed"/>).</exception>
public void ThrowIfFailed()
Expand All @@ -69,5 +94,8 @@ public void ThrowIfFailed()
/// <inheritdoc />
public override string ToString() => ToReport();

private string Summary() => string.Create(CultureInfo.InvariantCulture,
$"{Findings.Count} lint finding(s): {Count(LintSeverity.Error)} error, {Count(LintSeverity.Warning)} warning, {Count(LintSeverity.Info)} info.");

private int Count(LintSeverity severity) => Findings.Count(f => f.Severity == severity);
}
2 changes: 2 additions & 0 deletions src/McpProbe/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ McpProbe.Linting.LintReport.FailOn.get -> McpProbe.Linting.LintSeverity
McpProbe.Linting.LintReport.Failed.get -> bool
McpProbe.Linting.LintReport.Findings.get -> System.Collections.Generic.IReadOnlyList<McpProbe.Linting.LintFinding!>!
McpProbe.Linting.LintReport.ThrowIfFailed() -> void
McpProbe.Linting.LintReport.ToHtml() -> string!
McpProbe.Linting.LintReport.ToReport() -> string!
McpProbe.Linting.LintRule
McpProbe.Linting.LintRule.<Clone>$() -> McpProbe.Linting.LintRule!
Expand Down Expand Up @@ -207,6 +208,7 @@ McpProbe.Snapshots.ToolSurfaceDiff.Changes.get -> System.Collections.Generic.IRe
McpProbe.Snapshots.ToolSurfaceDiff.HasBreakingChanges.get -> bool
McpProbe.Snapshots.ToolSurfaceDiff.HasChanges.get -> bool
McpProbe.Snapshots.ToolSurfaceDiff.NonBreakingChanges.get -> System.Collections.Generic.IEnumerable<McpProbe.Snapshots.ToolSurfaceChange!>!
McpProbe.Snapshots.ToolSurfaceDiff.ToHtml() -> string!
McpProbe.Snapshots.ToolSurfaceDiff.ToReport() -> string!
const McpProbe.Snapshots.SnapshotOptions.UpdateEnvironmentVariable = "MCPPROBE_UPDATE_SNAPSHOTS" -> string!
const McpProbe.Snapshots.ToolSnapshot.DefaultFileName = "mcp-tools.json" -> string!
Expand Down
30 changes: 29 additions & 1 deletion src/McpProbe/Snapshots/ToolSurfaceDiff.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Globalization;
using System.Text;
using McpProbe.Internal;

namespace McpProbe.Snapshots;

Expand Down Expand Up @@ -35,7 +36,7 @@ public string ToReport()
var breaking = BreakingChanges.ToList();
var nonBreaking = NonBreakingChanges.ToList();
var sb = new StringBuilder();
sb.Append(CultureInfo.InvariantCulture, $"Tool surface changed: {breaking.Count} breaking, {nonBreaking.Count} non-breaking.").Append('\n');
sb.Append(Summary(breaking.Count, nonBreaking.Count)).Append('\n');

if (breaking.Count > 0)
{
Expand All @@ -58,6 +59,33 @@ public string ToReport()
return sb.ToString().TrimEnd('\n');
}

/// <summary>
/// Formats the changes as a complete, self-contained HTML document: inline CSS, no scripts and no external assets.
/// Server-supplied text is already sanitized and HTML-encoded, so the result is safe to write to a file.
/// </summary>
/// <returns>The HTML document.</returns>
public string ToHtml()
{
var rows = Changes.Select(c => (RowClass: c.IsBreaking ? "breaking" : "non-breaking", Cells: new[]
{
c.IsBreaking ? "breaking" : "non-breaking",
c.Kind.ToString(),
Printable.Text(c.ToolName, 100),
c.Path is null ? string.Empty : Printable.Text(c.Path, 200),
Printable.Text(c.Message, 500),
}));
return HtmlReport.Page(
"McpProbe diff report",
HasBreakingChanges ? "fail" : HasChanges ? "note" : "pass",
HasBreakingChanges ? "Breaking changes" : HasChanges ? "Non-breaking changes only" : "Unchanged",
HasChanges ? Summary(BreakingChanges.Count(), NonBreakingChanges.Count()) : "Tool surface unchanged.",
["Impact", "Kind", "Tool", "Path", "Message"],
rows);
}

private static string Summary(int breaking, int nonBreaking) => string.Create(CultureInfo.InvariantCulture,
$"Tool surface changed: {breaking} breaking, {nonBreaking} non-breaking.");

/// <inheritdoc />
public override string ToString() => ToReport();
}
Loading
Loading