get_ticker_info
Fetch detailed stock data such as company info, financials, trading metrics, and governance details using a specific stock symbol via the Yahoo Finance MCP Server.
Instructions
Retrieve stock data including company info, financials, trading metrics and governance data.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| symbol | Yes | The stock symbol |
Implementation Reference
- src/yfmcp/server.py:24-43 (handler)The main handler function for the 'get_ticker_info' tool. It fetches comprehensive stock information using yfinance.Ticker, converts timestamps to readable format, and returns the data as a JSON string. The @mcp.tool() decorator handles registration, and the Annotated parameter defines the input schema.@mcp.tool() def get_ticker_info(symbol: Annotated[str, Field(description="The stock symbol")]) -> str: """Retrieve stock data including company info, financials, trading metrics and governance data.""" ticker = yf.Ticker(symbol) # Convert timestamps to human-readable format info = ticker.info for key, value in info.items(): if not isinstance(key, str): continue if key.lower().endswith(("date", "start", "end", "timestamp", "time", "quarter")): try: info[key] = datetime.fromtimestamp(value).strftime("%Y-%m-%d %H:%M:%S") except Exception as e: logger.error("Unable to convert {}: {} to datetime, got error: {}", key, value, e) continue return json.dumps(info, ensure_ascii=False)