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

### Added

- Lint checks prompts when the server declares the prompts capability: MCPP017 (no description, warning), MCPP018 (short description), MCPP019 (argument has no description), MCPP020 (prompt name guidance), MCPP021 and MCPP022 (naming style), MCPP023 (vague argument name, info) and MCPP024 (description only restates the name). `LintFinding.Kind` says whether a finding is about a tool or a prompt. Lint baselines and `ignore` entries accept an optional `kind`; omitted means any kind. `--from-file` still lints tools only. JSON findings include an optional `kind` (`prompt`, `resource` or `resourceTemplate`); it is omitted for tools. Lint SARIF fingerprints for those kinds are `ruleId|kind|tool|path`; tool findings stay `ruleId|tool|path`, the same as format 1 on main. To keep the previous tool-only result, set `--rule MCPP017=none` through `--rule MCPP024=none`.
- 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.
- `--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.

### Changed
Expand Down
17 changes: 14 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,21 @@ strict.ThrowIfFailed();
| MCPP014 | warning | A description that promises structured results ("returns JSON", "structured content", ...) comes with an `outputSchema`. |
| MCPP015 | warning | The description says more than the tool name or title. |
| MCPP016 | warning | No empty `enum`, and an `enum` declares its `type`. |
| MCPP017 | warning | The prompt has a description. |
| MCPP018 | warning | The prompt description is at least `MinToolDescriptionLength` (20) characters, or at least `MinToolDescriptionWords` (4) words. |
| MCPP019 | warning | Every prompt argument has a description. |
| MCPP020 | warning | The prompt name is 1-128 characters of `A-Z a-z 0-9 _ - .`. |
| MCPP021 | warning | All prompt names use the same style. |
| MCPP022 | warning | All prompt argument names use the same style. |
| MCPP023 | info | Prompt argument names aren't vague (`data`, `value`, `input`, ...). |
| MCPP024 | warning | The prompt description says more than the prompt name or title. |

Change severities with `LintOptions.Severities["MCPP007"] = LintSeverity.None`, and the threshold with `LintOptions.FailOn`. By default MCPP003, MCPP006 and MCPP007 check top-level parameters. Set `LintOptions.CheckNestedParameters = true` (CLI: `mcpprobe lint --nested`) to also check nested object properties and array items (reported as `home.zip` or `stops[].city`), following local `$ref`s; a schema used in several places is checked once.

Set `LintOptions.Strict = true` (CLI: `mcpprobe lint --strict`) to also run MCPP009-MCPP012, the schema-portability checks from MCP Inspector, on `inputSchema` and `outputSchema`. Those findings are reported with paths such as `inputSchema.properties.city` (the existing parameter rules still use `city`). MCPP010 does not report `[T, "null"]` (for example `["integer","null"]`): the C# and Go SDKs write that for every nullable parameter and an author can't change it, so this differs from Inspector's type-union check; use Inspector if you need its exact report. Unions of two or more non-null types, and longer unions with `null`, are still reported. Portability findings fail the report only when their effective severity is error, so a type-union warning does not trip the default `FailOn = Warning` gate; use `--rule MCPP010=error` if you want that warning to fail. A single portability rule can be turned on without `--strict` by setting its severity, or turned off with `--rule MCPP011=none`. MCPP008 is reserved for a community issue and is not implemented here.

`lint` and `LintToolsAsync` also check prompts when the server declares the prompts capability. They skip `prompts/list` when it does not, so a tool-only server is unchanged. A snapshot passed with `--from-file` has tools only. Prompt findings are labeled `prompt` in the text and HTML reports. Ignore entries and lint baselines can set `kind` to `prompt`; if `kind` is omitted, the entry matches any kind. To get the previous tool-only lint result, turn the prompt rules off with `--rule MCPP017=none` through `--rule MCPP024=none`.

MCPP013-MCPP016 run by default and use `FailOn` like MCPP001-MCPP007. They are kept narrow on purpose: MCPP013 only reads explicit hints (an unset `destructiveHint` is fine) and matches whole name segments from `LintOptions.DestructiveNameTokens`; MCPP014 only fires on the phrases in `LintOptions.StructuredOutputCues`; MCPP016 walks `inputSchema` and `outputSchema` with the same paths as the `--strict` rules, and does not ask for a `type` on mixed-type enums (including ones with `null`) or on `anyOf`/`oneOf`/`allOf` branches, which usually take their type from the parent.

### Config file and ignore rules
Expand All @@ -172,15 +182,16 @@ A server with legacy debt can keep its lint settings, and the findings it has de
"rules": { "MCPP007": "none", "MCPP003": "error" },
"ignore": [
{ "rule": "MCPP005", "tool": "sql_*", "reason": "Server convention: namespace_resource_verb-noun" },
{ "rule": "MCPP003", "tool": "legacy_export", "parameter": "opts" }
{ "rule": "MCPP003", "tool": "legacy_export", "parameter": "opts" },
{ "rule": "MCPP017", "kind": "prompt", "reason": "Prompt descriptions come from the template" }
],
"baseline": "mcpprobe-lint-baseline.json"
}
}
```

- `failOn`, `strict`, `nested`, `minDescriptionLength` and `rules` are the same as `--fail-on`, `--strict`, `--nested`, `--min-description-length` and `--rule`. `minDescriptionWords` has no flag. Defaults come first, then the file, then the flags you type: `--fail-on error` beats `failOn` in the file, `--nested false` turns off `"nested": true`, and `--rule MCPP007=info` changes only MCPP007.
- Each `ignore` entry hides the findings that match every field it sets: `rule` (an id), `tool` and `parameter` (patterns where `*` matches any run of characters and `?` matches one; case-sensitive), plus a free-text `reason`. Set at least a `rule` or a `tool`. `parameter` is the path the finding prints: `city`, `address.zip`, `stops[].city`, or `inputSchema.properties.city` for the `--strict` rules.
- Each `ignore` entry hides the findings that match every field it sets: `rule` (an id), `tool` and `parameter` (patterns where `*` matches any run of characters and `?` matches one; case-sensitive), plus a free-text `reason`. `kind` limits the entry to `tool`, `prompt`, `resource` or `resourceTemplate`; omitted, it matches any kind. Set at least a `rule` or a `tool`. `parameter` is the path the finding prints: `city`, `address.zip`, `stops[].city`, or `inputSchema.properties.city` for the `--strict` rules.
- Hidden findings never fail the run. The report says how many were hidden (`Hidden: 3 ignored.`), and lists entries that matched nothing so you can delete them (this never fails the run either). An entry for a rule that did not run, such as MCPP010 without `--strict`, is not listed as unused.
- The file is strict: JSON with comments and trailing commas, but an unknown key, a wrong type or an unknown rule id is an error (exit 2) rather than being ignored. A CLI older than the file may not know a newer key.
- It holds lint settings only. It can't name a server to start or connect to, so a checked-out repository can't make `mcpprobe` run a command. `snapshot` and `diff` don't read it.
Expand Down Expand Up @@ -237,7 +248,7 @@ mcpprobe diff --stdio "dotnet run --project src/MyServer" --baseline mcp-tools.j

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.
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. Lint findings about a prompt, resource or resource template also include the finding `kind` (`ruleId|kind|tool|path`). Tool findings stay `ruleId|tool|path`, the same as format 1 on main, so existing code scanning alerts keep matching. When several results share the same identity (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. JSON lint findings include an optional `kind` (`prompt`, `resource` or `resourceTemplate`); it is omitted for tools.

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.

Expand Down
1 change: 1 addition & 0 deletions docs/mcpprobe-report.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"ruleId": { "type": "string", "pattern": "^MCPP[0-9]{3}$" },
"severity": { "enum": ["info", "warning", "error"] },
"tool": { "type": "string" },
"kind": { "description": "The item kind. Omitted for tools; prompt, resource or resourceTemplate otherwise.", "enum": ["tool", "prompt", "resource", "resourceTemplate"] },
"path": { "description": "The parameter or schema path. Omitted for tool-level findings.", "type": "string" },
"message": { "type": "string" },
"failsTheRun": { "type": "boolean" }
Expand Down
14 changes: 13 additions & 1 deletion docs/mcpprobe.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@
"type": "string",
"minLength": 1
},
"kind": {
"description": "Item kind: tool, prompt, resource or resourceTemplate. Omitted matches any kind.",
"enum": ["tool", "prompt", "resource", "resourceTemplate"]
},
"reason": {
"description": "Why the finding is accepted. Not evaluated.",
"type": "string"
Expand Down Expand Up @@ -119,7 +123,15 @@
"MCPP013",
"MCPP014",
"MCPP015",
"MCPP016"
"MCPP016",
"MCPP017",
"MCPP018",
"MCPP019",
"MCPP020",
"MCPP021",
"MCPP022",
"MCPP023",
"MCPP024"
]
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/McpProbe.Cli/CliApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static async Task<int> RunAsync(string[] args, TextWriter stdout, TextWri

private static RootCommand BuildRootCommand(TextWriter stdout, TextWriter stderr, string? workingDirectory)
{
var root = new RootCommand("Check an MCP server's tool surface: snapshot it, diff it against a committed snapshot, and lint it.")
var root = new RootCommand("Check an MCP server's tool surface: snapshot it, diff it against a committed snapshot, and lint it, including prompts when the server has them.")
{
BuildSnapshotCommand(stdout, stderr),
BuildDiffCommand(stdout, stderr, workingDirectory),
Expand Down Expand Up @@ -257,7 +257,7 @@ private static Command BuildLintCommand(TextWriter stdout, TextWriter stderr, st
var report = BuildReportOption();
var format = BuildFormatOption();
var sarif = BuildSarifOption();
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.");
var command = new Command("lint", "Lint tool names, descriptions and parameters, and prompts when the server has them. 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);
Expand Down Expand Up @@ -340,8 +340,8 @@ private static Command BuildLintCommand(TextWriter stdout, TextWriter stderr, st
options.Severities[parts[0]] = ParseSeverity(parts[1]);
}

var surface = await server.CaptureAsync(parse, stderr, ct).ConfigureAwait(false);
var lint = ToolLinter.Lint(surface, options);
var (surface, prompts) = await server.CaptureForLintAsync(parse, stderr, ct).ConfigureAwait(false);
var lint = prompts is null ? ToolLinter.Lint(surface, options) : ToolLinter.Lint(surface, prompts, options);
var artifact = SarifArtifact.Resolve(server.FromFilePath(parse), workingDirectory);
var sarifText = outputFormat == "sarif" || sarifPath is not null ? lint.ToSarif(artifact) : string.Empty;
await WriteOutputAsync(
Expand Down
15 changes: 13 additions & 2 deletions src/McpProbe.Cli/LintConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ internal sealed class LintConfig

public static readonly string[] RootKeys = ["$schema", "lint"];
public static readonly string[] LintKeys = ["failOn", "strict", "nested", "minDescriptionLength", "minDescriptionWords", "rules", "ignore", "baseline"];
public static readonly string[] IgnoreKeys = ["rule", "tool", "parameter", "reason"];
public static readonly string[] IgnoreKeys = ["rule", "tool", "parameter", "kind", "reason"];

private static readonly JsonDocumentOptions s_documentOptions = new() { CommentHandling = JsonCommentHandling.Skip, AllowTrailingCommas = true };

Expand Down Expand Up @@ -164,17 +164,28 @@ private static List<LintSuppression> ParseIgnore(JsonNode? node, string name)
var tool = entry.TryGetPropertyValue("tool", out var t) ? AsString(t, name, $"{where}.tool") : null;
var parameter = entry.TryGetPropertyValue("parameter", out var p) ? AsString(p, name, $"{where}.parameter") : null;
var reason = entry.TryGetPropertyValue("reason", out var why) ? AsString(why, name, $"{where}.reason", allowEmpty: true) : null;
var kind = entry.TryGetPropertyValue("kind", out var k) ? ParseKind(AsString(k, name, $"{where}.kind"), name, where) : (LintTargetKind?)null;
if (rule is null && tool is null)
{
throw new FormatException($"{name}: {where}: needs a 'rule' or a 'tool'. To hide everything, set lint.failOn to \"none\".");
}

entries.Add(new LintSuppression(rule, tool, parameter, reason));
entries.Add(new LintSuppression(rule, tool, parameter, reason) { Kind = kind });
}

return entries;
}

private static LintTargetKind ParseKind(string value, string name, string where) => value switch
{
"tool" => LintTargetKind.Tool,
"prompt" => LintTargetKind.Prompt,
"resource" => LintTargetKind.Resource,
"resourceTemplate" => LintTargetKind.ResourceTemplate,
"resource template" => LintTargetKind.ResourceTemplate,
_ => throw new FormatException($"{name}: {where}.kind: unknown kind '{Printable.Text(value, 50)}'. Use tool, prompt, resource or resourceTemplate."),
};

private static string FindRule(string id, string name, string where) =>
LintRules.All.FirstOrDefault(r => string.Equals(r.Id, id, StringComparison.OrdinalIgnoreCase))?.Id
?? throw new FormatException($"{name}: {where}: unknown rule '{Printable.Text(id, 50)}'. Rules: {string.Join(", ", LintRules.All.Select(r => r.Id))}.");
Expand Down
Loading
Loading