faostat-skills 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,109 @@
1
+ ---
2
+ name: faostat-compare
3
+ description: Use when the user wants to compare countries, commodities, or agricultural metrics side by side. Keywords: compare, comparison, versus, vs, benchmark, ranking, countries, crops, production, yield, area harvested, trade, growth rate
4
+ ---
5
+
6
+ # Comparative Agricultural Analysis
7
+
8
+ Produce a structured side-by-side comparison of countries, commodities, or both across agricultural metrics using FAOSTAT data.
9
+
10
+ ## Prerequisites
11
+
12
+ Verify that the following FAOSTAT MCP tools are available before proceeding:
13
+ - `faostat_search_codes`
14
+ - `faostat_get_data`
15
+ - `faostat_get_rankings`
16
+
17
+ If any tool is missing, inform the user: "This skill requires the FAOSTAT MCP server to be connected. Please ensure it is running and try again."
18
+
19
+ ## Workflow
20
+
21
+ ### Step 1: Clarify Comparison Parameters
22
+
23
+ Determine from the user's message (or ask if unclear):
24
+
25
+ 1. **What to compare:** Countries, commodities, or a cross-comparison (e.g., wheat production in Brazil vs. Argentina).
26
+ 2. **Metric:** Production volume, yield, area harvested, trade value, or another indicator. Default to production if unspecified.
27
+ 3. **Time range:** Specific years or a span. Default to the most recent 10 years if unspecified.
28
+ 4. **Domain:** Infer the FAOSTAT domain:
29
+ - Production/yield/area harvested: `QCL`
30
+ - Trade value/quantity: `TM`
31
+ - Food balance: `FBS`
32
+ - Food security indicators: `FS`
33
+
34
+ Map the metric to the correct FAOSTAT element FILTER codes:
35
+ - Production: `'2510'`
36
+ - Yield: `'2413'`
37
+ - Area harvested: `'2312'`
38
+ - For trade, use appropriate TM element codes
39
+
40
+ ### Step 2: Resolve All Codes
41
+
42
+ For each entity (country or commodity), call `faostat_search_codes`:
43
+
44
+ **Countries:**
45
+ `faostat_search_codes(domain_code='<domain>', dimension_id='area', query='<country_name>')`
46
+
47
+ **Commodities:**
48
+ `faostat_search_codes(domain_code='<domain>', dimension_id='item', query='<commodity_name>')`
49
+
50
+ **CRITICAL:** If ANY search returns `requires_confirmation: true`, present the options to the user and wait for confirmation before proceeding. Resolve each entity independently — do not skip confirmation for any of them.
51
+
52
+ Store all confirmed codes.
53
+
54
+ ### Step 3: Pull Data for All Entities
55
+
56
+ For each entity combination, call `faostat_get_data` with:
57
+ - `domain_code='<domain>'`
58
+ - `area='<area_code>'` (or comma-separated codes if comparing multiple countries for one item)
59
+ - `item='<item_code>'` (or comma-separated codes if comparing multiple items)
60
+ - `element='<element_filter_code>'`
61
+ - `year='<year_range>'` (e.g., `'2014:2023'` for a 10-year span)
62
+ - `response_format='compact'` (saves tokens for multi-entity queries)
63
+ - `limit=200` (increase limit for multi-year, multi-entity queries)
64
+ - `show_unit=True`
65
+
66
+ If comparing many entities, batch the calls to avoid excessively large responses. Prefer 2-4 entities per call.
67
+
68
+ ### Step 4: Calculate Derived Metrics
69
+
70
+ From the retrieved data, compute:
71
+
72
+ - **Growth rate:** Percentage change from first year to last year in the range.
73
+ - **Average annual growth rate (CAGR):** `(end_value / start_value) ^ (1 / years) - 1`
74
+ - **Period average:** Mean value across all years.
75
+ - **Volatility (optional):** Standard deviation of year-over-year changes, if the user is interested in stability.
76
+
77
+ ### Step 5: Present the Comparison
78
+
79
+ Structure the output as follows:
80
+
81
+ **Title:** Comparative Analysis: [Entity A] vs. [Entity B] [vs. Entity C...] — [Metric]
82
+
83
+ 1. **Comparison Table** — Tabular summary with entities as columns and years (or summary stats) as rows. Include units.
84
+
85
+ 2. **Growth Rates** — CAGR and total period change for each entity, clearly indicating which grew faster.
86
+
87
+ 3. **Key Differences** — Narrative highlighting:
88
+ - Largest producer/highest yield/biggest trader
89
+ - Fastest and slowest growth
90
+ - Any crossover points (where one entity overtook another)
91
+ - Notable divergences or convergences in trends
92
+
93
+ 4. **Context & Insights** — Brief interpretation:
94
+ - Possible explanations for differences (climate, policy, investment)
95
+ - Caveats about the data (reporting gaps, methodology changes)
96
+
97
+ End with:
98
+
99
+ > Source: FAOSTAT (FAO), accessed [current date].
100
+
101
+ ## Error Handling
102
+
103
+ - If data is missing for some years for an entity, note the gap and compute metrics on available data only.
104
+ - If an entity has no data for the chosen domain/metric, inform the user and suggest an alternative metric or domain.
105
+ - Limit comparisons to 5 entities maximum. If the user requests more, suggest narrowing the scope or running multiple comparisons.
106
+
107
+ ## Output Format
108
+
109
+ Use a clean tabular layout for numerical comparisons. Follow the table with a concise narrative analysis. Keep growth rate calculations transparent by showing the formula values used.
@@ -0,0 +1,122 @@
1
+ ---
2
+ name: faostat-country-profile
3
+ description: Use when the user asks for a food security profile, country agricultural overview, country hunger or nutrition assessment, or food system summary for a specific country. Keywords: country profile, food security, undernourishment, production, trade, nutrition, calorie supply, dietary energy
4
+ ---
5
+
6
+ # Country Food Security Profile
7
+
8
+ Generate a comprehensive food security and agricultural profile for a given country using FAOSTAT data.
9
+
10
+ ## Prerequisites
11
+
12
+ Verify that the following FAOSTAT MCP tools are available before proceeding:
13
+ - `faostat_search_codes`
14
+ - `faostat_get_data`
15
+ - `faostat_get_rankings`
16
+ - `faostat_list_domains`
17
+
18
+ If any tool is missing, inform the user: "This skill requires the FAOSTAT MCP server to be connected. Please ensure it is running and try again."
19
+
20
+ ## Workflow
21
+
22
+ ### Step 1: Accept Country Input
23
+
24
+ Identify the country name from the user's message or ask for it if not provided.
25
+
26
+ ### Step 2: Resolve Country Code
27
+
28
+ Call `faostat_search_codes(domain_code='QCL', dimension_id='area', query='<country_name>')`.
29
+
30
+ **CRITICAL:** If the response contains `requires_confirmation: true`, present ALL matching options to the user and ask them to select the correct one. Do NOT proceed until the user confirms. This commonly happens with names like "China" (mainland vs. aggregate), "Sudan" (former vs. current), or "Korea".
31
+
32
+ Store the confirmed `area` code for all subsequent queries.
33
+
34
+ ### Step 3: Pull Production Data (Top Crops)
35
+
36
+ Call `faostat_get_data` with:
37
+ - `domain_code='QCL'`
38
+ - `area='<resolved_area_code>'`
39
+ - `element='2510'` (Production — this is the FILTER code)
40
+ - `year='<most_recent_year>'` (try the current year minus 2; if no data, try minus 3)
41
+ - `response_format='compact'`
42
+ - `limit=20`
43
+ - `show_unit=True`
44
+
45
+ Sort the results by value descending and identify the **top 5 crops by production volume**.
46
+
47
+ ### Step 4: Pull Food Security Indicators
48
+
49
+ Call `faostat_get_data` with:
50
+ - `domain_code='FS'`
51
+ - `area='<resolved_area_code>'`
52
+ - `response_format='objects'`
53
+ - `limit=50`
54
+
55
+ Look for these key indicators:
56
+ - Prevalence of undernourishment (%)
57
+ - Number of undernourished people
58
+ - Average dietary energy supply adequacy (%)
59
+ - Prevalence of severe food insecurity (%)
60
+
61
+ If data is sparse, note which indicators are unavailable.
62
+
63
+ ### Step 5: Pull Food Balance Sheet Data
64
+
65
+ Call `faostat_get_data` with:
66
+ - `domain_code='FBS'`
67
+ - `area='<resolved_area_code>'`
68
+ - `response_format='compact'`
69
+ - `limit=50`
70
+
71
+ Extract:
72
+ - Dietary energy supply (kcal/capita/day)
73
+ - Protein supply (g/capita/day)
74
+ - Fat supply (g/capita/day)
75
+
76
+ ### Step 6: Pull Trade Summary
77
+
78
+ Call `faostat_get_data` with:
79
+ - `domain_code='TM'`
80
+ - `area='<resolved_area_code>'`
81
+ - `response_format='compact'`
82
+ - `limit=30`
83
+
84
+ Determine:
85
+ - Total import value vs. total export value
86
+ - Whether the country is a net food importer or exporter
87
+ - Key imported and exported commodities
88
+
89
+ ### Step 7: Synthesize the Report
90
+
91
+ Compose a narrative report with the following sections:
92
+
93
+ **Title:** Food Security Profile: [Country Name]
94
+
95
+ 1. **Production Capacity** — Top 5 crops, total agricultural output volume, any notable specializations.
96
+
97
+ 2. **Food Access & Security** — Undernourishment prevalence, food insecurity rates, trends over available years (improving/worsening/stable).
98
+
99
+ 3. **Nutritional Supply** — Calorie and protein supply per capita, how these compare to global benchmarks (2,100 kcal/day minimum; 2,500 kcal/day adequate).
100
+
101
+ 4. **Trade Position** — Net importer or exporter, main trade partners if available, key agricultural imports and exports.
102
+
103
+ 5. **Key Risks & Trends** — Synthesize insights: dependency on imports, narrow crop base, declining yields, improving food security, etc.
104
+
105
+ Include trend indicators where multi-year data is available:
106
+ - Rising trend
107
+ - Declining trend
108
+ - Stable
109
+
110
+ End the report with:
111
+
112
+ > Source: FAOSTAT (FAO), accessed [current date]. Data may reflect reporting lags of 1-3 years.
113
+
114
+ ## Error Handling
115
+
116
+ - If a domain returns no data for the country, note it in the report and continue with available data.
117
+ - If the country code cannot be resolved, ask the user to try an alternative name or spelling.
118
+ - If rate limits are hit, wait briefly and retry. Inform the user if delays are expected.
119
+
120
+ ## Output Format
121
+
122
+ Deliver the report as a well-structured narrative with clear section headings. Use bullet points for data summaries and tables where comparisons aid readability. Keep the tone analytical and factual.
@@ -0,0 +1,119 @@
1
+ ---
2
+ name: faostat-explore
3
+ description: Use when the user wants to discover what data is available in FAOSTAT, browse domains, understand what a domain contains, or is new to FAOSTAT and wants a guided tour. Use when the user mentions a topic and wants to know what FAOSTAT data covers it. Keywords: explore, discover, browse, what data, available, domains, catalog, tour, overview, what can I find, show me, help me understand, new to FAOSTAT, getting started
4
+ ---
5
+
6
+ # FAOSTAT Explorer
7
+
8
+ Guided discovery of FAOSTAT's data catalog. Help users understand what data is available, browse domains, see sample data, and find the right starting point for their analysis.
9
+
10
+ ## Prerequisites
11
+
12
+ Before starting, confirm the FAOSTAT MCP tools are available by checking that tools `faostat_list_groups`, `faostat_list_domains`, `faostat_get_dimensions`, `faostat_get_data`, and `faostat_get_metadata` are accessible. If they are not, inform the user that this skill requires the FAOSTAT MCP server to be connected and stop.
13
+
14
+ ## Workflow
15
+
16
+ ### Step 1 — Understand the User's Interest
17
+
18
+ Ask the user: "What topic are you interested in exploring?" Examples:
19
+ - A subject area: "fisheries", "fertilizers", "food prices", "livestock", "trade"
20
+ - A question: "What data does FAO have about rice production?"
21
+ - A broad theme: "climate and agriculture", "food security in Africa"
22
+ - Or just: "Show me what's available" (full catalog overview)
23
+
24
+ If the user provides their interest in their initial message, proceed without re-asking.
25
+
26
+ ### Step 2 — Map the FAOSTAT Catalog
27
+
28
+ Call `faostat_list_groups(lang='en')` to retrieve all domain groups in FAOSTAT.
29
+
30
+ Present the groups to the user in a clear, organized list. FAOSTAT organizes data into groups such as:
31
+ - Production
32
+ - Trade
33
+ - Food Security
34
+ - Food Balances
35
+ - Prices
36
+ - Inputs
37
+ - Population
38
+ - Investment
39
+ - Macro-Statistics
40
+ - Emissions (Agriculture, Land Use, Forestry)
41
+ - Climate Change
42
+ - and more
43
+
44
+ If the user gave a specific topic, identify which group(s) are most relevant. If the user asked for a full overview, present all groups briefly.
45
+
46
+ ### Step 3 — Drill Into Relevant Domain Groups
47
+
48
+ For each relevant group, call `faostat_list_domains(group_code, lang='en')` to list the specific domains within that group.
49
+
50
+ Present the domains with their codes and descriptions. For example, within the Production group:
51
+ - **QCL** — Crops and Livestock Products
52
+ - **QI** — Production Indices
53
+ - etc.
54
+
55
+ If the user's topic spans multiple groups, show domains from all relevant groups.
56
+
57
+ ### Step 4 — Explore Domain Structure
58
+
59
+ For each domain the user finds interesting (or the 1-3 most relevant domains if the user gave a specific topic):
60
+
61
+ **A. Show Dimensions**
62
+
63
+ Call `faostat_get_dimensions(domain_code, lang='en')` to show what dimensions (filters) the domain supports.
64
+
65
+ Present the dimensions in plain language. For example:
66
+ - "This domain lets you filter by: **Area** (countries/regions), **Item** (commodities like wheat, rice, cattle), **Element** (metrics like Production, Area Harvested, Yield), and **Year**."
67
+
68
+ **B. Show Sample Data**
69
+
70
+ Call `faostat_get_data(domain_code, lang='en', limit=5, response_format='objects')` to pull a small sample of data.
71
+
72
+ Present the sample rows in a readable format (a table or formatted list). Explain what each column means:
73
+ - What does the "Element" represent?
74
+ - What are the units?
75
+ - What time period is covered?
76
+
77
+ **C. Explain the Domain**
78
+
79
+ Call `faostat_get_metadata(domain_code, lang='en')` to retrieve the domain's metadata description.
80
+
81
+ Summarize the metadata for the user in accessible language:
82
+ - What does this domain measure?
83
+ - What is the data source?
84
+ - How frequently is it updated?
85
+ - What geographic and temporal coverage does it have?
86
+ - Any important caveats or methodology notes?
87
+
88
+ ### Step 5 — Suggest Analytical Paths
89
+
90
+ Based on what the user is exploring, suggest which skills would help them go deeper:
91
+
92
+ - **For production data:** "You could use `/faostat-commodity` for a deep dive into a specific crop, or `/faostat-country-profile` to see a country's full production picture."
93
+ - **For trade data:** "Try `/faostat-trade` to analyze import dependencies and trade flows."
94
+ - **For emissions/climate data:** "Use `/faostat-climate` to analyze emissions profiles, compare countries, or examine the inputs-emissions link."
95
+ - **For trends and changes:** "Use `/faostat-trends` to identify the biggest movers and anomalies."
96
+ - **For comparison questions:** "Try `/faostat-compare` for a structured side-by-side comparison."
97
+ - **For visual output:** "Use `/faostat-viz` to generate interactive charts from any data you find."
98
+ - **For narrative output:** "Use `/faostat-story` to build a data-driven article with embedded charts."
99
+
100
+ ### Step 6 — Offer to Run a Query
101
+
102
+ Ask the user:
103
+ - "Would you like me to pull specific data from any of these domains?"
104
+ - "Want me to search for a particular country, commodity, or indicator?"
105
+ - "Should I run one of the suggested skills for a deeper analysis?"
106
+
107
+ If the user wants to query, use `faostat_search_codes` to resolve any entity names to codes before calling `faostat_get_data`.
108
+
109
+ **CRITICAL:** If `requires_confirmation` is `true` in a search response (multiple matches), present the options to the user and ask them to choose before proceeding. Do NOT guess.
110
+
111
+ **Important:** Element FILTER codes differ from DISPLAY codes. When calling `faostat_get_data`, use the filter code for the `element` parameter. When calling `faostat_get_rankings`, use the DISPLAY code. If unsure, use `faostat_search_codes` with `dimension_id='element'` to find the correct code.
112
+
113
+ ### Step 7 — Attribution
114
+
115
+ When presenting any data, always include:
116
+
117
+ > Source: FAOSTAT (FAO), accessed [current date].
118
+
119
+ Replace `[current date]` with today's date. Include the domain code(s) referenced.
@@ -0,0 +1,161 @@
1
+ ---
2
+ name: faostat-story
3
+ description: Use when the user wants to build a data-driven narrative, article, or report from FAOSTAT data for journalists, researchers, or communicators. Use when the user provides a research question, story angle, or topic they want to explore as a data story with embedded charts. Keywords: story, narrative, article, journalism, report, data story, investigation, angle, headline, write-up, briefing, explainer, data journalism
4
+ ---
5
+
6
+ # Data Storyteller
7
+
8
+ Build data-driven narratives for journalists, researchers, and communicators using FAOSTAT data, with embedded interactive charts and properly sourced statistics.
9
+
10
+ ## Prerequisites
11
+
12
+ Before starting, confirm the FAOSTAT MCP tools are available by checking that tools `faostat_get_data`, `faostat_search_codes`, `faostat_list_groups`, `faostat_list_domains`, and `faostat_get_rankings` are accessible. If they are not, inform the user that this skill requires the FAOSTAT MCP server to be connected and stop.
13
+
14
+ ## Workflow
15
+
16
+ ### Step 1 — Understand the Story Angle
17
+
18
+ Ask the user for their research question or story angle. Examples:
19
+ - "The global avocado boom"
20
+ - "Africa's fertilizer gap"
21
+ - "Wheat after the Ukraine crisis"
22
+ - "Who feeds the world's growing cities?"
23
+ - "The rise of quinoa"
24
+
25
+ If the user provides the angle in their initial message, proceed without re-asking.
26
+
27
+ Identify:
28
+ - **Subject** — what commodity, country, or theme?
29
+ - **Tension** — what's surprising, changing, or at stake?
30
+ - **Scope** — global, regional, or country-level?
31
+ - **Time frame** — recent years, historical arc, or a specific event window?
32
+
33
+ ### Step 2 — Identify Relevant FAOSTAT Domains
34
+
35
+ Based on the story angle, determine which FAOSTAT domains contain relevant data. Use `faostat_list_groups` and `faostat_list_domains` to confirm domain availability.
36
+
37
+ Common domain mappings:
38
+ - Production stories: **QCL** (Crops and Livestock Products)
39
+ - Trade stories: **TM** (Trade Matrix)
40
+ - Food security stories: **FS** (Food Security), **FBS** (Food Balance Sheets)
41
+ - Climate/emissions stories: **GT** (Emissions Totals), **ET** (Temperature Change), **GF** (Forests)
42
+ - Input stories: **RFN/RFM/RFB** (Fertilizers), **RP** (Pesticides)
43
+ - Land use stories: **RL** (Land Use)
44
+
45
+ ### Step 3 — Resolve Codes and Pull Data
46
+
47
+ For each entity referenced in the story:
48
+
49
+ 1. Use `faostat_search_codes` with the appropriate `domain_code` and `dimension_id` to resolve names to codes.
50
+
51
+ **CRITICAL:** If `requires_confirmation` is `true` in the response (multiple matches), present the options to the user and ask them to choose before proceeding. Do NOT guess.
52
+
53
+ 2. Pull data using `faostat_get_data` with the resolved codes.
54
+
55
+ **Important:** Element FILTER codes differ from DISPLAY codes. When calling `faostat_get_data`, use the filter code for the `element` parameter (e.g., filter `'2510'` for Production). When calling `faostat_get_rankings`, use the DISPLAY code (e.g., `'5510'` for Production).
56
+
57
+ 3. Use `response_format='compact'` for multi-entity queries.
58
+
59
+ 4. Use `faostat_get_rankings` (with DISPLAY element codes) to find top producers, importers, or exporters for context and rankings.
60
+
61
+ Pull data across multiple domains to build a multi-dimensional picture. A good data story typically draws from at least 2-3 different domains.
62
+
63
+ ### Step 4 — Find the Narrative Arc
64
+
65
+ Analyze the pulled data to identify:
66
+
67
+ 1. **The hook** — what is the single most surprising or compelling finding? A number that stops the reader.
68
+ 2. **The trend** — what direction is the data moving, and does it break at some point? Inflection points make great story elements.
69
+ 3. **The key players** — which countries or entities dominate? Are there unexpected names in the top ranks?
70
+ 4. **The contrast** — what counterpoint or comparison makes the trend more vivid? (e.g., "Country X now produces more avocados than Y, which was the dominant producer just a decade ago")
71
+ 5. **The stakes** — why does this matter for food security, livelihoods, climate, or trade?
72
+
73
+ ### Step 5 — Generate Supporting Charts
74
+
75
+ For each key data point in the story, generate a standalone HTML chart using Chart.js. Each chart file must include:
76
+
77
+ - **Chart.js loaded via CDN** (`https://cdn.jsdelivr.net/npm/chart.js`)
78
+ - **Descriptive title** as an HTML heading above the chart
79
+ - **Properly labeled axes** with units (tonnes, hectares, USD, %, etc.)
80
+ - **Legend** with clear entity names
81
+ - **Colorblind-friendly palette** — use these colors in order:
82
+ `#2271B2`, `#F748A5`, `#359B73`, `#D55E00`, `#E69F00`, `#56B4E9`, `#009E73`, `#CC79A7`
83
+ - **Responsive design** — canvas should resize with the viewport
84
+ - **FAOSTAT source attribution** — a footer line: "Source: FAOSTAT (FAO), accessed [current date]"
85
+
86
+ Choose chart types that match the data relationship:
87
+ - **Line chart** for trends over time
88
+ - **Bar chart** for comparisons across entities at a point in time
89
+ - **Stacked bar** for composition breakdowns
90
+ - **Scatter plot** for correlations between two variables
91
+
92
+ Do NOT use pie charts for trends or comparisons with more than 5 categories.
93
+
94
+ Generate 3-5 charts that support the narrative arc. Save each as a separate HTML file.
95
+
96
+ ### Step 6 — Draft the Data Narrative
97
+
98
+ Compose an HTML report that interleaves narrative text with embedded charts. Structure:
99
+
100
+ ```html
101
+ <!DOCTYPE html>
102
+ <html lang="en">
103
+ <head>
104
+ <meta charset="UTF-8">
105
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
106
+ <title>[Story Title]</title>
107
+ <style>
108
+ /* Clean, readable typography */
109
+ body { font-family: Georgia, 'Times New Roman', serif; max-width: 800px; margin: 0 auto; padding: 2rem; line-height: 1.7; color: #1a1a1a; }
110
+ h1 { font-size: 2.2rem; line-height: 1.2; margin-bottom: 0.5rem; }
111
+ .subtitle { font-size: 1.1rem; color: #666; margin-bottom: 2rem; }
112
+ .stat-callout { background: #f0f4f8; border-left: 4px solid #2271B2; padding: 1rem 1.5rem; margin: 1.5rem 0; font-size: 1.2rem; }
113
+ .chart-container { margin: 2rem 0; }
114
+ .chart-container canvas { max-height: 400px; }
115
+ .source { font-size: 0.85rem; color: #888; margin-top: 0.5rem; }
116
+ .takeaways { background: #f8f8f8; padding: 1.5rem; border-radius: 4px; margin-top: 2rem; }
117
+ .takeaways h2 { margin-top: 0; }
118
+ footer { margin-top: 3rem; padding-top: 1rem; border-top: 1px solid #ddd; font-size: 0.85rem; color: #888; }
119
+ </style>
120
+ <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
121
+ </head>
122
+ <body>
123
+ <!-- Narrative sections interleaved with charts -->
124
+ </body>
125
+ </html>
126
+ ```
127
+
128
+ The narrative must include:
129
+
130
+ 1. **Headline** — concise, attention-grabbing, data-grounded
131
+ 2. **Subtitle** — one sentence expanding on the headline
132
+ 3. **Hook paragraph** — lead with the most surprising statistic or finding
133
+ 4. **Key statistics callouts** — highlighted stat boxes with the source noted
134
+ 5. **Body sections** — each building on the previous, with a chart following each major claim
135
+ 6. **Context paragraphs** — explain why the data looks the way it does (policy, climate, economic factors)
136
+ 7. **Key takeaways** — 3-5 bullet points summarizing the story
137
+ 8. **Footer** — full FAOSTAT attribution with access date and domain codes used
138
+
139
+ Every statistic cited must include the FAOSTAT domain it came from.
140
+
141
+ ### Step 7 — Produce the Final Output
142
+
143
+ Save the complete HTML report as a single file. If the charts are embedded inline (preferred), produce one HTML file. If charts are separate files, list them and explain how they connect to the narrative.
144
+
145
+ Open the HTML file in the browser for the user to review.
146
+
147
+ ### Step 8 — Attribution
148
+
149
+ Every chart and the report footer must include:
150
+
151
+ > Source: FAOSTAT (FAO), accessed [current date]. Domains: [list domain codes used].
152
+
153
+ Replace `[current date]` with today's date.
154
+
155
+ ### Step 9 — Offer Refinements
156
+
157
+ Ask the user:
158
+ - "Would you like me to adjust the angle or emphasis?"
159
+ - "Should I add more charts or data points?"
160
+ - "Want me to explore a related angle?" (e.g., if the story is about avocados, offer to look at trade flows or environmental impact)
161
+ - "Should I dig deeper into any country or time period?"
@@ -0,0 +1,154 @@
1
+ ---
2
+ name: faostat-trade
3
+ description: Use when the user asks about food import dependence, self-sufficiency ratio, supply chain risk, trade partners, trade concentration, food security vulnerability, import reliance, export dependence, or whether a country can feed itself for a specific commodity. Keywords: import, export, trade, self-sufficiency, dependency, supply chain, food security, trade partners, concentration risk, import reliance, vulnerability
4
+ ---
5
+
6
+ # Trade Dependency Analyzer
7
+
8
+ Assess a country's import dependence for critical food commodities, calculate self-sufficiency ratios, identify supply chain concentration risks, and track dependency trends over time.
9
+
10
+ ## Prerequisites
11
+
12
+ Before starting, verify that the FAOSTAT MCP tools are available: `faostat_search_codes`, `faostat_get_data`. If they are not available, inform the user they need the FAOSTAT MCP server configured and stop.
13
+
14
+ ## Domain Reference (CRITICAL -- use exactly these codes)
15
+
16
+ | Domain | Code | Content |
17
+ |--------|------|---------|
18
+ | Crops & Livestock Products | **QCL** | Domestic production (area, yield, production volume) |
19
+ | Trade Matrix | **TM** | Bilateral trade -- imports and exports by partner country |
20
+
21
+ ## Element Code Reference (CRITICAL)
22
+
23
+ - **Production quantity**: filter code `2510`, display code `5510`
24
+ - For `faostat_get_data` queries, use FILTER codes in the `element` parameter (e.g., `element='2510'`)
25
+ - For `faostat_get_rankings` queries, use DISPLAY codes in the `element_code` parameter (e.g., `element_code='5510'`)
26
+
27
+ ## Workflow
28
+
29
+ ### Step 1: Accept inputs
30
+
31
+ Ask the user for:
32
+ - **Country** (required) -- e.g., "Egypt", "Japan", "Nigeria"
33
+ - **Commodity** (required) -- e.g., "wheat", "rice", "soybeans", "palm oil"
34
+
35
+ If the user provides both in their initial message, proceed directly. If either is missing, ask.
36
+
37
+ ### Step 2: Resolve codes
38
+
39
+ 1. Resolve the country to an area code:
40
+ `faostat_search_codes(domain_code='QCL', dimension_id='area', query='<country>')`
41
+ - If `requires_confirmation` is true, present the matching options and ask the user to choose. Do NOT proceed until confirmed.
42
+
43
+ 2. Resolve the commodity to an item code in the production domain:
44
+ `faostat_search_codes(domain_code='QCL', dimension_id='item', query='<commodity>')`
45
+ - Handle `requires_confirmation` the same way.
46
+
47
+ 3. Also resolve the commodity in the trade domain (item codes may differ):
48
+ `faostat_search_codes(domain_code='TM', dimension_id='item', query='<commodity>')`
49
+ - Handle `requires_confirmation`.
50
+
51
+ ### Step 3: Pull domestic production
52
+
53
+ Query the QCL domain for the country's domestic production of this commodity:
54
+ ```
55
+ faostat_get_data(
56
+ domain_code='QCL',
57
+ area='<area_code>',
58
+ item='<item_code_qcl>',
59
+ element='2510',
60
+ response_format='compact'
61
+ )
62
+ ```
63
+ Extract production quantities for the most recent 10-15 years to establish a trend.
64
+
65
+ ### Step 4: Pull trade data
66
+
67
+ Query the TM domain for imports and exports of this commodity for the country:
68
+ ```
69
+ faostat_get_data(
70
+ domain_code='TM',
71
+ area='<area_code>',
72
+ item='<item_code_tm>',
73
+ response_format='compact'
74
+ )
75
+ ```
76
+ Extract:
77
+ - **Total import volume** (by year)
78
+ - **Total export volume** (by year)
79
+ - **Import values** (USD, if available)
80
+ - **Partner country breakdown** -- who supplies the imports, who receives the exports
81
+
82
+ ### Step 5: Calculate self-sufficiency ratio
83
+
84
+ For each year where data is available, calculate:
85
+
86
+ ```
87
+ Self-Sufficiency Ratio (SSR) = Production / (Production + Imports - Exports)
88
+ ```
89
+
90
+ Interpretation:
91
+ - **SSR > 1.0** -- the country produces more than it consumes; net exporter
92
+ - **SSR = 1.0** -- perfectly self-sufficient (rare)
93
+ - **SSR 0.7-1.0** -- mostly self-sufficient, moderate import reliance
94
+ - **SSR 0.5-0.7** -- significant import dependence
95
+ - **SSR < 0.5** -- heavily import-dependent; vulnerable
96
+
97
+ Calculate SSR for the latest year and for 5 and 10 years ago (if data available) to show the trend.
98
+
99
+ ### Step 6: Identify trading partners and concentration risk
100
+
101
+ From the trade data, rank import partners by volume:
102
+ 1. List the top 5 import source countries with their share of total imports.
103
+ 2. Calculate a concentration metric: what percentage of imports comes from the top 1, top 2, and top 3 suppliers?
104
+ 3. Assess concentration risk:
105
+ - **Top 1 supplier > 50%** -- HIGH concentration risk (single point of failure)
106
+ - **Top 3 suppliers > 80%** -- MODERATE concentration risk
107
+ - **No single supplier > 30%** -- LOW concentration risk (diversified)
108
+
109
+ ### Step 7: Trend analysis
110
+
111
+ Analyze the trajectory:
112
+ - Is the SSR **improving** (moving toward 1.0), **stable**, or **deteriorating** (moving away from 1.0)?
113
+ - Is import volume growing faster than domestic production?
114
+ - Are trading partners becoming more or less concentrated over time?
115
+
116
+ ### Step 8: Present the dependency assessment
117
+
118
+ Structure the output as follows:
119
+
120
+ **1. Self-Sufficiency Summary**
121
+ - Current SSR with interpretation
122
+ - SSR 5 years ago and 10 years ago
123
+ - Trend direction (improving / stable / deteriorating)
124
+
125
+ **2. Domestic Production**
126
+ - Latest production volume with units
127
+ - Production trend (growing / shrinking / stagnant)
128
+
129
+ **3. Trade Position**
130
+ - Total imports (volume and value)
131
+ - Total exports (volume and value)
132
+ - Net trade position (net importer or net exporter)
133
+
134
+ **4. Supply Chain Risk**
135
+ - Top 5 import partners with share percentages
136
+ - Concentration risk rating (HIGH / MODERATE / LOW)
137
+ - Any single-supplier vulnerability
138
+
139
+ **5. Trend & Outlook**
140
+ - Direction of dependency over time
141
+ - Key risk factors (e.g., "Production is flat while imports grow 5% annually")
142
+ - One-line vulnerability narrative (e.g., "Egypt imports 55% of its wheat, with 40% coming from a single supplier -- Russia")
143
+
144
+ **6. Source Attribution**
145
+ "Source: FAOSTAT (FAO), accessed [current date]"
146
+
147
+ ## Important Rules
148
+
149
+ - Always use `faostat_search_codes` before `faostat_get_data` to resolve codes. Never guess or hardcode domain-specific codes.
150
+ - When `requires_confirmation` is true in a search result, always present options to the user and wait for their choice.
151
+ - Use `response_format='compact'` for multi-year or multi-partner queries to keep response sizes manageable.
152
+ - For `faostat_get_data`, use FILTER element codes (e.g., '2510'). For `faostat_get_rankings`, use DISPLAY element codes (e.g., '5510').
153
+ - If production data returns zero or null for a country-commodity pair, note this explicitly -- it may mean the country does not produce this commodity at all (SSR = 0, fully import-dependent).
154
+ - Always include the source attribution line at the end of any output.