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

## [Unreleased]

### Added

- MCPP008: flags a `required` entry with no matching property (for example after a parameter rename that forgot to update `required`). Runs by default, like MCPP001-MCPP007, on `inputSchema` only; with `--nested`, also checks nested objects and array items. `allOf` branches are unioned into the check (following local `$ref`s); `anyOf`/`oneOf` are skipped, since only one branch has to apply. A `required` written alongside a `$ref` is checked against the ref's resolved properties, not dropped.

### Changed

- Package tags now include `mcp-server`, `dotnet` and `csharp`. The README opening line describes McpProbe as a .NET test kit for C# MCP server testing.
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ strict.ThrowIfFailed();
| MCPP005 | warning | All tool names use the same style (snake_case, camelCase, ...). |
| MCPP006 | warning | All parameter names use the same style. |
| MCPP007 | info | Parameter names aren't vague (`data`, `value`, `input`, ...). A top-level `value` or `data` is fine on a tool named `create_*`, `set_*`, `publish_*` and similar (`PayloadContextTokens`). |
| MCPP008 | error | Every name in `required` is defined in `properties` (checks `inputSchema` only, not `outputSchema`). `allOf` branches are unioned into the same check; `anyOf`/`oneOf` are skipped, since only one branch has to apply. A property defined through a local `$ref` counts as defined, including a `required` written alongside a `$ref`; an unresolved `$ref` is skipped to avoid false positives. |
| MCPP009 | error | No bare `true`/`false` where a schema object is expected (`--strict`). |
| MCPP010 | warning | `type` is not a union array (`--strict`). `[T, "null"]`, the nullable spelling the C# and Go SDKs emit, is not reported. |
| MCPP011 | warning | Every schema has a constraining keyword (`--strict`). |
Expand All @@ -141,9 +142,9 @@ strict.ThrowIfFailed();
| MCPP015 | warning | The description says more than the tool name or title. |
| MCPP016 | warning | No empty `enum`, and an `enum` declares its `type`. |

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.
Change severities with `LintOptions.Severities["MCPP007"] = LintSeverity.None`, and the threshold with `LintOptions.FailOn`. By default MCPP003, MCPP006, MCPP007 and MCPP008 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.
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`.

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.

Expand Down
1 change: 1 addition & 0 deletions docs/mcpprobe.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
"MCPP005",
"MCPP006",
"MCPP007",
"MCPP008",
"MCPP009",
"MCPP010",
"MCPP011",
Expand Down
2 changes: 1 addition & 1 deletion src/McpProbe/Linting/LintOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public sealed class LintOptions
public LintSeverity FailOn { get; set; } = LintSeverity.Warning;

/// <summary>
/// Gets or sets whether MCPP003, MCPP006 and MCPP007 also check nested object properties and array items
/// Gets or sets whether MCPP003, MCPP006, MCPP007 and MCPP008 also check nested object properties and array items
/// (reported as <c>address.zip</c> or <c>stops[].city</c>), following local <c>$ref</c>s. Defaults to <see langword="false"/>:
/// only top-level parameters are checked.
/// </summary>
Expand Down
4 changes: 3 additions & 1 deletion src/McpProbe/Linting/LintRule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ public static class LintRules
/// <summary>MCPP007: a parameter has a vague name such as <c>data</c> or <c>value</c>.</summary>
public static readonly LintRule VagueParameterName = new("MCPP007", "Parameter name is vague", LintSeverity.Info);

// MCPP008 is reserved for https://github.com/ShmueLior/mcpprobe/issues/8 (required entry with no property).
/// <summary>MCPP008: a <c>required</c> entry has no matching property.</summary>
public static readonly LintRule RequiredPropertyNotDefined = new("MCPP008", "Required parameter has no matching property", LintSeverity.Error);

/// <summary>MCPP009: a bare <c>true</c> or <c>false</c> is used where a schema object is expected. Requires <see cref="LintOptions.Strict"/>, or a severity override.</summary>
public static readonly LintRule BooleanSchema = new("MCPP009", "Bare boolean used where a schema object is expected", LintSeverity.Error);
Expand Down Expand Up @@ -66,6 +67,7 @@ public static class LintRules
InconsistentToolNaming,
InconsistentParameterNaming,
VagueParameterName,
RequiredPropertyNotDefined,
BooleanSchema,
TypeUnion,
UntypedSchema,
Expand Down
87 changes: 87 additions & 0 deletions src/McpProbe/Linting/ToolLinter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ private static List<LintFinding> Order(List<LintFinding> findings) => findings
private static void LintProperties(Walk walk, JsonNode? schema, string? prefix)
{
var nested = walk.Options.CheckNestedParameters;
var original = schema;

// Follow local refs. Each schema is linted once, at the first path that reaches it, so a type used
// twice or a recursive type doesn't repeat its findings.
Expand All @@ -131,6 +132,10 @@ private static void LintProperties(Walk walk, JsonNode? schema, string? prefix)
LintProperties(walk, items, prefix + "[]");
}

// Independent of 'nested': this only looks at the current node (plus local $refs and allOf branches
// it names), not at whether we also recurse further down.
CheckRequiredProperties(walk, original, prefix);

var properties = JsonSchemaReader.GetProperties(schema);
if (properties is null)
{
Expand Down Expand Up @@ -164,6 +169,88 @@ private static void LintProperties(Walk walk, JsonNode? schema, string? prefix)
}
}

private const int MaxCompositionDepth = 16;

// 'schema' is the node as written, before any $ref swap the caller made for its own purposes: a sibling
// 'required' next to a $ref describes the same object as the ref's target, so it must be checked against
// the ref's resolved properties, not dropped. Runs regardless of CheckNestedParameters.
private static void CheckRequiredProperties(Walk walk, JsonNode? schema, string? prefix)
{
var (tool, options, findings) = (walk.Tool, walk.Options, walk.Findings);
if (options.SeverityOf(LintRules.RequiredPropertyNotDefined) == LintSeverity.None)
{
return;
}

var required = new HashSet<string>(StringComparer.Ordinal);
var properties = new HashSet<string>(StringComparer.Ordinal);
if (!CollectRequiredAndProperties(schema, walk.Root, required, properties, depth: 0))
{
return;
}

foreach (var name in required)
{
if (!properties.Contains(name))
{
var path = prefix is null ? name : $"{prefix}.{name}";
var noun = prefix is null ? "Parameter" : "Property";
Add(findings, options, LintRules.RequiredPropertyNotDefined, tool, path,
$"{noun} '{path}' is required but not defined in properties.");
}
}
}

// Follows a local $ref (via TryResolveRef, so a sibling keyword like 'required' is merged rather than lost)
// and treats 'allOf' branches as additive: they describe the same instance, so their properties and required
// names are unioned (following refs inside a branch too). 'anyOf'/'oneOf' pick between alternatives that
// can't be resolved statically, so their presence anywhere in the walk makes the whole check bail out rather
// than guess which branch applies; an unresolved $ref bails out for the same reason.
private static bool CollectRequiredAndProperties(JsonNode? schema, JsonNode? root, HashSet<string> required, HashSet<string> properties, int depth)
{
if (depth > MaxCompositionDepth)
{
return false;
}

if (JsonSchemaReader.GetString(schema, "$ref") is not null)
{
if (!JsonSchemaReader.TryResolveRef(schema, root, out var resolved, out _))
{
return false;
}

schema = resolved;
}

if (schema is not JsonObject obj || obj.ContainsKey("anyOf") || obj.ContainsKey("oneOf"))
{
return false;
}

required.UnionWith(JsonSchemaReader.GetRequired(obj));
if (JsonSchemaReader.GetProperties(obj) is { } props)
{
foreach (var (name, _) in props)
{
properties.Add(name);
}
}

if (JsonSchemaReader.Get(obj, "allOf") is JsonArray allOf)
{
foreach (var branch in allOf)
{
if (!CollectRequiredAndProperties(branch, root, required, properties, depth + 1))
{
return false;
}
}
}

return true;
}

// "value" on set_secret or "data" on publish_events says what it is through the tool name. Top level only.
private static bool IsPayloadOfCreateTool(string tool, string? prefix, string name, LintOptions options) =>
prefix is null &&
Expand Down
1 change: 1 addition & 0 deletions src/McpProbe/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ static readonly McpProbe.Linting.LintRules.InconsistentToolNaming -> McpProbe.Li
static readonly McpProbe.Linting.LintRules.InvalidToolName -> McpProbe.Linting.LintRule!
static readonly McpProbe.Linting.LintRules.ParameterMissingDescription -> McpProbe.Linting.LintRule!
static readonly McpProbe.Linting.LintRules.RemoteRef -> McpProbe.Linting.LintRule!
static readonly McpProbe.Linting.LintRules.RequiredPropertyNotDefined -> 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!
Expand Down
2 changes: 1 addition & 1 deletion tests/McpProbe.Tests/CliTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ public async Task Report_ReplacesAnExistingFile_AndAFailedWriteLeavesNoPartialFi

[Theory]
[InlineData("MCPP999=none")]
[InlineData("MCPP008=error")]
[InlineData("MCPP017=error")]
[InlineData("MCPP002")]
[InlineData("MCPP002=loud")]
public async Task Lint_InvalidRuleIsAnError(string rule)
Expand Down
2 changes: 1 addition & 1 deletion tests/McpProbe.Tests/LintConfigTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public void ApplyTo_OverridesTheDefaultsAndAddsRulesAndSuppressions()
[InlineData("""{"lint":{"minDescriptionWords":99999999999}}""", "mcpprobe.json: lint.minDescriptionWords: expected a whole number, 0 or more.")]
[InlineData("""{"lint":{"rules":[]}}""", "mcpprobe.json: lint.rules: expected a JSON object.")]
[InlineData("""{"lint":{"rules":{"MCPP099":"none"}}}""", "mcpprobe.json: lint.rules: unknown rule 'MCPP099'. Rules: MCPP001, MCPP002")]
[InlineData("""{"lint":{"rules":{"MCPP008":"none"}}}""", "mcpprobe.json: lint.rules: unknown rule 'MCPP008'.")]
[InlineData("""{"lint":{"rules":{"MCPP017":"none"}}}""", "mcpprobe.json: lint.rules: unknown rule 'MCPP017'.")]
[InlineData("""{"lint":{"rules":{"MCPP007":"quiet"}}}""", "mcpprobe.json: lint.rules.MCPP007: unknown severity 'quiet'.")]
[InlineData("""{"lint":{"rules":{"MCPP007":"none","mcpp007":"info"}}}""", "mcpprobe.json: lint.rules: rule 'MCPP007' is listed twice.")]
[InlineData("""{"lint":{"ignore":{}}}""", "mcpprobe.json: lint.ignore: expected an array of entries.")]
Expand Down
59 changes: 59 additions & 0 deletions tests/McpProbe.Tests/ToolLinterNestedTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,65 @@ public void RefsThatFanOutALot_FinishQuickly()
Assert.Empty(findings);
}

[Fact]
public void MCPP008_ChecksNestedObjectsAndArrayItems()
{
var findings = Lint("""
{"type":"object","properties":{
"home":{"type":"object","description":"Home.","properties":{"zip":{"type":"string","description":"Zip."}},"required":["zip","floor"]},
"stops":{"type":"array","description":"Stops.","items":{"type":"object","properties":{"city":{"type":"string","description":"City."}},"required":["city","country"]}}}}
""");

Assert.Equal(
["home.floor", "stops[].country"],
findings.Where(f => f.RuleId == "MCPP008").Select(f => f.ParameterName!).Order(StringComparer.Ordinal));
}

[Fact]
public void MCPP008_ByDefault_OnlyTopLevelIsChecked()
{
var schema = """{"type":"object","properties":{"home":{"type":"object","description":"Home.","properties":{"zip":{"type":"string","description":"Zip."}},"required":["floor"]}}}""";

Assert.DoesNotContain(ToolLinter.Lint([Tool("t", schema, GoodDescription)], new LintOptions()).Findings, f => f.RuleId == "MCPP008");
}

[Fact]
public void MCPP008_PropertyDefinedThroughLocalRefCountsAsDefined()
{
var findings = Lint("""
{"type":"object","properties":{
"home":{"$ref":"#/$defs/address","required":["zip"]}},
"$defs":{"address":{"type":"object","properties":{"zip":{"type":"string","description":"Zip."}}}}}
""");

Assert.DoesNotContain(findings, f => f.RuleId == "MCPP008");
}

[Fact]
public void MCPP008_RefWithSiblingRequired_NameNotInTheDefStillFlags()
{
var findings = Lint("""
{"type":"object","properties":{
"home":{"$ref":"#/$defs/address","required":["zip","floor"]}},
"$defs":{"address":{"type":"object","properties":{"zip":{"type":"string","description":"Zip."}}}}}
""");

var finding = Assert.Single(findings, f => f.RuleId == "MCPP008");
Assert.Equal(("home.floor", "Property 'home.floor' is required but not defined in properties."), (finding.ParameterName, finding.Message));
Assert.DoesNotContain(findings, f => f.RuleId == "MCPP008" && f.ParameterName == "home.zip");
}

[Fact]
public void MCPP008_UnresolvableRefIsSkipped()
{
var findings = Lint("""
{"type":"object","properties":{
"home":{"$ref":"#/$defs/missing","required":["zip"]}}}
""");

Assert.DoesNotContain(findings, f => f.RuleId == "MCPP008");
}

[Fact]
public void RulesTurnedOff_DoNotReportNestedFindings()
{
Expand Down
Loading
Loading