Skip to main content
Glama
c-cf

IMF Data MCP Server

by c-cf

list_countries

Retrieve available countries for a specific IMF dataset to filter and access relevant economic data for analysis.

Instructions

Returns a list of available countries for the specified dataset, read from the corresponding .json file in the local areas directory. Args: dataset_id (str): Dataset ID, such as "IFS", "DOT", "BOP", etc. Returns: list: List of countries.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
dataset_idYes

Implementation Reference

  • Handler function that implements the list_countries tool by loading a dataset-specific JSON file containing country codes from the resources/areas directory and returning the list or an appropriate error.
    def list_countries(dataset_id: str) -> list: """ Returns a list of available countries for the specified dataset, read from the corresponding .json file in the local areas directory. Args: dataset_id (str): Dataset ID, such as "IFS", "DOT", "BOP", etc. Returns: list: List of countries. """ file_path = os.path.join(os.path.dirname(__file__), "resources", "areas", f"{dataset_id.lower()}.json") try: with open(file_path, 'r', encoding='utf-8') as file: data = json.load(file) return data except FileNotFoundError: return {"error": f"File not found: {file_path}"} except json.JSONDecodeError: return {"error": f"Error decoding JSON from file: {file_path}"} except Exception as e: return {"error": f"Error reading file: {str(e)}"}
  • Registers the list_countries function as a tool in the FastMCP server.
    @mcp.tool()
  • Type hints and docstring defining the input parameter dataset_id (str) and return type list for the list_countries tool.
    def list_countries(dataset_id: str) -> list: """ Returns a list of available countries for the specified dataset, read from the corresponding .json file in the local areas directory. Args: dataset_id (str): Dataset ID, such as "IFS", "DOT", "BOP", etc. Returns: list: List of countries. """
  • Prompt template that references and describes the list_countries tool for use in guiding users.
    @mcp.prompt() def imf_query_prompt() -> str: """ Returns a prompt template explaining how to query IMF data with indicators and user intentions. Returns: str: A prompt template for guiding users on querying IMF data. """ prompt_text = """ You are a professional IMF data analysis assistant. Please follow these steps to help users obtain and analyze IMF data: 1. First, use the imf://datasets resource to get a list of available datasets and show the user the 5-10 most commonly used datasets with a brief description. 2. When the user selects a dataset, use the following two tools to get detailed information about the dataset: - list_countries: List available country or region codes - list_indicators: List available indicator codes and names 3. Assist the user in determining their interests: - Country or region (provide codes, and multiple country codes can be connected with "+") - Indicator (provide codes and names) - Time range (start year and end year) - Data frequency (if applicable: annual A, quarterly Q, monthly M, etc.) 4. Based on the user's selection, construct appropriate query parameters and use the fetch_compact_data tool to get the data ** Note: When you get warnings like "Warning: No indicator value" or "Warning: No indicator value for {country} in that Year," it means there is a lack of data for that period. Do not perform further analysis or retry. ** """ return prompt_text

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/c-cf/imf-data-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server