faostat-mcp-server
UN FAOSTAT global food & agriculture statistics over a local SQLite mirror, via MCP.
Sollte ich dies verwenden
Qualität und Sicherheit
Befunde (3)
- HIGH
- INFOin faostat_dataframe_query
- INFOin faostat_dataframe_describe
Basierend auf einer automatisierten Analyse der Tool-Definitionen und der Einhaltung des Protokolls.
Kontextkosten
Dies ist die ungefähre Anzahl der Tokens, die jedes Mal verbraucht werden, wenn die Tools des Servers in den Kontext eines Modells geladen werden. Höhere Werte verringern die Aufmerksamkeit, die für andere Aufgaben verfügbar ist.
Installieren
Installation mit einem Klick
Fügen Sie dies Ihrer Datei `claude_desktop_config.json` hinzu:
{
"mcpServers": {
"faostat-mcp-server": {
"command": "node",
"args": [
"@cyanheads/faostat-mcp-server"
]
}
}
}Ausführbare Pakete
0.2.4streamable-httpRemote-Endpunkte
https://faostat.caseyjhand.com/mcpstreamable-httpWas es kann
Tool-Inventar
Tools (6)
🟢faostat_list_domains(code, topic, indexed_only, limit, offset)
Discover FAOSTAT statistical domains (production, trade, food balances, food security, land use, agri-emissions, prices, value) with their codes, descriptions, last-update date, upstream row count, and local index status. Every query keys on a domain code from here. The `indexed` flag tells you which domains are queryable right now; un-indexed domains exist in the catalog but must be added to FAOSTAT_DOMAINS and re-synced before faostat_query_observations can read them. The catalog runs to ~69 domains with long descriptions, so responses are paged: narrow with `topic` / `indexed_only`, pass `code` to fetch one domain outright, or page with `offset` + `limit` — when the response reports `truncated`, pass the returned `nextOffset` to fetch the rest.
Eingabe-Schema
{
"type": "object",
"properties": {
"code": {
"description": "Exact domain code lookup (e.g. \"RL\"), case-insensitive. Returns that one domain's full record on a single page. Takes precedence over `topic` / `indexed_only` when provided.",
"type": "string"
},
"topic": {
"description": "Case-insensitive substring filter over domain code, name, and topic (e.g. \"trade\", \"emissions\", \"QCL\"). Omit to list the full catalog.",
"type": "string"
},
"indexed_only": {
"default": false,
"description": "When true, return only domains indexed in the local mirror (queryable now).",
"type": "boolean"
},
"limit": {
"default": 20,
"description": "Maximum domains to return on this page (max 200 — above the catalog size, so raise it to fetch everything at once). Domain descriptions are long; the default keeps a browse call small.",
"type": "integer",
"minimum": 1,
"maximum": 200
},
"offset": {
"default": 0,
"description": "Zero-based pagination offset into the matching domains (code-sorted). When the response reports truncated, pass the returned nextOffset here to fetch the next page. Ignored for exact-code lookups (always single-page).",
"type": "integer",
"minimum": 0,
"maximum": 9007199254740991
}
},
"$schema": "https://json-schema.org/draft/2020-12/schema",
"additionalProperties": false
}Ausgabe-Schema
{
"type": "object",
"properties": {
"domains": {
"type": "array",
"items": {
"type": "object",
"properties": {
"code": {
"type": "string",
"description": "Domain code — the key for every query (e.g. \"QCL\")."
},
"name": {
"type": "string",
"description": "Human-readable domain name."
},
"topic": {
"description": "FAOSTAT topic grouping, when provided.",
"type": "string"
},
"description": {
"description": "Domain description, when provided.",
"type": "string"
},
"last_update": {
"type": "string",
"description": "Upstream last-update date (ISO 8601) from the manifest."
},
"upstream_row_count": {
"description": "Row count reported by the manifest for the full domain.",
"type": "number"
},
"file_size_in_bytes": {
"description": "Compressed ZIP size in bytes, parsed from the manifest size string.",
"type": "number"
},
"indexed": {
"type": "boolean",
"description": "True when this domain is in the local mirror selection (FAOSTAT_DOMAINS)."
},
"index_ready": {
"type": "boolean",
"description": "True when the local mirror for this domain has completed an initial sync."
},
"indexed_row_count": {
"description": "Rows in the local mirror for this domain (present when indexed and synced).",
"type": "number"
},
"indexed_last_sync": {
"description": "ISO 8601 timestamp of the last completed local sync (when synced).",
"type": "string"
}
},
"required": [
"code",
"name",
"last_update",
"indexed",
"index_ready"
],
"additionalProperties": false,
"description": "One FAOSTAT domain with catalog metadata and local mirror status."
},
"description": "Matching domains, sorted by code."
},
"totalCount": {
"type": "number",
"description": "Total domains in the FAOSTAT catalog, independent of any filter."
},
"totalMatches": {
"type": "number",
"description": "Domains matching the current filters, before the page limit is applied."
},
"truncated": {
"type": "boolean",
"description": "True when more matches remain beyond the returned page — fetch them with nextOffset."
},
"nextOffset": {
"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.",
"type": "integer",
"minimum": -9007199254740991,
"maximum": 9007199254740991
},
"indexedCount": {
"type": "number",
"description": "Domains currently indexed in the local mirror."
},
"notice": {
"description": "Guidance when a filter matched nothing, more pages remain, or no domains are indexed yet.",
"type": "string"
},
"error": {
"description": "Present when the call failed. Absent on success.",
"type": "object",
"properties": {
"code": {
"type": "integer",
"minimum": -9007199254740991,
"maximum": 9007199254740991,
"description": "JSON-RPC error code for this failure."
},
"message": {
"type": "string",
"description": "Human-readable description of what went wrong."
},
"data": {
"type": "object",
"properties": {
"reason": {
"type": "string",
"description": "Machine-readable failure mode."
},
"recovery": {
"description": "Actionable next step for the caller.",
"type": "object",
"properties": {
"hint": {
"type": "string"
}
},
"required": [
"hint"
],
"additionalProperties": {}
},
"retryable": {
"description": "Whether retrying may succeed.",
"type": "boolean"
}
},
"additionalProperties": {}
}
},
"required": [
"code",
"message"
],
"additionalProperties": {}
}
},
"$schema": "https://json-schema.org/draft/2020-12/schema",
"additionalProperties": false,
"anyOf": [
{
"not": {
"required": [
"error"
]
},
"required": [
"domains",
"totalCount",
"totalMatches",
"truncated",
"indexedCount"
]
},
{
"required": [
"error"
]
}
]
}🟢faostat_resolve_codes(domain, dimension, query, name_contains, code, ...)
Resolve human terms to the opaque integer codes faostat_query_observations needs, within a dimension: areas (countries/regions), items (commodities), or elements (metrics like production, yield, import quantity). Pass `query` for fuzzy full-text matching ("maize" → item 56), `name_contains` for a substring filter, or `code` for an exact-code lookup; omit all three to list the whole dimension. Item and element results are scoped to the requested domain — only codes present in that domain's cube are returned, so a resolved code is always queryable there (areas are shared across domains). Page large listings with `offset` + `limit`: when the response reports `truncated`, pass the returned `nextOffset` to fetch the next page. Every area match is flagged `country` or `aggregate` — aggregates (World, continents, economic groupings — codes ≥ 5000 plus a few curated sub-threshold roll-ups such as China=351, which sums mainland + Taiwan + Hong Kong + Macao) double-count if summed with their member countries, so resolve before querying and exclude aggregates unless you want the regional roll-up.
Eingabe-Schema
{
"type": "object",
"properties": {
"domain": {
"type": "string",
"minLength": 1,
"description": "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."
},
"dimension": {
"type": "string",
"enum": [
"area",
"item",
"element"
],
"description": "Which dimension to resolve: \"area\" (countries/regions), \"item\" (commodities), or \"element\" (metrics)."
},
"query": {
"description": "Full-text search term, FTS5-matched against the dimension labels with prefix matching (e.g. \"wheat\", \"import quantity\"). Relevance-ranked.",
"type": "string"
},
"name_contains": {
"description": "Case-insensitive substring filter over the label. Used only when `query` is omitted.",
"type": "string"
},
"code": {
"description": "Exact code lookup. Takes precedence over `query`/`name_contains` when provided.",
"type": "integer",
"minimum": -9007199254740991,
"maximum": 9007199254740991
},
"limit": {
"default": 50,
"description": "Maximum matches to return (max 200).",
"type": "integer",
"minimum": 1,
"maximum": 200
},
"offset": {
"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).",
"type": "integer",
"minimum": 0,
"maximum": 9007199254740991
}
},
"required": [
"domain",
"dimension"
],
"$schema": "https://json-schema.org/draft/2020-12/schema",
"additionalProperties": false
}Ausgabe-Schema
{
"type": "object",
"properties": {
"domain": {
"type": "string",
"description": "The domain code echoed back."
},
"dimension": {
"type": "string",
"description": "The dimension resolved."
},
"matches": {
"type": "array",
"items": {
"type": "object",
"properties": {
"code": {
"type": "number",
"description": "The opaque integer code to pass into faostat_query_observations."
},
"name": {
"type": "string",
"description": "Human-readable label."
},
"kind": {
"anyOf": [
{
"type": "string",
"enum": [
"country",
"aggregate"
]
},
{
"type": "null"
}
],
"description": "For areas: \"country\" (individual nation) or \"aggregate\" (region/grouping; excluded from sums by default). Null for items/elements."
},
"cpc_code": {
"description": "CPC crosswalk code for items (apostrophe stripped), when available.",
"type": "string"
}
},
"required": [
"code",
"name",
"kind"
],
"additionalProperties": false,
"description": "One resolved code match."
},
"description": "Matching codes, relevance-ranked for query mode, else by code."
},
"totalMatches": {
"type": "number",
"description": "Total matches in this domain before the result cap."
},
"truncated": {
"type": "boolean",
"description": "True when more matches remain beyond the returned page — fetch them with nextOffset."
},
"nextOffset": {
"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.",
"type": "integer",
"minimum": -9007199254740991,
"maximum": 9007199254740991
},
"notice": {
"description": "Guidance when nothing matched, more pages remain, or the dimension is not yet indexed.",
"type": "string"
},
"error": {
"description": "Present when the call failed. Absent on success.",
"type": "object",
"properties": {
"code": {
"type": "integer",
"minimum": -9007199254740991,
"maximum": 9007199254740991,
"description": "JSON-RPC error code for this failure."
},
"message": {
"type": "string",
"description": "Human-readable description of what went wrong."
},
"data": {
"type": "object",
"properties": {
"reason": {
"type": "string",
"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"
]
},
"recovery": {
"description": "Actionable next step for the caller.",
"type": "object",
"properties": {
"hint": {
"type": "string"
}
},
"required": [
"hint"
],
"additionalProperties": {}
},
"retryable": {
"description": "Whether retrying may succeed.",
"type": "boolean"
}
},
"additionalProperties": {}
}
},
"required": [
"code",
"message"
],
"additionalProperties": {}
}
},
"$schema": "https://json-schema.org/draft/2020-12/schema",
"additionalProperties": false,
"anyOf": [
{
"not": {
"required": [
"error"
]
},
"required": [
"domain",
"dimension",
"matches",
"totalMatches",
"truncated"
]
},
{
"required": [
"error"
]
}
]
}🟢faostat_query_observations(domain, area_codes, item_codes, element_codes, year_start, ...)
Query a FAOSTAT domain's data cube by area(s), item(s), element(s), and year range, returning observations (area, item, element, year, value, unit, and the data-quality flag). Resolve codes first with faostat_resolve_codes — the cube is unqueryable without them. Aggregate regions (World, continents, economic groupings) are EXCLUDED by default so a naive SUM does not double-count a region with its member countries; set include_aggregates=true to get the regional roll-ups, or pass explicit area_codes to query exactly what you name. Small result sets return inline; large ones spill to a DataCanvas table (returned canvas_id + table_name) for GROUP BY / ranking / time-series analysis via faostat_dataframe_query. Every row carries its flag — commonly A=Official, B=time-series break, E=Estimated, I=Imputed, M=Missing (value cannot exist), T=Unofficial, X=from an international organization, plus others FAOSTAT defines per domain — so honor it, treat any unrecognized flag as informational, and never assume an estimated, imputed, or unrecognized value is official.
Eingabe-Schema
{
"type": "object",
"properties": {
"domain": {
"type": "string",
"minLength": 1,
"description": "FAOSTAT domain code (e.g. \"QCL\"). Must be indexed locally."
},
"area_codes": {
"description": "Area codes from faostat_resolve_codes. When set, aggregates are NOT auto-excluded — the codes are honored verbatim.",
"type": "array",
"items": {
"type": "integer",
"minimum": -9007199254740991,
"maximum": 9007199254740991
}
},
"item_codes": {
"description": "Item codes from faostat_resolve_codes.",
"type": "array",
"items": {
"type": "integer",
"minimum": -9007199254740991,
"maximum": 9007199254740991
}
},
"element_codes": {
"description": "Element codes from faostat_resolve_codes (e.g. 5510 Production).",
"type": "array",
"items": {
"type": "integer",
"minimum": -9007199254740991,
"maximum": 9007199254740991
}
},
"year_start": {
"description": "Inclusive start year (e.g. 2000).",
"type": "integer",
"minimum": -9007199254740991,
"maximum": 9007199254740991
},
"year_end": {
"description": "Inclusive end year (e.g. 2022).",
"type": "integer",
"minimum": -9007199254740991,
"maximum": 9007199254740991
},
"include_aggregates": {
"default": false,
"description": "When false (default), exclude aggregate-region rows (codes ≥ 5000 plus a few curated sub-threshold roll-ups such as China=351) so sums are not double-counted. Set true for World/continent/grouping roll-ups. Ignored when explicit area_codes are passed.",
"type": "boolean"
},
"limit": {
"default": 200,
"description": "Max observations returned inline — also the preview size when the result stages to a canvas table. Rows past it are never dropped silently: a match larger than limit stages in full to a DataCanvas table (canvas_id + table_name), and when no table is staged the notice reports how many matched so you can raise limit or narrow the filters. Max 1000.",
"type": "integer",
"minimum": 1,
"maximum": 1000
},
"canvas_id": {
"description": "Canvas ID to stage onto, as returned by a prior faostat_query_observations / faostat_commodity_profile call — exactly 10 characters of letters, digits, hyphens, and underscores. Omit to stage onto this session’s canvas, created on the first spill and reused by every later call, so tables staged earlier in the session sit alongside this one.",
"type": "string",
"pattern": "^[A-Za-z0-9_-]{10}$"
}
},
"required": [
"domain"
],
"$schema": "https://json-schema.org/draft/2020-12/schema",
"additionalProperties": false
}Ausgabe-Schema
{
"type": "object",
"properties": {
"domain": {
"type": "string",
"description": "The domain code echoed back."
},
"observations": {
"type": "array",
"items": {
"type": "object",
"properties": {
"area_code": {
"type": "number",
"description": "Area code."
},
"area": {
"type": "string",
"description": "Area name."
},
"item_code": {
"type": "number",
"description": "Item code."
},
"item": {
"type": "string",
"description": "Item name."
},
"element_code": {
"type": "number",
"description": "Element code."
},
"element": {
"type": "string",
"description": "Element (metric) name."
},
"year": {
"type": "number",
"description": "Observation year."
},
"value": {
"description": "Observed value; null when the cell is empty.",
"type": [
"number",
"null"
]
},
"unit": {
"description": "Unit of measure; null when unspecified.",
"type": [
"string",
"null"
]
},
"flag": {
"description": "Data-quality flag — commonly A=Official, B=time-series break, E=Estimated, I=Imputed, M=Missing (value cannot exist), T=Unofficial, X=from an international organization, plus others FAOSTAT defines per domain; treat any unrecognized flag as informational, never assume official. Null when unflagged.",
"type": [
"string",
"null"
]
}
},
"required": [
"area_code",
"area",
"item_code",
"item",
"element_code",
"element",
"year",
"value",
"unit",
"flag"
],
"additionalProperties": false,
"description": "One observation. The flag is load-bearing — never drop or ignore it."
},
"description": "Inline observations (preview when the full set spilled to a canvas table)."
},
"spilled": {
"type": "boolean",
"description": "True when the full result was staged on a DataCanvas table."
},
"truncated": {
"type": "boolean",
"description": "True when the staged table hit the 50,000-row staging cap — the staged set is a PREFIX of the match, not the complete result. Partition the query by year or code ranges to capture the rest."
},
"canvas_id": {
"description": "Canvas ID holding the staged result — pass to faostat_dataframe_query / _describe.",
"type": "string"
},
"table_name": {
"description": "Canvas table name holding the full result set (present when spilled).",
"type": "string"
},
"staged_row_count": {
"description": "Rows actually staged on the canvas table (present when spilled). Equals the full match count unless truncated, in which case it is the 50,000-row cap.",
"type": "number"
},
"totalCount": {
"type": "number",
"description": "Observations matched. Exact when the result was returned inline or fully staged. A floor — more matched — in two cases, both named by the notice: the match exceeded the 50,000-row staging cap (truncated is then true), or staging failed and the response fell back to an inline page."
},
"notice": {
"description": "Guidance on empty results, aggregate exclusion, or how to reach the spilled set.",
"type": "string"
},
"error": {
"description": "Present when the call failed. Absent on success.",
"type": "object",
"properties": {
"code": {
"type": "integer",
"minimum": -9007199254740991,
"maximum": 9007199254740991,
"description": "JSON-RPC error code for this failure."
},
"message": {
"type": "string",
"description": "Human-readable description of what went wrong."
},
"data": {
"type": "object",
"properties": {
"reason": {
"type": "string",
"description": "Machine-readable failure mode. Declared by this tool: `domain_not_indexed`: The domain is not in the local mirror selection (FAOSTAT_DOMAINS) — whether a valid FAOSTAT code or not. `index_not_ready`: The domain mirror is cold — its initial sync has never completed. `canvas_disabled`: The result is too large to inline but DataCanvas is off, so it cannot be staged for SQL. `invalid_year_range`: year_start is greater than year_end — a self-contradictory range that can never match. Other values are possible when a failure originates below the handler.",
"examples": [
"domain_not_indexed",
"index_not_ready",
"canvas_disabled",
"invalid_year_range"
]
},
"recovery": {
"description": "Actionable next step for the caller.",
"type": "object",
"properties": {
"hint": {
"type": "string"
}
},
"required": [
"hint"
],
"additionalProperties": {}
},
"retryable": {
"description": "Whether retrying may succeed.",
"type": "boolean"
}
},
"additionalProperties": {}
}
},
"required": [
"code",
"message"
],
"additionalProperties": {}
}
},
"$schema": "https://json-schema.org/draft/2020-12/schema",
"additionalProperties": false,
"anyOf": [
{
"not": {
"required": [
"error"
]
},
"required": [
"domain",
"observations",
"spilled",
"truncated",
"totalCount"
]
},
{
"required": [
"error"
]
}
]
}🟢faostat_commodity_profile(item_query, year_start, year_end, top_n, canvas_id)
Assemble a global profile for one commodity in a single call: top-producing countries, the annual production trend, and trade flows (top exporters and importers). Accepts a commodity name, resolves it to item codes, then queries the production (QCL) and trade (TCL) domains and merges the results. Each ranking is a per-country sum across the resolved items, taken at that country's own latest year with data and grouped by unit so incomparable quantities are never added. The trend is returned inline as year/value points. Country-level only (aggregates excluded). When a required domain is not indexed locally, returns a partial profile with a notice naming the gap rather than failing. The full merged observation set spills to a DataCanvas table for deeper SQL via faostat_dataframe_query.
Eingabe-Schema
{
"type": "object",
"properties": {
"item_query": {
"type": "string",
"minLength": 1,
"description": "Commodity name to profile (e.g. \"maize\", \"wheat\", \"coffee green\"). Matched by relevance; the 5 best-matching items are folded into one profile, so a broad name such as \"milk\" is narrowed — the response discloses how many items matched in total."
},
"year_start": {
"description": "Inclusive start year for the trend (e.g. 1990).",
"type": "integer",
"minimum": -9007199254740991,
"maximum": 9007199254740991
},
"year_end": {
"description": "Inclusive end year for the trend (e.g. 2022).",
"type": "integer",
"minimum": -9007199254740991,
"maximum": 9007199254740991
},
"top_n": {
"default": 10,
"description": "Number of top producers / exporters / importers to return. Max 50.",
"type": "integer",
"minimum": 1,
"maximum": 50
},
"canvas_id": {
"description": "Canvas ID to stage onto, as returned by a prior faostat_query_observations / faostat_commodity_profile call — exactly 10 characters of letters, digits, hyphens, and underscores. Omit to stage onto this session’s canvas, created on the first spill and reused by every later call, so tables staged earlier in the session sit alongside this one.",
"type": "string",
"pattern": "^[A-Za-z0-9_-]{10}$"
}
},
"required": [
"item_query"
],
"$schema": "https://json-schema.org/draft/2020-12/schema",
"additionalProperties": false
}Ausgabe-Schema
{
"type": "object",
"properties": {
"item_query": {
"type": "string",
"description": "The commodity query echoed back."
},
"resolved_items": {
"type": "array",
"items": {
"type": "object",
"properties": {
"code": {
"type": "number",
"description": "Resolved item code."
},
"name": {
"type": "string",
"description": "Resolved item name."
}
},
"required": [
"code",
"name"
],
"additionalProperties": false,
"description": "One resolved commodity."
},
"description": "Commodities the query resolved to (the profile aggregates across all of them)."
},
"top_producers": {
"type": "array",
"items": {
"type": "object",
"properties": {
"area_code": {
"type": "number",
"description": "Country code."
},
"area": {
"type": "string",
"description": "Country name."
},
"value": {
"type": "number",
"description": "Production summed across the resolved items for this country, in its latest reporting year."
},
"observations": {
"type": "number",
"description": "Observations summed into value — one per resolved item reporting that year."
},
"unit": {
"description": "Unit of measure for value; null when unspecified. Rows are grouped by unit, so values in different units are never summed together — a country can appear once per unit.",
"type": [
"string",
"null"
]
},
"year": {
"type": "number",
"description": "This country's own latest year with data, computed per country — a country whose series ends earlier still ranks, at its own last reported year."
},
"flags": {
"description": "Distinct data-quality flags across the summed observations, comma-separated and sorted — commonly A=Official, B=time-series break, E=Estimated, I=Imputed, M=Missing (value cannot exist), T=Unofficial, X=from an international organization, plus others FAOSTAT defines per domain; treat any unrecognized flag as informational, never assume official. Null when no summed observation carried a flag. More than one flag means the total mixes data qualities.",
"type": [
"string",
"null"
]
}
},
"required": [
"area_code",
"area",
"value",
"observations",
"unit",
"year",
"flags"
],
"additionalProperties": false,
"description": "One top-producing country."
},
"description": "Top producers by summed production (countries only)."
},
"top_exporters": {
"type": "array",
"items": {
"type": "object",
"properties": {
"area_code": {
"type": "number",
"description": "Country code."
},
"area": {
"type": "string",
"description": "Country name."
},
"value": {
"type": "number",
"description": "Export quantity summed across the resolved items for this country, in its latest reporting year."
},
"observations": {
"type": "number",
"description": "Observations summed into value — one per resolved item reporting that year."
},
"unit": {
"description": "Unit of measure for value; null when unspecified. Rows are grouped by unit, so values in different units are never summed together — a country can appear once per unit.",
"type": [
"string",
"null"
]
},
"year": {
"type": "number",
"description": "This country's own latest year with data, computed per country — a country whose series ends earlier still ranks, at its own last reported year."
},
"flags": {
"description": "Distinct data-quality flags across the summed observations, comma-separated and sorted — commonly A=Official, B=time-series break, E=Estimated, I=Imputed, M=Missing (value cannot exist), T=Unofficial, X=from an international organization, plus others FAOSTAT defines per domain; treat any unrecognized flag as informational, never assume official. Null when no summed observation carried a flag. More than one flag means the total mixes data qualities.",
"type": [
"string",
"null"
]
}
},
"required": [
"area_code",
"area",
"value",
"observations",
"unit",
"year",
"flags"
],
"additionalProperties": false,
"description": "One top-exporting country."
},
"description": "Top exporters by summed export quantity (empty when trade is not indexed)."
},
"top_importers": {
"type": "array",
"items": {
"type": "object",
"properties": {
"area_code": {
"type": "number",
"description": "Country code."
},
"area": {
"type": "string",
"description": "Country name."
},
"value": {
"type": "number",
"description": "Import quantity summed across the resolved items for this country, in its latest reporting year."
},
"observations": {
"type": "number",
"description": "Observations summed into value — one per resolved item reporting that year."
},
"unit": {
"description": "Unit of measure for value; null when unspecified. Rows are grouped by unit, so values in different units are never summed together — a country can appear once per unit.",
"type": [
"string",
"null"
]
},
"year": {
"type": "number",
"description": "This country's own latest year with data, computed per country — a country whose series ends earlier still ranks, at its own last reported year."
},
"flags": {
"description": "Distinct data-quality flags across the summed observations, comma-separated and sorted — commonly A=Official, B=time-series break, E=Estimated, I=Imputed, M=Missing (value cannot exist), T=Unofficial, X=from an international organization, plus others FAOSTAT defines per domain; treat any unrecognized flag as informational, never assume official. Null when no summed observation carried a flag. More than one flag means the total mixes data qualities.",
"type": [
"string",
"null"
]
}
},
"required": [
"area_code",
"area",
"value",
"observations",
"unit",
"year",
"flags"
],
"additionalProperties": false,
"description": "One top-importing country."
},
"description": "Top importers by summed import quantity (empty when trade is not indexed)."
},
"production_trend": {
"type": "array",
"items": {
"type": "object",
"properties": {
"year": {
"type": "number",
"description": "Observation year."
},
"value": {
"type": "number",
"description": "Production summed across every country and resolved item reporting that year."
},
"observations": {
"type": "number",
"description": "Observations summed into value — read it alongside value, since a change in coverage moves the total independently of production."
},
"unit": {
"description": "Unit of measure for value; null when unspecified. Points are grouped by unit, so a year can appear once per unit rather than summing incomparable quantities.",
"type": [
"string",
"null"
]
},
"flags": {
"description": "Distinct data-quality flags across the summed observations, comma-separated and sorted — commonly A=Official, B=time-series break, E=Estimated, I=Imputed, M=Missing (value cannot exist), T=Unofficial, X=from an international organization, plus others FAOSTAT defines per domain; treat any unrecognized flag as informational, never assume official. Null when no summed observation carried a flag. More than one flag means the total mixes data qualities.",
"type": [
"string",
"null"
]
}
},
"required": [
"year",
"value",
"observations",
"unit",
"flags"
],
"additionalProperties": false,
"description": "One annual trend point."
},
"description": "The annual production series for the resolved commodity, summed over countries and items per year and ordered oldest-first. Aggregated in SQL over the complete filtered match, so it is not affected by the canvas staging cap."
},
"trend_points": {
"type": "number",
"description": "Total production observations aggregated into production_trend. Exact — the aggregation runs over the complete filtered match, not a capped page."
},
"spilled": {
"type": "boolean",
"description": "True when the merged observation set was staged on a canvas table."
},
"truncated": {
"type": "boolean",
"description": "True when the STAGED CANVAS TABLE hit the 50,000-row staging cap and is therefore a PREFIX of the merged observation set — re-query faostat_query_observations partitioned by year to stage the rest. The rankings and production_trend above are SQL aggregates over the complete match and stay exact either way."
},
"canvas_id": {
"description": "Canvas ID holding the merged set — pass to faostat_dataframe_query / _describe.",
"type": "string"
},
"table_name": {
"description": "Canvas table holding the staged observations — production plus trade when the trade domain (TCL) is indexed, production only when it is not (present when spilled). The notice names which of the two the table holds.",
"type": "string"
},
"staged_row_count": {
"description": "Rows actually staged on the merged canvas table (present when spilled). Equals the 50,000-row cap when truncated.",
"type": "number"
},
"resolvedItemCodes": {
"type": "array",
"items": {
"type": "number"
},
"description": "Item codes the commodity query resolved to."
},
"resolvedItemMatches": {
"type": "number",
"description": "Total items the commodity query matched in QCL, before the 5-item profile cap."
},
"itemsTruncated": {
"type": "boolean",
"description": "True when the commodity name matched more items than the profile folded in — the profile then covers only the most relevant few."
},
"notice": {
"description": "Names any required domain that was not indexed, item-resolution truncation, mixed units in the rankings, or other partial-result context.",
"type": "string"
},
"error": {
"description": "Present when the call failed. Absent on success.",
"type": "object",
"properties": {
"code": {
"type": "integer",
"minimum": -9007199254740991,
"maximum": 9007199254740991,
"description": "JSON-RPC error code for this failure."
},
"message": {
"type": "string",
"description": "Human-readable description of what went wrong."
},
"data": {
"type": "object",
"properties": {
"reason": {
"type": "string",
"description": "Machine-readable failure mode. Declared by this tool: `no_match`: The item query resolved to no commodity code. `index_not_ready`: The production (QCL) mirror is cold — its initial sync has never completed. `invalid_year_range`: year_start is greater than year_end — a self-contradictory range that can never match. The bounds reach the production, trade, and merged canvas-stream queries alike, so every one of them would return nothing. Other values are possible when a failure originates below the handler.",
"examples": [
"no_match",
"index_not_ready",
"invalid_year_range"
]
},
"recovery": {
"description": "Actionable next step for the caller.",
"type": "object",
"properties": {
"hint": {
"type": "string"
}
},
"required": [
"hint"
],
"additionalProperties": {}
},
"retryable": {
"description": "Whether retrying may succeed.",
"type": "boolean"
}
},
"additionalProperties": {}
}
},
"required": [
"code",
"message"
],
"additionalProperties": {}
}
},
"$schema": "https://json-schema.org/draft/2020-12/schema",
"additionalProperties": false,
"anyOf": [
{
"not": {
"required": [
"error"
]
},
"required": [
"item_query",
"resolved_items",
"top_producers",
"top_exporters",
"top_importers",
"production_trend",
"trend_points",
"spilled",
"truncated",
"resolvedItemCodes",
"resolvedItemMatches",
"itemsTruncated"
]
},
{
"required": [
"error"
]
}
]
}🟢faostat_dataframe_query(canvas_id, sql, row_limit)
Run a single-statement SELECT against the canvas tables staged by faostat_query_observations and faostat_commodity_profile (table names look like faostat_xxxxxxxx). Use this for cross-country and cross-item aggregation, GROUP BY rankings, joins, and time-series analysis over the full result set the inline preview only sampled. Standard DuckDB SQL — joins, aggregates, window functions, CTEs all work. Read-only: writes, DDL, DROP, COPY, PRAGMA, ATTACH, and external-file table functions are rejected; system catalogs (information_schema, sqlite_master, duckdb_*) are denied — list staged tables via faostat_dataframe_describe. Every row carries its data-quality `flag` — commonly A=Official, B=time-series break, E=Estimated, I=Imputed, M=Missing (value cannot exist), T=Unofficial, X=from an international organization, plus others FAOSTAT defines per domain — keep it in projections, treat any unrecognized flag as informational, and never assume it is official.
Eingabe-Schema
{
"type": "object",
"properties": {
"canvas_id": {
"description": "Optional canvas ID as returned by a prior faostat_query_observations / faostat_commodity_profile call — exactly 10 characters of letters, digits, hyphens, and underscores. Omit to query the tables staged in this session (the common case).",
"type": "string",
"pattern": "^[A-Za-z0-9_-]{10}$"
},
"sql": {
"type": "string",
"minLength": 1,
"description": "Single-statement read-only SELECT against staged faostat_<id> tables. Columns: area_code, area, item_code, item, element_code, element, year, unit, value, flag. CAST(value AS DOUBLE) for arithmetic."
},
"row_limit": {
"default": 1000,
"description": "Hard cap on rows in the response. Default 1000, max 10000.",
"type": "integer",
"minimum": 1,
"maximum": 10000
}
},
"required": [
"sql"
],
"$schema": "https://json-schema.org/draft/2020-12/schema",
"additionalProperties": false
}Ausgabe-Schema
{
"type": "object",
"properties": {
"columns": {
"type": "array",
"items": {
"type": "string"
},
"description": "Column names in projection order."
},
"row_count": {
"type": "number",
"description": "Rows returned in this response — the materialized count, equal to rows.length. When truncated is true this is NOT the full result total (this path computes no exact total); page or aggregate to reach the rest."
},
"rows": {
"type": "array",
"items": {
"type": "object",
"propertyNames": {
"type": "string"
},
"additionalProperties": {}
},
"description": "Materialized result rows, bounded by row_limit."
},
"truncated": {
"type": "boolean",
"description": "True when row_limit capped the result and more rows exist than were returned. To reach them: page with ORDER BY + SQL LIMIT/OFFSET, raise row_limit (max 10000), or aggregate with GROUP BY."
},
"notice": {
"description": "Guidance when the query returned no rows or when results were capped.",
"type": "string"
},
"error": {
"description": "Present when the call failed. Absent on success.",
"type": "object",
"properties": {
"code": {
"type": "integer",
"minimum": -9007199254740991,
"maximum": 9007199254740991,
"description": "JSON-RPC error code for this failure."
},
"message": {
"type": "string",
"description": "Human-readable description of what went wrong."
},
"data": {
"type": "object",
"properties": {
"reason": {
"type": "string",
"description": "Machine-readable failure mode. Declared by this tool: `canvas_disabled`: The DataCanvas service is not configured for this deployment. `canvas_not_found`: An explicit canvas_id does not resolve to a live canvas — unknown, expired, or owned by another tenant. `missing_table`: The SQL references a faostat_<id> table that has expired or was never staged. `system_catalog_access`: The SQL references a denied system catalog (information_schema, sqlite_master, duckdb_*). `invalid_sql`: The SQL has a syntax or execution error, or is not a single read-only SELECT. Other values are possible when a failure originates below the handler.",
"examples": [
"canvas_disabled",
"canvas_not_found",
"missing_table",
"system_catalog_access",
"invalid_sql"
]
},
"recovery": {
"description": "Actionable next step for the caller.",
"type": "object",
"properties": {
"hint": {
"type": "string"
}
},
"required": [
"hint"
],
"additionalProperties": {}
},
"retryable": {
"description": "Whether retrying may succeed.",
"type": "boolean"
}
},
"additionalProperties": {}
}
},
"required": [
"code",
"message"
],
"additionalProperties": {}
}
},
"$schema": "https://json-schema.org/draft/2020-12/schema",
"additionalProperties": false,
"anyOf": [
{
"not": {
"required": [
"error"
]
},
"required": [
"columns",
"row_count",
"rows",
"truncated"
]
},
{
"required": [
"error"
]
}
]
}🟢faostat_dataframe_describe(canvas_id, name, limit, offset)
List the canvas tables (faostat_xxxxxxxx) staged by faostat_query_observations and faostat_commodity_profile, each with its source tool, the query parameters that produced it, creation/expiry timestamps, row count, and column schema. Call this before faostat_dataframe_query to discover the exact table and column names to reference in SQL. Tables are listed newest-first and paged: pass `name` to describe one table outright, or page with `offset` + `limit` — when the response reports `truncated`, pass the returned `nextOffset` to fetch the rest.
Eingabe-Schema
{
"type": "object",
"properties": {
"canvas_id": {
"description": "Optional canvas ID as returned by a prior faostat_query_observations / faostat_commodity_profile call — exactly 10 characters of letters, digits, hyphens, and underscores. Omit to list the tables staged in this session (the common case).",
"type": "string",
"pattern": "^[A-Za-z0-9_-]{10}$"
},
"name": {
"description": "Optional table name (faostat_xxxxxxxx) to describe a single staged table. Takes precedence over `offset` / `limit`, which are ignored for a name lookup (always single-page).",
"type": "string"
},
"limit": {
"default": 20,
"description": "Maximum staged tables to return on this page (max 100). Each entry carries a full column schema, so the default keeps a discovery call small.",
"type": "integer",
"minimum": 1,
"maximum": 100
},
"offset": {
"default": 0,
"description": "Zero-based pagination offset into the staged tables (newest first). When the response reports truncated, pass the returned nextOffset here to fetch the next page. Ignored for `name` lookups.",
"type": "integer",
"minimum": 0,
"maximum": 9007199254740991
}
},
"$schema": "https://json-schema.org/draft/2020-12/schema",
"additionalProperties": false
}Ausgabe-Schema
{
"type": "object",
"properties": {
"tables": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {
"type": "string",
"description": "Canvas table name (faostat_xxxxxxxx)."
},
"source_tool": {
"type": "string",
"description": "Tool that staged this table."
},
"query_params": {
"type": "object",
"propertyNames": {
"type": "string"
},
"additionalProperties": {},
"description": "Input parameters the source tool was called with."
},
"created_at": {
"type": "string",
"description": "ISO 8601 creation timestamp."
},
"expires_at": {
"type": "string",
"description": "ISO 8601 expiry timestamp. Sliding TTL touched on every staged-table op."
},
"row_count": {
"type": "number",
"description": "Rows staged in the table."
},
"truncated": {
"type": "boolean",
"description": "True when the staging cap was hit and the table holds fewer rows than the full result."
},
"column_schema": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {
"type": "string",
"description": "Column name."
},
"type": {
"type": "string",
"description": "Canvas column type (VARCHAR, BIGINT, DOUBLE, …)."
}
},
"required": [
"name",
"type"
],
"additionalProperties": false,
"description": "One column declaration."
},
"description": "Resolved column schema for the staged table."
}
},
"required": [
"name",
"source_tool",
"query_params",
"created_at",
"expires_at",
"row_count",
"truncated",
"column_schema"
],
"additionalProperties": false,
"description": "Provenance and schema for one staged table."
},
"description": "Active staged tables for this session, newest first — one page of them. Empty when none are staged."
},
"totalMatches": {
"type": "number",
"description": "Staged tables on the resolved canvas, before the page limit is applied."
},
"truncated": {
"type": "boolean",
"description": "True when more staged tables remain beyond the returned page — fetch them with nextOffset. Always false for a single-table `name` lookup, which is never paged."
},
"nextOffset": {
"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 `name` lookups.",
"type": "integer",
"minimum": -9007199254740991,
"maximum": 9007199254740991
},
"notice": {
"description": "Guidance when nothing is staged yet or more pages remain.",
"type": "string"
},
"error": {
"description": "Present when the call failed. Absent on success.",
"type": "object",
"properties": {
"code": {
"type": "integer",
"minimum": -9007199254740991,
"maximum": 9007199254740991,
"description": "JSON-RPC error code for this failure."
},
"message": {
"type": "string",
"description": "Human-readable description of what went wrong."
},
"data": {
"type": "object",
"properties": {
"reason": {
"type": "string",
"description": "Machine-readable failure mode. Declared by this tool: `canvas_disabled`: The DataCanvas service is not configured for this deployment. `canvas_not_found`: An explicit canvas_id does not resolve to a live canvas — unknown, expired, or owned by another tenant. `missing_table`: A name filter was supplied but no staged table on the resolved canvas matches it. Other values are possible when a failure originates below the handler.",
"examples": [
"canvas_disabled",
"canvas_not_found",
"missing_table"
]
},
"recovery": {
"description": "Actionable next step for the caller.",
"type": "object",
"properties": {
"hint": {
"type": "string"
}
},
"required": [
"hint"
],
"additionalProperties": {}
},
"retryable": {
"description": "Whether retrying may succeed.",
"type": "boolean"
}
},
"additionalProperties": {}
}
},
"required": [
"code",
"message"
],
"additionalProperties": {}
}
},
"$schema": "https://json-schema.org/draft/2020-12/schema",
"additionalProperties": false,
"anyOf": [
{
"not": {
"required": [
"error"
]
},
"required": [
"tables",
"totalMatches",
"truncated"
]
},
{
"required": [
"error"
]
}
]
}Community
Nachweis