Skip to main content
Glama
leoncuhk

MCP Yahoo Finance

by leoncuhk

get_stock_price_by_date

Retrieve the stock price for a specific symbol on a particular date using the YYYY-MM-DD format, providing accurate financial data for analysis or record-keeping.

Instructions

Get the stock price for a given stock symbol on a specific date.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
dateYesThe date in YYYY-MM-DD format.
symbolYesStock symbol in Yahoo Finance format.

Implementation Reference

  • The MCP tool handler function decorated with @mcp_instance.tool(), which registers the tool and executes the logic by delegating to the YahooFinance instance method.
    @mcp_instance.tool() def get_stock_price_by_date(symbol: str, date: str) -> str: """Get the stock price for a given stock symbol on a specific date. Args: symbol (str): Stock symbol in Yahoo Finance format. date (str): The date in YYYY-MM-DD format. """ return yf_instance.get_stock_price_by_date(symbol, date)
  • The supporting method in the YahooFinance class that implements the core logic: fetches the stock ticker, retrieves 1-day history starting from the given date, and returns the closing price formatted to 4 decimals.
    def get_stock_price_by_date(self, symbol: str, date: str) -> str: """Get the stock price for a given stock symbol on a specific date. Args: symbol (str): Stock symbol in Yahoo Finance format. date (str): The date in YYYY-MM-DD format. """ stock = Ticker(ticker=symbol, session=self.session) price = stock.history(start=date, period="1d") return f"{price.iloc[0]['Close']:.4f}"
  • The @mcp_instance.tool() decorator line that registers the get_stock_price_by_date function as an MCP tool.
    @mcp_instance.tool()

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