get_dividends
Retrieve dividend data for a specific stock symbol using the MCP Yahoo Finance server. Input the stock symbol to access accurate dividend payout information for analysis or decision-making.
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:87-98 (handler)The primary handler function that executes the get_dividends tool logic: fetches dividends data using yfinance.Ticker(symbol).dividends and returns formatted 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/server.py:227-227 (registration)Registers the get_dividends tool in the server's list_tools() method by wrapping the handler with generate_tool.generate_tool(yf.get_dividends),
- src/mcp_yahoo_finance/server.py:252-254 (registration)Handles tool invocation dispatch for 'get_dividends' in the server's call_tool() method, calling the handler with arguments.case "get_dividends": price = yf.get_dividends(**args) return [TextContent(type="text", text=price)]
- src/mcp_yahoo_finance/utils.py:31-65 (schema)Generates the input schema for get_dividends (and other tools) from function signature, 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/utils.py:7-29 (helper)Helper function used by generate_tool to parse docstring for parameter descriptions in the schema.def parse_docstring(docstring: str) -> dict[str, str]: """Parses a Google-style docstring to extract parameter descriptions.""" descriptions = {} if not docstring: return descriptions lines = docstring.split("\n") current_param = None for line in lines: line = line.strip() if line.startswith("Args:"): continue elif line and "(" in line and ")" in line and ":" in line: param = line.split("(")[0].strip() desc = line.split("):")[1].strip() descriptions[param] = desc current_param = param elif current_param and line: descriptions[current_param] += " " + line.strip() return descriptions