GnistAI GnistAI
Log in

Getting Started with IMF

International Monetary Fund datasets — global economic indicators and financial statistics.

All Tutorials   |   Overview   |   Playground   |   MCP   |   REST API   |   Home
Economics

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

  1. Sign up at https://context.gnist.ai/signup for a free API key (100 calls/day).
  2. Choose your integration method: MCP protocol or REST API.

Connect via MCP

Add to your MCP client config (Claude Desktop, Cursor, etc.):

MCP Config
{
  "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).

ParameterTypeRequiredDescription
countrystringrequiredISO alpha-3 country code (e.g. 'USA', 'NOR', 'DEU', 'CHN').
indicatorsanyoptionalWEO indicator codes. If omitted, returns the 6 defaults. Use list_weo_indicators() to discover all available codes.
start_yearanyoptionalInclude observations from this year (inclusive).
end_yearanyoptionalInclude 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.

ParameterTypeRequiredDescription
commoditiesanyoptionalList of PCPS commodity codes. Defaults to 5 key commodities.
start_periodanyoptionalStart period (YYYY-MM for monthly, YYYY for annual).
end_periodanyoptionalEnd period (YYYY-MM or YYYY).
frequencystringoptional'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.

ParameterTypeRequiredDescription
reporterstringrequiredISO alpha-2 country code of the reporting country (e.g. 'US', 'DE').
partneranyoptionalISO alpha-2 partner code, or 'W00' for world total (default).
start_yearanyoptionalStart year (inclusive).
end_yearanyoptionalEnd 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.

ParameterTypeRequiredDescription
countrystringrequiredISO 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'.

ParameterTypeRequiredDescription
feedbackstringrequired
feedback_typestringoptional (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

Search then retrieve
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.

Next Steps

Related Tutorials