get_earning_dates
Retrieve upcoming and historical earnings dates for stocks using the stock symbol in Yahoo Finance format. Customize results by specifying the number of dates to return.
Instructions
Get earning dates.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| limit | No | max amount of upcoming and recent earnings dates to return. Default value 12 should return next 4 quarters and last 8 quarters. Increase if more history is needed. | |
| symbol | Yes | Stock symbol in Yahoo Finance format. |
Input Schema (JSON Schema)
{
"properties": {
"limit": {
"description": "max amount of upcoming and recent earnings dates to return. Default value 12 should return next 4 quarters and last 8 quarters. Increase if more history is needed.",
"type": "string"
},
"symbol": {
"description": "Stock symbol in Yahoo Finance format.",
"type": "string"
}
},
"required": [
"symbol"
],
"type": "object"
}
Implementation Reference
- src/mcp_yahoo_finance/server.py:173-188 (handler)The core handler function implementing the get_earning_dates tool logic using yfinance to fetch earnings dates and return formatted JSON.def get_earning_dates(self, symbol: str, limit: int = 12) -> str: """Get earning dates. Args: symbol (str): Stock symbol in Yahoo Finance format. limit (int): max amount of upcoming and recent earnings dates to return. Default value 12 should return next 4 quarters and last 8 quarters. Increase if more history is needed. """ stock = Ticker(ticker=symbol, session=self.session) earning_dates = stock.get_earnings_dates(limit=limit) if isinstance(earning_dates, pd.DataFrame): earning_dates.index = earning_dates.index.date.astype(str) # type: ignore return f"{earning_dates.to_json(indent=2)}" return f"{earning_dates}"
- src/mcp_yahoo_finance/server.py:204-218 (registration)Registers all tools including get_earning_dates via generate_tool in the MCP server's list_tools handler, which provides tool schemas.@server.list_tools() async def list_tools() -> list[Tool]: return [ generate_tool(yf.cmd_run), generate_tool(yf.get_recommendations), generate_tool(yf.get_news), generate_tool(yf.get_current_stock_price), generate_tool(yf.get_stock_price_by_date), generate_tool(yf.get_stock_price_date_range), generate_tool(yf.get_historical_stock_prices), generate_tool(yf.get_dividends), generate_tool(yf.get_income_statement), generate_tool(yf.get_cashflow), generate_tool(yf.get_earning_dates), ]
- src/mcp_yahoo_finance/server.py:244-246 (handler)Dispatches execution of get_earning_dates tool in the MCP server's call_tool handler.case "get_earning_dates": price = yf.get_earning_dates(**args) return [TextContent(type="text", text=price)]
- src/mcp_yahoo_finance/utils.py:31-65 (schema)Generates the JSON schema for tools like get_earning_dates by inspecting function signature and docstring.def generate_tool(func: Any) -> Tool: """Generates a tool schema from a Python function.""" signature = inspect.signature(func) docstring = inspect.getdoc(func) or "" param_descriptions = parse_docstring(docstring) schema = { "name": func.__name__, "description": docstring.split("Args:")[0].strip(), "inputSchema": { "type": "object", "properties": {}, }, } for param_name, param in signature.parameters.items(): param_type = ( "number" if param.annotation is float else "string" if param.annotation is str else "string" ) schema["inputSchema"]["properties"][param_name] = { "type": param_type, "description": param_descriptions.get(param_name, ""), } if "required" not in schema["inputSchema"]: schema["inputSchema"]["required"] = [param_name] else: if "=" not in str(param): schema["inputSchema"]["required"].append(param_name) return Tool(**schema)