Skip to main content
Glama
marckwei

MCP Yahoo Finance

by marckwei

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
NameRequiredDescriptionDefault
symbolYesStock symbol in Yahoo Finance format.

Implementation Reference

  • 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')}"
  • 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)
  • Registers the get_dividends tool in the MCP server's list_tools() by generating its Tool object.
    generate_tool(yf.get_dividends),
  • 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)]

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