Skip to main content
Glama
devops-gm88

mcp-validation-server

by devops-gm88

count_distinct

Count distinct entities by a stable key, compare with row count, and report gaps from repeated or blank keys.

Instructions

Count distinct entities on a stable key, and report the gap to a row count.

Use this instead of counting rows whenever the unit you are reporting on is an entity — customers, patients, households, sites, invoices — rather than a line in a table. One customer can appear on fifty rows; "50" is a row count, not a customer count, and the difference is the error that survives review because the number looks plausible.

This tool returns both numbers and the difference between them, broken into the two causes: keys repeated across rows, and rows that carry no usable key. Rows with a blank key are excluded from the count and listed individually — never counted as one entity, never dropped.

Args: rows: The data, as an array of objects. Example: [{"customer_id": "C-1", "site": "A"}, {"customer_id": "C-1", "site": "B"}]. key: The column holding the stable identifier. Choose a real identifier (an account number, a registration key), not a name — names collide, and two different people sharing a name are not one entity. case_sensitive: If false (the default), keys are compared after trimming surrounding whitespace and folding case, so "C-1" and " c-1 " count as one entity. Set true to treat any difference as a different entity. Nothing else is normalised: no punctuation is stripped and no fuzzy matching is applied, because those change which records are considered the same entity, and that is a decision for a person.

Returns: An object with: ok (true when the row count and the distinct count agree), verdict ("clean" | "review_required"), row_count, distinct_count, difference, difference_breakdown ({from_repeated_keys, from_rows_with_blank_key}), rows_with_a_key, rows_with_blank_key, blank_key_rows, repeated_keys (each with its key and the row indexes it appears on), findings, and guidance.

Report `distinct_count` as the entity count. Report `row_count` as the
row count. Never present one as the other.

Raises: ToolError: if key is not a non-empty string. Rows that are not objects, or whose key is missing or blank, never raise — they are held back, counted in rows_with_blank_key, and listed in blank_key_rows.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
keyYes
rowsYes
case_sensitiveNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv0.1.0

TDQS

A4.5/5.0
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description carries the full burden and does so well: it discloses that blank-key rows are excluded, counted, and listed (never dropped or merged), that normalization is limited to trim+case-fold with no fuzzy matching, and exactly which inputs raise ToolError versus which are silently held back. This is exactly the behavioral context an agent needs for a mutation of judgement calls.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Front-loaded with the purpose and cleanly organized into Args/Returns/Raises. Some motivational prose ('the error that survives review because the number looks plausible') is rhetorical padding, but the structure is tight and every section is scannable.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

An output schema exists, so return-value explanation is not strictly required, yet the description still enumerates the key return fields and even the reporting obligation ('never present one as the other'). For a tool with real ambiguity around entity identity and error handling, nothing an agent needs is missing.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must compensate, and it does: rows is illustrated with a concrete example, key is given selection guidance (real identifier, not a name, with a reason), and case_sensitive's default and exact normalization semantics are spelled out. All three parameters are fully covered.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

States a specific verb+resource ('Count distinct entities on a stable key') and immediately clarifies the crucial distinction from a row count. It sharply frames what the tool is versus generic row counting, but never names or differentiates itself from its actual siblings (duplicate_report, reconcile, validate_rows).

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Gives a clear when-to-use rule: use it instead of counting rows when the reported unit is an entity rather than a line in a table. The inverse condition is implied rather than stated, and no sibling alternative is named, so routing to duplicate_report vs. reconcile is left to inference.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.