Skip to main content
Glama
16Coffee

Yahoo Finance MCP Server

by 16Coffee

get_economic_data

Retrieve macroeconomic data such as treasury rates, indicators, calendar events, and market risk premiums from Yahoo Finance, using date ranges and specific parameters for targeted insights.

Instructions

获取宏观经济数据。

参数说明: data_type: str treasury_rates、economic_indicators、economic_calendar、market_risk_premium name: str 经济指标名称,data_type 为 economic_indicators 时必填 from_date: str 起始日期,格式 YYYY-MM-DD to_date: str 结束日期,格式 YYYY-MM-DD

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
data_typeYes
from_dateNo
nameNo
to_dateNo

Implementation Reference

  • The handler function that implements the get_economic_data tool, fetching macroeconomic data from Financial Modeling Prep API based on specified data_type, handling parameters like name, dates, and different endpoints.
    async def get_economic_data(
        data_type: str,
        name: str = "",
        from_date: str = "",
        to_date: str = "",
    ) -> str:
        """根据类型获取经济数据"""
    
        api_key = os.environ.get("FMP_API_KEY")
        if not api_key:
            return "Error: FMP_API_KEY environment variable not set."
    
        base = "https://financialmodelingprep.com/stable"
        endpoint_map = {
            "treasury_rates": "treasury-rates",
            "economic_indicators": "economic-indicators",
            "economic_calendar": "economic-calendar",
            "market_risk_premium": "market-risk-premium",
        }
        endpoint = endpoint_map.get(data_type.lower())
        if not endpoint:
            return "Error: invalid data type"
    
        params = {"apikey": api_key}
        if data_type == "economic_indicators":
            if not name:
                return "Error: name is required for economic_indicators"
            params["name"] = name
        if from_date and to_date:
            params.update({"from": from_date, "to": to_date})
    
        url = f"{base}/{endpoint}"
        try:
            resp = requests.get(url, params=params, timeout=10)
            resp.raise_for_status()
            data = resp.json()
        except Exception as e:
            return f"Error: getting economic data {data_type}: {e}"
        return json.dumps(data)
  • server.py:525-538 (registration)
    The @fmp_server.tool decorator that registers the get_economic_data function as an MCP tool, providing the name and detailed description of parameters serving as schema documentation.
    @fmp_server.tool(
        name="get_economic_data",
        description="""获取宏观经济数据。
    
    参数说明:
        data_type: str
            treasury_rates、economic_indicators、economic_calendar、market_risk_premium
        name: str
            经济指标名称,data_type 为 economic_indicators 时必填
        from_date: str
            起始日期,格式 YYYY-MM-DD
        to_date: str
            结束日期,格式 YYYY-MM-DD""",
    )
  • The function signature defining the input parameters and return type for the tool, which implicitly serves as the input schema.
    async def get_economic_data(
        data_type: str,
        name: str = "",
        from_date: str = "",
        to_date: str = "",
    ) -> str:

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/16Coffee/finance-mcp'

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