
FAOSTAT MCP
io.github.berba-q由 GitHub 账号 berba-q 发布v1.3.0更新于 Oct 27, 2026
FAOSTAT data for 245 countries: crops, trade, food security, and emissions via 23 MCP tools.
概览
本地运行的 MCP 服务器,封装联合国 FAOSTAT API,让助手查询 245 个国家的粮食、农业、贸易、粮食安全与排放统计数据。
- 可以做什么
- 发现数据组、领域、维度和元数据,并检查 API 健康状态
- 搜索和浏览国家、项目、要素的筛选代码,并按 FAO 定义核对地区或指标名称
- 获取统计数据、在取数前估算结果规模、获取国家排名
- 读取报告数据与表头,列出批量下载文件和相关文档
- 校验并保存 FAOSTAT 凭据,刷新 API 访问令牌
- 适用场景
- 适合农业经济学者、记者、政策分析人员和开发者,希望用自然语言询问作物产量、贸易、粮食安全、排放、林业或渔业数据,并直接从 FAOSTAT 得到答案而无需编写 API 调用。
- 运行要求
- 以 Python 包形式通过 stdio 在本机运行(需 Python 3.10+),可用 uvx 或 pip 启动。需要免费的 FAOSTAT 开发者账号:FAOSTAT_USERNAME(邮箱)与 FAOSTAT_PASSWORD,或可选的 FAOSTAT_API_TOKEN。需要访问 FAOSTAT 生产 API 的网络。共享缓存可选 Redis,通过 REDIS_HOST_IP_ADDRESS、REDIS_HOST_PORT_NUMBER 和 REDIS_DATABASE 配置。
安装
在 SourceWeft 中
- 打开 控制台中的 FAOSTAT MCP,将其添加到工作区。
- 为需要使用其工具的对话启用该服务。
Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。
其他 MCP 客户端
参照 仓库 中的启动说明。
README
FAOSTAT MCP Server
Query UN food and agriculture statistics with AI — powered by the Model Context Protocol
[Version] [PyPI] [MCP Registry] [Python 3.10+] [MCP Compatible] [License: MIT]
An MCP (Model Context Protocol) server that exposes the full FAOSTAT API as tools for AI assistants. Connect any MCP-compatible client — Claude, Cursor, Windsurf, Zed, or your own agent — to the world's most comprehensive database of food, agriculture, fisheries, forestry, and nutrition statistics, covering 245 countries and territories from the United Nations Food and Agriculture Organization (FAO).
Keywords: FAOSTAT, MCP server, Model Context Protocol, AI agriculture data, FAO statistics, food security AI, agricultural data Python, UN data, crop production statistics, Claude, Cursor, Windsurf
Why Use This?
Researchers, data journalists, policy analysts, and developers can ask natural-language questions and get answers directly from FAOSTAT — without writing a single API call. Your AI assistant handles domain discovery, filtering, and interpretation automatically.
Who is this for?
- Agricultural economists and food security researchers
- Journalists and policy analysts working with FAO data
- Developers building AI pipelines on top of FAOSTAT
- Anyone who wants to explore crop, trade, nutrition, or emissions data conversationally
What is FAOSTAT?
FAOSTAT is the statistical database of the United Nations Food and Agriculture Organization (FAO). It is the world's most comprehensive freely available source of data on food and agriculture, covering:
- Crop and livestock production — yields, harvested area, and quantities for hundreds of commodities
- Trade — import/export volumes and values between countries
- Food security — prevalence of undernourishment, dietary energy supply, and access indicators
- Emissions — greenhouse gas emissions from agriculture, land use, and food systems
- Forestry and fisheries — production and trade data
- Prices, inputs, and population — producer prices, fertilizer use, and demographic context
Data spans from 1961 to the present, across 245 countries and territories, in multiple languages.
What is MCP?
The Model Context Protocol is an open standard that lets AI assistants call external tools at runtime. This server registers all FAOSTAT API endpoints as discoverable tools — your AI assistant automatically selects and chains the right calls when you ask a question.
Features
- 23 MCP tools covering every FAOSTAT endpoint (data, metadata, rankings, bulk downloads, reports)
- 245 countries and territories across dozens of domains: crops, livestock, trade, food security, emissions, forestry, fisheries, and more
- Built-in rate limiting (2 req/s) — safe for the FAOSTAT production API out of the box
- Auto-retry with exponential backoff on transient network errors
- Rich tool descriptions so the AI knows exactly when and how to call each tool
- 3-tier hybrid caching — in-memory (20 min) → SQLite disk (24 h, cross-session) → Redis (optional, 30 min)
- Zero-config auth via
faostat_setup— store credentials once, never touch a config file again - Disambiguation via
faostat_search_codes— agents ask before guessing ambiguous codes - Works with Claude Desktop, Claude Code, Cursor, Windsurf, Zed, and any MCP-compatible client
Quick Start
Prerequisites
- Python 3.10+
- Any MCP-compatible client (Claude Desktop, Cursor, Windsurf, Zed, or a custom agent)
Option A — Install via MCP Registry (recommended)
Listed on the official MCP Registry — discoverable directly from Claude Desktop, Cursor, and any MCP-compatible client.
Updating: uvx faostat-mcp picks up new releases when your AI client restarts the server; if you still see an old version, run uvx faostat-mcp@latest once. pip and uv tool install don't upgrade on their own: run pip install -U faostat-mcp or uv tool upgrade faostat-mcp, then restart your client. The server also checks PyPI once per session and logs a notice to stderr when a newer version exists (opt out with FAOSTAT_NO_UPDATE_CHECK=1).
Option B — Install from source
Configure credentials
Easiest — use the faostat_setup tool (no config files needed):
Once the server is running and connected to your AI client, ask your assistant:
"Call faostat_setup with my FAOSTAT username and password."
The tool validates your credentials against the API, then stores them securely in your system keychain (macOS/Windows) or ~/.config/faostat-mcp/credentials.json (Linux/Docker). All subsequent sessions authenticate automatically — no env vars or .env file required.
Alternative — environment variables (CI/CD, Docker, advanced):
Register for a free FAOSTAT API account at the FAOSTAT Developer Portal.
Optional — Redis caching (multi-user / high-volume deployments)
The server works without Redis (SQLite disk cache is used instead). For shared or high-volume setups, launch Redis via Docker:
Then set REDIS_HOST_IP_ADDRESS, REDIS_HOST_PORT_NUMBER, and REDIS_DATABASE in .env.
Running the Server
Development mode (interactive MCP Inspector UI)
Opens a browser UI at http://localhost:5173 where you can browse and test all 23 tools interactively.
Production mode (stdio transport, for Claude Desktop)
Caching
The server uses a 3-tier cache to minimise redundant API calls. FAOSTAT data updates at most daily, so most repeated queries are served instantly.
Cache lookup order: memory → disk → Redis → API call. A disk or Redis hit promotes the value to memory for the rest of the session.
To disable the disk cache (e.g. on a read-only filesystem), set FAOSTAT_DISK_CACHE=false.
MCP Client Integration
The server speaks standard MCP over stdio, so it works with any compatible client.
Recommended config (PyPI install)
Dev / source config
Claude Desktop
Add one of the blocks above to:
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json - Windows:
%APPDATA%\Claude\claude_desktop_config.json
Restart Claude Desktop — faostat will appear in the tools panel.
Cursor
Add the block to .cursor/mcp.json in your project root, or to your global Cursor MCP settings. See the Cursor MCP docs for details.
Windsurf / Zed / other clients
Any client that supports MCP stdio servers accepts the same config shape. Consult your client's documentation for the config file location.
Example Queries
Once connected, ask your AI assistant questions like:
Your AI assistant will automatically:
- Call
faostat_list_groupsorfaostat_groups_and_domainsto find the right domain - Call
faostat_search_codesto look up a code by name — if multiple codes match (e.g. "production" matches both Production and Gross Production Index), the assistant pauses and asks you to choose before proceeding- Regions and indicators are checked with
faostat_resolve_name— if no matching FAOSTAT definition is found for your request (e.g. "Global South"), the assistant tells you so and offers the FAO-defined alternatives (e.g. "West Africa" → Western Africa) instead of inventing one
- Regions and indicators are checked with
- Call
faostat_get_dataorfaostat_get_rankingswith the confirmed codes - Interpret and summarize the results in plain language
Available MCP Tools
Discovery & Metadata
Data Retrieval
Authentication
Project Structure
Important: Filter Codes vs Display Codes
The FAOSTAT API uses two different code systems: filter codes (used in query parameters) and display codes (shown in response data and bulk CSVs). Always use filter codes from faostat_get_codes when calling faostat_get_data.
Area, item, and year codes are the same for both. Only element codes differ:
QCL — Crops and Livestock Products
TM — Trade Matrix
FS — Food Security
Always call
faostat_get_codes(dimension_id='element', domain_code=...)before querying data. Filter codes vary by domain and cannot be inferred from display codes.
Limitations & Notes
- This server targets the FAOSTAT production API (
https://faostatservices.fao.org/api/v1). - Rate limit: 2 requests/second, enforced automatically via token bucket.
- Responses are cached across 3 tiers (memory → SQLite disk → Redis) to reduce API calls — see
.env.examplefor TTL and size configuration. - The SQLite disk cache lives at
~/.cache/faostat-mcp/cache.dband defaults to 24 h TTL with a 1,000-entry LRU cap. SetFAOSTAT_DISK_CACHE=falseto disable. - For large domains (e.g., Trade Matrix), always apply area, item, and year filters to keep response sizes manageable.
Skills
Want guided analysis workflows on top of this server? Check out FAOSTAT Skills — 9 platform-agnostic AI skills for country profiles, commodity briefings, trade analysis, climate assessments, data visualization, and more. Works with Claude Code, OpenAI Codex, and any AI assistant that supports the SKILL.md format.
Related Projects & Resources
- FAOSTAT Skills — analysis skills built on top of this MCP server
- Model Context Protocol — the open standard powering this server
- FAOSTAT — UN FAO's official statistics portal
- FAOSTAT API Docs — developer reference
- Claude Desktop — one of the AI assistants this server works with
- Cursor — AI code editor with MCP support
- Windsurf — AI IDE with MCP support
Contributors
Thanks to everyone who has contributed to this project.
Contributions are welcome — see CONTRIBUTING.md for guidelines.
Citation
If you use this tool in academic work or research, please cite it:
Plain text:
Obli-Laryea, G., & Contributors. (2026). FAOSTAT MCP Server: AI-assisted access to FAOSTAT (v1.2.2) [Computer software]. https://github.com/berba-q/faostat-mcp
BibTeX:
See the Contributors section for a full list of authors.
When citing the underlying FAOSTAT data, use the FAO's recommended format with the specific domain:
FAO, {year}. FAOSTAT: {Domain Name}, http://www.fao.org/faostat/en/#data/{domain_code}
For example:
FAO, 2026. FAOSTAT: Crops and Livestock Products, http://www.fao.org/faostat/en/#data/QCL
FAO, 2026. FAOSTAT: Emissions Totals, http://www.fao.org/faostat/en/#data/GT
Changelog
See CHANGELOG.md for a full history of changes, generated automatically from conventional commits.
GitHub Topics
If you fork or star this repo, suggested topics: mcp, faostat, model-context-protocol, ai-tools, agriculture, food-security, fao, un-data, python, llm, unfao, undata
Smaller tool responses
Data, rankings, and global definitions default to response_format="compact" (column names once, followed by row arrays). Use response_format="objects" for the previous object-per-row shape, or "csv" for data and rankings. Select fields on data queries while preserving units needed to interpret values. Search results default to 25 matches; narrow the query if _truncated is true.
When the domain is known, use faostat_search_codes directly. The global name resolver returns definition_code, which is not necessarily a query filter code. A no_matching_definition result describes this lookup, not all FAO terminology. Code browsing, search, and validation share a cached table; repeated data queries reuse raw responses across formats, field selections, and row limits.
来源:README.md,提交 0201f8e
工具
0版本历史
2- v1.3.0最新Oct 2, 2026
- v1.2.2Sep 16, 2026
评分
已满足适用检查项的 50%
该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。
- 近 30 天内可连通25 分
请保持端点能够响应 MCP 握手;SourceWeft 每 30 天探测一次。
- 已声明认证方式10 分
请在注册中心条目中声明凭据请求头,或保持端点能够响应探测,以便判定其认证方式。
- 已列出工具15 分
请让服务器在无凭据时响应 tools/list,或发布可在沙箱中无凭据启动的软件包。
- 描述必需15 分
- 图标10 分
- 文档15 分
- 许可证10 分