get_income_statement
Retrieve income statement data for stocks to analyze financial performance, with options for yearly, quarterly, or trailing frequency reporting.
Instructions
Get income statement for a given stock symbol.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| symbol | Yes | Stock symbol in Yahoo Finance format. | |
| freq | No | At what frequency to get cashflow statements. Defaults to "yearly". Valid freqencies: "yearly", "quarterly", "trainling" |
Implementation Reference
- src/mcp_yahoo_finance/server.py:135-154 (handler)Core handler method in the YahooFinance class that fetches the income statement data for a given stock symbol using yfinance Ticker.get_income_stmt(), formats the DataFrame columns to dates, and returns as JSON string.def get_income_statement( self, symbol: str, freq: Literal["yearly", "quarterly", "trainling"] = "yearly" ) -> str: """Get income statement 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) income_statement = stock.get_income_stmt(freq=freq, pretty=True) if isinstance(income_statement, pd.DataFrame): income_statement.columns = [ str(col.date()) for col in income_statement.columns ] return f"{income_statement.to_json()}" return f"{income_statement}"
- src/mcp_yahoo_finance/utils.py:31-65 (schema)Generates the Tool object including inputSchema derived from the function's type annotations, signature parameters, and docstring descriptions. Used to register the get_income_statement tool.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:204-218 (registration)The tool 'get_income_statement' is registered in the MCP server's list_tools() by calling generate_tool on the bound method yf.get_income_statement.@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), ]
- src/mcp_yahoo_finance/server.py:238-240 (handler)Dispatch logic in the server's call_tool() handler that invokes the get_income_statement method with parsed arguments and returns the result as TextContent.case "get_income_statement": price = yf.get_income_statement(**args) return [TextContent(type="text", text=price)]