From 7aa50db50aea319cbb317322065d8f55fb45ec59 Mon Sep 17 00:00:00 2001 From: Lior Shmueli <48066416+ShmueLior@users.noreply.github.com> Date: Fri, 4 Dec 2026 09:14:56 +0200 Subject: [PATCH 1/5] Lint resource templates and icons (MCPP025-MCPP028), add --resources --- CHANGELOG.md | 1 + README.md | 7 + docs/mcpprobe.schema.json | 10 +- src/McpProbe.Cli/CliApp.cs | 16 +- src/McpProbe.Cli/LintConfig.cs | 6 +- src/McpProbe.Cli/ServerOptions.cs | 17 +- src/McpProbe/Internal/ListedContracts.cs | 32 ++- src/McpProbe/Linting/IconLinter.cs | 126 ++++++++++++ src/McpProbe/Linting/LintListedContracts.cs | 29 +++ src/McpProbe/Linting/LintOptions.cs | 6 + src/McpProbe/Linting/LintRule.cs | 16 ++ src/McpProbe/Linting/ResourceLinter.cs | 129 ++++++++++++ src/McpProbe/Linting/ToolLinter.cs | 20 +- src/McpProbe/McpProbeHost.cs | 6 +- src/McpProbe/PublicAPI.Unshipped.txt | 17 ++ tests/McpProbe.Tests/LintConfigTests.cs | 2 +- tests/McpProbe.Tests/PromptLinterTests.cs | 10 +- tests/McpProbe.Tests/ResourceLinterTests.cs | 210 ++++++++++++++++++++ tests/McpProbe.Tests/ToolLinterTests.cs | 2 +- 19 files changed, 630 insertions(+), 32 deletions(-) create mode 100644 src/McpProbe/Linting/IconLinter.cs create mode 100644 src/McpProbe/Linting/LintListedContracts.cs create mode 100644 src/McpProbe/Linting/ResourceLinter.cs create mode 100644 tests/McpProbe.Tests/ResourceLinterTests.cs diff --git a/CHANGELOG.md b/CHANGELOG.md index c98e0f2..17bc643 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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, and snapshots don't carry icons. - 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`. diff --git a/README.md b/README.md index e401e29..12eb162 100644 --- a/README.md +++ b/README.md @@ -157,6 +157,10 @@ 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. @@ -164,6 +168,8 @@ Set `LintOptions.Strict = true` (CLI: `mcpprobe lint --strict`) to also run MCPP `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. A snapshot doesn't carry icons, so `--from-file` doesn't check them. 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 @@ -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" }, diff --git a/docs/mcpprobe.schema.json b/docs/mcpprobe.schema.json index fbfcc2f..d397338 100644 --- a/docs/mcpprobe.schema.json +++ b/docs/mcpprobe.schema.json @@ -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", @@ -131,7 +135,11 @@ "MCPP021", "MCPP022", "MCPP023", - "MCPP024" + "MCPP024", + "MCPP025", + "MCPP026", + "MCPP027", + "MCPP028" ] } } diff --git a/src/McpProbe.Cli/CliApp.cs b/src/McpProbe.Cli/CliApp.cs index d5f0878..180010c 100644 --- a/src/McpProbe.Cli/CliApp.cs +++ b/src/McpProbe.Cli/CliApp.cs @@ -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("--resources") + { + Description = "Also lint the resources from resources/list. Resource templates are always linted.", + }; var config = new Option("--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.", @@ -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); @@ -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); @@ -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( diff --git a/src/McpProbe.Cli/LintConfig.cs b/src/McpProbe.Cli/LintConfig.cs index 6e5777a..eb176c5 100644 --- a/src/McpProbe.Cli/LintConfig.cs +++ b/src/McpProbe.Cli/LintConfig.cs @@ -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 }; @@ -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; } @@ -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(), @@ -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) diff --git a/src/McpProbe.Cli/ServerOptions.cs b/src/McpProbe.Cli/ServerOptions.cs index 153abb2..51caf4c 100644 --- a/src/McpProbe.Cli/ServerOptions.cs +++ b/src/McpProbe.Cli/ServerOptions.cs @@ -1,5 +1,6 @@ using System.CommandLine; using McpProbe.Internal; +using McpProbe.Linting; using McpProbe.Snapshots; using ModelContextProtocol.Client; using ModelContextProtocol.Protocol; @@ -131,12 +132,12 @@ public void AddTo(Command command) internal string? FromFilePath(ParseResult parse) => _file is null ? null : parse.GetValue(_file); public async Task 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? 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? 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) { @@ -174,14 +175,14 @@ public async Task 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) diff --git a/src/McpProbe/Internal/ListedContracts.cs b/src/McpProbe/Internal/ListedContracts.cs index 336d9a0..dad77cb 100644 --- a/src/McpProbe/Internal/ListedContracts.cs +++ b/src/McpProbe/Internal/ListedContracts.cs @@ -1,19 +1,39 @@ +using McpProbe.Linting; using ModelContextProtocol.Client; using ModelContextProtocol.Protocol; namespace McpProbe.Internal; -/// Lists prompts when the server declares the prompts capability. +/// Lists prompts, resource templates and (when opted in) resources, skipping contracts the server does not declare. internal static class ListedContracts { - public static async Task?> ListPromptsAsync(McpClient client, CancellationToken cancellationToken) + public static async Task ListAsync(McpClient client, bool includeResources, CancellationToken cancellationToken) { - if (client.ServerCapabilities.Prompts is null) + var capabilities = client.ServerCapabilities; + IReadOnlyList? prompts = null; + IReadOnlyList? templates = null; + IReadOnlyList? resources = null; + IReadOnlyList? 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 ?? [] }; } } diff --git a/src/McpProbe/Linting/IconLinter.cs b/src/McpProbe/Linting/IconLinter.cs new file mode 100644 index 0000000..ad853f0 --- /dev/null +++ b/src/McpProbe/Linting/IconLinter.cs @@ -0,0 +1,126 @@ +using System.Globalization; +using System.Text.RegularExpressions; +using ModelContextProtocol.Protocol; + +namespace McpProbe.Linting; + +public static partial class ToolLinter +{ + [GeneratedRegex("^(?:[0-9]+x[0-9]+|any)$")] + private static partial Regex IconSize(); + + [GeneratedRegex("^[A-Za-z0-9!#$&^_.+\\-]+/[A-Za-z0-9!#$&^_.+\\-]+$")] + private static partial Regex MimeTypeShape(); + + // MCPP028. Never fetches anything; only looks at the declared values. + private static void LintIcons(LintListedContracts? contracts, LintOptions options, List findings) + { + if (options.SeverityOf(LintRules.InvalidIcon) == LintSeverity.None || contracts is null) + { + return; + } + + if (contracts.Tools is { } tools) + { + foreach (var tool in tools) + { + CheckIcons(tool?.Name ?? string.Empty, tool?.Icons, LintTargetKind.Tool, options, findings); + } + } + + if (contracts.Prompts is { } prompts) + { + foreach (var prompt in prompts) + { + CheckIcons(prompt?.Name ?? string.Empty, prompt?.Icons, LintTargetKind.Prompt, options, findings); + } + } + + if (contracts.ResourceTemplates is { } templates) + { + foreach (var template in templates) + { + CheckIcons(template?.UriTemplate ?? string.Empty, template?.Icons, LintTargetKind.ResourceTemplate, options, findings); + } + } + + if (options.LintResources && contracts.Resources is { } resources) + { + foreach (var resource in resources) + { + CheckIcons(resource?.Uri ?? string.Empty, resource?.Icons, LintTargetKind.Resource, options, findings); + } + } + } + + private static void CheckIcons(string id, IList? icons, LintTargetKind kind, LintOptions options, List findings) + { + if (icons is null) + { + return; + } + + for (var i = 0; i < icons.Count; i++) + { + var path = string.Create(CultureInfo.InvariantCulture, $"icons[{i}]"); + var icon = icons[i]; + if (icon is null) + { + Add(findings, options, LintRules.InvalidIcon, id, path, "Icon entry is null. Remove it or give it a 'src'.", kind); + continue; + } + + var src = icon.Source; + if (string.IsNullOrWhiteSpace(src)) + { + Add(findings, options, LintRules.InvalidIcon, id, path + ".src", "Icon has no src. Use an https: URL or a data: URI.", kind); + } + else if (!HasAllowedIconScheme(src)) + { + Add(findings, options, LintRules.InvalidIcon, id, path + ".src", + $"Icon src '{DescribeIconSrc(src)}' is not an http:, https: or data: URI.", kind); + } + + if (icon.MimeType is { } mime && !MimeTypeShape().IsMatch(mime)) + { + Add(findings, options, LintRules.InvalidIcon, id, path + ".mimeType", + $"Icon mimeType '{mime}' is not a type/subtype value, for example 'image/png'.", kind); + } + + if (icon.Sizes is { } sizes) + { + for (var s = 0; s < sizes.Count; s++) + { + if (sizes[s] is not { } size || !IconSize().IsMatch(size)) + { + Add(findings, options, LintRules.InvalidIcon, id, string.Create(CultureInfo.InvariantCulture, $"{path}.sizes[{s}]"), + $"Icon size '{sizes[s]}' is not 'WxH' (for example '48x48') or 'any'.", kind); + } + } + } + + if (icon.Theme is { } theme && theme is not ("light" or "dark")) + { + Add(findings, options, LintRules.InvalidIcon, id, path + ".theme", + $"Icon theme '{theme}' is not 'light' or 'dark'.", kind); + } + } + } + + private static bool HasAllowedIconScheme(string src) => + src.StartsWith("https://", StringComparison.OrdinalIgnoreCase) || + src.StartsWith("http://", StringComparison.OrdinalIgnoreCase) || + src.StartsWith("data:", StringComparison.OrdinalIgnoreCase); + + // data: URIs can be large base64 payloads; show only the media type. + private static string DescribeIconSrc(string src) + { + if (src.StartsWith("data:", StringComparison.OrdinalIgnoreCase)) + { + var comma = src.IndexOf(',', StringComparison.Ordinal); + return (comma < 0 ? src : src[..comma]) + ",..."; + } + + return src.Length > 100 ? src[..100] + "..." : src; + } +} diff --git a/src/McpProbe/Linting/LintListedContracts.cs b/src/McpProbe/Linting/LintListedContracts.cs new file mode 100644 index 0000000..55cff13 --- /dev/null +++ b/src/McpProbe/Linting/LintListedContracts.cs @@ -0,0 +1,29 @@ +using McpProbe.Snapshots; +using ModelContextProtocol.Protocol; + +namespace McpProbe.Linting; + +/// +/// The non-tool contracts a server listed, passed to . +/// A null list means that contract was not listed (the server does not declare the capability, or the caller chose not to list it), +/// and no rule runs on it. An empty list means the server listed nothing of that kind. +/// +public sealed class LintListedContracts +{ + /// Gets or sets the prompts from prompts/list. + public IReadOnlyList? Prompts { get; init; } + + /// Gets or sets the resource templates from resources/templates/list. + public IReadOnlyList? ResourceTemplates { get; init; } + + /// + /// Gets or sets the resources from resources/list. They are linted only when is . + /// + public IReadOnlyList? Resources { get; init; } + + /// + /// Gets or sets the protocol tools from tools/list, used to check tool icons (MCPP028). + /// A snapshot file does not carry icons, so tool icons are checked only when the tools were listed from a live server. + /// + public IReadOnlyList? Tools { get; init; } +} diff --git a/src/McpProbe/Linting/LintOptions.cs b/src/McpProbe/Linting/LintOptions.cs index a6a2b66..949e221 100644 --- a/src/McpProbe/Linting/LintOptions.cs +++ b/src/McpProbe/Linting/LintOptions.cs @@ -68,6 +68,12 @@ public sealed class LintOptions /// public bool CheckNestedParameters { get; set; } + /// + /// Gets or sets whether to also lint the resources from resources/list (MCPP025-MCPP028). Defaults to , + /// because file-style servers can list hundreds of resources. Resource templates are always linted when the server lists them. + /// + public bool LintResources { get; set; } + /// /// Gets or sets whether to run the schema-portability rules MCPP009-MCPP012 (bare boolean schemas, type unions, /// untyped schemas and remote $refs), matching MCP Inspector's --strict checks. Defaults to . diff --git a/src/McpProbe/Linting/LintRule.cs b/src/McpProbe/Linting/LintRule.cs index 27b467e..425c35b 100644 --- a/src/McpProbe/Linting/LintRule.cs +++ b/src/McpProbe/Linting/LintRule.cs @@ -80,6 +80,18 @@ public static class LintRules /// MCPP024: the prompt description only restates the prompt name or title. public static readonly LintRule PromptDescriptionRestatesName = new("MCPP024", "Prompt description only restates the name", LintSeverity.Warning); + /// MCPP025: a resource template (or a listed resource, with ) has no description. + public static readonly LintRule ResourceMissingDescription = new("MCPP025", "Resource or resource template has no description", LintSeverity.Warning); + + /// MCPP026: a resource uri, resource template uriTemplate or prompt name is missing, invalid, or listed more than once. + public static readonly LintRule InvalidOrDuplicateIdentity = new("MCPP026", "Missing, invalid or duplicate identity", LintSeverity.Error); + + /// MCPP027: a resource template (or a listed resource, with ) has no name. + public static readonly LintRule ResourceMissingName = new("MCPP027", "Resource or resource template has no name", LintSeverity.Warning); + + /// MCPP028: an icon has a missing or non-http(s)/data src, a bad mimeType, size or theme. + public static readonly LintRule InvalidIcon = new("MCPP028", "Invalid icon", LintSeverity.Warning); + /// Gets all built-in rules, ordered by id. public static IReadOnlyList All { get; } = [ @@ -106,6 +118,10 @@ public static class LintRules InconsistentPromptArgumentNaming, VaguePromptArgumentName, PromptDescriptionRestatesName, + ResourceMissingDescription, + InvalidOrDuplicateIdentity, + ResourceMissingName, + InvalidIcon, ]; internal static bool IsPortabilityRule(string ruleId) => diff --git a/src/McpProbe/Linting/ResourceLinter.cs b/src/McpProbe/Linting/ResourceLinter.cs new file mode 100644 index 0000000..aa4620a --- /dev/null +++ b/src/McpProbe/Linting/ResourceLinter.cs @@ -0,0 +1,129 @@ +using System.Text.RegularExpressions; +using ModelContextProtocol.Protocol; + +namespace McpProbe.Linting; + +public static partial class ToolLinter +{ + // Scheme per RFC 3986, before the first template expression. + [GeneratedRegex("^[A-Za-z][A-Za-z0-9+.\\-]*:")] + private static partial Regex SchemePrefix(); + + private static void LintResources(LintListedContracts? contracts, LintOptions options, List findings) + { + if (contracts is null) + { + return; + } + + if (contracts.ResourceTemplates is { } templates) + { + var seen = new HashSet(StringComparer.Ordinal); + foreach (var template in templates) + { + if (template is null) + { + continue; + } + + var id = template.UriTemplate ?? string.Empty; + CheckTemplateIdentity(id, seen, options, findings); + CheckResourceMetadata(id, template.Name, template.Description, LintTargetKind.ResourceTemplate, options, findings); + } + } + + if (options.LintResources && contracts.Resources is { } resources) + { + var seen = new HashSet(StringComparer.Ordinal); + foreach (var resource in resources) + { + if (resource is null) + { + continue; + } + + var id = resource.Uri ?? string.Empty; + CheckResourceIdentity(id, seen, options, findings); + CheckResourceMetadata(id, resource.Name, resource.Description, LintTargetKind.Resource, options, findings); + } + } + + if (contracts.Prompts is { } prompts) + { + var seen = new HashSet(StringComparer.Ordinal); + foreach (var prompt in prompts) + { + var name = prompt?.Name ?? string.Empty; + if (name.Length > 0 && !seen.Add(name)) + { + Add(findings, options, LintRules.InvalidOrDuplicateIdentity, name, null, + $"Prompt name '{name}' is listed more than once. Clients address prompts by name, so keep names unique.", + LintTargetKind.Prompt); + } + } + } + } + + private static void CheckTemplateIdentity(string id, HashSet seen, LintOptions options, List findings) + { + if (string.IsNullOrWhiteSpace(id)) + { + Add(findings, options, LintRules.InvalidOrDuplicateIdentity, id, null, + "Resource template has no uriTemplate. Give it an RFC 6570 URI template with a scheme, for example 'weather://cities/{city}'.", + LintTargetKind.ResourceTemplate); + return; + } + + var literal = id.Split('{', 2)[0]; + if (!SchemePrefix().IsMatch(literal)) + { + Add(findings, options, LintRules.InvalidOrDuplicateIdentity, id, null, + $"Resource template '{id}' has no URI scheme before its first template expression. Start it with a scheme, for example 'weather://' or 'file:///'.", + LintTargetKind.ResourceTemplate); + } + + if (!seen.Add(id)) + { + Add(findings, options, LintRules.InvalidOrDuplicateIdentity, id, null, + $"Resource template '{id}' is listed more than once. Keep uriTemplate values unique.", + LintTargetKind.ResourceTemplate); + } + } + + private static void CheckResourceIdentity(string id, HashSet seen, LintOptions options, List findings) + { + if (string.IsNullOrWhiteSpace(id) || !Uri.TryCreate(id, UriKind.Absolute, out var uri) || uri.Scheme.Length == 0) + { + Add(findings, options, LintRules.InvalidOrDuplicateIdentity, id, null, + string.IsNullOrWhiteSpace(id) + ? "Resource has no uri. Give it an absolute URI with a scheme." + : $"Resource uri '{id}' is not an absolute URI with a scheme.", + LintTargetKind.Resource); + } + + if (id.Length > 0 && !seen.Add(id)) + { + Add(findings, options, LintRules.InvalidOrDuplicateIdentity, id, null, + $"Resource uri '{id}' is listed more than once. Keep resource URIs unique.", + LintTargetKind.Resource); + } + } + + private static void CheckResourceMetadata(string id, string? name, string? description, LintTargetKind kind, LintOptions options, List findings) + { + var noun = kind == LintTargetKind.Resource ? "Resource" : "Resource template"; + if (string.IsNullOrWhiteSpace(description)) + { + Add(findings, options, LintRules.ResourceMissingDescription, id, null, + $"{noun} has no description. Say what it contains and when to read it.", + kind); + } + + if (string.IsNullOrWhiteSpace(name)) + { + Add(findings, options, LintRules.ResourceMissingName, id, null, + $"{noun} has no name. Give it a short display name.", + kind); + } + } +} diff --git a/src/McpProbe/Linting/ToolLinter.cs b/src/McpProbe/Linting/ToolLinter.cs index 5c9853a..1f50431 100644 --- a/src/McpProbe/Linting/ToolLinter.cs +++ b/src/McpProbe/Linting/ToolLinter.cs @@ -48,7 +48,7 @@ public static LintReport Lint(IEnumerable tools, LintOptions? opt /// Rule options. Defaults to defaults. /// The findings. public static LintReport Lint(ToolSurface surface, LintOptions? options = null) => - LintCore(surface, prompts: null, options); + LintCore(surface, contracts: null, options); /// Lints a captured tool surface and the prompts from prompts/list. /// The tool surface. @@ -58,12 +58,24 @@ public static LintReport Lint(ToolSurface surface, LintOptions? options = null) public static LintReport Lint(ToolSurface surface, IEnumerable prompts, LintOptions? options = null) { ArgumentNullException.ThrowIfNull(prompts); - return LintCore(surface, prompts, options); + return LintCore(surface, new LintListedContracts { Prompts = prompts.ToList() }, options); } - private static LintReport LintCore(ToolSurface surface, IEnumerable? prompts, LintOptions? options) + /// Lints a captured tool surface and the prompts, resource templates and resources the server listed. + /// The tool surface. + /// Listed prompts, resource templates, resources and protocol tools. If those contracts were not listed, call instead. + /// Rule options. Defaults to defaults. + /// The findings. + public static LintReport Lint(ToolSurface surface, LintListedContracts contracts, LintOptions? options = null) + { + ArgumentNullException.ThrowIfNull(contracts); + return LintCore(surface, contracts, options); + } + + private static LintReport LintCore(ToolSurface surface, LintListedContracts? contracts, LintOptions? options) { ArgumentNullException.ThrowIfNull(surface); + var prompts = contracts?.Prompts; options ??= new LintOptions(); if (options.MinToolDescriptionLength < 0) { @@ -112,6 +124,8 @@ private static LintReport LintCore(ToolSurface surface, IEnumerable? pro findings); LintPrompts(prompts, options, findings); + LintResources(contracts, options, findings); + LintIcons(contracts, options, findings); var listed = prompts is null ? LintListedKinds.None : LintListedKinds.Prompts; var (active, suppressed, unused) = LintSuppression.Apply(findings, options.Suppressions, options, listed); diff --git a/src/McpProbe/McpProbeHost.cs b/src/McpProbe/McpProbeHost.cs index 62cc01e..a811b97 100644 --- a/src/McpProbe/McpProbeHost.cs +++ b/src/McpProbe/McpProbeHost.cs @@ -193,9 +193,9 @@ public Task VerifyToolSnapshotAsync( /// The lint report. Call to fail a test on findings. public async Task LintToolsAsync(LintOptions? options = null, CancellationToken cancellationToken = default) { - var surface = await ToolSurface.CaptureAsync(Client, cancellationToken).ConfigureAwait(false); - var prompts = await ListedContracts.ListPromptsAsync(Client, cancellationToken).ConfigureAwait(false); - return prompts is null ? ToolLinter.Lint(surface, options) : ToolLinter.Lint(surface, prompts, options); + var contracts = await ListedContracts.ListAsync(Client, options?.LintResources ?? false, cancellationToken).ConfigureAwait(false); + var surface = ToolSurface.FromTools(contracts.Tools ?? []); + return ToolLinter.Lint(surface, contracts, options); } /// diff --git a/src/McpProbe/PublicAPI.Unshipped.txt b/src/McpProbe/PublicAPI.Unshipped.txt index 24f7e90..4507776 100644 --- a/src/McpProbe/PublicAPI.Unshipped.txt +++ b/src/McpProbe/PublicAPI.Unshipped.txt @@ -82,6 +82,16 @@ McpProbe.Linting.LintFinding.Severity.get -> McpProbe.Linting.LintSeverity McpProbe.Linting.LintFinding.Severity.init -> void McpProbe.Linting.LintFinding.ToolName.get -> string! McpProbe.Linting.LintFinding.ToolName.init -> void +McpProbe.Linting.LintListedContracts +McpProbe.Linting.LintListedContracts.LintListedContracts() -> void +McpProbe.Linting.LintListedContracts.Prompts.get -> System.Collections.Generic.IReadOnlyList? +McpProbe.Linting.LintListedContracts.Prompts.init -> void +McpProbe.Linting.LintListedContracts.ResourceTemplates.get -> System.Collections.Generic.IReadOnlyList? +McpProbe.Linting.LintListedContracts.ResourceTemplates.init -> void +McpProbe.Linting.LintListedContracts.Resources.get -> System.Collections.Generic.IReadOnlyList? +McpProbe.Linting.LintListedContracts.Resources.init -> void +McpProbe.Linting.LintListedContracts.Tools.get -> System.Collections.Generic.IReadOnlyList? +McpProbe.Linting.LintListedContracts.Tools.init -> void McpProbe.Linting.LintOptions McpProbe.Linting.LintOptions.Baseline.get -> McpProbe.Linting.LintBaseline? McpProbe.Linting.LintOptions.Baseline.set -> void @@ -91,6 +101,8 @@ McpProbe.Linting.LintOptions.DestructiveNameTokens.get -> System.Collections.Gen McpProbe.Linting.LintOptions.FailOn.get -> McpProbe.Linting.LintSeverity McpProbe.Linting.LintOptions.FailOn.set -> void McpProbe.Linting.LintOptions.LintOptions() -> void +McpProbe.Linting.LintOptions.LintResources.get -> bool +McpProbe.Linting.LintOptions.LintResources.set -> void McpProbe.Linting.LintOptions.MinToolDescriptionLength.get -> int McpProbe.Linting.LintOptions.MinToolDescriptionLength.set -> void McpProbe.Linting.LintOptions.MinToolDescriptionWords.get -> int @@ -317,6 +329,7 @@ static McpProbe.Linting.LintRule.operator ==(McpProbe.Linting.LintRule? left, Mc static McpProbe.Linting.LintRules.All.get -> System.Collections.Generic.IReadOnlyList! static McpProbe.Linting.LintSuppression.operator !=(McpProbe.Linting.LintSuppression? left, McpProbe.Linting.LintSuppression? right) -> bool static McpProbe.Linting.LintSuppression.operator ==(McpProbe.Linting.LintSuppression? left, McpProbe.Linting.LintSuppression? right) -> bool +static McpProbe.Linting.ToolLinter.Lint(McpProbe.Snapshots.ToolSurface! surface, McpProbe.Linting.LintListedContracts! contracts, McpProbe.Linting.LintOptions? options = null) -> McpProbe.Linting.LintReport! static McpProbe.Linting.ToolLinter.Lint(McpProbe.Snapshots.ToolSurface! surface, McpProbe.Linting.LintOptions? options = null) -> McpProbe.Linting.LintReport! static McpProbe.Linting.ToolLinter.Lint(McpProbe.Snapshots.ToolSurface! surface, System.Collections.Generic.IEnumerable! prompts, McpProbe.Linting.LintOptions? options = null) -> McpProbe.Linting.LintReport! static McpProbe.Linting.ToolLinter.Lint(System.Collections.Generic.IEnumerable! tools, McpProbe.Linting.LintOptions? options = null) -> McpProbe.Linting.LintReport! @@ -353,6 +366,8 @@ static readonly McpProbe.Linting.LintRules.InconsistentParameterNaming -> McpPro static readonly McpProbe.Linting.LintRules.InconsistentPromptArgumentNaming -> McpProbe.Linting.LintRule! static readonly McpProbe.Linting.LintRules.InconsistentPromptNaming -> McpProbe.Linting.LintRule! static readonly McpProbe.Linting.LintRules.InconsistentToolNaming -> McpProbe.Linting.LintRule! +static readonly McpProbe.Linting.LintRules.InvalidIcon -> McpProbe.Linting.LintRule! +static readonly McpProbe.Linting.LintRules.InvalidOrDuplicateIdentity -> McpProbe.Linting.LintRule! static readonly McpProbe.Linting.LintRules.InvalidPromptName -> McpProbe.Linting.LintRule! static readonly McpProbe.Linting.LintRules.InvalidToolName -> McpProbe.Linting.LintRule! static readonly McpProbe.Linting.LintRules.ParameterMissingDescription -> McpProbe.Linting.LintRule! @@ -361,6 +376,8 @@ static readonly McpProbe.Linting.LintRules.PromptDescriptionRestatesName -> McpP static readonly McpProbe.Linting.LintRules.PromptDescriptionTooShort -> McpProbe.Linting.LintRule! static readonly McpProbe.Linting.LintRules.PromptMissingDescription -> McpProbe.Linting.LintRule! static readonly McpProbe.Linting.LintRules.RemoteRef -> McpProbe.Linting.LintRule! +static readonly McpProbe.Linting.LintRules.ResourceMissingDescription -> McpProbe.Linting.LintRule! +static readonly McpProbe.Linting.LintRules.ResourceMissingName -> McpProbe.Linting.LintRule! static readonly McpProbe.Linting.LintRules.StructuredOutputWithoutSchema -> McpProbe.Linting.LintRule! static readonly McpProbe.Linting.LintRules.ToolDescriptionTooShort -> McpProbe.Linting.LintRule! static readonly McpProbe.Linting.LintRules.ToolMissingDescription -> McpProbe.Linting.LintRule! diff --git a/tests/McpProbe.Tests/LintConfigTests.cs b/tests/McpProbe.Tests/LintConfigTests.cs index c608555..f6f3986 100644 --- a/tests/McpProbe.Tests/LintConfigTests.cs +++ b/tests/McpProbe.Tests/LintConfigTests.cs @@ -217,7 +217,7 @@ public void KnownKeys_MatchWhatTheLoaderAccepts() lint[key] = key switch { "failOn" => "info", - "strict" or "nested" => true, + "strict" or "nested" or "resources" => true, "minDescriptionLength" or "minDescriptionWords" => 1, "rules" => new JsonObject(), "baseline" => "mcpprobe-lint-baseline.json", diff --git a/tests/McpProbe.Tests/PromptLinterTests.cs b/tests/McpProbe.Tests/PromptLinterTests.cs index 00b9b26..988f437 100644 --- a/tests/McpProbe.Tests/PromptLinterTests.cs +++ b/tests/McpProbe.Tests/PromptLinterTests.cs @@ -231,10 +231,10 @@ public async Task Host_ListsPrompts_WhenCapabilityPresent() { await using var probe = await McpProbeHost.StartAsync(mcp => mcp.WithPromptsFromAssembly(typeof(WeatherPrompts).Assembly), TestContext.Current.CancellationToken); - var prompts = await ListedContracts.ListPromptsAsync(probe.Client, TestContext.Current.CancellationToken); + var prompts = await ListedContracts.ListAsync(probe.Client, includeResources: false, TestContext.Current.CancellationToken); - Assert.NotNull(prompts); - Assert.Contains(prompts, p => p.Name == "plan_trip"); + Assert.NotNull(prompts.Prompts); + Assert.Contains(prompts.Prompts, p => p.Name == "plan_trip"); } [Fact] @@ -242,10 +242,10 @@ public async Task Host_NoPromptsCapability_DoesNotListPrompts() { await using var probe = await McpProbeHost.StartAsync(mcp => mcp.WithToolsFromAssembly(typeof(WeatherTools).Assembly), TestContext.Current.CancellationToken); - var prompts = await ListedContracts.ListPromptsAsync(probe.Client, TestContext.Current.CancellationToken); + var prompts = await ListedContracts.ListAsync(probe.Client, includeResources: false, TestContext.Current.CancellationToken); var report = await probe.LintToolsAsync(cancellationToken: TestContext.Current.CancellationToken); - Assert.Null(prompts); + Assert.Null(prompts.Prompts); Assert.DoesNotContain(report.Findings, f => f.Kind == LintTargetKind.Prompt); } diff --git a/tests/McpProbe.Tests/ResourceLinterTests.cs b/tests/McpProbe.Tests/ResourceLinterTests.cs new file mode 100644 index 0000000..7635f07 --- /dev/null +++ b/tests/McpProbe.Tests/ResourceLinterTests.cs @@ -0,0 +1,210 @@ +using McpProbe.Internal; +using McpProbe.Linting; +using McpProbe.Snapshots; +using Microsoft.Extensions.DependencyInjection; +using ModelContextProtocol.Protocol; +using WeatherServer; + +namespace McpProbe.Tests; + +public sealed class ResourceLinterTests +{ + private static readonly ToolSurface EmptySurface = ToolSurface.Parse("""{"formatVersion":1,"tools":[]}"""); + + private static ResourceTemplate T(string uriTemplate, string? name = "cities", string? description = "The cities this server has forecasts for.", IList? icons = null) => + new() { UriTemplate = uriTemplate, Name = name!, Description = description, Icons = icons }; + + private static Resource R(string uri, string? name = "readme", string? description = "The project readme file contents.", IList? icons = null) => + new() { Uri = uri, Name = name!, Description = description, Icons = icons }; + + private static Icon I(string src, string? mime = null, string? theme = null, params string[] sizes) => + new() { Source = src, MimeType = mime, Theme = theme, Sizes = sizes.Length == 0 ? null : sizes }; + + private static IReadOnlyList Lint(LintListedContracts contracts, LintOptions? options = null) => + ToolLinter.Lint(EmptySurface, contracts, options).Findings; + + [Fact] + public void NothingListed_NoFindings() + { + Assert.Empty(Lint(new LintListedContracts())); + Assert.Empty(ToolLinter.Lint(EmptySurface, (LintListedContracts?)null).Findings); + } + + [Fact] + public void GoodTemplate_NoFindings() + { + Assert.Empty(Lint(new LintListedContracts { ResourceTemplates = [T("weather://cities/{city}")] })); + } + + [Fact] + public void MCPP025_TemplateMissingDescription() + { + var finding = Assert.Single(Lint(new LintListedContracts { ResourceTemplates = [T("weather://cities", description: " ")] })); + + Assert.Equal(("MCPP025", LintSeverity.Warning, "weather://cities", LintTargetKind.ResourceTemplate), (finding.RuleId, finding.Severity, finding.ToolName, finding.Kind)); + Assert.StartsWith("warning MCPP025 resource template weather://cities:", finding.ToString(), StringComparison.Ordinal); + } + + [Fact] + public void MCPP027_TemplateMissingName() + { + var finding = Assert.Single(Lint(new LintListedContracts { ResourceTemplates = [T("weather://cities", name: "")] })); + + Assert.Equal("MCPP027", finding.RuleId); + } + + [Theory] + [InlineData("")] + [InlineData(" ")] + [InlineData("cities/{city}")] + [InlineData("{scheme}://cities")] + public void MCPP026_InvalidTemplateIdentity(string uriTemplate) + { + var findings = Lint(new LintListedContracts { ResourceTemplates = [T(uriTemplate)] }); + + Assert.Contains(findings, f => f.RuleId == "MCPP026" && f.Severity == LintSeverity.Error && f.Kind == LintTargetKind.ResourceTemplate); + } + + [Theory] + [InlineData("file:///{path}")] + [InlineData("weather://cities{?units}")] + [InlineData("urn:example:{id}")] + public void MCPP026_ValidTemplateIdentity(string uriTemplate) + { + Assert.DoesNotContain(Lint(new LintListedContracts { ResourceTemplates = [T(uriTemplate)] }), f => f.RuleId == "MCPP026"); + } + + [Fact] + public void MCPP026_DuplicateTemplates() + { + var findings = Lint(new LintListedContracts { ResourceTemplates = [T("weather://cities"), T("weather://cities")] }); + + var finding = Assert.Single(findings); + Assert.Equal("MCPP026", finding.RuleId); + Assert.Contains("more than once", finding.Message, StringComparison.Ordinal); + } + + [Fact] + public void MCPP026_DuplicatePromptNames() + { + var prompts = new[] + { + new Prompt { Name = "plan_trip", Description = "Asks the model to plan what to pack for a trip." }, + new Prompt { Name = "plan_trip", Description = "Asks the model to plan what to pack for a trip." }, + }; + + var finding = Assert.Single(Lint(new LintListedContracts { Prompts = prompts })); + + Assert.Equal(("MCPP026", LintTargetKind.Prompt), (finding.RuleId, finding.Kind)); + } + + [Fact] + public void ListedResources_NotLintedByDefault() + { + Assert.Empty(Lint(new LintListedContracts { Resources = [R("readme.txt", name: "", description: null)] })); + } + + [Theory] + [InlineData("")] + [InlineData("readme.txt")] + public void MCPP026_InvalidResourceUri_WithResources(string uri) + { + var findings = Lint(new LintListedContracts { Resources = [R(uri)] }, new LintOptions { LintResources = true }); + + Assert.Contains(findings, f => f.RuleId == "MCPP026" && f.Kind == LintTargetKind.Resource); + } + + [Fact] + public void ListedResources_DescriptionAndName_WithResources() + { + var findings = Lint(new LintListedContracts { Resources = [R("file:///readme.txt", name: "", description: null)] }, new LintOptions { LintResources = true }); + + Assert.Equal(["MCPP025", "MCPP027"], findings.Select(f => f.RuleId).Order(StringComparer.Ordinal)); + Assert.All(findings, f => Assert.Equal(LintTargetKind.Resource, f.Kind)); + } + + [Fact] + public void MCPP026_DuplicateResources_WithResources() + { + var findings = Lint(new LintListedContracts { Resources = [R("file:///a.txt"), R("file:///a.txt")] }, new LintOptions { LintResources = true }); + + Assert.Equal("MCPP026", Assert.Single(findings).RuleId); + } + + [Fact] + public void MCPP028_GoodIcons_NoFindings() + { + var icons = new List { I("https://example.com/icon.png", "image/png", "dark", "48x48", "any"), I("data:image/svg+xml;base64,PHN2Zz4=") }; + + Assert.Empty(Lint(new LintListedContracts { Tools = [new Tool { Name = "get_forecast", Description = "Gets the forecast for a city.", Icons = icons }] })); + } + + [Fact] + public void MCPP028_BadIconFields() + { + var icons = new List { I("ftp://example.com/i.png", "png", "Dark", "48", "48x"), I("") }; + + var findings = Lint(new LintListedContracts { Tools = [new Tool { Name = "get_forecast", Icons = icons }] }); + + Assert.Equal( + ["icons[0].mimeType", "icons[0].sizes[0]", "icons[0].sizes[1]", "icons[0].src", "icons[0].theme", "icons[1].src"], + findings.Where(f => f.RuleId == "MCPP028").Select(f => f.ParameterName).Order(StringComparer.Ordinal)); + Assert.All(findings.Where(f => f.RuleId == "MCPP028"), f => Assert.Equal((LintSeverity.Warning, LintTargetKind.Tool), (f.Severity, f.Kind))); + } + + [Fact] + public void MCPP028_PromptAndTemplateIcons() + { + var contracts = new LintListedContracts + { + Prompts = [new Prompt { Name = "plan_trip", Description = "Asks the model to plan what to pack for a trip.", Icons = [I("/icon.png")] }], + ResourceTemplates = [T("weather://cities", icons: [I("icons/city.png")])], + }; + + var findings = Lint(contracts); + + Assert.Equal([LintTargetKind.Prompt, LintTargetKind.ResourceTemplate], findings.Select(f => f.Kind).Order()); + Assert.All(findings, f => Assert.Equal("MCPP028", f.RuleId)); + } + + [Fact] + public void MCPP028_ResourceIcons_OnlyWithResources() + { + var contracts = new LintListedContracts { Resources = [R("file:///a.txt", icons: [I("/i.png")])] }; + + Assert.Empty(Lint(contracts)); + Assert.Equal("MCPP028", Assert.Single(Lint(contracts, new LintOptions { LintResources = true })).RuleId); + } + + [Fact] + public void MCPP028_MissingIconsArray_NoFinding() + { + Assert.Empty(Lint(new LintListedContracts { Tools = [new Tool { Name = "get_forecast", Description = "Gets the forecast for a city." }] })); + } + + [Fact] + public async Task Host_LintsResourceTemplates_FromSampleServer() + { + await using var probe = await McpProbeHost.StartAsync(mcp => mcp.WithWeatherFeatures(), TestContext.Current.CancellationToken); + + var contracts = await ListedContracts.ListAsync(probe.Client, includeResources: true, TestContext.Current.CancellationToken); + var report = await probe.LintToolsAsync(cancellationToken: TestContext.Current.CancellationToken); + + // The SDK lists a resource without template expressions in resources/list, not resources/templates/list. + Assert.NotNull(contracts.ResourceTemplates); + Assert.Empty(contracts.ResourceTemplates); + Assert.Contains(contracts.Resources!, r => r.Uri == "weather://cities"); + Assert.Empty(report.Findings); + } + + [Fact] + public async Task Listing_NoResourcesCapability_DoesNotListTemplates() + { + await using var probe = await McpProbeHost.StartAsync(mcp => mcp.WithToolsFromAssembly(typeof(WeatherTools).Assembly), TestContext.Current.CancellationToken); + + var contracts = await ListedContracts.ListAsync(probe.Client, includeResources: true, TestContext.Current.CancellationToken); + + Assert.Null(contracts.ResourceTemplates); + Assert.Null(contracts.Resources); + } +} diff --git a/tests/McpProbe.Tests/ToolLinterTests.cs b/tests/McpProbe.Tests/ToolLinterTests.cs index aa5784c..8cbb03d 100644 --- a/tests/McpProbe.Tests/ToolLinterTests.cs +++ b/tests/McpProbe.Tests/ToolLinterTests.cs @@ -294,7 +294,7 @@ public void Report_SummarizesCounts() public void Rules_HaveUniqueIds() { Assert.Equal(LintRules.All.Count, LintRules.All.Select(r => r.Id).Distinct().Count()); - Assert.Equal(["MCPP001", "MCPP002", "MCPP003", "MCPP004", "MCPP005", "MCPP006", "MCPP007", "MCPP009", "MCPP010", "MCPP011", "MCPP012", "MCPP013", "MCPP014", "MCPP015", "MCPP016", "MCPP017", "MCPP018", "MCPP019", "MCPP020", "MCPP021", "MCPP022", "MCPP023", "MCPP024"], LintRules.All.Select(r => r.Id)); + Assert.Equal(["MCPP001", "MCPP002", "MCPP003", "MCPP004", "MCPP005", "MCPP006", "MCPP007", "MCPP009", "MCPP010", "MCPP011", "MCPP012", "MCPP013", "MCPP014", "MCPP015", "MCPP016", "MCPP017", "MCPP018", "MCPP019", "MCPP020", "MCPP021", "MCPP022", "MCPP023", "MCPP024", "MCPP025", "MCPP026", "MCPP027", "MCPP028"], LintRules.All.Select(r => r.Id)); Assert.DoesNotContain(LintRules.All, r => r.Id == "MCPP008"); } From 14bc7e18e079154e6352f06ec319fed44919ac18 Mon Sep 17 00:00:00 2001 From: Lior Shmueli <48066416+ShmueLior@users.noreply.github.com> Date: Fri, 4 Dec 2026 09:18:12 +0200 Subject: [PATCH 2/5] Count resource templates and resources as listed for stale baseline entries, write resourceTemplate kind --- src/McpProbe/Linting/LintBaseline.cs | 2 +- src/McpProbe/Linting/ToolLinter.cs | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/McpProbe/Linting/LintBaseline.cs b/src/McpProbe/Linting/LintBaseline.cs index ab507ee..add718a 100644 --- a/src/McpProbe/Linting/LintBaseline.cs +++ b/src/McpProbe/Linting/LintBaseline.cs @@ -138,7 +138,7 @@ public string ToJson() if (entry.Kind is { } kind && kind != LintTargetKind.Tool) { - node["kind"] = LintFinding.KindLabel(kind); + node["kind"] = kind == LintTargetKind.ResourceTemplate ? "resourceTemplate" : LintFinding.KindLabel(kind); } findings.Add(node); diff --git a/src/McpProbe/Linting/ToolLinter.cs b/src/McpProbe/Linting/ToolLinter.cs index 1f50431..0c55ccb 100644 --- a/src/McpProbe/Linting/ToolLinter.cs +++ b/src/McpProbe/Linting/ToolLinter.cs @@ -127,7 +127,22 @@ private static LintReport LintCore(ToolSurface surface, LintListedContracts? con LintResources(contracts, options, findings); LintIcons(contracts, options, findings); - var listed = prompts is null ? LintListedKinds.None : LintListedKinds.Prompts; + var listed = LintListedKinds.None; + if (prompts is not null) + { + listed |= LintListedKinds.Prompts; + } + + if (contracts?.ResourceTemplates is not null) + { + listed |= LintListedKinds.ResourceTemplates; + } + + if (options.LintResources && contracts?.Resources is not null) + { + listed |= LintListedKinds.Resources; + } + var (active, suppressed, unused) = LintSuppression.Apply(findings, options.Suppressions, options, listed); var (remaining, baselined, stale) = LintBaseline.Apply(findings, active, options.Baseline, options, listed); return new LintReport(Order(remaining), options.FailOn, Order(suppressed), unused, Order(baselined), stale); From c5ced208410614ad0f03c6143075c72d399a20c6 Mon Sep 17 00:00:00 2001 From: Lior Shmueli <48066416+ShmueLior@users.noreply.github.com> Date: Fri, 4 Dec 2026 09:21:35 +0200 Subject: [PATCH 3/5] Flag rooted paths as invalid resource URIs and show (empty) for a missing identity --- src/McpProbe/Linting/LintFinding.cs | 3 ++- src/McpProbe/Linting/ResourceLinter.cs | 3 ++- tests/McpProbe.Tests/ResourceLinterTests.cs | 9 +++++++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/McpProbe/Linting/LintFinding.cs b/src/McpProbe/Linting/LintFinding.cs index 3c0291b..58710c9 100644 --- a/src/McpProbe/Linting/LintFinding.cs +++ b/src/McpProbe/Linting/LintFinding.cs @@ -18,7 +18,8 @@ public sealed record LintFinding(string RuleId, LintSeverity Severity, string To /// public override string ToString() { - var name = string.IsNullOrEmpty(ParameterName) ? Printable.Text(ToolName, 100) : $"{Printable.Text(ToolName, 100)}.{Printable.Text(ParameterName, 100)}"; + var entity = ToolName.Length == 0 && Kind != LintTargetKind.Tool ? "(empty)" : Printable.Text(ToolName, 100); + var name = string.IsNullOrEmpty(ParameterName) ? entity : $"{entity}.{Printable.Text(ParameterName, 100)}"; var target = Kind == LintTargetKind.Tool ? name : $"{KindLabel(Kind)} {name}"; return $"{SeverityLabel(Severity)} {RuleId} {target}: {Printable.Text(Message, 500)}"; } diff --git a/src/McpProbe/Linting/ResourceLinter.cs b/src/McpProbe/Linting/ResourceLinter.cs index aa4620a..3d485f6 100644 --- a/src/McpProbe/Linting/ResourceLinter.cs +++ b/src/McpProbe/Linting/ResourceLinter.cs @@ -92,7 +92,8 @@ private static void CheckTemplateIdentity(string id, HashSet seen, LintO private static void CheckResourceIdentity(string id, HashSet seen, LintOptions options, List findings) { - if (string.IsNullOrWhiteSpace(id) || !Uri.TryCreate(id, UriKind.Absolute, out var uri) || uri.Scheme.Length == 0) + // Uri.TryCreate treats a rooted path like "/docs/a.txt" (or "C:\a.txt" on Windows) as a file URI, so also require a scheme in the text. + if (string.IsNullOrWhiteSpace(id) || !SchemePrefix().IsMatch(id) || !Uri.TryCreate(id, UriKind.Absolute, out var uri) || uri.Scheme.Length == 0) { Add(findings, options, LintRules.InvalidOrDuplicateIdentity, id, null, string.IsNullOrWhiteSpace(id) diff --git a/tests/McpProbe.Tests/ResourceLinterTests.cs b/tests/McpProbe.Tests/ResourceLinterTests.cs index 7635f07..0d3427b 100644 --- a/tests/McpProbe.Tests/ResourceLinterTests.cs +++ b/tests/McpProbe.Tests/ResourceLinterTests.cs @@ -107,6 +107,7 @@ public void ListedResources_NotLintedByDefault() [Theory] [InlineData("")] [InlineData("readme.txt")] + [InlineData("/docs/readme.txt")] public void MCPP026_InvalidResourceUri_WithResources(string uri) { var findings = Lint(new LintListedContracts { Resources = [R(uri)] }, new LintOptions { LintResources = true }); @@ -207,4 +208,12 @@ public async Task Listing_NoResourcesCapability_DoesNotListTemplates() Assert.Null(contracts.ResourceTemplates); Assert.Null(contracts.Resources); } + + [Fact] + public void FindingToString_EmptyIdentity_ShowsPlaceholder() + { + var finding = Assert.Single(Lint(new LintListedContracts { ResourceTemplates = [T("")] }), f => f.RuleId == "MCPP026"); + + Assert.StartsWith("error MCPP026 resource template (empty):", finding.ToString(), StringComparison.Ordinal); + } } From e653d3b038731aca41f6d4b95a0e1864a91fb871 Mon Sep 17 00:00:00 2001 From: Lior Shmueli <48066416+ShmueLior@users.noreply.github.com> Date: Fri, 4 Dec 2026 09:34:14 +0200 Subject: [PATCH 4/5] Reject Windows drive-letter resource URIs and keep Lint(surface, null) bound to options A path such as C:\a.txt matches a scheme-prefix regex as C: and can parse as a file URI on Windows. The parsed scheme must now also be a prefix of the original text. Lint overloads for prompts and listed contracts are non-nullable so Lint(surface, null) still means options. Docs now say MCPP028 does not run on --from-file, which stays true after snapshots gain icons. --- CHANGELOG.md | 2 +- README.md | 2 +- src/McpProbe.Cli/CliApp.cs | 2 +- src/McpProbe/Linting/LintReport.cs | 2 +- src/McpProbe/Linting/ResourceLinter.cs | 6 ++++-- tests/McpProbe.Tests/ResourceLinterTests.cs | 23 ++++++++++++++++++++- 6 files changed, 30 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 17bc643..e371322 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +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, and snapshots don't carry icons. +- 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`. diff --git a/README.md b/README.md index 12eb162..9d0998c 100644 --- a/README.md +++ b/README.md @@ -168,7 +168,7 @@ Set `LintOptions.Strict = true` (CLI: `mcpprobe lint --strict`) to also run MCPP `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. A snapshot doesn't carry icons, so `--from-file` doesn't check them. Icons are never fetched. +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. diff --git a/src/McpProbe.Cli/CliApp.cs b/src/McpProbe.Cli/CliApp.cs index 180010c..b81da98 100644 --- a/src/McpProbe.Cli/CliApp.cs +++ b/src/McpProbe.Cli/CliApp.cs @@ -40,7 +40,7 @@ public static async Task 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), diff --git a/src/McpProbe/Linting/LintReport.cs b/src/McpProbe/Linting/LintReport.cs index 1d43106..918f4e3 100644 --- a/src/McpProbe/Linting/LintReport.cs +++ b/src/McpProbe/Linting/LintReport.cs @@ -136,7 +136,7 @@ public string ToHtml() { LintFinding.SeverityLabel(f.Severity), f.RuleId, - f.Kind == LintTargetKind.Tool ? Printable.Text(f.ToolName, 100) : $"{LintFinding.KindLabel(f.Kind)} {Printable.Text(f.ToolName, 100)}", + f.Kind == LintTargetKind.Tool ? Printable.Text(f.ToolName, 100) : $"{LintFinding.KindLabel(f.Kind)} {(f.ToolName.Length == 0 ? "(empty)" : Printable.Text(f.ToolName, 100))}", string.IsNullOrEmpty(f.ParameterName) ? string.Empty : Printable.Text(f.ParameterName, 100), Printable.Text(f.Message, 500), FindingFails(f) ? "yes" : "no", diff --git a/src/McpProbe/Linting/ResourceLinter.cs b/src/McpProbe/Linting/ResourceLinter.cs index 3d485f6..231bb13 100644 --- a/src/McpProbe/Linting/ResourceLinter.cs +++ b/src/McpProbe/Linting/ResourceLinter.cs @@ -92,8 +92,10 @@ private static void CheckTemplateIdentity(string id, HashSet seen, LintO private static void CheckResourceIdentity(string id, HashSet seen, LintOptions options, List findings) { - // Uri.TryCreate treats a rooted path like "/docs/a.txt" (or "C:\a.txt" on Windows) as a file URI, so also require a scheme in the text. - if (string.IsNullOrWhiteSpace(id) || !SchemePrefix().IsMatch(id) || !Uri.TryCreate(id, UriKind.Absolute, out var uri) || uri.Scheme.Length == 0) + // Uri.TryCreate treats a rooted path like "/docs/a.txt" (or "C:\a.txt" on Windows) as a file URI. + // SchemePrefix alone is not enough: "C:\a.txt" looks like scheme "C". The parsed scheme must also be a prefix of the text. + if (string.IsNullOrWhiteSpace(id) || !SchemePrefix().IsMatch(id) || !Uri.TryCreate(id, UriKind.Absolute, out var uri) || uri.Scheme.Length == 0 || + !id.StartsWith(uri.Scheme + ":", StringComparison.OrdinalIgnoreCase)) { Add(findings, options, LintRules.InvalidOrDuplicateIdentity, id, null, string.IsNullOrWhiteSpace(id) diff --git a/tests/McpProbe.Tests/ResourceLinterTests.cs b/tests/McpProbe.Tests/ResourceLinterTests.cs index 0d3427b..a34572b 100644 --- a/tests/McpProbe.Tests/ResourceLinterTests.cs +++ b/tests/McpProbe.Tests/ResourceLinterTests.cs @@ -27,7 +27,8 @@ private static IReadOnlyList Lint(LintListedContracts contracts, Li public void NothingListed_NoFindings() { Assert.Empty(Lint(new LintListedContracts())); - Assert.Empty(ToolLinter.Lint(EmptySurface, (LintListedContracts?)null).Findings); + Assert.Empty(ToolLinter.Lint(EmptySurface).Findings); + Assert.Empty(ToolLinter.Lint(EmptySurface, (LintOptions?)null).Findings); } [Fact] @@ -108,6 +109,8 @@ public void ListedResources_NotLintedByDefault() [InlineData("")] [InlineData("readme.txt")] [InlineData("/docs/readme.txt")] + [InlineData("C:\\a.txt")] + [InlineData("C:/a.txt")] public void MCPP026_InvalidResourceUri_WithResources(string uri) { var findings = Lint(new LintListedContracts { Resources = [R(uri)] }, new LintOptions { LintResources = true }); @@ -115,6 +118,16 @@ public void MCPP026_InvalidResourceUri_WithResources(string uri) Assert.Contains(findings, f => f.RuleId == "MCPP026" && f.Kind == LintTargetKind.Resource); } + [Theory] + [InlineData("https://example.com/a.txt")] + [InlineData("weather://cities")] + [InlineData("file:///readme.txt")] + [InlineData("urn:example:res:1")] + public void MCPP026_ValidResourceUri_WithResources(string uri) + { + Assert.DoesNotContain(Lint(new LintListedContracts { Resources = [R(uri)] }, new LintOptions { LintResources = true }), f => f.RuleId == "MCPP026"); + } + [Fact] public void ListedResources_DescriptionAndName_WithResources() { @@ -216,4 +229,12 @@ public void FindingToString_EmptyIdentity_ShowsPlaceholder() Assert.StartsWith("error MCPP026 resource template (empty):", finding.ToString(), StringComparison.Ordinal); } + [Fact] + public void HtmlReport_EmptyIdentity_ShowsPlaceholder() + { + var report = ToolLinter.Lint(EmptySurface, new LintListedContracts { ResourceTemplates = [T("")] }); + + Assert.Contains("resource template (empty)", report.ToHtml(), StringComparison.Ordinal); + } + } From 541553154460697e51429f804f96b676bff35031 Mon Sep 17 00:00:00 2001 From: Lior Shmueli <48066416+ShmueLior@users.noreply.github.com> Date: Fri, 4 Dec 2026 09:54:50 +0200 Subject: [PATCH 5/5] Add resource lint rules to the SARIF golden and cover JSON kinds --- src/McpProbe/Linting/LintBaseline.cs | 2 +- tests/McpProbe.Tests/Goldens/lint.sarif | 64 +++++++++++++++++++ .../MachineReadableOutputTests.cs | 23 +++++++ 3 files changed, 88 insertions(+), 1 deletion(-) diff --git a/src/McpProbe/Linting/LintBaseline.cs b/src/McpProbe/Linting/LintBaseline.cs index add718a..fd28cdf 100644 --- a/src/McpProbe/Linting/LintBaseline.cs +++ b/src/McpProbe/Linting/LintBaseline.cs @@ -138,7 +138,7 @@ public string ToJson() if (entry.Kind is { } kind && kind != LintTargetKind.Tool) { - node["kind"] = kind == LintTargetKind.ResourceTemplate ? "resourceTemplate" : LintFinding.KindLabel(kind); + node["kind"] = LintFinding.JsonKind(kind); } findings.Add(node); diff --git a/tests/McpProbe.Tests/Goldens/lint.sarif b/tests/McpProbe.Tests/Goldens/lint.sarif index 74f3105..56b21c3 100644 --- a/tests/McpProbe.Tests/Goldens/lint.sarif +++ b/tests/McpProbe.Tests/Goldens/lint.sarif @@ -377,6 +377,70 @@ "tools" ] } + }, + { + "id": "MCPP025", + "name": "MCPP025", + "shortDescription": { + "text": "Resource or resource template has no description" + }, + "defaultConfiguration": { + "level": "warning" + }, + "properties": { + "tags": [ + "mcp", + "tools" + ] + } + }, + { + "id": "MCPP026", + "name": "MCPP026", + "shortDescription": { + "text": "Missing, invalid or duplicate identity" + }, + "defaultConfiguration": { + "level": "error" + }, + "properties": { + "tags": [ + "mcp", + "tools" + ] + } + }, + { + "id": "MCPP027", + "name": "MCPP027", + "shortDescription": { + "text": "Resource or resource template has no name" + }, + "defaultConfiguration": { + "level": "warning" + }, + "properties": { + "tags": [ + "mcp", + "tools" + ] + } + }, + { + "id": "MCPP028", + "name": "MCPP028", + "shortDescription": { + "text": "Invalid icon" + }, + "defaultConfiguration": { + "level": "warning" + }, + "properties": { + "tags": [ + "mcp", + "tools" + ] + } } ] } diff --git a/tests/McpProbe.Tests/MachineReadableOutputTests.cs b/tests/McpProbe.Tests/MachineReadableOutputTests.cs index 2b8f2ad..1d38fc1 100644 --- a/tests/McpProbe.Tests/MachineReadableOutputTests.cs +++ b/tests/McpProbe.Tests/MachineReadableOutputTests.cs @@ -372,6 +372,29 @@ public void LintSarif_PromptFingerprint_IncludesKind() } } + [Fact] + public void LintJson_ResourceFindings_IncludeKind() + { + var empty = ToolSurface.Parse("{\"formatVersion\":1,\"tools\":[]}"); + var contracts = new LintListedContracts + { + ResourceTemplates = [new ModelContextProtocol.Protocol.ResourceTemplate { UriTemplate = "weather://cities/{city}", Name = "cities" }], + Resources = [new ModelContextProtocol.Protocol.Resource { Uri = "file:///a.txt", Name = "readme" }], + }; + var json = ToolLinter.Lint(empty, contracts, new LintOptions { LintResources = true }).ToJson(); + + using (var doc = JsonDocument.Parse(json)) + { + var kinds = doc.RootElement.GetProperty("findings").EnumerateArray() + .Select(f => f.GetProperty("kind").GetString()) + .ToHashSet(StringComparer.Ordinal); + Assert.Contains("resourceTemplate", kinds); + Assert.Contains("resource", kinds); + } + + AssertValid(Path.Combine(RepoRoot(), "docs", "mcpprobe-report.schema.json"), json); + } + [Fact] public void DiffJson_IconChange_IsIconsChanged() {