get_fundamentals
Retrieve core financial data for stock analysis, including fundamentals like earnings, revenue, and balance sheet metrics to support investment decisions.
Instructions
Retrieves core financial and fundamental data.
Args:
symbol: The ticker symbol.
Returns:
Dictionary containing fundamental data.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| symbol | Yes |
Implementation Reference
- tools/market_data.py:87-108 (handler)The main handler function for the get_fundamentals tool. It fetches key fundamental metrics (PE ratios, margins, market cap, etc.) from Yahoo Finance using yfinance.Ticker(symbol).info and returns a filtered dictionary of available metrics.def get_fundamentals(symbol: str) -> Dict[str, Any]: """ Retrieves core financial and fundamental data. Args: symbol: The ticker symbol. Returns: Dictionary containing fundamental data. """ try: ticker = yf.Ticker(symbol) info = ticker.info # Filter for key metrics to avoid overwhelming context key_metrics = [ "marketCap", "forwardPE", "trailingPE", "pegRatio", "priceToBook", "profitMargins", "revenueGrowth", "returnOnEquity", "totalDebt", "totalCash", "sector", "industry" ] return {k: info.get(k) for k in key_metrics if k in info} except Exception as e: return {"error": f"Error fetching fundamentals for {symbol}: {str(e)}"}
- server.py:370-373 (registration)Registers the get_fundamentals tool in the MCP server under the 'Market Data' category by applying the @mcp.tool() decorator via the register_tools helper function.register_tools( [get_price, get_fundamentals, get_orderbook], "Market Data" )
- app.py:47-47 (registration)Imports the get_fundamentals function from tools.market_data for use in the application (Gradio UI tools map).from tools.market_data import get_price, get_fundamentals, get_orderbook
- server.py:12-12 (registration)Imports the get_fundamentals function required for MCP tool registration in the server.from tools.market_data import get_price, get_fundamentals, get_orderbook