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
| Name | Required | Description | Default |
|---|---|---|---|
| data_type | Yes | ||
| from_date | No | ||
| name | No | ||
| to_date | No |
Implementation Reference
- server.py:539-577 (handler)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""", )
- server.py:539-544 (schema)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: