Data source: FAOSTAT API
Overview
FAOSTAT (FAO Food & Agriculture) wraps FAOSTAT API, handling authentication, pagination, and rate limits for you. This tutorial covers all 7 tools with working code examples you can copy and run.
Prerequisites
- Sign up at https://context.gnist.ai/signup for a free API key (100 calls/day).
- Choose your integration method: MCP protocol or REST API.
Connect via MCP
Add to your MCP client config (Claude Desktop, Cursor, etc.):
{
"mcpServers": {
"gnist-faostat": {
"url": "https://context.gnist.ai/mcp/faostat/",
"headers": {
"Gnist-API-Key": "YOUR_API_KEY"
}
}
}
}
Tools (7)
search_datasets
Search the FAOSTAT dataset catalog by keyword. Search across all FAO domains for datasets matching your query. FAOSTAT covers crop production, livestock, trade, prices, food security, land use, fertilizers, emissions, and more for 193+ countries. Args: query: Search term (e.g. "wheat", "rice", "food prices"). limit: Number of results to return (1-50, default 20). Returns: Matching datasets with domain codes needed for get_data calls.
| Parameter | Type | Required | Description |
|---|---|---|---|
query | string | required | Search term for FAOSTAT datasets (e.g. "wheat", "rice production", "food prices", "fertilizer", "livestock"). |
limit | integer | optional | Number of results to return (1-50, default 20). (default: 20) |
curl -X POST "https://context.gnist.ai/mcp/faostat/" \
-H "Content-Type: application/json" \
-H "Gnist-API-Key: YOUR_API_KEY" \
-d '{"jsonrpc": "2.0", "method": "tools/call", "id": 1, "params": {"name": "search_datasets", "arguments": {"query": "wheat"}}}'
import httpx
resp = httpx.post(
"https://context.gnist.ai/mcp/faostat/",
headers={"Gnist-API-Key": "YOUR_API_KEY"},
json={'id': 1,
'jsonrpc': '2.0',
'method': 'tools/call',
'params': {'arguments': {'query': 'wheat'}, 'name': 'search_datasets'}},
)
print(resp.json())
list_datasets
List available FAOSTAT dataset groups and domains. Browse the full FAOSTAT catalog organized by topic group. Use this to discover available domains before querying data. Key groups: Production (QCL, QI, QV), Trade (TCL, TM), Prices (PP, CP), Food Security (FS), Food Balances (FBS), Emissions (GT, GCE). Args: group: Optional group name filter. Omit to list all datasets. limit: Maximum datasets to return (1-200, default 50). Returns: List of datasets with group and domain codes.
| Parameter | Type | Required | Description |
|---|---|---|---|
group | any | optional | Optional group filter (e.g. "Production", "Trade", "Prices", "Food Security", "Emissions"). Omit to list all. |
limit | integer | optional | Maximum datasets to return (1-200, default 50). (default: 50) |
curl -X POST "https://context.gnist.ai/mcp/faostat/" \
-H "Content-Type: application/json" \
-H "Gnist-API-Key: YOUR_API_KEY" \
-d '{"jsonrpc": "2.0", "method": "tools/call", "id": 1, "params": {"name": "list_datasets", "arguments": {"group": "Production"}}}'
import httpx
resp = httpx.post(
"https://context.gnist.ai/mcp/faostat/",
headers={"Gnist-API-Key": "YOUR_API_KEY"},
json={'id': 1,
'jsonrpc': '2.0',
'method': 'tools/call',
'params': {'arguments': {'group': 'Production'}, 'name': 'list_datasets'}},
)
print(resp.json())
get_domain_dimensions
Get available dimensions and filter options for a FAOSTAT domain. Shows what filters (area, element, item, year) are available for a dataset, so you know what parameters to pass to get_data. Use get_dimension_codes to see the valid values for each dimension. Args: domain: FAOSTAT domain code from list_datasets. Returns: List of dimensions with IDs and labels.
| Parameter | Type | Required | Description |
|---|---|---|---|
domain | string | required | FAOSTAT domain code (e.g. "QCL" for crops, "TCL" for trade, "PP" for prices, "FS" for food security). Use list_datasets to find codes. |
curl -X POST "https://context.gnist.ai/mcp/faostat/" \
-H "Content-Type: application/json" \
-H "Gnist-API-Key: YOUR_API_KEY" \
-d '{"jsonrpc": "2.0", "method": "tools/call", "id": 1, "params": {"name": "get_domain_dimensions", "arguments": {"domain": "QCL"}}}'
import httpx
resp = httpx.post(
"https://context.gnist.ai/mcp/faostat/",
headers={"Gnist-API-Key": "YOUR_API_KEY"},
json={'id': 1,
'jsonrpc': '2.0',
'method': 'tools/call',
'params': {'arguments': {'domain': 'QCL'}, 'name': 'get_domain_dimensions'}},
)
print(resp.json())
get_dimension_codes
Get valid codes for a specific dimension of a FAOSTAT domain. Look up what area codes, element codes, item codes, or year values are valid for a domain. Use these codes in get_data filters. Common area codes: 231 (USA), 351 (China), 100 (India), 5000 (World). Common element codes vary by domain (e.g. 2510=Production quantity). Args: domain: FAOSTAT domain code. dimension: Dimension name (area, element, item, year, etc.). limit: Maximum codes to return (1-500, default 100). Returns: List of valid codes with labels and descriptions.
| Parameter | Type | Required | Description |
|---|---|---|---|
domain | string | required | FAOSTAT domain code (e.g. "QCL", "TCL", "PP"). |
dimension | string | required | Dimension name (e.g. "area" for countries, "element" for indicators, "item" for commodities, "year" for time periods). |
limit | integer | optional | Maximum codes to return (1-500, default 100). (default: 100) |
curl -X POST "https://context.gnist.ai/mcp/faostat/" \
-H "Content-Type: application/json" \
-H "Gnist-API-Key: YOUR_API_KEY" \
-d '{"jsonrpc": "2.0", "method": "tools/call", "id": 1, "params": {"name": "get_dimension_codes", "arguments": {"domain": "QCL", "dimension": "area"}}}'
import httpx
resp = httpx.post(
"https://context.gnist.ai/mcp/faostat/",
headers={"Gnist-API-Key": "YOUR_API_KEY"},
json={'id': 1,
'jsonrpc': '2.0',
'method': 'tools/call',
'params': {'arguments': {'dimension': 'area', 'domain': 'QCL'},
'name': 'get_dimension_codes'}},
)
print(resp.json())
get_data
Fetch data from a FAOSTAT domain. Query any FAOSTAT dataset filtered by area (country/region), element (indicator), item (commodity), and year. Covers production, trade, prices, food security, land use, emissions, and more for 193+ countries from 1961 to present. Args: domain: FAOSTAT domain code. Use list_datasets to find codes. areas: FAO area codes. Omit for all areas. elements: Element codes for indicator type. items: Item codes for commodities. years: Year values. area_cs: Area coding system (M49, FAO, ISO2, ISO3). limit: Maximum records to return (1-2000, default 500). Returns: Data records with area, element, item, year, value, unit, and flags.
| Parameter | Type | Required | Description |
|---|---|---|---|
domain | string | required | FAOSTAT domain code (e.g. "QCL" for crops/livestock, "TCL" for trade, "PP" for producer prices, "FS" for food security, "FBS" for food balances). Use list_datasets to find codes. |
areas | any | optional | FAO area codes (e.g. ["231", "351", "5000"] for USA, China, World). Use get_dimension_codes to find codes. Omit for all areas. |
elements | any | optional | Element codes for the indicator type (e.g. ["2510"] for production quantity, ["2610"] for import quantity). Use get_dimension_codes to find valid codes. |
items | any | optional | Item codes for commodities (e.g. ["15"] for wheat, ["27"] for rice). Use get_dimension_codes to find valid codes. |
years | any | optional | Year values (e.g. ["2020", "2021", "2022"]). Omit for all available years. |
area_cs | any | optional | Area coding system: "M49" (default), "FAO", "ISO2", or "ISO3". |
limit | integer | optional | Maximum records to return (1-2000, default 500). (default: 500) |
curl -X POST "https://context.gnist.ai/mcp/faostat/" \
-H "Content-Type: application/json" \
-H "Gnist-API-Key: YOUR_API_KEY" \
-d '{"jsonrpc": "2.0", "method": "tools/call", "id": 1, "params": {"name": "get_data", "arguments": {"domain": "QCL"}}}'
import httpx
resp = httpx.post(
"https://context.gnist.ai/mcp/faostat/",
headers={"Gnist-API-Key": "YOUR_API_KEY"},
json={'id': 1,
'jsonrpc': '2.0',
'method': 'tools/call',
'params': {'arguments': {'domain': 'QCL'}, 'name': 'get_data'}},
)
print(resp.json())
compare_countries
Compare data across countries/regions for a FAOSTAT domain. Fetches the same indicator for multiple areas side by side. Useful for cross-country analysis of production, trade volumes, food prices, food security metrics, and more. Args: domain: FAOSTAT domain code. area_codes: FAO area codes to compare. Maximum 20. elements: Element codes to filter by. items: Item codes to filter by. years: Year values to filter by. area_cs: Area coding system. Returns: Data grouped by area for easy comparison.
| Parameter | Type | Required | Description |
|---|---|---|---|
domain | string | required | FAOSTAT domain code (e.g. "QCL", "FS", "PP"). |
area_codes | list[string] | required | FAO area codes to compare (e.g. ["231", "351", "100"] for USA, China, India). Maximum 20. |
elements | any | optional | Element codes to filter by. |
items | any | optional | Item codes to filter by. |
years | any | optional | Year values to filter by. |
area_cs | any | optional | Area coding system: "M49", "FAO", "ISO2", or "ISO3". |
curl -X POST "https://context.gnist.ai/mcp/faostat/" \
-H "Content-Type: application/json" \
-H "Gnist-API-Key: YOUR_API_KEY" \
-d '{"jsonrpc": "2.0", "method": "tools/call", "id": 1, "params": {"name": "compare_countries", "arguments": {"domain": "QCL", "area_codes": "[\"231\""}}}'
import httpx
resp = httpx.post(
"https://context.gnist.ai/mcp/faostat/",
headers={"Gnist-API-Key": "YOUR_API_KEY"},
json={'id': 1,
'jsonrpc': '2.0',
'method': 'tools/call',
'params': {'arguments': {'area_codes': '["231"', 'domain': 'QCL'},
'name': 'compare_countries'}},
)
print(resp.json())
report_feedback
Report a bug, feature request, or general feedback for this data source. Use this when something doesn't work as expected, when you'd like a new feature, or when you have suggestions for improvement. Args: feedback: Describe the issue or suggestion. feedback_type: One of 'bug', 'feature_request', or 'general'.
| Parameter | Type | Required | Description |
|---|---|---|---|
feedback | string | required | |
feedback_type | string | optional | (default: general) |
curl -X POST "https://context.gnist.ai/mcp/faostat/" \
-H "Content-Type: application/json" \
-H "Gnist-API-Key: YOUR_API_KEY" \
-d '{"jsonrpc": "2.0", "method": "tools/call", "id": 1, "params": {"name": "report_feedback", "arguments": {"feedback": "example"}}}'
import httpx
resp = httpx.post(
"https://context.gnist.ai/mcp/faostat/",
headers={"Gnist-API-Key": "YOUR_API_KEY"},
json={'id': 1,
'jsonrpc': '2.0',
'method': 'tools/call',
'params': {'arguments': {'feedback': 'example'}, 'name': 'report_feedback'}},
)
print(resp.json())
Common Patterns
Use
search_datasets to find items, then get_domain_dimensions to get full details. This two-step pattern is common for exploring data before drilling down.Several tools support
limit, offset, or page parameters. Start with small limits during development, then increase for production queries.FAQ
What data does FAOSTAT (FAO Food & Agriculture) provide?
FAO food and agriculture statistics — crop production, livestock, trade, prices, food security, land use, fertilizers, and emissions data for 193+ countries from 1961 to present. It exposes 7 tools: search_datasets, list_datasets, get_domain_dimensions, get_dimension_codes, get_data, compare_countries, report_feedback.
What do I need to get started?
A Gnist API key (free tier: 100 calls/day). Sign up at https://context.gnist.ai/signup.
What format does the FAOSTAT (FAO Food & Agriculture) API return?
JSON, via either MCP protocol (JSON-RPC 2.0) or REST API.