Skip to main content
Glama

MCP Yahoo Finance

by marckwei

get_dividends

Retrieve dividend information for a specific stock symbol using the MCP Yahoo Finance server. Input the stock symbol to access accurate dividend data for informed financial decisions.

Instructions

Get dividends for a given stock symbol.

Input Schema

NameRequiredDescriptionDefault
symbolYesStock symbol in Yahoo Finance format.

Input Schema (JSON Schema)

{ "properties": { "symbol": { "description": "Stock symbol in Yahoo Finance format.", "type": "string" } }, "required": [ "symbol" ], "type": "object" }

Implementation Reference

  • The primary handler function that executes the tool logic: fetches dividends data using yfinance Ticker for the given symbol and returns it formatted 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')}"
  • Registers the 'get_dividends' tool (via generate_tool(yf.get_dividends)) in the MCP server's list_tools handler, which provides the tool schema to clients.
    @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), ]
  • Dispatches tool calls to 'get_dividends' in the MCP server's call_tool handler, invoking the method with arguments and returning the result.
    case "get_dividends": price = yf.get_dividends(**args) return [TextContent(type="text", text=price)]
  • Helper function that generates the JSON schema for the tool based on function signature, type annotations, and docstring (used for get_dividends schema).
    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)

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/marckwei/no-use-tools'

If you have feedback or need assistance with the MCP directory API, please join our Discord server