get_current_stock_price
Retrieve the current stock price by providing the stock symbol in Yahoo Finance format. Ideal for accessing real-time financial data for analysis or decision-making.
Instructions
Get the current stock price based on stock symbol.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| symbol | Yes | Stock symbol in Yahoo Finance format. |
Implementation Reference
- src/mcp_yahoo_finance/server.py:201-208 (handler)MCP tool registration and handler function for 'get_current_stock_price'. This is the entry point decorated with @mcp_instance.tool() that delegates to the YahooFinance instance method.@mcp_instance.tool() def get_current_stock_price(symbol: str) -> str: """Get the current stock price based on stock symbol. Args: symbol (str): Stock symbol in Yahoo Finance format. """ return yf_instance.get_current_stock_price(symbol)
- Core implementation in YahooFinance class that fetches the current stock price using yfinance Ticker.info and formats the response.def get_current_stock_price(self, symbol: str) -> str: """Get the current stock price based on stock symbol. Args: symbol (str): Stock symbol in Yahoo Finance format. """ stock = Ticker(ticker=symbol, session=self.session).info current_price = stock.get( "regularMarketPrice", stock.get("currentPrice", "N/A") ) return ( f"{current_price:.4f}" if current_price else f"Couldn't fetch {symbol} current price" )