Skip to main content
Glama

faostat-mcp-server: resolve codes

faostat_resolve_codes
Read-onlyIdempotent

Resolve labels to the numeric codes or exact alphanumeric item identities faostat_query_observations needs: areas (countries/regions), items (commodities), and elements (metrics). Use query for full-text matching, name_contains for substring matching, code or code_text for exact identity, or omit them to list. Item and element matches occur in the selected domain; areas use shared vocabulary. For elements, optionally pass item_codes or item_codes_text to discover metrics and distinct units observed for those items; this does not establish area/year/source coverage. Empty item selectors match nothing. Page with offset and limit using nextOffset when truncated. Areas carry country/aggregate classification. Verified domain-specific item groups carry aggregate; null means unclassified, not safe-to-sum. Item groups can overlap their members even with matching units. Area aggregates include codes ≥ 5000 and curated roll-ups such as China=351; exclude overlapping regional and country rows when summing.

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": {
      "domain": "<domain>",
      "dimension": "<dimension>"
    },
    "name": "faostat_resolve_codes"
  }
}

Input Schema

NameRequiredDescriptionDefault
codeNoExact code lookup. Takes precedence over `query`/`name_contains` when provided.
limitNoMaximum matches to return (max 200).
queryNoFull-text search term, FTS5-matched against the dimension labels with prefix matching (e.g. "wheat", "import quantity"). Relevance-ranked.
domainYesFAOSTAT domain code (e.g. "QCL"). Item and element resolution is scoped to the codes present in this domain's data; area code lists are shared across all indexed domains.
offsetNoZero-based pagination offset into the match set. When the response reports truncated, pass the returned nextOffset here to fetch the next page. Ignored for exact-code lookups (always single-page).
code_textNoExact alphanumeric item code. Only for dimension item; mutually exclusive with code. Numeric identities use code.
dimensionYesWhich dimension to resolve: "area" (countries/regions), "item" (commodities), or "element" (metrics).
item_codesNoFor element resolution only: restrict elements and units to these items. Empty matches nothing; omit for domain-wide elements. Mutually exclusive with item_codes_text.
name_containsNoCase-insensitive substring filter over the label. Used only when `query` is omitted.
item_codes_textNoFor element resolution only: restrict elements and units to these exact text items. Empty matches nothing; mutually exclusive with item_codes.

Output Schema

NameRequiredDescriptionDefault
errorNoPresent when the call failed. Absent on success.
domainNoThe domain code echoed back.
noticeNoGuidance when nothing matched, more pages remain, or the dimension is not yet indexed.
matchesNoMatching codes, relevance-ranked for query mode, else by code.
dimensionNoThe dimension resolved.
truncatedNoTrue when more matches remain beyond the returned page — fetch them with nextOffset.
nextOffsetNoOffset to pass on the next call to fetch the following page. Present only when truncated is true; absent on the last page and for exact-code lookups.
totalMatchesNoTotal matches in this domain before the result cap.

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed11 schema fields changed
    • addedInput schema / properties / code_text
      Added value: +{
      +  "description": "Exact alphanumeric item code. Only for dimension item; mutually exclusive with code. Numeric identities use code.",
      +  "pattern": "^\\d+[A-Za-z][A-Za-z0-9]*$",
      +  "type": "string"
      +}
    • addedInput schema / properties / item_codes
      Added value: +{
      +  "description": "For element resolution only: restrict elements and units to these items. Empty matches nothing; omit for domain-wide elements. Mutually exclusive with item_codes_text.",
      +  "items": {
      +    "maximum": 9007199254740991,
      +    "minimum": -9007199254740991,
      +    "type": "integer"
      +  },
      +  "type": "array"
      +}
    • addedInput schema / properties / item_codes_text
      Added value: +{
      +  "description": "For element resolution only: restrict elements and units to these exact text items. Empty matches nothing; mutually exclusive with item_codes.",
      +  "items": {
      +    "description": "Exact alphanumeric item identity.",
      +    "pattern": "^\\d+[A-Za-z][A-Za-z0-9]*$",
      +    "type": "string"
      +  },
      +  "type": "array"
      +}
    • changedOutput schema / properties / error / properties / data / properties / reason / description
      Previous value: -"Machine-readable failure mode. Declared by this tool: `unknown_domain`: The domain code is not a selected (indexed) FAOSTAT domain. `index_not_ready`: The dimension tables are not yet populated (mirror has never completed a sync). `query_timeout`: The item or element lookup's mirror read — time queued behind other calls' reads plus execution — ran past the 45-second per-call ceiling. Other values are possible when a failure originates below the handler."New value: +"Machine-readable failure mode. Declared by this tool: `invalid_item_scope`: Item selectors are combined or supplied outside element resolution. `invalid_text_selector`: code_text is supplied with code or outside the item dimension. `unknown_domain`: The domain code is not a selected (indexed) FAOSTAT domain. `index_not_ready`: The shared dimension tables are empty, or the selected item/element domain requires an initial sync or an ingest upgrade. `query_timeout`: The item or element lookup's mirror read — time queued behind other calls' reads plus execution — ran past the 45-second per-call ceiling. Other values are possible when a failure originates below the handler."
    • changedOutput schema / properties / error / properties / data / properties / reason / examples
      Previous value: -[
      -  "unknown_domain",
      -  "index_not_ready",
      -  "query_timeout"
      -]New value: +[
      +  "invalid_item_scope",
      +  "invalid_text_selector",
      +  "unknown_domain",
      +  "index_not_ready",
      +  "query_timeout"
      +]
    • changedOutput schema / properties / matches / items / properties / code / description
      Previous value: -"The opaque integer code to pass into faostat_query_observations."New value: +"Numeric code for faostat_query_observations; null for alphanumeric items carried by code_text."
    • changedOutput schema / properties / matches / items / properties / code / type
      Previous value: -"number"New value: +[
      +  "number",
      +  "null"
      +]
    • addedOutput schema / properties / matches / items / properties / code_text
      Added value: +{
      +  "description": "Exact alphanumeric item identity for item_codes_text; null for numeric codes.",
      +  "type": [
      +    "string",
      +    "null"
      +  ]
      +}
    • changedOutput schema / properties / matches / items / properties / kind / description
      Previous value: -"For areas: \"country\" (individual nation) or \"aggregate\" (region/grouping; excluded from sums by default). Null for items/elements."New value: +"For areas: country or aggregate region. For items: aggregate only for verified domain-specific groups; null means unclassified, never safe-to-sum. Null for elements."
    • addedOutput schema / properties / matches / items / properties / units
      Added value: +{
      +  "description": "Element matches only: distinct non-null units observed in the selected domain and item scope. Empty means no specified units.",
      +  "items": {
      +    "description": "Observed unit label.",
      +    "type": "string"
      +  },
      +  "type": "array"
      +}
    • changedOutput schema / properties / matches / items / required
      Previous value: -[
      -  "code",
      -  "name",
      -  "kind"
      -]New value: +[
      +  "code",
      +  "code_text",
      +  "name",
      +  "kind"
      +]
  2. Changed2 schema fields changed
    • changedOutput schema / properties / error / properties / data / properties / reason / description
      Previous value: -"Machine-readable failure mode. Declared by this tool: `unknown_domain`: The domain code is not a selected (indexed) FAOSTAT domain. `index_not_ready`: The dimension tables are not yet populated (mirror has never completed a sync). Other values are possible when a failure originates below the handler."New value: +"Machine-readable failure mode. Declared by this tool: `unknown_domain`: The domain code is not a selected (indexed) FAOSTAT domain. `index_not_ready`: The dimension tables are not yet populated (mirror has never completed a sync). `query_timeout`: The item or element lookup's mirror read — time queued behind other calls' reads plus execution — ran past the 45-second per-call ceiling. Other values are possible when a failure originates below the handler."
    • changedOutput schema / properties / error / properties / data / properties / reason / examples
      Previous value: -[
      -  "unknown_domain",
      -  "index_not_ready"
      -]New value: +[
      +  "unknown_domain",
      +  "index_not_ready",
      +  "query_timeout"
      +]
  3. Changed6 schema fields changed
    • changedInput schema / $schema
      Previous value: -"http://json-schema.org/draft-07/schema#"New value: +"https://json-schema.org/draft/2020-12/schema"
    • addedInput schema / additionalProperties
      Added value: +false
    • changedOutput schema / $schema
      Previous value: -"http://json-schema.org/draft-07/schema#"New value: +"https://json-schema.org/draft/2020-12/schema"
    • addedOutput schema / anyOf
      Added value: +[
      +  {
      +    "not": {
      +      "required": [
      +        "error"
      +      ]
      +    },
      +    "required": [
      +      "domain",
      +      "dimension",
      +      "matches",
      +      "totalMatches",
      +      "truncated"
      +    ]
      +  },
      +  {
      +    "required": [
      +      "error"
      +    ]
      +  }
      +]
    • addedOutput schema / properties / error
      Added value: +{
      +  "additionalProperties": {},
      +  "description": "Present when the call failed. Absent on success.",
      +  "properties": {
      +    "code": {
      +      "description": "JSON-RPC error code for this failure.",
      +      "maximum": 9007199254740991,
      +      "minimum": -9007199254740991,
      +      "type": "integer"
      +    },
      +    "data": {
      +      "additionalProperties": {},
      +      "properties": {
      +        "reason": {
      +          "description": "Machine-readable failure mode. Declared by this tool: `unknown_domain`: The domain code is not a selected (indexed) FAOSTAT domain. `index_not_ready`: The dimension tables are not yet populated (mirror has never completed a sync). Other values are possible when a failure originates below the handler.",
      +          "examples": [
      +            "unknown_domain",
      +            "index_not_ready"
      +          ],
      +          "type": "string"
      +        },
      +        "recovery": {
      +          "additionalProperties": {},
      +          "description": "Actionable next step for the caller.",
      +          "properties": {
      +            "hint": {
      +              "type": "string"
      +            }
      +          },
      +          "required": [
      +            "hint"
      +          ],
      +          "type": "object"
      +        },
      +        "retryable": {
      +          "description": "Whether retrying may succeed.",
      +          "type": "boolean"
      +        }
      +      },
      +      "type": "object"
      +    },
      +    "message": {
      +      "description": "Human-readable description of what went wrong.",
      +      "type": "string"
      +    }
      +  },
      +  "required": [
      +    "code",
      +    "message"
      +  ],
      +  "type": "object"
      +}
    • removedOutput schema / required
      Removed value: -[
      -  "domain",
      -  "dimension",
      -  "matches",
      -  "totalMatches",
      -  "truncated"
      -]
  4. Changed6 schema fields changed
    • changedInput schema / properties / domain / description
      Previous value: -"FAOSTAT domain code to verify the index is ready (e.g. \"QCL\"). Dimension code lists (areas, items, elements) are shared across all indexed domains."New value: +"FAOSTAT domain code (e.g. \"QCL\"). Item and element resolution is scoped to the codes present in this domain's data; area code lists are shared across all indexed domains."
    • addedInput schema / properties / offset
      Added value: +{
      +  "default": 0,
      +  "description": "Zero-based pagination offset into the match set. When the response reports truncated, pass the returned nextOffset here to fetch the next page. Ignored for exact-code lookups (always single-page).",
      +  "maximum": 9007199254740991,
      +  "minimum": 0,
      +  "type": "integer"
      +}
    • addedOutput schema / properties / nextOffset
      Added value: +{
      +  "description": "Offset to pass on the next call to fetch the following page. Present only when truncated is true; absent on the last page and for exact-code lookups.",
      +  "maximum": 9007199254740991,
      +  "minimum": -9007199254740991,
      +  "type": "integer"
      +}
    • changedOutput schema / properties / notice / description
      Previous value: -"Guidance when nothing matched or the dimension is not yet indexed."New value: +"Guidance when nothing matched, more pages remain, or the dimension is not yet indexed."
    • changedOutput schema / properties / totalMatches / description
      Previous value: -"Total matches before the result cap."New value: +"Total matches in this domain before the result cap."
    • changedOutput schema / properties / truncated / description
      Previous value: -"True when matches were capped at the limit."New value: +"True when more matches remain beyond the returned page — fetch them with nextOffset."
  5. First observed

TDQS

A4.6/5.0
Behavior4/5

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

Annotations already declare readOnly/idempotent/closed-world, so the bar is lower, and the description clears it by disclosing domain scoping (items/elements domain-bound, areas shared), truncation/nextOffset paging, and that empty item selectors match nothing. It goes further with aggregation hazards: null aggregate means unclassified not safe-to-sum, item groups overlap their members, and area aggregates include codes >= 5000 plus curated roll-ups like China=351. Only the absence of a concrete return-shape note keeps it from 5, and an output schema exists anyway.

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?

Purpose and selector routing are front-loaded, and every sentence carries operational content. It is a dense single paragraph with compressed jargon in the aggregate/overlap sentences, which slows parsing for an agent skimming the definition.

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?

For a 10-parameter resolver with an output schema, the description covers the remaining risk surface: selector precedence, pagination, domain scoping, and double-counting pitfalls when summing aggregates. Nothing an agent needs to call and interpret this correctly is missing.

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

Parameters4/5

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

Schema coverage is 100%, so baseline is 3, but the description adds workflow-level meaning beyond field docs: the precedence of code over query/name_contains and the caveat that element item filtering does not establish area/year/source coverage. Some of it repeats the schema (nextOffset paging, empty-selector behavior), so it is additive rather than transformative.

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 (resolve) and resource (area/item/element labels to codes) and ties the output directly to what faostat_query_observations consumes, which distinguishes it from every sibling. An agent can tell it is the code-lookup prerequisite step 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 Guidelines5/5

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

Explicitly routes between selector modes: query for full-text, name_contains for substring, code/code_text for exact identity, omit to list. It also states the downstream consumer (faostat_query_observations) and the element-specific item_codes workflow, leaving little to inference.

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.