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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ All notable changes to this project are documented here. The format is based on

### Added

- `--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.
- `--bearer-env <VAR>` and `--header-env 'Name: VAR'` on the CLI: HTTP authentication read from environment variables, so tokens are not on the command line. Later sources win for the same header name (`--header`, then `--header-env`, then `--bearer-env`). A missing or empty variable is exit 2 and names the variable, not the value. GitHub Action inputs `bearer-env` and `header-env`, and Azure Pipelines parameters `bearerEnv` and `headerEnv`, pass the variable names through. They need a CLI that has these flags.
- `McpProbeHostOptions.IncludeServerExceptions` (default `true`): in the in-memory host, when a tool throws an exception that is not an `McpException`, the tool error result shows the exception type and message (for example `An error occurred invoking 'update_todo_item': FormatException: ...`) instead of the SDK's generic message, `An error occurred invoking 'update_todo_item'.` Prompts and resources that throw are reported the same way. Set it to `false` for the generic text a remote client would see.
- `ToolSurfaceChange.Before` and `After` hold the previous and current title or description when that is what changed. Other change kinds leave them unset.
Expand Down
1 change: 1 addition & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@
<PackageVersion Include="System.CommandLine" Version="3.0.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.PublicApiAnalyzers" Version="5.6.0" />
<PackageVersion Include="xunit.v3" Version="4.0.3" />
<PackageVersion Include="JsonSchema.Net" Version="9.4.0" />
</ItemGroup>
</Project>
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,37 @@ The `mcpprobe` tool is packed for net8.0 and net10.0 (`RollForward=Major`), so a

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. To compare two snapshots, use `mcpprobe diff --baseline old.json --from-file new.json`. Run `mcpprobe <command> --help` for every option.

### JSON and SARIF output

`lint` and `diff` take `--format text|json|sarif` to choose what goes to stdout. The default is `text`, so nothing changes unless you pass the flag. `--format json` writes the [McpProbe report format](docs/mcpprobe-report.schema.json) (format 1): a summary with counts, then the findings or changes. For title and description changes, a diff change also has `before` and `after`. `--format sarif` writes a [SARIF 2.1.0](https://docs.oasis-open.org/sarif/sarif/v2.1.0/sarif-v2.1.0.html) log.

`--sarif <file>` is the SARIF version of `--report`: it writes the SARIF file and leaves stdout and the exit code alone. You can combine it with `--format` and `--report`. Like `--report`, nothing is written on a usage or connection error (exit `2`).

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

With `--format json` or `--format sarif`, stdout holds exactly one document. The `diff` hint ("If the change is intended, ...") and the lint `--write-baseline` line ("Wrote N finding(s) to ...") go to stderr instead. Exit codes don't change. The JSON `result` is `fail` when the command exits `1` and `pass` when it exits `0`, so `--fail-on-non-breaking` and `--write-baseline` are reflected there.

SARIF levels: lint errors are `error`, warnings are `warning`, info is `note`. Diff breaking changes are `error`, non-breaking changes are `note`. Lint rules keep their `MCPP0xx` ids; diff change kinds use kebab-case ids such as `tool-removed` or `description-changed`. Every result has a `partialFingerprints.primaryLocationLineHash` computed from the rule id, tool and path, so GitHub code scanning recognizes the same alert from run to run even when the snapshot is rewritten. When several results share the same rule, tool and path (for example allowed values removed and added on one parameter), they get `:1`, `:2` and so on in the order they appear, like GitHub's own fingerprints.

Each SARIF result points at a file in the repository, because GitHub doesn't display results without one. `diff` uses `--baseline` and `lint` uses `--from-file`, relative to the working directory with forward slashes. If that path is outside the working directory, only the file name is used. When lint reads a live server, the default is `mcp-tools.json`, so in CI run lint from the repo root or pass a real `--from-file` snapshot. Run `diff` from the repo root too, so the `--baseline` artifact path is relative to the repository root and GitHub can resolve it.

To send the file to GitHub code scanning, upload it in your own workflow (the McpProbe Action doesn't upload SARIF yet):

```yaml
- run: mcpprobe lint --stdio "dotnet run --project src/MyServer" --sarif mcp-lint.sarif
- uses: github/codeql-action/upload-sarif@v3
if: always()
with:
sarif_file: mcp-lint.sarif
```

One limitation: GitHub shows PR annotations only for alerts whose file lines changed in that PR. A finding on a live server, or a tool-surface change whose `mcp-tools.json` line didn't move, still shows up in the repository's code scanning alerts, but it may not annotate the PR diff. The text output in the job summary and the HTML report stay the best view of a PR.

In code, use `LintReport.ToJson()`, `LintReport.ToSarif(artifactUri)`, `ToolSurfaceDiff.ToJson(failOnNonBreakingChanges)` and `ToolSurfaceDiff.ToSarif(artifactUri)`.

### 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. 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()`.
Expand Down
117 changes: 117 additions & 0 deletions docs/mcpprobe-report.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://raw.githubusercontent.com/ShmueLior/mcpprobe/main/docs/mcpprobe-report.schema.json",
"title": "McpProbe JSON report",
"description": "Output of 'mcpprobe lint --format json' and 'mcpprobe diff --format json', and of LintReport.ToJson() and ToolSurfaceDiff.ToJson(). Fields may be added in later versions; formatVersion changes only on a breaking change to this shape.",
"oneOf": [
{ "$ref": "#/$defs/lint" },
{ "$ref": "#/$defs/diff" }
],
"$defs": {
"tool": {
"type": "object",
"additionalProperties": false,
"required": ["name", "version"],
"properties": {
"name": { "const": "McpProbe" },
"version": { "description": "The McpProbe package version, without build metadata.", "type": "string" }
}
},
"result": {
"description": "Whether the command exited 1 (fail) or 0 (pass).",
"enum": ["pass", "fail"]
},
"lint": {
"type": "object",
"additionalProperties": false,
"required": ["formatVersion", "kind", "tool", "result", "summary", "findings"],
"properties": {
"formatVersion": { "const": 1 },
"kind": { "const": "lint" },
"tool": { "$ref": "#/$defs/tool" },
"result": { "$ref": "#/$defs/result" },
"summary": {
"type": "object",
"additionalProperties": false,
"required": ["findings", "error", "warning", "info", "hiddenIgnored", "hiddenBaselined", "unusedIgnore", "staleBaseline", "failOn"],
"properties": {
"findings": { "type": "integer", "minimum": 0 },
"error": { "type": "integer", "minimum": 0 },
"warning": { "type": "integer", "minimum": 0 },
"info": { "type": "integer", "minimum": 0 },
"hiddenIgnored": { "description": "Findings hidden by ignore entries.", "type": "integer", "minimum": 0 },
"hiddenBaselined": { "description": "Findings hidden by the lint baseline.", "type": "integer", "minimum": 0 },
"unusedIgnore": { "description": "Ignore entries that matched nothing.", "type": "integer", "minimum": 0 },
"staleBaseline": { "description": "Lint baseline entries that no longer match.", "type": "integer", "minimum": 0 },
"failOn": { "$ref": "#/$defs/lintSeverity" }
}
},
"findings": {
"description": "The visible findings, most severe first. Hidden findings are only counted in the summary.",
"type": "array",
"items": { "$ref": "#/$defs/finding" }
}
}
},
"lintSeverity": { "enum": ["none", "info", "warning", "error"] },
"finding": {
"type": "object",
"additionalProperties": false,
"required": ["ruleId", "severity", "tool", "message", "failsTheRun"],
"properties": {
"ruleId": { "type": "string", "pattern": "^MCPP[0-9]{3}$" },
"severity": { "enum": ["info", "warning", "error"] },
"tool": { "type": "string" },
"path": { "description": "The parameter or schema path. Omitted for tool-level findings.", "type": "string" },
"message": { "type": "string" },
"failsTheRun": { "type": "boolean" }
}
},
"diff": {
"type": "object",
"additionalProperties": false,
"required": ["formatVersion", "kind", "tool", "result", "summary", "changes"],
"properties": {
"formatVersion": { "const": 1 },
"kind": { "const": "diff" },
"tool": { "$ref": "#/$defs/tool" },
"result": { "$ref": "#/$defs/result" },
"summary": {
"type": "object",
"additionalProperties": false,
"required": ["changes", "breaking", "nonBreaking"],
"properties": {
"changes": { "type": "integer", "minimum": 0 },
"breaking": { "type": "integer", "minimum": 0 },
"nonBreaking": { "type": "integer", "minimum": 0 }
}
},
"changes": {
"description": "Every change, breaking first.",
"type": "array",
"items": { "$ref": "#/$defs/change" }
}
}
},
"change": {
"type": "object",
"additionalProperties": false,
"required": ["tool", "kind", "severity", "message"],
"properties": {
"tool": { "type": "string" },
"path": { "description": "Where in the tool, for example input.city. Omitted for tool-level changes.", "type": "string" },
"kind": {
"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"
]
},
"severity": { "enum": ["breaking", "nonBreaking"] },
"message": { "type": "string" },
"before": { "description": "The previous title or description. Only for title-changed and description-changed; omitted when there was none.", "type": "string" },
"after": { "description": "The current title or description. Only for title-changed and description-changed; omitted when there is none.", "type": "string" }
}
}
}
}
Loading
Loading