get_cashflow
Retrieve cash flow statements for a specific stock symbol on Yahoo Finance. Choose between yearly, quarterly, or trailing frequencies to analyze financial data.
Instructions
Get cashflow for a given stock symbol.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| freq | No | At what frequency to get cashflow statements. Defaults to "yearly". Valid freqencies: "yearly", "quarterly", "trainling" | |
| symbol | Yes | Stock symbol in Yahoo Finance format. |
Implementation Reference
- src/mcp_yahoo_finance/server.py:120-136 (handler)Core handler function for the get_cashflow tool. Fetches cashflow statements using yfinance Ticker.get_cashflow() and formats as pretty JSON string.def get_cashflow( self, symbol: str, freq: Literal["yearly", "quarterly", "trainling"] = "yearly" ): """Get cashflow for a given stock symbol. Args: symbol (str): Stock symbol in Yahoo Finance format. freq (str): At what frequency to get cashflow statements. Defaults to "yearly". Valid freqencies: "yearly", "quarterly", "trainling" """ stock = Ticker(ticker=symbol, session=self.session) cashflow = stock.get_cashflow(freq=freq, pretty=True) if isinstance(cashflow, pd.DataFrame): cashflow.columns = [str(col.date()) for col in cashflow.columns] return f"{cashflow.to_json(indent=2)}" return f"{cashflow}"
- src/mcp_yahoo_finance/server.py:229-229 (registration)Registers the get_cashflow tool in the MCP server's tool list by generating a Tool object from the handler function.generate_tool(yf.get_cashflow),
- src/mcp_yahoo_finance/server.py:258-260 (handler)Dispatch handler in the MCP server's call_tool method that invokes the get_cashflow function with arguments and returns the result as TextContent.case "get_cashflow": price = yf.get_cashflow(**args) return [TextContent(type="text", text=price)]
- src/mcp_yahoo_finance/utils.py:31-65 (helper)Helper utility that inspects the handler function to generate the MCP Tool object, including input schema from signature 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)
- Type annotations and signature that define the input schema for the tool (symbol: str, freq: Literal[...]).def get_cashflow( self, symbol: str, freq: Literal["yearly", "quarterly", "trainling"] = "yearly" ):