get_dividends
Retrieve dividend payment information for stocks using Yahoo Finance data. Input a stock symbol to access dividend history and details.
Instructions
Get dividends for a given stock symbol.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| symbol | Yes | Stock symbol in Yahoo Finance format. |
Implementation Reference
- src/mcp_yahoo_finance/server.py:122-133 (handler)Core handler function that implements the get_dividends tool logic using yfinance to fetch and format dividends data as JSON.def get_dividends(self, symbol: str) -> str: """Get dividends for a given stock symbol. Args: symbol (str): Stock symbol in Yahoo Finance format. """ stock = Ticker(ticker=symbol, session=self.session) dividends = stock.dividends if hasattr(dividends.index, "date"): dividends.index = dividends.index.date.astype(str) # type: ignore return f"{dividends.to_json(orient='index')}"
- src/mcp_yahoo_finance/utils.py:31-65 (schema)Generates the input schema for tools like get_dividends based on function signature, type annotations, 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)
- src/mcp_yahoo_finance/server.py:214-214 (registration)Registers the get_dividends tool in the MCP server's list_tools() by generating its Tool object.generate_tool(yf.get_dividends),
- src/mcp_yahoo_finance/server.py:235-237 (handler)MCP server call_tool handler that dispatches to the get_dividends implementation.case "get_dividends": price = yf.get_dividends(**args) return [TextContent(type="text", text=price)]