Skip to main content
Glama
leoncuhk

MCP Yahoo Finance

by leoncuhk

get_historical_stock_prices

Retrieve historical stock price data for analysis by specifying a stock symbol, time period, and data interval through the MCP Yahoo Finance server.

Instructions

Get historical stock prices for a given stock symbol.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
symbolYesStock symbol in Yahoo Finance format.
periodNoThe period for historical data. Defaults to "1mo". Valid periods: "1d", "5d", "1mo", "3mo", "6mo", "1y", "2y", "5y", "10y", "ytd", "max"
intervalNoThe interval beween data points. Defaults to "1d". Valid intervals: "1d", "5d", "1wk", "1mo", "3mo"

Implementation Reference

  • MCP tool handler registered with @mcp_instance.tool(), defines input schema via type annotations and docstring, executes by delegating to YahooFinance instance method.
    @mcp_instance.tool() def get_historical_stock_prices( symbol: str, period: Literal[ "1d", "5d", "1mo", "3mo", "6mo", "1y", "2y", "5y", "10y", "ytd", "max" ] = "1mo", interval: Literal["1d", "5d", "1wk", "1mo", "3mo"] = "1d", ) -> str: """Get historical stock prices for a given stock symbol. Args: symbol (str): Stock symbol in Yahoo Finance format. period (str): The period for historical data. Defaults to "1mo". Valid periods: "1d", "5d", "1mo", "3mo", "6mo", "1y", "2y", "5y", "10y", "ytd", "max" interval (str): The interval beween data points. Defaults to "1d". Valid intervals: "1d", "5d", "1wk", "1mo", "3mo" """ return yf_instance.get_historical_stock_prices(symbol, period, interval)
  • Core helper method in YahooFinance class that implements the logic to fetch historical stock prices using yfinance Ticker.history() and formats as JSON.
    def get_historical_stock_prices( self, symbol: str, period: Literal[ "1d", "5d", "1mo", "3mo", "6mo", "1y", "2y", "5y", "10y", "ytd", "max" ] = "1mo", interval: Literal["1d", "5d", "1wk", "1mo", "3mo"] = "1d", ) -> str: """Get historical stock prices for a given stock symbol. Args: symbol (str): Stock symbol in Yahoo Finance format. period (str): The period for historical data. Defaults to "1mo". Valid periods: "1d", "5d", "1mo", "3mo", "6mo", "1y", "2y", "5y", "10y", "ytd", "max" interval (str): The interval beween data points. Defaults to "1d". Valid intervals: "1d", "5d", "1wk", "1mo", "3mo" """ stock = Ticker(ticker=symbol, session=self.session) prices = stock.history(period=period, interval=interval) if hasattr(prices.index, "date"): prices.index = prices.index.date.astype(str) # type: ignore 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