Skip to main content
Glama
kukapay

crypto-stocks-mcp

get_historical_prices

Fetch historical stock price data for crypto-related companies to analyze market trends and investment opportunities. Retrieve closing prices and volume in table format for specified time periods.

Instructions

Fetch historical stock prices for the given ticker over the specified number of days in a table format.

Args: ticker (str): The stock ticker symbol (e.g., 'COIN' for Coinbase). days (int, optional): Number of days for historical data (default: 30). Returns: str: An ASCII table string containing the date, closing price, and volume for the specified stock. Returns an error message if the ticker is invalid.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
tickerYes
daysNo

Implementation Reference

  • main.py:76-107 (handler)
    The complete handler function for the 'get_historical_prices' tool, including the @mcp.tool() decorator which also serves as registration. It validates the ticker against CRYPTO_STOCKS, fetches historical data using yfinance, and formats it as an ASCII table.
    @mcp.tool() def get_historical_prices(ticker: str, days: int = 30) -> str: """Fetch historical stock prices for the given ticker over the specified number of days in a table format. Args: ticker (str): The stock ticker symbol (e.g., 'COIN' for Coinbase). days (int, optional): Number of days for historical data (default: 30). Returns: str: An ASCII table string containing the date, closing price, and volume for the specified stock. Returns an error message if the ticker is invalid. """ if ticker not in CRYPTO_STOCKS: return f"Error: Unknown ticker {ticker}" stock = yf.Ticker(ticker) end_date = datetime.now() start_date = end_date - timedelta(days=days) hist = stock.history(start=start_date, end=end_date) # Format historical data as a table table_data = [ [index.strftime("%Y-%m-%d"), row["Close"], row["Volume"]] for index, row in hist.iterrows() ] return tabulate( table_data, headers=["Date", "Close", "Volume"], tablefmt="grid", stralign="left", floatfmt=".2f" )

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/kukapay/crypto-stocks-mcp'

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