faostat-mcp-server

v0.6.0 pre-1.0

Global food & agriculture statistics from the UN FAOSTAT bulk-download corpus, served from a local SQLite mirror with a DataCanvas SQL surface, via MCP. STDIO or Streamable HTTP.

faostat.caseyjhand.com/mcp
claude mcp add --transport http faostat-mcp-server https://faostat.caseyjhand.com/mcp
codex mcp add faostat-mcp-server --url https://faostat.caseyjhand.com/mcp
{
  "mcpServers": {
    "faostat-mcp-server": {
      "url": "https://faostat.caseyjhand.com/mcp"
    }
  }
}
gemini mcp add --transport http faostat-mcp-server https://faostat.caseyjhand.com/mcp
{
  "mcpServers": {
    "faostat-mcp-server": {
      "command": "bunx",
      "args": [
        "mcp-remote",
        "https://faostat.caseyjhand.com/mcp"
      ]
    }
  }
}
{
  "mcpServers": {
    "faostat-mcp-server": {
      "type": "http",
      "url": "https://faostat.caseyjhand.com/mcp"
    }
  }
}
curl -X POST https://faostat.caseyjhand.com/mcp \
  -H "Content-Type: application/json" \
  -H "Accept: application/json, text/event-stream" \
  -d '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-11-25","capabilities":{},"clientInfo":{"name":"curl","version":"1.0.0"}}}'

Tools

7

read 6

faostat_list_domains

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.

read
invocation
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/call",
  "params": {
    "name": "faostat_list_domains",
    "arguments": {}
  }
}
schema
{
  "$schema": "https://json-schema.org/draft/2020-12/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
    }
  },
  "required": [
    "indexed_only",
    "limit",
    "offset"
  ],
  "additionalProperties": false
}
view source ↗

faostat_resolve_codes

Resolve labels to the numeric codes or exact alphanumeric item identities faostat_query_observations needs: areas (countries/regions), items (commodities), and elements (metrics). Use query for full-text matching, name_contains for substring matching, code or code_text for exact identity, or omit them to list. Item and element matches occur in the selected domain; areas use shared vocabulary. For elements, optionally pass item_codes or item_codes_text to discover metrics and distinct units observed for those items; this does not establish area/year/source coverage. Empty item selectors match nothing. Page with offset and limit using nextOffset when truncated. Areas carry country/aggregate classification. Verified domain-specific item groups carry aggregate; null means unclassified, not safe-to-sum. Item groups can overlap their members even with matching units. Area aggregates include codes ≥ 5000 and curated roll-ups such as China=351; exclude overlapping regional and country rows when summing.

read
invocation
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/call",
  "params": {
    "name": "faostat_resolve_codes",
    "arguments": {
      "domain": "<domain>",
      "dimension": "<dimension>"
    }
  }
}
schema
{
  "$schema": "https://json-schema.org/draft/2020-12/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
    },
    "code_text": {
      "description": "Exact alphanumeric item code. Only for dimension item; mutually exclusive with code. Numeric identities use code.",
      "type": "string",
      "pattern": "^\\d+[A-Za-z][A-Za-z0-9]*$"
    },
    "item_codes": {
      "description": "For element resolution only: restrict elements and units to these items. Empty matches nothing; omit for domain-wide elements. Mutually exclusive with item_codes_text.",
      "type": "array",
      "items": {
        "type": "integer",
        "minimum": -9007199254740991,
        "maximum": 9007199254740991
      }
    },
    "item_codes_text": {
      "description": "For element resolution only: restrict elements and units to these exact text items. Empty matches nothing; mutually exclusive with item_codes.",
      "type": "array",
      "items": {
        "type": "string",
        "pattern": "^\\d+[A-Za-z][A-Za-z0-9]*$",
        "description": "Exact alphanumeric item identity."
      }
    },
    "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",
    "limit",
    "offset"
  ],
  "additionalProperties": false
}
view source ↗

faostat_query_observations

Query a FAOSTAT domain's data cube by area(s), item(s), element(s), sources, and year range, returning values with units and data-quality flags. Resolve numeric codes or exact alphanumeric item identities with faostat_resolve_codes; element resolution accepts item selectors and returns units. Empty queries with explicit items and elements list available elements for those items across the domain, without establishing area/year/source coverage. Aggregate regions are excluded by default; include_aggregates=true returns roll-ups, and explicit area_codes are honored verbatim. Item groups can overlap their members even with matching units; they remain included, and kind=null does not establish safe-to-sum. Keep source methodologies separate. Small results return inline; large ones spill to a DataCanvas table (canvas_id + table_name); call faostat_dataframe_describe for columns, then faostat_dataframe_query for analysis. Honor every row's flag: commonly A=Official, B=time-series break, E=Estimated, I=Imputed, M=Missing, T=Unofficial, X=international organization; unrecognized flags never establish official status.

read
invocation
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/call",
  "params": {
    "name": "faostat_query_observations",
    "arguments": {
      "domain": "<domain>"
    }
  }
}
schema
{
  "$schema": "https://json-schema.org/draft/2020-12/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
      }
    },
    "item_codes_text": {
      "description": "Exact alphanumeric item identities from resolver code_text; mutually exclusive with item_codes. Numeric codes use item_codes.",
      "type": "array",
      "items": {
        "type": "string",
        "pattern": "^\\d+[A-Za-z][A-Za-z0-9]*$",
        "description": "Exact alphanumeric item code."
      }
    },
    "source_codes": {
      "description": "Exact source codes, such as 3050 or 3051 in GLE. Omit to return every methodology; choose or group sources before summing.",
      "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",
    "include_aggregates",
    "limit"
  ],
  "additionalProperties": false
}
view source ↗

faostat_commodity_profile

Assemble a global profile for one QCL item in a single call: top-producing countries, the annual production trend, and trade flows (top exporters and importers). Supply item_code or item_query; code wins when both are supplied. A query selects a unique normalized exact label, otherwise a unique relevance match; ambiguous queries require an explicit code. Each ranking uses the selected item at each country's own latest year with data, grouped by unit. The trend is returned inline as year/value points. Country-level only (aggregates excluded). QCL is required; unavailable TCL yields a production-only profile with a notice. When the merged observation set is too large to inline, it spills to a DataCanvas table (canvas_id + table_name) — call faostat_dataframe_describe for its columns, then faostat_dataframe_query for deeper SQL.

read
invocation
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/call",
  "params": {
    "name": "faostat_commodity_profile",
    "arguments": {}
  }
}
schema
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "item_code": {
      "description": "Exact item code present in QCL; takes precedence over item_query. Obtain it from faostat_resolve_codes with domain QCL and dimension item.",
      "type": "integer",
      "minimum": 1,
      "maximum": 9007199254740991
    },
    "item_query": {
      "description": "Commodity label or search term (e.g. \"Wheat\"). A unique normalized exact QCL label wins, otherwise the relevance search must match exactly one item. Broad queries such as \"maize\" or \"milk\" require item_code. Supply this or item_code.",
      "type": "string",
      "minLength": 1
    },
    "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": [
    "top_n"
  ],
  "additionalProperties": false
}
view source ↗

faostat_dataframe_query

Run a single-statement SELECT against canvas tables staged by faostat_query_observations and faostat_commodity_profile (faostat_xxxxxxxx). Use DuckDB joins, aggregates, window functions, and CTEs for rankings and time-series analysis. Item groups can overlap their members even with matching units; do not sum them together, and resolver kind=null does not establish safe-to-sum. Separate source methodologies and respect bounded values and multi-year periods. Read-only: writes, DDL, DROP, COPY, PRAGMA, ATTACH, and external-file functions are rejected; system catalogs are denied. List tables and columns with faostat_dataframe_describe. Preserve data-quality flags in projections: commonly A=Official, B=time-series break, E=Estimated, I=Imputed, M=Missing, T=Unofficial, X=international organization; unrecognized flags never establish official status.

read
invocation
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/call",
  "params": {
    "name": "faostat_dataframe_query",
    "arguments": {
      "sql": "<sql>"
    }
  }
}
schema
{
  "$schema": "https://json-schema.org/draft/2020-12/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 — plus domain (QCL or TCL) on tables staged by faostat_commodity_profile."
    },
    "row_limit": {
      "default": 1000,
      "description": "Hard cap on rows in the response. Default 1000, max 10000.",
      "type": "integer",
      "minimum": 1,
      "maximum": 10000
    }
  },
  "required": [
    "sql",
    "row_limit"
  ],
  "additionalProperties": false
}
view source ↗

faostat_dataframe_describe

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.

read
invocation
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/call",
  "params": {
    "name": "faostat_dataframe_describe",
    "arguments": {}
  }
}
schema
{
  "$schema": "https://json-schema.org/draft/2020-12/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
    }
  },
  "required": [
    "limit",
    "offset"
  ],
  "additionalProperties": false
}
view source ↗

disabled 1

faostat_dataframe_drop

Drop one canvas table (faostat_xxxxxxxx) staged by faostat_query_observations or faostat_commodity_profile, together with its provenance, before its 2-hour TTL removes it — once an analysis with it is finished. Idempotent: a name that is not staged on the resolved canvas returns dropped false and changes nothing. faostat_dataframe_describe lists the staged table names.

disabledwould be destructive

Disabled. Dropping staged tables is turned off in this deployment; staged tables expire on their own 2-hour TTL.

FAOSTAT_DATAFRAME_DROP_ENABLED=true
schema
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "name": {
      "type": "string",
      "pattern": "^faostat_[a-z0-9]{8}$",
      "description": "Staged table to drop — \"faostat_\" plus 8 lowercase letters and digits, exactly as faostat_dataframe_describe lists it."
    },
    "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 drop from the tables staged in this session (the common case).",
      "type": "string",
      "pattern": "^[A-Za-z0-9_-]{10}$"
    }
  },
  "required": [
    "name"
  ],
  "additionalProperties": false
}
view source ↗

Extensions

1

io.modelcontextprotocol/skills

{
  "directoryRead": true
}