get_current_stock_price
Retrieve real-time stock price data for any publicly traded company using its stock symbol. This tool provides current market prices to support investment decisions and financial analysis.
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)The primary MCP tool handler for 'get_current_stock_price', registered via @mcp_instance.tool() decorator. It delegates execution to the YahooFinance instance's 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)
- Supporting helper method in the YahooFinance class that performs the actual API call to yfinance to retrieve the current stock price.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" )