@cyanheads/faostat-mcp-server
Provides tools for querying FAOSTAT, the UN Food and Agriculture Organization's global agriculture statistics database, enabling access to crop production, trade, food balances, and more for 245+ countries from 1961 to present.
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@@cyanheads/faostat-mcp-serverWhat is the rice production in Vietnam in 2020?"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
Public Hosted Server: https://faostat.caseyjhand.com/mcp
Overview
FAOSTAT is the UN Food and Agriculture Organization's authoritative global statistics service — crop and livestock production, agricultural trade, food balances, food security and nutrition, land use, fertilizer use, and agrifood-systems emissions for 245+ countries and territories from 1961 to the present. Each domain is a data cube of area (country/region) × item (commodity) × element (metric) × year, with a data-quality flag on every observation.
This server does not call the FAOSTAT REST query API — that endpoint is auth-gated (HTTP 401 keyless). Instead it syncs FAOSTAT's keyless bulk-download service (per-domain ZIPs of normalized CSVs plus their dimension code lists) into a persistent local SQLite mirror (embedded, with FTS5 over the dimension labels) and serves every query from that mirror — fast, offline-capable, and free of per-request rate limits. Analytical query results spill to a DataCanvas (DuckDB-backed) so an agent can run SQL GROUP BY, rankings, joins, and time-series analysis over the full result set.
First run requires a mirror build. The corpus is not bundled. Run bun run mirror:init once to download and index the selected FAOSTAT domains before querying. The read tools return index_not_ready until the first sync completes. See Building the mirror.
Related MCP server: unicefstats-mcp
Tools
Six tools organized around the mirror's discover → resolve → query flow, with a DataCanvas pair for SQL over large result sets:
Tool | Description |
| Discover FAOSTAT statistical domains with codes, descriptions, last-update date, upstream row count, and local index status. The entry point — every query keys on a domain code. |
| Resolve human terms to the opaque integer codes a query needs (areas, items, elements), flagging each area as a country or an aggregate region. |
| Query a domain's cube by area(s), item(s), element(s), and year range. Inline preview for small results; large sets spill to a DataCanvas table. |
| Workflow: assemble top producers, the production trend, and trade flows for one commodity from the production and trade domains in a single call. |
| Run a read-only SQL |
| List the canvas tables staged this session, each with provenance, row count, and column schema. |
faostat_list_domains
Discover the catalog and what's queryable right now.
Full FAOSTAT catalog read live from the bulk manifest, annotated with local mirror status
Per-domain
indexed/index_readyflags, local row count, and last completed synctopicsubstring filter over code, name, and topic (e.g."trade","emissions","QCL")indexed_onlyto list just the domains queryable from the local mirrorcodefor an exact domain lookup (e.g."RL") — one full record, without a topic search that can match unrelated domainsoffset+limitto page the catalog; the response reportstotalMatches,truncated, and thenextOffsetto resume at. Domain descriptions are long, so a browse call is bounded by default — raiselimit(max 200) to pull the whole catalog in one response
faostat_resolve_codes
Turn names into the integer codes the cube requires — FAOSTAT is unqueryable without code resolution.
FTS5 full-text matching (
query, e.g."maize"→ item 56), substring filter (name_contains), or exact-code lookup (code)Resolves within a
dimension:area(countries/regions),item(commodities), orelement(metrics like production, yield, import quantity)Every area match is flagged
countryoraggregate(World, continents, economic groupings; codes ≥ 5000) so an agent can avoid summing a region with its member countriesSurfaces the CPC crosswalk code for items where available
Omit all of
query/name_contains/codeto list the whole dimension
faostat_query_observations
The core data tool — query a domain's cube and get observations with their data-quality flag.
Filter by
area_codes,item_codes,element_codes(resolve them first), and ayear_start/year_endrangeAggregate regions are excluded by default (
include_aggregates: false) so a naiveSUMdoes not double-count a region with its members — setinclude_aggregates: truefor World/continent roll-ups, or pass explicitarea_codesto query exactly what you nameSmall result sets return inline; large ones spill to a DataCanvas table (returned
canvas_id+table_name) for SQL aggregationlimitcaps the inline page (default 200, max 1000); a match that outgrows the page is staged to the canvas table in full, and when no table is staged the response reports how many matched — so a lowlimittrims the response without putting rows out of reachEvery row carries its flag (
A=Official,E=Estimated,I=Imputed,B=break,X=external) — honor it; never treat estimated/imputed values as official
faostat_commodity_profile
A workflow tool that assembles a global profile for one commodity in a single call.
Accepts a commodity name, resolves it to at most five item codes, then queries the production (
QCL) and trade (TCL) domains and merges the results — the response discloses how many items the name matched in total, so a broad term like"milk"never silently narrowsRanks top producers, top exporters, and top importers by a per-country sum across the resolved items, each country taken at its own latest year with data and grouped by unit so incomparable quantities are never added — countries only, aggregates excluded
Returns the annual production trend inline as year/value points. Rankings and trend are aggregated in SQL over the complete filtered match, so neither is bounded by the canvas staging cap
Returns a partial profile with a notice naming the gap when a required domain (e.g. trade) is not indexed, rather than failing
Rejects a reversed
year_start/year_endrange withinvalid_year_rangeinstead of returning an empty profileThe full merged production + trade observation set spills to a DataCanvas table for deeper SQL
faostat_dataframe_query / faostat_dataframe_describe
SQL analytics over the canvas tables (faostat_xxxxxxxx) that faostat_query_observations and faostat_commodity_profile stage. Call faostat_dataframe_describe first to discover table and column names, then faostat_dataframe_query for cross-country and cross-item aggregation, GROUP BY rankings, joins, window functions, and CTEs — standard DuckDB SQL.
Read-only. Writes, DDL,
DROP,COPY,PRAGMA,ATTACH, and external-file table functions are rejected by the framework SQL gate. System catalogs (information_schema,sqlite_master,duckdb_*) are denied so a caller can't enumerate staged tables it doesn't hold a handle for — list them viafaostat_dataframe_describe.Staged-table columns:
area_code,area,item_code,item,element_code,element,year,unit,value,flag. Keepflagin projections and honor it in interpretation.canvas_idis optional on both tools — omit it to operate on the tables staged in the current session (the common case).
All tool output is also rendered as human-readable markdown (content[]) alongside the structured payload, so tool-only MCP clients reach the same data.
Features
Built on @cyanheads/mcp-ts-core:
Declarative tool definitions — single file per tool, framework handles registration and validation
Unified error handling — handlers throw, the framework catches, classifies, and formats; typed error contracts give agents actionable recovery hints
Pluggable auth:
none,jwt,oauthStructured logging with optional OpenTelemetry tracing
STDIO and Streamable HTTP transports
FAOSTAT-specific:
Persistent local SQLite mirror of the FAOSTAT bulk corpus via the framework
MirrorService— one indexed table per selected domain plus shared dimension tables, with FTS5 over the dimension labels driving code resolutionStreaming bulk-ZIP ingester — fetches the manifest, compares each domain's update date against the stored checkpoint to skip unchanged domains, and stream-parses the normalized CSV (∼18× decompression ratio) into SQLite without materializing the full file in memory
Config-driven domain selection (
FAOSTAT_DOMAINS) — the indexed set can grow without code changes;faostat_list_domainscovers the full catalog — paged, and annotated with which domains are locally queryableDataCanvas SQL surface (DuckDB) — analytical cube queries spill to a staged table for ad-hoc
GROUP BY/ ranking / time-series analysis
Agent-friendly output:
Country-vs-aggregate classification on every area, plus aggregate exclusion by default — guards against the double-counting hazard of summing World/continent rows with their member countries
Data-quality flags carried through on every observation (
A/E/I/B/X) — never dropped, so downstream rigor can honor official-vs-estimated distinctionsGraceful partial results —
faostat_commodity_profilereturns a production-only profile with a notice when trade is not indexed, rather than failing the requestTyped error contracts —
index_not_ready,domain_not_indexed,empty_result,canvas_disabled, andno_matcheach carry a concrete recovery hint (run the init script, pick an indexed domain, widen the query, enable the canvas)
Getting started
Public Hosted Instance
A public instance is available at https://faostat.caseyjhand.com/mcp — no installation required. Point any MCP client at it via Streamable HTTP:
{
"mcpServers": {
"faostat-mcp-server": {
"type": "streamable-http",
"url": "https://faostat.caseyjhand.com/mcp"
}
}
}Self-Hosted / Local
Add the following to your MCP client configuration file. The server runs entirely on a local mirror, so build the mirror once before querying.
{
"mcpServers": {
"faostat-mcp-server": {
"type": "stdio",
"command": "bunx",
"args": ["@cyanheads/faostat-mcp-server@latest"],
"env": {
"MCP_TRANSPORT_TYPE": "stdio",
"MCP_LOG_LEVEL": "info"
}
}
}
}Or with npx (no Bun required):
{
"mcpServers": {
"faostat-mcp-server": {
"type": "stdio",
"command": "npx",
"args": ["-y", "@cyanheads/faostat-mcp-server@latest"],
"env": {
"MCP_TRANSPORT_TYPE": "stdio",
"MCP_LOG_LEVEL": "info"
}
}
}
}Or with Docker:
{
"mcpServers": {
"faostat-mcp-server": {
"type": "stdio",
"command": "docker",
"args": [
"run", "-i", "--rm",
"-e", "MCP_TRANSPORT_TYPE=stdio",
"-v", "faostat-mirror:/usr/src/app/.faostat-mirror",
"ghcr.io/cyanheads/faostat-mcp-server:latest"
]
}
}
}For Streamable HTTP, set the transport and start the server:
MCP_TRANSPORT_TYPE=http MCP_HTTP_PORT=3010 bun run start:http
# Server listens at http://localhost:3010/mcpNo API key is required — the FAOSTAT bulk-download service is public and keyless.
Prerequisites
Bun v1.3.0 or higher (or Node.js v24+).
Disk for the local mirror. The default domain set (
QCL,TCL,FBS,FS,RL,GLE,RFN,QV, ∼37M rows) needs a few GB;TCL(∼17M rows) dominates and can be dropped fromFAOSTAT_DOMAINSon a constrained host.
Installation
Clone the repository:
git clone https://github.com/cyanheads/faostat-mcp-server.gitNavigate into the directory:
cd faostat-mcp-serverInstall dependencies:
bun installConfigure environment:
cp .env.example .env
# edit .env to override the default domain set, mirror path, or refresh cronBuilding the mirror
The corpus is not bundled. Before the data tools can answer queries, sync the selected domains into the local mirror:
bun run mirror:init # one-time bootstrap — downloads and indexes the FAOSTAT_DOMAINS set
bun run mirror:refresh # re-sync domains whose upstream update date has advanced
bun run mirror:verify # report sync status, local row counts, and sample readsmirror:init is idempotent and resumable per domain — re-running after an interrupt re-streams only the unfinished domain ZIP. FAOSTAT_DOMAINS selects which domains are indexed; everything else in the catalog shows in faostat_list_domains with indexed: false until added and re-synced. On HTTP transport, set FAOSTAT_REFRESH_CRON to refresh in-process on a schedule; on stdio, run mirror:refresh out-of-band.
Configuration
Variable | Description | Default |
| Comma-separated FAOSTAT domain codes to index into the local mirror. Domains outside this set appear in |
|
| Directory holding the per-domain SQLite stores and the shared dimension database. Created if absent. |
|
| FAOSTAT bulk-download service base URL (manifest + per-domain ZIPs). |
|
| Cron for the in-process incremental refresh (HTTP transport only). Omit to disable and run | — |
| DataCanvas engine. |
|
| Transport: |
|
| Port for the HTTP server. |
|
| Auth mode: |
|
| Log level (RFC 5424). |
|
| Directory for log files (Node.js only). |
|
See .env.example for the full list of optional overrides.
Running the server
Local development
Build and run:
# One-time build bun run rebuild # Run the built server bun run start:stdio # or bun run start:httpRun checks and tests:
bun run devcheck # Lint, format, typecheck, security bun run test # Vitest test suite bun run lint:mcp # Validate MCP definitions against spec
Docker
docker build -t faostat-mcp-server .
docker run --rm -p 3010:3010 -v faostat-mirror:/usr/src/app/.faostat-mirror faostat-mcp-serverThe Dockerfile defaults to HTTP transport, stateless session mode, and logs to /var/log/faostat-mcp-server. The build stage compiles the native dependencies (@duckdb/node-api, better-sqlite3) and the production stage reuses the prebuilt node_modules, so the slim runtime image carries no build toolchain. OpenTelemetry peer dependencies are installed by default — build with --build-arg OTEL_ENABLED=false to omit them. Mount a volume at the mirror path to persist the corpus across container recreations, and bootstrap it inside the container:
docker exec <container> bun run mirror:init # one-time bootstrap
docker exec <container> bun run mirror:verify # sync status + sample reads
docker exec <container> bun run mirror:refresh # re-sync when FAO has updated a domainProject structure
Directory | Purpose |
|
|
| Server-specific environment variable parsing and validation with Zod. |
| Tool definitions ( |
| The bulk-download mirror service — manifest discovery, streaming ZIP ingester, CSV parsing, dimension store, SQLite-backed |
| DataCanvas accessor and the spill/query/describe staging layer. |
|
|
| Unit and integration tests mirroring |
Development guide
See CLAUDE.md/AGENTS.md for development guidelines and architectural rules. The short version:
Handlers throw, framework catches — no
try/catchin tool logicUse
ctx.logfor request-scoped logging,ctx.statefor tenant-scoped storageRegister new tools in the
createApp()array insrc/index.tsWrap external data: validate raw → normalize to domain type → return output schema; never fabricate missing fields, and carry the data-quality flag through
Data attribution
Data is sourced from FAOSTAT, the statistics division of the Food and Agriculture Organization of the United Nations (FAO). FAOSTAT data is published under CC BY-4.0; cite FAO as the source in downstream use. This project is not affiliated with or endorsed by the FAO.
Contributing
Issues and pull requests are welcome. Run checks and tests before submitting:
bun run devcheck
bun run testLicense
Apache-2.0 — see LICENSE for details.
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Servers
- AlicenseAqualityCmaintenanceEnables AI assistants to query the full FAOSTAT API for global food and agriculture statistics, allowing natural-language questions about crop production, trade, food security, emissions, and more.Last updated2116MIT
- AlicenseAqualityAmaintenanceMCP server for UNICEF child development statistics. Query 790+ child-focused indicators across 200+ countries with disaggregations by sex, age, wealth quintile, and residence. No API key required.Last updated95MIT
- Alicense-qualityBmaintenanceMCP server that exposes SQLite datasets as queryable tools and resources via Streamable HTTP, enabling read-only exploration and SQL queries.Last updatedApache 2.0
- FlicenseAqualityDmaintenanceAn MCP server that provides official statistical data for development indicators in Asia-Pacific. It wraps the ESCAP Data Explorer API, letting any MCP-compatible host query SDG and thematic data through natural language.Last updated5
Related MCP Connectors
FAS MCP — USDA Foreign Agricultural Service (trade & global production data)
MCP server for Statistics Sweden (SCB) - 1200+ tables with population, economy, environment data
MCP server for Mireye Earth — federal-source-cited geospatial data for any MCP-aware agent.
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/cyanheads/faostat-mcp-server'
If you have feedback or need assistance with the MCP directory API, please join our Discord server