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

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

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"
        )
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden. It discloses output format (ASCII table), error behavior (returns error message for invalid ticker), and default value for days parameter. However, it doesn't mention rate limits, authentication needs, data source limitations, or pagination behavior.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is efficiently structured with a clear purpose statement followed by well-organized Args and Returns sections. Every sentence adds value: the first states what the tool does, the Args explain parameters with examples, and the Returns specifies output format and error behavior.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's moderate complexity (2 parameters, no annotations, but has output schema), the description is quite complete. It covers purpose, parameters, output format, and error handling. The output schema exists, so the description appropriately doesn't need to detail return structure. Minor gaps include lack of rate limit or data freshness information.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The description adds significant value beyond the schema (0% coverage). It explains that 'ticker' is a stock symbol with an example ('COIN' for Coinbase), clarifies that 'days' is optional with default 30, and specifies what the parameters control (historical data range). This fully compensates for the lack of schema descriptions.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action ('Fetch historical stock prices'), resource ('for the given ticker'), and output format ('in a table format'). It distinguishes from siblings like 'get_stock_price' (likely current price) and 'get_stock_list' (likely list of stocks).

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage context by specifying 'historical' data and table format, but doesn't explicitly state when to use this tool versus alternatives like 'get_stock_price' (which might provide current or real-time data). It provides clear default behavior for optional parameters.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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