Skip to main content
Glama

Calculer une métrique

calculate_metric
Read-only

Calculate a single metric on a dataset column: avg, sum, min, max, stats, value_count, cardinality, percentiles. For per-group breakdowns, use datafair_aggregate_data.

Tool call template

Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.

{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "tools/call",
  "params": {
    "arguments": {
      "datasetId": "<datasetId>",
      "metric": "<metric>",
      "fieldKey": "<fieldKey>"
    },
    "name": "calculate_metric"
  }
}

Input Schema

NameRequiredDescriptionDefault
qNoFull-text search across all columns, restricting the rows. Prefer filters for structured criteria.
bboxNoBounding box "lonMin,latMin,lonMax,latMax" (lon before lat), e.g. "-2.5,43,3,47". Geolocalized datasets only.
metricYesavg, sum, min, max (numbers); min, max, cardinality, value_count (strings); stats returns count/min/max/avg/sum; percentiles returns a distribution.
filtersNoColumn filters { "<column key><suffix>": "<value as a string>" }, e.g. { "ville_eq": "Paris", "age_lte": "30", "nom_search": "Jean" }. Suffixes: _eq _neq _in _nin (comma-separated) _gt _gte _lt _lte _starts _exists _nexists _search (words, the default for text) _contains (when enabled). A rejected suffix answers a 400 listing the column's. Never prefix with _c_.
fieldKeyYesThe column key to calculate the metric on (use keys from datafair_describe_dataset)
percentsNoComma-separated percentages for the percentiles metric (default "1,5,25,50,75,95,99").1,5,25,50,75,95,99
datasetIdYesThe "id" of a datafair_list_account_datasets result, not its title or slug.
dateMatchNoDate "YYYY-MM-DD" (single day) or "YYYY-MM-DD,YYYY-MM-DD" (range), e.g. "2023-11-21". Temporal datasets only.
geoDistanceNoProximity filter "lon,lat,distance" (lon first), e.g. "2.35,48.85,10km"; distance "0" = point-in-polygon. Geolocalized datasets only.

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed15 schema fields changed
    • removedInput schema / $schema
      Removed value: -"http://json-schema.org/draft-07/schema#"
    • addedInput schema / properties / bbox / examples
      Added value: +[
      +  "2.2241,48.8156,2.4699,48.9022"
      +]
    • changedInput schema / properties / datasetId / description
      Previous value: -"The exact dataset ID from the \"id\" field in list_datasets results. Do not use the title or slug."New value: +"The \"id\" of a datafair_list_account_datasets result, not its title or slug."
    • changedInput schema / properties / fieldKey / description
      Previous value: -"The column key to calculate the metric on (use keys from describe_dataset)"New value: +"The column key to calculate the metric on (use keys from datafair_describe_dataset)"
    • removedInput schema / properties / filters / additionalProperties
      Removed value: -{
      -  "type": "string"
      -}
    • changedInput schema / properties / filters / description
      Previous value: -"Column filters as key-value pairs: column_key + suffix, all values strings. Example: { \"ville_eq\": \"Paris\", \"age_lte\": \"30\", \"nom_search\": \"Jean\" }. Suffixes include _eq, _in, _gt/_lt, _search and more; if one is rejected the 400 error lists what the column supports. Never _c_-prefix a column filter (use ville_eq, not _c_ville_eq)."New value: +"Column filters { \"<column key><suffix>\": \"<value as a string>\" }, e.g. { \"ville_eq\": \"Paris\", \"age_lte\": \"30\", \"nom_search\": \"Jean\" }. Suffixes: _eq _neq _in _nin (comma-separated) _gt _gte _lt _lte _starts _exists _nexists _search (words, the default for text) _contains (when enabled). A rejected suffix answers a 400 listing the column's. Never prefix with _c_."
    • addedInput schema / properties / filters / patternProperties
      Added value: +{
      +  ".*": {
      +    "default": "",
      +    "type": "string"
      +  }
      +}
    • removedInput schema / properties / filters / propertyNames
      Removed value: -{
      -  "pattern": "^.+_(search|eq|neq|in|nin|starts|contains|gte?|lte?|n?exists)$"
      -}
    • changedInput schema / properties / metric / description
      Previous value: -"Metric to calculate. Available: avg, sum, min, max (for numbers); min, max, cardinality, value_count (for strings); value_count (for others); stats returns count/min/max/avg/sum; percentiles returns distribution."New value: +"avg, sum, min, max (numbers); min, max, cardinality, value_count (strings); stats returns count/min/max/avg/sum; percentiles returns a distribution."
    • changedInput schema / properties / metric / enum
      Previous value: -[
      -  "avg",
      -  "sum",
      -  "min",
      -  "max",
      -  "stats",
      -  "value_count",
      -  "cardinality",
      -  "percentiles"
      -]New value: +[
      +  "avg",
      +  "sum",
      +  "min",
      +  "max",
      +  "stats",
      +  "value_count",
      +  "percentiles",
      +  "cardinality"
      +]
    • addedInput schema / properties / percents / default
      Added value: +"1,5,25,50,75,95,99"
    • changedInput schema / properties / percents / description
      Previous value: -"Comma-separated percentages for percentiles metric (default: \"1,5,25,50,75,95,99\"). Only used when metric is \"percentiles\"."New value: +"Comma-separated percentages for the percentiles metric (default \"1,5,25,50,75,95,99\")."
    • addedInput schema / properties / q
      Added value: +{
      +  "description": "Full-text search across all columns, restricting the rows. Prefer filters for structured criteria.",
      +  "maxLength": 1000,
      +  "type": "string"
      +}
    • changedInput schema / required
      Previous value: -[
      -  "datasetId",
      -  "fieldKey",
      -  "metric"
      -]New value: +[
      +  "datasetId",
      +  "metric",
      +  "fieldKey"
      +]
    • changedOutput schema / (root)
      Previous value: -{
      -  "$schema": "http://json-schema.org/draft-07/schema#",
      -  "additionalProperties": false,
      -  "properties": {
      -    "datasetId": {
      -      "description": "The dataset ID that was queried",
      -      "type": "string"
      -    },
      -    "fieldKey": {
      -      "description": "The column key that was queried",
      -      "type": "string"
      -    },
      -    "total": {
      -      "description": "Total number of rows included in the calculation",
      -      "type": "number"
      -    },
      -    "value": {
      -      "description": "The calculated metric value. For avg/sum/min/max/value_count/cardinality: a single number. For stats: an object {count, min, max, avg, sum}. For percentiles: an object mapping percentage strings to values, e.g. {\"25\": 30000, \"50\": 42000, \"75\": 55000}."
      -    }
      -  },
      -  "required": [
      -    "datasetId",
      -    "fieldKey",
      -    "total"
      -  ],
      -  "type": "object"
      -}New value: +null
  2. Changed7 schema fields changed
    • changedInput schema / properties / bbox / description
      Previous value: -"Geographic bounding box filter (only for geolocalized datasets). Format: \"lonMin,latMin,lonMax,latMax\". Example: \"-2.5,43,3,47\"."New value: +"Bounding box \"lonMin,latMin,lonMax,latMax\" (lon before lat), e.g. \"-2.5,43,3,47\". Geolocalized datasets only."
    • changedInput schema / properties / datasetId / description
      Previous value: -"The exact dataset ID from the \"id\" field in search_datasets results. Do not use the title or slug."New value: +"The exact dataset ID from the \"id\" field in list_datasets results. Do not use the title or slug."
    • changedInput schema / properties / dateMatch / description
      Previous value: -"Temporal filter (only for temporal datasets with date fields). Accepts a single date \"YYYY-MM-DD\" to match that day, or a date range \"YYYY-MM-DD,YYYY-MM-DD\" to match an overlapping period. ISO datetimes also accepted. Example: \"2023-11-21\" or \"2023-01-01,2023-12-31\"."New value: +"Date \"YYYY-MM-DD\" (single day) or \"YYYY-MM-DD,YYYY-MM-DD\" (range), e.g. \"2023-11-21\". Temporal datasets only."
    • changedInput schema / properties / filters / description
      Previous value: -"Column filters as key-value pairs. Key format: column_key + suffix (see server instructions for available suffixes). All values must be strings, even for numbers/dates. If a column key has underscores (e.g., code_postal), just append the suffix: code_postal_eq. Example: { \"nom_search\": \"Jean\", \"age_lte\": \"30\", \"ville_eq\": \"Paris\" }"New value: +"Column filters as key-value pairs: column_key + suffix, all values strings. Example: { \"ville_eq\": \"Paris\", \"age_lte\": \"30\", \"nom_search\": \"Jean\" }. Suffixes include _eq, _in, _gt/_lt, _search and more; if one is rejected the 400 error lists what the column supports. Never _c_-prefix a column filter (use ville_eq, not _c_ville_eq)."
    • changedInput schema / properties / geoDistance / description
      Previous value: -"Geographic proximity filter (only for geolocalized datasets). Restricts results to within a distance from a point. Format: \"lon,lat,distance\". Example: \"2.35,48.85,10km\". Use distance \"0\" for point-in-polygon containment."New value: +"Proximity filter \"lon,lat,distance\" (lon first), e.g. \"2.35,48.85,10km\"; distance \"0\" = point-in-polygon. Geolocalized datasets only."
    • removedOutput schema / properties / metric
      Removed value: -{
      -  "description": "The metric that was calculated",
      -  "type": "string"
      -}
    • changedOutput schema / required
      Previous value: -[
      -  "datasetId",
      -  "fieldKey",
      -  "metric",
      -  "total"
      -]New value: +[
      +  "datasetId",
      +  "fieldKey",
      +  "total"
      +]
  3. Changed3 schema fields changed
    • addedInput schema / properties / bbox
      Added value: +{
      +  "description": "Geographic bounding box filter (only for geolocalized datasets). Format: \"lonMin,latMin,lonMax,latMax\". Example: \"-2.5,43,3,47\".",
      +  "type": "string"
      +}
    • addedInput schema / properties / dateMatch
      Added value: +{
      +  "description": "Temporal filter (only for temporal datasets with date fields). Accepts a single date \"YYYY-MM-DD\" to match that day, or a date range \"YYYY-MM-DD,YYYY-MM-DD\" to match an overlapping period. ISO datetimes also accepted. Example: \"2023-11-21\" or \"2023-01-01,2023-12-31\".",
      +  "type": "string"
      +}
    • addedInput schema / properties / geoDistance
      Added value: +{
      +  "description": "Geographic proximity filter (only for geolocalized datasets). Restricts results to within a distance from a point. Format: \"lon,lat,distance\". Example: \"2.35,48.85,10km\". Use distance \"0\" for point-in-polygon containment.",
      +  "type": "string"
      +}
  4. Changed3 schema fields changed
    • changedInput schema / properties / datasetId / description
      Previous value: -"The unique dataset ID obtained from search_datasets or provided by the user"New value: +"The exact dataset ID from the \"id\" field in search_datasets results. Do not use the title or slug."
    • changedInput schema / properties / filters / description
      Previous value: -"Column filters as key-value pairs. Key format: column_key + suffix (see server instructions for available suffixes). Example: { \"nom_search\": \"Jean\", \"age_lte\": \"30\", \"ville_eq\": \"Paris\" }"New value: +"Column filters as key-value pairs. Key format: column_key + suffix (see server instructions for available suffixes). All values must be strings, even for numbers/dates. If a column key has underscores (e.g., code_postal), just append the suffix: code_postal_eq. Example: { \"nom_search\": \"Jean\", \"age_lte\": \"30\", \"ville_eq\": \"Paris\" }"
    • changedOutput schema / properties / value / description
      Previous value: -"The calculated metric value (number for most metrics, object for stats/percentiles)"New value: +"The calculated metric value. For avg/sum/min/max/value_count/cardinality: a single number. For stats: an object {count, min, max, avg, sum}. For percentiles: an object mapping percentage strings to values, e.g. {\"25\": 30000, \"50\": 42000, \"75\": 55000}."
  5. First observed

TDQS

A3.9/5.0
Behavior3/5

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

Annotations already declare a safe read-only, non-destructive operation, so the safety burden is lifted. The description adds the relevant scope constraint ('single metric' on one column, no grouping), but says nothing about return shape or how percentiles/stats results are presented, which matters since no output schema exists.

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

Conciseness5/5

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

Two sentences, front-loaded with the core action and metric list, followed by the routing rule. No redundant or filler wording.

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

Completeness3/5

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

For a 9-parameter tool with no output schema, the description covers routing and scope but leaves the returned value unexplained, and does not note how the optional geographic/temporal filters interact with the metric. Adequate to call correctly, but not fully complete.

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

Parameters3/5

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

Schema description coverage is 100%, so every parameter is already documented, including the metric enum and percents. The description's metric list merely restates the enum and adds no format or interaction detail beyond the schema; baseline 3 applies.

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

Purpose5/5

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

States a specific verb and resource ('Calculate a single metric on a dataset column') and enumerates the supported metrics, which immediately separates it from multi-metric or grouping tools. An agent can tell what it does without opening the schema.

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?

Explicitly routes the agent away from this tool when per-group breakdowns are needed, naming 'datafair_aggregate_data' as the alternative. It gives no guidance on the other siblings (describe_dataset, get_field_values), but the primary ambiguity is resolved.

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

Try in Browser

Glama MCP Gateway

Add one secure layer between your agents and this server.

Resources