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

### Added

- Lint checks resource templates when the server declares the resources capability: MCPP025 (no description), MCPP026 (missing, invalid or duplicate uri, uriTemplate or prompt name, error) and MCPP027 (no name). Listed resources are checked only with `--resources` (config `lint.resources`). MCPP028 checks icons on tools, prompts and resource templates from a live server, without fetching them. `--from-file` lints tools only, so MCPP028 does not run on a snapshot file.
- 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`.
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,19 @@ strict.ThrowIfFailed();
| 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. |
| MCPP025 | warning | A resource template has a description. Listed resources are checked only with `--resources`. |
| MCPP026 | error | A resource `uri` is a non-empty absolute URI with a scheme, a resource template `uriTemplate` is non-empty and has a scheme before its first `{`, and prompt names, resource URIs and uriTemplates aren't listed twice. |
| MCPP027 | warning | A resource template has a `name`. Listed resources are checked only with `--resources`. |
| MCPP028 | warning | Icons use an `http:`, `https:` or `data:` `src`, `mimeType` looks like `type/subtype`, each size is `WxH` or `any`, and `theme` is `light` or `dark`. Checked on tools, prompts and resource templates from a live server. Nothing is fetched. |

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

They also check resource templates (MCPP025-MCPP027) when the server declares the resources capability. Resources from `resources/list` are checked only with `--resources` (config `lint.resources`), because file-style servers can list hundreds of them. Note that the C# SDK lists a resource declared with a fixed URI (no `{...}`) in `resources/list`, not in `resources/templates/list`, so it is only linted with `--resources`. MCPP028 checks icons on tools, prompts and resource templates listed from a live server. `--from-file` does not check them, because that path lints the snapshot's tools only. Icons are never fetched.

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 @@ -177,6 +183,7 @@ A server with legacy debt can keep its lint settings, and the findings it has de
"failOn": "warning",
"strict": false,
"nested": false,
"resources": false,
"minDescriptionLength": 20,
"minDescriptionWords": 4,
"rules": { "MCPP007": "none", "MCPP003": "error" },
Expand Down
10 changes: 9 additions & 1 deletion docs/mcpprobe.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
"description": "Also check nested object properties and array items. Same as --nested.",
"type": "boolean"
},
"resources": {
"description": "Also lint the resources from resources/list. Resource templates are always linted. Same as --resources.",
"type": "boolean"
},
"minDescriptionLength": {
"description": "Minimum tool description length for MCPP002. Same as --min-description-length. Default: 20.",
"type": "integer",
Expand Down Expand Up @@ -131,7 +135,11 @@
"MCPP021",
"MCPP022",
"MCPP023",
"MCPP024"
"MCPP024",
"MCPP025",
"MCPP026",
"MCPP027",
"MCPP028"
]
}
}
Expand Down
18 changes: 14 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, including prompts when the server has them.")
var root = new RootCommand("Check an MCP server's tool surface: snapshot it, diff it against a committed snapshot, and lint it, including prompts and resource templates when the server has them.")
{
BuildSnapshotCommand(stdout, stderr),
BuildDiffCommand(stdout, stderr, workingDirectory),
Expand Down Expand Up @@ -238,6 +238,10 @@ private static Command BuildLintCommand(TextWriter stdout, TextWriter stderr, st
{
Description = "Also run schema-portability rules MCPP009-MCPP012. Those findings fail the command only when their severity is error.",
};
var resources = new Option<bool>("--resources")
{
Description = "Also lint the resources from resources/list. Resource templates are always linted.",
};
var config = new Option<string?>("--config")
{
Description = $"Read lint settings from this file instead of the nearest {LintConfig.FileName} (looked up from the current directory to the repository root). Flags override the file.",
Expand All @@ -257,13 +261,14 @@ 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, 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.");
var command = new Command("lint", "Lint tool names, descriptions and parameters, prompts and resource templates 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);
command.Options.Add(rules);
command.Options.Add(nested);
command.Options.Add(strict);
command.Options.Add(resources);
command.Options.Add(config);
command.Options.Add(noConfig);
command.Options.Add(baseline);
Expand Down Expand Up @@ -328,6 +333,11 @@ private static Command BuildLintCommand(TextWriter stdout, TextWriter stderr, st
options.Strict = parse.GetValue(strict);
}

if (IsSet(parse, resources))
{
options.LintResources = parse.GetValue(resources);
}

foreach (var rule in parse.GetValue(rules) ?? [])
{
var parts = rule.Split('=', 2, StringSplitOptions.TrimEntries);
Expand All @@ -340,8 +350,8 @@ private static Command BuildLintCommand(TextWriter stdout, TextWriter stderr, st
options.Severities[parts[0]] = ParseSeverity(parts[1]);
}

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 (surface, contracts) = await server.CaptureForLintAsync(parse, stderr, options.LintResources, ct).ConfigureAwait(false);
var lint = contracts is null ? ToolLinter.Lint(surface, options) : ToolLinter.Lint(surface, contracts, 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
6 changes: 5 additions & 1 deletion src/McpProbe.Cli/LintConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ internal sealed class LintConfig
public const string FileName = "mcpprobe.json";

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

private static readonly JsonDocumentOptions s_documentOptions = new() { CommentHandling = JsonCommentHandling.Skip, AllowTrailingCommas = true };
Expand All @@ -27,6 +27,8 @@ internal sealed class LintConfig

public bool? Nested { get; private init; }

public bool? Resources { get; private init; }

public int? MinDescriptionLength { get; private init; }

public int? MinDescriptionWords { get; private init; }
Expand Down Expand Up @@ -101,6 +103,7 @@ private static LintConfig ParseNodes(JsonNode? root, string name, string path)
FailOn = lint.TryGetPropertyValue("failOn", out var failOn) ? ParseSeverity(failOn, name, "lint.failOn") : null,
Strict = lint.TryGetPropertyValue("strict", out var strict) ? AsBool(strict, name, "lint.strict") : null,
Nested = lint.TryGetPropertyValue("nested", out var nested) ? AsBool(nested, name, "lint.nested") : null,
Resources = lint.TryGetPropertyValue("resources", out var resources) ? AsBool(resources, name, "lint.resources") : null,
MinDescriptionLength = lint.TryGetPropertyValue("minDescriptionLength", out var length) ? AsCount(length, name, "lint.minDescriptionLength") : null,
MinDescriptionWords = lint.TryGetPropertyValue("minDescriptionWords", out var words) ? AsCount(words, name, "lint.minDescriptionWords") : null,
Rules = lint.TryGetPropertyValue("rules", out var rules) ? ParseRules(rules, name) : new Dictionary<string, LintSeverity>(),
Expand All @@ -117,6 +120,7 @@ public void ApplyTo(LintOptions options)
options.FailOn = FailOn ?? options.FailOn;
options.Strict = Strict ?? options.Strict;
options.CheckNestedParameters = Nested ?? options.CheckNestedParameters;
options.LintResources = Resources ?? options.LintResources;
options.MinToolDescriptionLength = MinDescriptionLength ?? options.MinToolDescriptionLength;
options.MinToolDescriptionWords = MinDescriptionWords ?? options.MinToolDescriptionWords;
foreach (var (rule, severity) in Rules)
Expand Down
17 changes: 9 additions & 8 deletions src/McpProbe.Cli/ServerOptions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.CommandLine;
using McpProbe.Internal;
using McpProbe.Linting;
using McpProbe.Snapshots;
using ModelContextProtocol.Client;
using ModelContextProtocol.Protocol;
Expand Down Expand Up @@ -131,12 +132,12 @@ public void AddTo(Command command)
internal string? FromFilePath(ParseResult parse) => _file is null ? null : parse.GetValue(_file);

public async Task<ToolSurface> CaptureAsync(ParseResult parse, TextWriter stderr, CancellationToken cancellationToken) =>
(await CaptureCoreAsync(parse, stderr, includeListedContracts: false, cancellationToken).ConfigureAwait(false)).Surface;
(await CaptureCoreAsync(parse, stderr, includeListedContracts: false, includeResources: false, cancellationToken).ConfigureAwait(false)).Surface;

public async Task<(ToolSurface Surface, IReadOnlyList<Prompt>? Prompts)> CaptureForLintAsync(ParseResult parse, TextWriter stderr, CancellationToken cancellationToken) =>
await CaptureCoreAsync(parse, stderr, includeListedContracts: true, cancellationToken).ConfigureAwait(false);
public async Task<(ToolSurface Surface, LintListedContracts? Contracts)> CaptureForLintAsync(ParseResult parse, TextWriter stderr, bool includeResources, CancellationToken cancellationToken) =>
await CaptureCoreAsync(parse, stderr, includeListedContracts: true, includeResources, cancellationToken).ConfigureAwait(false);

private async Task<(ToolSurface Surface, IReadOnlyList<Prompt>? Prompts)> CaptureCoreAsync(ParseResult parse, TextWriter stderr, bool includeListedContracts, CancellationToken cancellationToken)
private async Task<(ToolSurface Surface, LintListedContracts? Contracts)> CaptureCoreAsync(ParseResult parse, TextWriter stderr, bool includeListedContracts, bool includeResources, CancellationToken cancellationToken)
{
if (_file is not null && parse.GetValue(_file) is { } file)
{
Expand Down Expand Up @@ -174,14 +175,14 @@ public async Task<ToolSurface> CaptureAsync(ParseResult parse, TextWriter stderr
var client = await ServerConnector.ConnectAsync(target, serverStderr, challenge, timeout.Token).ConfigureAwait(false);
await using (client.ConfigureAwait(false))
{
var surface = await ToolSurface.CaptureAsync(client, timeout.Token).ConfigureAwait(false);
if (!includeListedContracts)
{
return (surface, null);
return (await ToolSurface.CaptureAsync(client, timeout.Token).ConfigureAwait(false), null);
}

var prompts = await ListedContracts.ListPromptsAsync(client, timeout.Token).ConfigureAwait(false);
return (surface, prompts);
var contracts = await ListedContracts.ListAsync(client, includeResources, timeout.Token).ConfigureAwait(false);
var surface = ToolSurface.FromTools(contracts.Tools ?? []);
return (surface, contracts);
}
}
catch (Exception ex)
Expand Down
32 changes: 26 additions & 6 deletions src/McpProbe/Internal/ListedContracts.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,39 @@
using McpProbe.Linting;
using ModelContextProtocol.Client;
using ModelContextProtocol.Protocol;

namespace McpProbe.Internal;

/// <summary>Lists prompts when the server declares the prompts capability.</summary>
/// <summary>Lists prompts, resource templates and (when opted in) resources, skipping contracts the server does not declare.</summary>
internal static class ListedContracts
{
public static async Task<IReadOnlyList<Prompt>?> ListPromptsAsync(McpClient client, CancellationToken cancellationToken)
public static async Task<LintListedContracts> ListAsync(McpClient client, bool includeResources, CancellationToken cancellationToken)
{
if (client.ServerCapabilities.Prompts is null)
var capabilities = client.ServerCapabilities;
IReadOnlyList<Prompt>? prompts = null;
IReadOnlyList<ResourceTemplate>? templates = null;
IReadOnlyList<Resource>? resources = null;
IReadOnlyList<Tool>? tools = null;

if (capabilities.Tools is not null)
{
tools = (await client.ListToolsAsync(cancellationToken: cancellationToken).ConfigureAwait(false)).Select(t => t.ProtocolTool).ToList();
}

if (capabilities.Prompts is not null)
{
prompts = (await client.ListPromptsAsync(cancellationToken: cancellationToken).ConfigureAwait(false)).Select(p => p.ProtocolPrompt).ToList();
}

if (capabilities.Resources is not null)
{
return null;
templates = (await client.ListResourceTemplatesAsync(cancellationToken: cancellationToken).ConfigureAwait(false)).Select(t => t.ProtocolResourceTemplate).ToList();
if (includeResources)
{
resources = (await client.ListResourcesAsync(cancellationToken: cancellationToken).ConfigureAwait(false)).Select(r => r.ProtocolResource).ToList();
}
}

var prompts = await client.ListPromptsAsync(cancellationToken: cancellationToken).ConfigureAwait(false);
return prompts.Select(p => p.ProtocolPrompt).ToList();
return new LintListedContracts { Prompts = prompts, ResourceTemplates = templates, Resources = resources, Tools = tools ?? [] };
}
}
Loading
Loading