get_earning_dates
Retrieve upcoming and historical earnings dates for a specific stock symbol directly from Yahoo Finance. Specify the stock symbol and adjust the limit to control the number of dates returned.
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:138-154 (handler)Core handler function implementing the get_earning_dates tool. Fetches earnings dates using yfinance Ticker.get_earnings_dates, processes index to string dates if DataFrame, and returns JSON string.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:230-230 (registration)Registration of the get_earning_dates tool in the list_tools() handler using generate_tool to create the Tool object.generate_tool(yf.get_earning_dates),
- src/mcp_yahoo_finance/server.py:261-263 (registration)Dispatch logic in call_tool() handler that invokes the get_earning_dates method with parsed arguments and returns the result as TextContent.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)Helper function that generates the tool schema dynamically from the handler function's signature, type annotations, and docstring parameters.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)