xippios-faostat-mcp
This server does not currently have a deployable release on Glama. Follow the repository's setup instructions to install and configure it for your MCP client, including any required credentials and local dependencies.
xippios-faostat
Typed Python client, MCP server and FastAPI routes for
FAOSTAT, part of the
xippios SDK family. Names and semantics follow the
upstream documentation; every response carries its metadata (source, endpoint,
retrieved_at, request), and get_data, get_series and download_dataset carry the
release FAOSTAT states for it in vintage.
Install
uv add xippios-faostat # client only
uv add "xippios-faostat[mcp]" # + MCP server
uv add "xippios-faostat[http]" # + FastAPI routerA FAO account is needed: FAOSTAT_USERNAME (the account's e-mail) and
FAOSTAT_PASSWORD in the environment. The client logs in with them on its first request
(POST /auth/login, FAOSTAT's auth_login), once per process, sends the access token
with every request to the API, and logs in again when the token lapses (after an hour) or a request
is refused with HTTP 401 or 403. Neither the credentials nor a token is logged, and the
tasks return neither. The bulk downloads need none.
Related MCP server: usda-nass
30-second example
from xippios.faostat import (
count_data,
get_data,
get_series,
list_codes,
list_dimensions,
list_domains,
)
from xippios.faostat.models import Lang, Section
wheat = get_data("QCL", area="231", element="2510", item="15", year=range(2015, 2022))
row = wheat.data[0] # wheat production in the United States of America, 2015
row.area, row.item, row.year # ("United States of America", "Wheat", "2015")
row.element_code, row.element # ("5510", "Production"): the answer's code, not the 2510 sent
row.value, row.value_number # ("55839540", Decimal("55839540")): as printed, and its number
row.unit, row.flag_description # ("t", "Official value")
wheat.meta.vintage # "2025-12-31": QCL's last update, as list_domains prints it
wheat.meta.request # {"lang": "en", "domain_code": "QCL", "area": "231", ...}
series = get_series("QCL", area="231", item="15", element="2510", since=2015, until=2021)
series.meta.request["year"], series.meta.request["since"] # ("2015,2016,...,2021", 2015)
counted = count_data("QCL", element="2510") # every row of QCL's element 2510, counted first
counted.data, counted.meta.total # (1643610, 1643610): a whole number, meta.total the same
january = get_data("PP", area="231", item="15", year=2020, filters={"month": "7001"})
january.data[0].months_code, january.data[0].months # ("7001", "January"): PP's month
fr = get_data("QCL", area="231", element="2510", item="15", year=2020, lang=Lang.FR)
fr.data[0].item, fr.data[0].value # ("Blé", "49751180"): French labels, the same fields
periods = get_series("FS", area="2", item="21010", since=2001, until=2002)
periods.meta.request["filters"] # {"year3": "20013,20023"}: FS's codes for those middle years
list_domains(search="prices").data # PP, CP, PD, PE (group Prices) and PA, an archive
list_domains(section=Section.COMPARE).data # the portal's compare list: no subgroups, no CP
list_codes("QCL", "element", search="production").data[0] # code "2510", "Production Quantity"
get_data("QCL", area="231", element="5510") # no rows: InvalidRequestError, Did you mean 2510?
[dimension.id for dimension in list_dimensions("FS").data] # area, element, item, year3
list_codes("FS", "year3").data[0] # code "20253", "2025 / 2024-2026": one per middle year
list_codes(
"FS", "year"
) # NotFoundError: FS has no dimension 'year' ... Did you mean year3, years3?get_data(domain_code, *, area, item, element, year, filters, area_cs, item_cs, null_values, page_size, page_number, lang) sends one request to FAOSTAT's data endpoint
(get_data, GET /{lang}/data/{domain_code}), in the language lang names, en, fr or
es, with the output options the portal sends (codes, units, flags and notes shown); each
filter is a code or a list of codes. filters takes any other dimension of the dataset by
its id, as list_dimensions names it, {"month": "7001"} in PP, {"survey": "024_2024"}
in MDDW or {"reporterarea": "231", "partnerarea": "110"} in TM, and sends each under its
id, the parameter FAOSTAT filters by; an id that get_data sends itself, such as area or
page_size, is refused. At least one filter is needed: FAOSTAT refuses a query without
one, and so does get_data, before sending, saying that nothing was sent. Without
page_size every matching row comes in one answer, which count_data counts first; with
page_size and page_number, one page. page_number without page_size, and a
page_size below 1, are refused before sending, since FAOSTAT answers page_number alone
and page_size=0 with every row. A whole year of TM, EA or FT takes FAOSTAT longer than its gateway waits, which
answers HTTP 504, so name a country there. null_values=True adds the rows of which
FAOSTAT holds nothing, without a unit, a value or flags. A query filters by the element
codes of the domain's element list (2510, Production Quantity), and the rows print other
codes (5510, Production). FAOSTAT answers a code it does not know with no rows, so
get_data checks the codes against the dataset's own lists (getCodeList), by one rule
in each of the 69 datasets: a filter of several codes is checked against its list before
the data is asked for, and with one code per filter the rows prove the codes, so only an
answer without rows has the list of each filter read. A wrong code, or a year or a
dimension that the dataset lacks, raises InvalidRequestError, naming the closest codes
and list_codes; where every code is right, the answer without rows comes with each
code's name in meta.names. area_cs and item_cs choose the coding system in which the
rows print the area and item codes, one that the dataset's dimensions name (M49, FAO, ISO2
or ISO3 for QCL's areas, CPC or FAO for its items, and in a dataset without area the
systems of its countries' dimensions, reporterarea and partnerarea in TM), checked
against its structure before the data; the filter takes FAO's codes whatever the system. A call sends at most twelve
requests: the structure, one list per filtered dimension, the data and the release date,
the structure and the lists kept for a day. An unknown domain raises NotFoundError, and
an empty domain_code, . or .. is refused before sending. meta.vintage is
the domain's date_update from list_domains (groupsanddomains); meta.published_at
stays None, since a date is no release time. Where that list cannot be read, the rows
come all the same, with meta.vintage None and a note in meta.notes naming the error.
A row is a DataRecord with the columns of its dataset's dimensions, which differ by
dataset: each field but domain_code and domain is None where the row does not print
its column, as area in TM, whose rows print the reporter and partner countries, and
area, item and year in MDDW, which prints surveys. Every column no field names stays
under FAOSTAT's header in columns, TM's countries and MDDW's surveys among them. A row
whose value is missing prints no Value, flagged O, and has value and value_number
None. In French and Spanish the headers are translated as the labels are (Code zone,
Valeur), so a row is read by the type and the dimension that the answer's metadata.dsd
gives each column, and has the same fields in each language; a column that no field reads
stays under the header FAOSTAT prints in that language.
get_series(domain_code, *, area, item, element, filters, since, until, lang) is one
get_data request for a yearly series, filtered as get_data filters, an area, an item
and an element only where the dataset has them: since and until become the years from
one to the other, or no year filter when both are left out, which answers every year the
domain holds; one without the other is refused before sending. With both, the dataset's
structure is read first, and kept for a day: the years go as upstream's comma list to
year, or to year3 where the dataset has that instead. FS has year3, ignores year
and answers neither the single years nor the codes its rows print there, so get_series
sends the codes of its own year3 list, one per middle year of three, those whose label
opens with a year from since to until (20013, 2001 / 2000-2002), the list kept for
a day too. A dataset with neither, MDDW or WCAD say, refuses since and until, once its
structure is read and before any data is asked for. The rows come in upstream's order,
area, item, year ascending in the recorded answers, and a year the domain does not hold
has no row. The codes are checked as get_data checks them, the years as a range, refused
only where an answer without rows comes and the dataset's year list holds none of them, and
meta is get_data's, with since and until added to meta.request.
count_data(domain_code, *, area, item, element, year, filters, null_values) counts the
rows of a query before they are fetched: one get_data request with no_records=true, a
parameter that the OpenAPI document names under post_datasize alone, which FAOSTAT
answers with the number of rows that the query has. data is that number, a whole number
though FAOSTAT prints a large one with a fraction part, and meta.total repeats it. It
takes the filters of get_data and null_values, which decide the rows, and checks the
codes as get_data does but in one point: the dataset's structure is read first in every
call, kept for a day, since a count prints no column that would show a filter's dimension
to be the dataset's, and FAOSTAT ignores a filter by a dimension that the dataset lacks.
A count of 0 has each filter's list read, as an answer without rows has: a wrong code
raises InvalidRequestError naming the closest codes, and right ones are named in
meta.names. meta.vintage is the domain's date_update, as get_data's is, and a call
sends at most twelve requests.
list_domains(*, search, section, lang) lists the domains and subgroups of
groupsanddomains, each with its group and release dates; search keeps the rows whose
code or name, or whose group's name, contains the text. section asks for the list of a
section of FAOSTAT's portal: download lists every domain and subgroup, as the list
without it does, browse leaves the subgroups out, and compare some datasets too.
list_dimensions(domain_code, *, lang) lists the dimensions of any of FAOSTAT's datasets
(get_dimensions, GET /{lang}/dimensions/{domain_code}), each with its id, the name its
data is filtered by, and its parts, each a code list of its own with its coding systems:
QCL has area, element, item and year, PP adds month, and FS has year3 in place
of year. list_codes(domain_code, dimension_id, *, search, show_lists, lang) lists the
codes of any of those ids as FAOSTAT serves them (getCodeList); show_lists=False
leaves out the codes that stand for a list of others, those ending >. Both answers are
kept for a day, and lang takes en, fr or es. The package ships no copy of a list,
so a look-up needs the account and, once a day, a request (ADR-0001). FAOSTAT answers an
unknown dataset, an unknown dimension and a dimension that the dataset lacks alike, with
HTTP 500 and no body, which raises NotFoundError; the task then reads the list of domains
and the dataset's structure, and names the closest dataset or dimension where they lack what
was asked.
Bulk downloads
from pathlib import Path
from xippios.faostat import download_dataset, list_bulk_datasets
from xippios.faostat.parse import parse_bulk_codes, parse_bulk_csv
list_bulk_datasets(search="land use").data[0] # dataset_code "RL", file_size "2902KB", ...
land = download_dataset("RL", dest=Path("RL.zip")) # Land Use's ZIP, written whole
land.data.path # PosixPath("RL.zip"): the ZIP as FAOSTAT serves it
land.meta.vintage # "2026-10-02T00:00:00": the catalogue's DateUpdate as printed
land.meta.published_at # 2026-10-02 00:00 without a zone, meta.published_at_naive set
rows = parse_bulk_csv(land.data.path) # one BulkRecord per row of its table, read lazily
first = next(rows)
first.area, first.area_code_m49, first.item, first.year # ("Afghanistan", "'004", ...)
first.value, first.value_number # ("65286.000000", Decimal("65286.000000"))
women = download_dataset("MDDW", dest=Path("MDDW.zip")) # the smallest dataset's ZIP
codes = list(parse_bulk_codes(women.data.path)) # one BulkCode per row of its code lists
flags = {code.flag: code.description for code in codes if code.flag}
flags["A"] # "Official figure"list_bulk_datasets(*, search) lists the datasets FAOSTAT publishes as files, from the
bulk downloads' catalogue (production/datasets_E.json on
bulks-faostat.fao.org), fetched without the account: each with its code, the domain
code get_data takes, its name, last update, the ZIP's size and URL and the rows of its
table; search keeps the datasets whose code or name contains the text.
download_dataset(dataset_code, *, dest) looks the dataset up in the catalogue and streams its
ZIP to dest, without the account, never holding it in memory or caching it; it returns
core's Downloaded (path, size, content type, ETag, Last-Modified, retrieval time).
It is a bulk task: Python only, so the MCP server and the router skip it and no agent is
handed a file path. The files run from MDDW's, the smallest, to TM's, the largest, and
list_bulk_datasets prints each one's file_size.
meta.vintage is the catalogue's DateUpdate as printed and meta.published_at the
same time, which the catalogue prints without a zone. parse_bulk_csv(path) reads the
ZIP's normalized table, the member <Name>_E_All_Data_(Normalized).csv, row by row,
straight from the archive: each BulkRecord has the columns of the production files
(area_code, area_code_m49 as printed with its apostrophe, area, item_code,
item_code_cpc, item, element_code, element, year_code, year, unit,
value as printed with value_number beside it, flag, note), None where a dataset does not print one, and
every other column of a dataset under its header in columns, as MDDW's surveys and
food groups; TCLI's table prints the items' CPC codes, '01341 for apples.
parse_bulk_codes(path) reads the code lists beside that table, the ZIP's other CSV files,
a file kind of their own with its own module, xippios.faostat.parse.bulk_codes, as the
table has xippios.faostat.parse.bulk_csv. The lists differ by dataset: ..._Elements.csv
and ..._Flags.csv, and beside them ..._AreaCodes.csv and ..._ItemCodes.csv in RL's
ZIP, ..._Indicators.csv and ..._Surveys.csv in MDDW's. Each row of each list is a
BulkCode: the list's file name in member, the columns area_code, m49_code, area, item_code, cpc_code, item,
element_code, element, flag and description, None in a list without them, and every
other column under its header in columns, as MDDW's surveys. Nothing is joined: a caller looks
a row up by its code, since a list prints a semicolon where the table has a comma in a name
(China; mainland). The lists are read row by row as the table is, and a file that is no bulk
ZIP, or a list that does not read whole, is refused with ValidationError, as is a table or a
list that is encrypted or compressed by a method that Python's zipfile does not read.
MCP
{
"mcpServers": {
"faostat": {
"command": "uvx",
"args": ["--from", "xippios-faostat[mcp]", "xippios-faostat-mcp"]
}
}
}Tools are read-only and named faostat_<verb>_<noun>. Results are capped, at 200 rows or
64 KB unless a tool has a cap of its own, with a note on how to see the rest, after the
client fetched the whole answer. The tools whose next page sends nothing new,
faostat_list_codes, faostat_list_dimensions, faostat_list_domains and
faostat_list_bulk_datasets, take offset, which the note names; faostat_get_data pages
by FAOSTAT's page_size and page_number, and faostat_get_series is narrowed by its
years and codes. --http serves streamable HTTP instead of stdio.
Status
Upstream operation | Task function | MCP tool | Status |
|
|
| alpha |
|
|
| alpha |
|
|
| alpha |
|
|
| alpha |
|
|
| alpha |
|
|
| alpha |
|
|
| alpha |
The catalogue's |
| none: a bulk task, Python only, which the adapters skip | alpha |
Every request to the API logs in first where the process has no current token
(auth_login, POST /auth/login); the login is the client's, no task's. The bulk
downloads' catalogue and files are fetched without it.
Scope
FAOSTAT's OpenAPI document holds 24 operations, and the package's scope is its data, its
lists and its releases, sixteen of them: the login, auth_login; get_data, with
post_datasize as its count; the code lists getCodeList, get_codes and
get_dimensions; the domains and their groups, get_groupsanddomains, get_domains and
get_groups; get_bulkdownloads, beside the bulk catalogue and its ZIPs; the history of
updates, get_updates; the four definitions, get_definitions_domain,
get_definitions_domain_by_type, get_definitions_types and get_definitions_by_type;
and get_metadata. Five of them are wrapped today, the login, the data, the groups and
domains, the code list and the structure, get_dimensions, as the status table above
names them; the count that post_datasize stands for is count_data's, sent as
get_data with no_records, which the document names under post_datasize alone, so
post_datasize itself is not sent. Eight are left out: post_rankings, post_reportdata and
post_reportheaders, since they are FAOSTAT's computed rankings and report tables of the
data, and
get_search, get_suggestions, get_documents, get_metadata_print and get_ping,
since they serve FAOSTAT's portal: its search, its suggestions, its list of documents, its
printable metadata and its ping. One documented parameter of the wrapped operations waits:
the value csv of get_data's output_type
(https://github.com/xippios/sdk-faostat/issues/41). These are left out: datasource on
get_data, get_groupsanddomains and get_dimensions, since it has one value, the
PRODUCTION that every answer's metadata names
(https://github.com/xippios/sdk-faostat/issues/72); List1Codes to List9Codes on
get_data, since FAOSTAT ignores them where another filter stands beside them and refuses
a query by them alone, and filters sends each dimension under its id instead
(https://github.com/xippios/sdk-faostat/issues/22); and three of get_dimensions's,
which https://github.com/xippios/sdk-faostat/issues/114 holds: full, since it adds only
the names of FAOSTAT's procedure (List1Codes and on), which the data query ignores as
filters, and the portal's form options; report_code, which serves the report tables left
out above; and the query's domain_code, which repeats the path's.
Upstream terms and attribution
Data comes from FAOSTAT (https://www.fao.org/faostat/) under the FAO Statistical Database Terms of Use: unless their metadata or webpage say otherwise, the datasets FAO's corporate statistical databases disseminate, FAOSTAT among them (the terms' Annex 1), are licensed under the Creative Commons Attribution-4.0 International licence (CC BY 4.0), as complemented by those terms. The terms ask for this citation:
FAO. [YYYY (year of last update)]. [Name of database: Name of dataset OR Name of database]. [Accessed on [DD Month YYYY]]. [URL] Licence: CC-BY-4.0.
This package adds no rights to the data. Documentation snapshot and its attribution:
docs/upstream/FETCHED.md.
Workflows
ci.yml runs ruff, its format check, mypy, pytest and pre-commit on Python 3.12, 3.13 and
3.14, requires a changelog entry of every pull request but Dependabot's and refuses a
fixture file over 256 KiB that a pull request adds or changes. It runs on every pull request and,
called by publish.yml, once for a release, and its job ci is the check the
organization's ruleset requires. It is handed no secret, and no variable switches it off.
publish.yml is the release train (conventions §12): on a push to main whose
pyproject.toml names a version that has no tag yet and has its section in CHANGELOG.md,
it runs ci.yml, refuses a core pinned to git, tags the merge commit, builds the package
and, once a reviewer of the environment pypi approves the run, publishes it to PyPI by
trusted publishing. Every push to main and a dispatch start it, and a push that brings no
release ends quietly. It is handed no secret: the step that tells a release is handed the
job's token as GH_TOKEN, the tag goes with the job's token and PyPI trusts the workflow
itself. Its job tag holds the one checkout of the repository that keeps its credentials,
since it pushes the tag with the job's token; every other checkout sets
persist-credentials: false (conventions §13). No variable switches it off.
live.yml runs every live test against the upstream with --tb=short --assert=plain, so
its public log holds neither a failing test's arguments nor the values an assertion compared.
It runs every night at 02:10 UTC and on demand, never on a pull request.
Its pytest step alone is handed XIPPIOS_LIVE_TESTS and, each from the secret of the same
name, FAOSTAT_USERNAME, FAOSTAT_PASSWORD, so the checkout, setup-uv and uv sync see none.
A variable WORKFLOW_LIVE of off, the repository's over the organization's, switches it off.
conventions.yml calls the organization's review of a pull request against the documents
listed under Documents below, the check conventions / conventions, when a pull request
opens, is pushed to, reopens or is edited, and on a push to main or a dispatch the review
of the range of commits, range / range. It hands the review the organization's
secret of the model's key, by name. A variable WORKFLOW_CONVENTIONS of off, the
repository's over the organization's, switches both off.
adr-index.yml calls the organization's check of the ADR index, adr-index / adr-index,
which runs scripts/adr_index.py --check, when a pull request opens, is pushed to or
reopens. It hands over nothing, and the called workflow reads its switch itself: a variable
WORKFLOW_ADR_INDEX of off, the repository's over the organization's, skips the check.
Documents
sdk-core: docs/conventions.md — the conventions every xippios source package follows: its layout, names, results, tests and releases.
sdk-core: docs/adr.md — the index of the family's architecture decisions, which the conventions cite.
sdk-core: docs/definition-of-done.md — what a change satisfies before its pull request is opened.
sdk-core: docs/review-checklist.md — what the review of a pull request checks, in order.
sdk-faostat: docs/adr.md — the index of this package's own decisions, generated from the records in
docs/adr/.sdk-faostat: docs/upstream/FETCHED.md — the snapshot of the upstream documentation, the reference for names, parameters and semantics.
Licence
Apache-2.0. See LICENSE.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
This server cannot be deployed
Maintenance
Related MCP Connectors
Read-only cited financial datasets, bounded research queries and source diagnostics.
Search and query 1,500+ OECD statistical datasets via SDMX. Keyless.
Query official statistics through MCP, with periods, places and citable sources in every answer.
Search ILOSTAT labour indicators, query and compare series, build country profiles, run SQL.
Related MCP Servers
- AlicenseNot gradedqualityBmaintenanceEnables users to query UN international trade statistics and row counts through read-only MCP tools, with validated parameters and safeguards for large queries.132 PyPIApache 2.0
- AlicenseNot gradedqualityAmaintenanceExposes read-only tools for querying USDA NASS Quick Stats, covering reported counts, filtered data pulls, parameter values, crop progress and condition, county yield and production, acreage and forecasts, and prices received. Results are capped with guidance on narrowing queries.Apache 2.0
- AlicenseNot gradedqualityBmaintenanceExposes read-only tools for querying USDA FAS PSD Online commodity supply and distribution data, with every response carrying release metadata such as source, endpoint, retrieval time and vintage. Results are capped by row count and size, with guidance returned on how to narrow a query.Apache 2.0
- AlicenseNot gradedqualityBmaintenanceRead-only MCP tools for querying USDA FAS Global Agricultural Trade System census export and import records by partner country, year, month and HS10 code prefix, plus the release-date lists for each flow. Results are capped with notes on omitted rows, and responses carry release vintages and retrieval metadata.Apache 2.0