Data source: IMF Data API
Overview
IMF wraps IMF Data API, handling authentication, pagination, and rate limits for you. This tutorial covers all 6 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-imf": {
"url": "https://context.gnist.ai/mcp/imf/",
"headers": {
"Gnist-API-Key": "YOUR_API_KEY"
}
}
}
}
Tools (6)
list_weo_indicators
List all available World Economic Outlook indicators from the IMF. The WEO covers macroeconomic variables across 196 countries with historical data and 5-year forecasts, updated twice per year (April and October). Use this to discover indicator codes before calling get_weo_forecast() with specific indicators. Returns: count and list of indicators with code, label, description, unit, source, dataset.
curl -X POST "https://context.gnist.ai/mcp/imf/" \
-H "Content-Type: application/json" \
-H "Gnist-API-Key: YOUR_API_KEY" \
-d '{"jsonrpc": "2.0", "method": "tools/call", "id": 1, "params": {"name": "list_weo_indicators", "arguments": {}}}'
import httpx
resp = httpx.post(
"https://context.gnist.ai/mcp/imf/",
headers={"Gnist-API-Key": "YOUR_API_KEY"},
json={'id': 1,
'jsonrpc': '2.0',
'method': 'tools/call',
'params': {'arguments': {}, 'name': 'list_weo_indicators'}},
)
print(resp.json())
get_weo_forecast
Get World Economic Outlook forecasts and historical data for a country. By default returns 6 headline macro indicators: real GDP growth, inflation, unemployment, current account balance, government debt, and fiscal balance. Country codes use ISO alpha-3 (e.g. USA, GBR, DEU, NOR, CHN, JPN, BRA). Args: country: ISO alpha-3 country code (e.g. 'USA', 'NOR', 'DEU', 'CHN'). indicators: WEO indicator codes. If omitted, returns the 6 defaults. Use list_weo_indicators() to discover all available codes. start_year: Include observations from this year (inclusive). end_year: Include observations up to this year (inclusive). Returns: country, source note, and indicators list with observations (period, value).
| Parameter | Type | Required | Description |
|---|---|---|---|
country | string | required | ISO alpha-3 country code (e.g. 'USA', 'NOR', 'DEU', 'CHN'). |
indicators | any | optional | WEO indicator codes. If omitted, returns the 6 defaults. Use list_weo_indicators() to discover all available codes. |
start_year | any | optional | Include observations from this year (inclusive). |
end_year | any | optional | Include observations up to this year (inclusive). |
curl -X POST "https://context.gnist.ai/mcp/imf/" \
-H "Content-Type: application/json" \
-H "Gnist-API-Key: YOUR_API_KEY" \
-d '{"jsonrpc": "2.0", "method": "tools/call", "id": 1, "params": {"name": "get_weo_forecast", "arguments": {"country": "'USA'"}}}'
import httpx
resp = httpx.post(
"https://context.gnist.ai/mcp/imf/",
headers={"Gnist-API-Key": "YOUR_API_KEY"},
json={'id': 1,
'jsonrpc': '2.0',
'method': 'tools/call',
'params': {'arguments': {'country': "'USA'"}, 'name': 'get_weo_forecast'}},
)
print(resp.json())
get_commodity_prices
Get primary commodity price data from the IMF PCPS dataset. Default commodities: Brent Crude Oil, Gold, Copper, Aluminum, Natural Gas (US). Args: commodities: List of PCPS commodity codes. Defaults to 5 key commodities. start_period: Start period (YYYY-MM for monthly, YYYY for annual). end_period: End period (YYYY-MM or YYYY). frequency: 'M' for monthly (default) or 'A' for annual. Returns: source, available_codes list, and series with code, name, unit, and observations.
| Parameter | Type | Required | Description |
|---|---|---|---|
commodities | any | optional | List of PCPS commodity codes. Defaults to 5 key commodities. |
start_period | any | optional | Start period (YYYY-MM for monthly, YYYY for annual). |
end_period | any | optional | End period (YYYY-MM or YYYY). |
frequency | string | optional | 'M' for monthly (default) or 'A' for annual. (default: M) |
curl -X POST "https://context.gnist.ai/mcp/imf/" \
-H "Content-Type: application/json" \
-H "Gnist-API-Key: YOUR_API_KEY" \
-d '{"jsonrpc": "2.0", "method": "tools/call", "id": 1, "params": {"name": "get_commodity_prices", "arguments": {"commodities": "example"}}}'
import httpx
resp = httpx.post(
"https://context.gnist.ai/mcp/imf/",
headers={"Gnist-API-Key": "YOUR_API_KEY"},
json={'id': 1,
'jsonrpc': '2.0',
'method': 'tools/call',
'params': {'arguments': {'commodities': 'example'},
'name': 'get_commodity_prices'}},
)
print(resp.json())
get_trade_balance
Get bilateral or aggregate trade statistics from the IMF DOTS dataset. Use partner='W00' (or omit) to get a country's total world trade. Specify a partner code for bilateral flows. Args: reporter: ISO alpha-2 country code of the reporting country (e.g. 'US', 'DE'). partner: ISO alpha-2 partner code, or 'W00' for world total (default). start_year: Start year (inclusive). end_year: End year (inclusive). Returns: reporter, partner, and series with exports, imports, and trade balance.
| Parameter | Type | Required | Description |
|---|---|---|---|
reporter | string | required | ISO alpha-2 country code of the reporting country (e.g. 'US', 'DE'). |
partner | any | optional | ISO alpha-2 partner code, or 'W00' for world total (default). |
start_year | any | optional | Start year (inclusive). |
end_year | any | optional | End year (inclusive). |
curl -X POST "https://context.gnist.ai/mcp/imf/" \
-H "Content-Type: application/json" \
-H "Gnist-API-Key: YOUR_API_KEY" \
-d '{"jsonrpc": "2.0", "method": "tools/call", "id": 1, "params": {"name": "get_trade_balance", "arguments": {"reporter": "'US'"}}}'
import httpx
resp = httpx.post(
"https://context.gnist.ai/mcp/imf/",
headers={"Gnist-API-Key": "YOUR_API_KEY"},
json={'id': 1,
'jsonrpc': '2.0',
'method': 'tools/call',
'params': {'arguments': {'reporter': "'US'"}, 'name': 'get_trade_balance'}},
)
print(resp.json())
get_country_overview
Get a macro snapshot for a country combining WEO headline indicators. Returns the most recent actuals and near-term IMF forecasts covering GDP growth, inflation, unemployment, current account, government debt, and fiscal balance. Args: country: ISO alpha-3 country code (e.g. 'USA', 'NOR', 'DEU'). Returns: country, source, window (year range), and indicators dict with latest values.
| Parameter | Type | Required | Description |
|---|---|---|---|
country | string | required | ISO alpha-3 country code (e.g. 'USA', 'NOR', 'DEU'). |
curl -X POST "https://context.gnist.ai/mcp/imf/" \
-H "Content-Type: application/json" \
-H "Gnist-API-Key: YOUR_API_KEY" \
-d '{"jsonrpc": "2.0", "method": "tools/call", "id": 1, "params": {"name": "get_country_overview", "arguments": {"country": "'USA'"}}}'
import httpx
resp = httpx.post(
"https://context.gnist.ai/mcp/imf/",
headers={"Gnist-API-Key": "YOUR_API_KEY"},
json={'id': 1,
'jsonrpc': '2.0',
'method': 'tools/call',
'params': {'arguments': {'country': "'USA'"}, 'name': 'get_country_overview'}},
)
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/imf/" \
-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/imf/",
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
list_weo_indicators to find items, then get_weo_forecast to get full details. This two-step pattern is common for exploring data before drilling down.FAQ
What data does IMF provide?
International Monetary Fund datasets — global economic indicators and financial statistics. It exposes 6 tools: list_weo_indicators, get_weo_forecast, get_commodity_prices, get_trade_balance, get_country_overview, 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 IMF API return?
JSON, via either MCP protocol (JSON-RPC 2.0) or REST API.