get_income_statement
Retrieve income statement data for a stock symbol in Yahoo Finance format, specifying frequency as yearly, quarterly, or trailing. Use this to analyze financial performance directly from the MCP Yahoo Finance server.
Instructions
Get income statement for a given stock symbol.
Input 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. |
Input Schema (JSON Schema)
{
"properties": {
"freq": {
"description": "At what frequency to get cashflow statements. Defaults to \"yearly\". Valid freqencies: \"yearly\", \"quarterly\", \"trainling\"",
"type": "string"
},
"symbol": {
"description": "Stock symbol in Yahoo Finance format.",
"type": "string"
}
},
"required": [
"symbol"
],
"type": "object"
}
Implementation Reference
- src/mcp_yahoo_finance/server.py:100-119 (handler)Core handler function in YahooFinance class that fetches the income statement using yfinance Ticker.get_income_stmt, formats 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/server.py:220-235 (registration)Tool registration in the list_tools handler, including generate_tool(yf.get_income_statement) to provide the tool schema.@server.list_tools() async def list_tools() -> list[Tool]: return [ 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), generate_tool(yf.get_news), generate_tool(yf.get_recommendations), generate_tool(yf.get_option_expiration_dates), generate_tool(yf.get_option_chain), ]
- src/mcp_yahoo_finance/server.py:255-257 (registration)Dispatch registration in call_tool handler that invokes the get_income_statement method.case "get_income_statement": price = yf.get_income_statement(**args) return [TextContent(type="text", text=price)]
- src/mcp_yahoo_finance/utils.py:31-66 (schema)generate_tool function that dynamically creates the Tool schema (including inputSchema) from the handler's 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)
- src/mcp_yahoo_finance/utils.py:7-28 (helper)Helper function to parse docstrings for parameter descriptions used in schema generation.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