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
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@ All notable changes to this project are documented here. The format is based on
- `mcpprobe lint --report <file>` and `mcpprobe diff --report <file>` also write that page. Stdout and exit codes are unchanged. The file is written on exit 0 and 1, not on a usage or connection error (exit 2).
- GitHub Action and Azure Pipelines template inputs `strict`, `transport`, and `report`. All three are off by default, so existing workflows keep the same CLI invocation. `report` is a directory (`lint.html` and `diff.html`); the job summary is unchanged, and artifact upload is left to the workflow (`actions/upload-artifact` / `PublishPipelineArtifact@1`). `report` requires a CLI that has `--report`; the wrapper fails fast if the installed tool does not.

### Changed

- `lint --strict`: MCPP010 no longer reports the nullable spelling `[T, "null"]` (for example `["integer","null"]`), which the C# and Go SDKs emit for every nullable parameter. Unions of two or more non-null types, and longer unions that include `null`, are still reported, with a shorter message. This differs from Inspector's type-union check.
- MCPP002 also needs fewer than `MinToolDescriptionWords` (default 4) words, so a clear description like "Delete a file share" is not flagged for being one character short. Set `LintOptions.MinToolDescriptionWords = 0` for the old character-only check.
- MCPP007 skips a top-level `value`, `data`, `payload` and similar parameter on tools whose name has a segment like `create`, `set` or `publish`. Configure it with `LintOptions.PayloadContextTokens`.
- MCPP005 and MCPP006 say what is mixed in a name, for example "mixed ('_' and '-')", instead of just "mixed".

### Fixed

- MCPP005 and MCPP006 no longer report "most names are X" when two styles tie. With no majority they report nothing.

## [0.3.0-preview] - 2026-11-28

### Added
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,14 @@ strict.ThrowIfFailed();
| Id | Default | Checks |
|---|---|---|
| MCPP001 | error | The tool has a description. |
| MCPP002 | warning | The description is at least `MinToolDescriptionLength` (20) characters. |
| MCPP002 | warning | The description is at least `MinToolDescriptionLength` (20) characters, or at least `MinToolDescriptionWords` (4) words. |
| MCPP003 | warning | Every parameter has a description. |
| MCPP004 | warning | The tool name is 1-128 characters of `A-Z a-z 0-9 _ - .`. |
| 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`, ...). |
| 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`). |
| MCPP009 | error | No bare `true`/`false` where a schema object is expected (`--strict`). |
| MCPP010 | warning | `type` is not a union array (`--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`). |
| MCPP012 | warning | `$ref` does not point outside the document (`--strict`). |
| MCPP013 | warning | Hints don't contradict: not read-only and destructive at once, and a `delete_*`-style name isn't marked `destructiveHint: false` or `readOnlyHint: true`. |
Expand All @@ -119,7 +119,7 @@ strict.ThrowIfFailed();

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`). They 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`. MCPP008 is reserved for a community issue and is not implemented here.

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
16 changes: 16 additions & 0 deletions src/McpProbe/Linting/LintOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,28 @@ public sealed class LintOptions
/// <summary>Gets or sets the minimum tool description length, in characters, for MCPP002. Defaults to 20.</summary>
public int MinToolDescriptionLength { get; set; } = 20;

/// <summary>
/// Gets or sets how many words a description needs to be exempt from MCPP002 when it is shorter than
/// <see cref="MinToolDescriptionLength"/>. Defaults to 4, so "Delete a file share" passes. Set 0 to check length only, as before.
/// </summary>
public int MinToolDescriptionWords { get; set; } = 4;

/// <summary>Gets the parameter names MCPP007 treats as vague. Compared case-insensitively.</summary>
public ISet<string> VagueParameterNames { get; } = new HashSet<string>(StringComparer.OrdinalIgnoreCase)
{
"arg", "args", "data", "input", "item", "obj", "object", "param", "params", "payload", "str", "thing", "val", "value", "x",
};

/// <summary>
/// Gets the tool name segments (such as <c>create</c> in <c>keyvault_secret_create</c>) that make MCPP007 skip a top-level
/// <c>value</c>, <c>data</c>, <c>payload</c> or similar parameter, because the tool name says what it is. Names are split
/// on '_', '-', '.' and case changes. Compared case-insensitively. Clear it to check those parameters everywhere.
/// </summary>
public ISet<string> PayloadContextTokens { get; } = new HashSet<string>(StringComparer.OrdinalIgnoreCase)
{
"add", "create", "insert", "patch", "post", "publish", "put", "replace", "send", "set", "update", "upsert", "write",
};

/// <summary>
/// Gets the name segments MCPP013 treats as destructive, such as <c>delete</c> in <c>delete_file</c> or <c>DeleteFile</c>.
/// Names are split on '_', '-', '.' and case changes; a whole segment must match. Compared case-insensitively.
Expand Down
37 changes: 37 additions & 0 deletions src/McpProbe/Linting/NamingStyle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,43 @@ public static NamingStyle Detect(string name)
_ => "mixed",
};

/// <summary>Like <see cref="Label"/>, but names the markers that make a name <see cref="NamingStyle.Other"/>.</summary>
public static string Describe(string name, NamingStyle style)
{
if (style != NamingStyle.Other)
{
return Label(style);
}

var markers = new List<string>();
if (name.Contains('_', StringComparison.Ordinal))
{
markers.Add("'_'");
}

if (name.Contains('-', StringComparison.Ordinal))
{
markers.Add("'-'");
}

if (name.Contains('.', StringComparison.Ordinal))
{
markers.Add("'.'");
}

if (name.Any(char.IsUpper))
{
markers.Add("uppercase");
}

return markers.Count switch
{
0 => Label(style),
1 => $"irregular ({markers[0]})",
_ => $"mixed ({string.Join(" and ", markers)})",
};
}

private static bool IsSeparated(string name, char separator)
{
var parts = name.Split(separator);
Expand Down
12 changes: 9 additions & 3 deletions src/McpProbe/Linting/SchemaPortabilityLinter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,16 @@ private static void Walk(JsonNode? node, string path, string? keyword, int depth

private static void LintNode(JsonObject node, string path, string? keyword, WalkContext ctx)
{
if (TryGetPortableTypeUnion(node, out var types) && ctx.Options.IsPortabilityRuleEnabled(LintRules.TypeUnion))
if (TryGetPortableTypeUnion(node, out var types) &&
!IsNullableUnion(types) &&
ctx.Options.IsPortabilityRuleEnabled(LintRules.TypeUnion))
{
var rendered = string.Join(",", types.Select(t => "{\"type\":\"" + t + "\"}"));
var caveat = types.Contains("null", StringComparer.Ordinal)
? " OpenAPI 3.0 writes nullability as nullable: true, which is not JSON Schema."
? " A null branch is not the same as an optional property."
: "";
Add(ctx, LintRules.TypeUnion, path,
$"`type` is an array ({FormatTypeArray(types)}). This is legal JSON Schema but less portable: a client that expects a single type may reject the tool. Split it into anyOf of single types: {{\"anyOf\":[{rendered}]}}. Optional is a different contract: absent is not null.{caveat}");
$"`type` is a union array ({FormatTypeArray(types)}). Some clients expect a single type and may reject the tool. Prefer anyOf of single-type schemas: {{\"anyOf\":[{rendered}]}}.{caveat}");
}

var reference = JsonSchemaReader.GetString(node, "$ref");
Expand Down Expand Up @@ -287,6 +289,10 @@ private static bool TryGetPortableTypeUnion(JsonObject node, out List<string> ty
return true;
}

// [T,"null"] is how the C# and Go SDKs spell T?, and an author can't change it, so it is not reported.
private static bool IsNullableUnion(List<string> types) =>
types.Count == 2 && types.Contains("null", StringComparer.Ordinal);

private static string FormatTypeArray(List<string> types) =>
"[" + string.Join(",", types.Select(t => "\"" + t + "\"")) + "]";

Expand Down
37 changes: 28 additions & 9 deletions src/McpProbe/Linting/ToolLinter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ namespace McpProbe.Linting;
/// </remarks>
public static class ToolLinter
{
private static readonly HashSet<string> PayloadParameterNames = new(StringComparer.OrdinalIgnoreCase)
{
"arg", "args", "data", "input", "item", "obj", "object", "param", "params", "payload", "val", "value",
};

/// <summary>Lints protocol tools.</summary>
/// <param name="tools">The tools.</param>
/// <param name="options">Rule options. Defaults to <see cref="LintOptions"/> defaults.</param>
Expand Down Expand Up @@ -51,6 +56,11 @@ public static LintReport Lint(ToolSurface surface, LintOptions? options = null)
throw new ArgumentOutOfRangeException(nameof(options), "MinToolDescriptionLength can't be negative.");
}

if (options.MinToolDescriptionWords < 0)
{
throw new ArgumentOutOfRangeException(nameof(options), "MinToolDescriptionWords can't be negative.");
}

var findings = new List<LintFinding>();
var parameterNames = new List<(string Tool, string Path, string Name)>();

Expand Down Expand Up @@ -130,7 +140,7 @@ private static void LintProperties(Walk walk, JsonNode? schema, string? prefix)
$"{noun} '{path}' has no description. Say what it is and what format it expects.");
}

if (options.VagueParameterNames.Contains(name))
if (options.VagueParameterNames.Contains(name) && !IsPayloadOfCreateTool(walk.Tool, prefix, name, options))
{
Add(findings, options, LintRules.VagueParameterName, tool, path,
$"{noun} name '{path}' is vague. Use a name that says what the value is (for example 'city' instead of 'value').");
Expand All @@ -143,6 +153,12 @@ private static void LintProperties(Walk walk, JsonNode? schema, string? prefix)
}
}

// "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 &&
PayloadParameterNames.Contains(name) &&
SplitName(tool).Any(options.PayloadContextTokens.Contains);

private static void CheckToolName(string name, LintOptions options, List<LintFinding> findings)
{
if (name.Length is < 1 or > 128 || !name.All(IsAllowedToolNameChar))
Expand All @@ -169,7 +185,8 @@ private static void CheckToolDescription(ToolContract tool, LintOptions options,
Add(findings, options, LintRules.DescriptionRestatesName, tool.Name, null,
"Description only restates the tool name. Say what the tool does, what it returns and when to use it.");
}
else if (description.Length < options.MinToolDescriptionLength)
else if (description.Length < options.MinToolDescriptionLength &&
(options.MinToolDescriptionWords == 0 || description.Split((char[]?)null, StringSplitOptions.RemoveEmptyEntries).Length < options.MinToolDescriptionWords))
{
Add(findings, options, LintRules.ToolDescriptionTooShort, tool.Name, null,
string.Create(CultureInfo.InvariantCulture,
Expand Down Expand Up @@ -320,17 +337,19 @@ private static void CheckConsistency(
return;
}

// Majority wins; ties go to the style used first (inputs are sorted by tool name).
var majority = counts
.OrderByDescending(c => c.Count)
.ThenBy(c => classified.FindIndex(i => i.Style == c.Style))
.First()
.Style;
// A majority needs strictly more names than every other style. On a tie nothing is "most", so report nothing.
var top = counts.Max(c => c.Count);
var leaders = counts.Where(c => c.Count == top).ToList();
if (leaders.Count != 1)
{
return;
}

var majority = leaders[0].Style;
foreach (var item in classified.Where(i => i.Style != majority))
{
Add(findings, options, rule, item.Tool, item.Parameter,
$"{noun} name '{item.Name}' is {NamingStyles.Label(item.Style)}, but most {noun.ToLowerInvariant()} names on this server are {NamingStyles.Label(majority)}.");
$"{noun} name '{item.Name}' is {NamingStyles.Describe(item.Name, item.Style)}, but most {noun.ToLowerInvariant()} names on this server are {NamingStyles.Label(majority)}.");
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/McpProbe/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ McpProbe.Linting.LintOptions.FailOn.set -> void
McpProbe.Linting.LintOptions.LintOptions() -> void
McpProbe.Linting.LintOptions.MinToolDescriptionLength.get -> int
McpProbe.Linting.LintOptions.MinToolDescriptionLength.set -> void
McpProbe.Linting.LintOptions.MinToolDescriptionWords.get -> int
McpProbe.Linting.LintOptions.MinToolDescriptionWords.set -> void
McpProbe.Linting.LintOptions.PayloadContextTokens.get -> System.Collections.Generic.ISet<string!>!
McpProbe.Linting.LintOptions.Severities.get -> System.Collections.Generic.IDictionary<string!, McpProbe.Linting.LintSeverity>!
McpProbe.Linting.LintOptions.Strict.get -> bool
McpProbe.Linting.LintOptions.Strict.set -> void
Expand Down
6 changes: 3 additions & 3 deletions tests/McpProbe.Tests/CliTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ public async Task Lint_SampleServerOverStdio_PassesWithStrict()
[Fact]
public async Task Lint_Strict_IsOptInAndFailsOnlyOnPortabilityErrors()
{
var allRules = """{"type":"object","properties":{"city":{"description":"City name.","anyOf":[true,{"type":["null","boolean"]},{},{"$ref":"https://example.com/schema.json"}]}}}""";
var warningsOnly = """{"type":"object","properties":{"city":{"description":"City name.","type":["null","boolean"]}}}""";
var allRules = """{"type":"object","properties":{"city":{"description":"City name.","anyOf":[true,{"type":["boolean","integer"]},{},{"$ref":"https://example.com/schema.json"}]}}}""";
var warningsOnly = """{"type":"object","properties":{"city":{"description":"City name.","type":["boolean","integer"]}}}""";
var allFile = WriteSurface("all.json", Surface(Tool("unportable", allRules, "A tool whose schema exercises each portability rule.")));
var warnFile = WriteSurface("warn.json", Surface(Tool("union", warningsOnly, "A tool whose schema uses a type union.")));

Expand All @@ -177,7 +177,7 @@ public async Task Lint_Strict_IsOptInAndFailsOnlyOnPortabilityErrors()
Assert.Equal(ExitCodes.CheckFailed, exit);
Assert.Contains("error MCPP009", output, StringComparison.Ordinal);
Assert.Contains("warning MCPP010", output, StringComparison.Ordinal);
Assert.Contains("nullable: true", output, StringComparison.Ordinal);
Assert.Contains("`type` is a union array", output, StringComparison.Ordinal);
Assert.DoesNotContain("...", output, StringComparison.Ordinal);
Assert.Contains("warning MCPP011", output, StringComparison.Ordinal);
Assert.Contains("warning MCPP012", output, StringComparison.Ordinal);
Expand Down
10 changes: 10 additions & 0 deletions tests/McpProbe.Tests/ToolLinterNestedTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ public void ByDefault_OnlyTopLevelParametersAreChecked()
Assert.Equal(["home.zip", "stops[].data", "stops[].data"], Lint(schema).Select(f => f.ParameterName!).Order(StringComparer.Ordinal));
}

[Fact]
public void PayloadSkip_AppliesToTopLevelOnly_SoANestedDataOnACreateToolStillFlags()
{
var schema = """{"type":"object","properties":{"data":{"type":"object","description":"Payload.","properties":{"data":{"type":"string","description":"Inner."}}}}}""";
var findings = ToolLinter.Lint([Tool("create_item", schema, GoodDescription)], new LintOptions { CheckNestedParameters = true }).Findings;

var finding = Assert.Single(findings);
Assert.Equal(("MCPP007", "data.data"), (finding.RuleId, finding.ParameterName));
}

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