Skip to main content
Glama
leoncuhk

MCP Yahoo Finance

by leoncuhk

get_stock_price_date_range

Retrieve historical stock prices for a specific symbol within a defined date range using YYYY-MM-DD format for accurate financial analysis.

Instructions

Get the stock prices for a given date range for a given stock symbol.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
end_dateYesThe end date in YYYY-MM-DD format.
start_dateYesThe start date in YYYY-MM-DD format.
symbolYesStock symbol in Yahoo Finance format.

Implementation Reference

  • The MCP tool handler for 'get_stock_price_date_range', registered via @mcp_instance.tool() decorator. It delegates execution to the yf_instance helper method.
    @mcp_instance.tool() def get_stock_price_date_range(symbol: str, start_date: str, end_date: str) -> str: """Get the stock prices for a given date range for a given stock symbol. Args: symbol (str): Stock symbol in Yahoo Finance format. start_date (str): The start date in YYYY-MM-DD format. end_date (str): The end date in YYYY-MM-DD format. """ return yf_instance.get_stock_price_date_range(symbol, start_date, end_date)
  • The supporting method in the YahooFinance class that implements the core logic: retrieves historical closing prices for the given symbol and date range using yfinance, formats dates as strings, and returns JSON.
    def get_stock_price_date_range( self, symbol: str, start_date: str, end_date: str ) -> str: """Get the stock prices for a given date range for a given stock symbol. Args: symbol (str): Stock symbol in Yahoo Finance format. start_date (str): The start date in YYYY-MM-DD format. end_date (str): The end date in YYYY-MM-DD format. """ stock = Ticker(ticker=symbol, session=self.session) prices = stock.history(start=start_date, end=end_date) prices.index = prices.index.astype(str) return f"{prices['Close'].to_json(orient='index')}"

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/leoncuhk/mcp-yahoo-finance'

If you have feedback or need assistance with the MCP directory API, please join our Discord server