Skip to main content
Glama
dev484p

Agentic AI with MCP

by dev484p

yahoo_finance_search

Retrieve stock data and financial information from Yahoo Finance by entering a stock symbol and optional time period.

Instructions

Get stock information from Yahoo Finance.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
symbolYes
periodNo1mo

Implementation Reference

  • The handler function for 'yahoo_finance_search' tool. It fetches stock data from Yahoo Finance API using the provided symbol and period, extracts key metrics like current price, open, high, low, close, volume, and formats them into a readable string response. The @mcp.tool() decorator registers it with the MCP server.
    @mcp.tool()
    async def yahoo_finance_search(symbol: str, period: str = "1mo") -> str:
        """Get stock information from Yahoo Finance."""
        try:
            valid_periods = ["1d", "5d", "1mo", "3mo", "6mo", "1y", "5y"]
            if period not in valid_periods:
                return f"Invalid period. Must be one of: {', '.join(valid_periods)}"
            
            params = {
                "symbol": symbol,
                "range": period,
                "interval": "1d",
                "includePrePost": "false"
            }
            
            data = await make_api_request(f"{YAHOO_FINANCE_BASE}{symbol}", params=params)
            
            if not data or "chart" not in data or not data["chart"]["result"]:
                return f"Could not retrieve data for symbol {symbol}"
            
            result = data["chart"]["result"][0]
            meta = result["meta"]
            indicators = result["indicators"]["quote"][0]
            
            timestamps = result["timestamp"]
            dates = [datetime.fromtimestamp(ts).strftime('%Y-%m-%d') for ts in timestamps]
            
            latest_idx = -1
            latest_date = dates[latest_idx]
            latest_open = indicators["open"][latest_idx]
            latest_high = indicators["high"][latest_idx]
            latest_low = indicators["low"][latest_idx]
            latest_close = indicators["close"][latest_idx]
            latest_volume = indicators["volume"][latest_idx]
            
            response = [
                f"Stock: {meta['symbol']} ({meta['exchangeName']})",
                f"Currency: {meta['currency']}",
                f"Current Price: {meta['regularMarketPrice']}",
                f"Previous Close: {meta['chartPreviousClose']}",
                "\nLatest Trading Day:",
                f"Date: {latest_date}",
                f"Open: {latest_open}",
                f"High: {latest_high}",
                f"Low: {latest_low}",
                f"Close: {latest_close}",
                f"Volume: {latest_volume}"
            ]
            
            return "\n".join(response)
        except Exception as e:
            logger.error(f"Error in yahoo_finance_search: {e}")
            return f"Failed to retrieve finance data for {symbol} due to an internal error."
  • server.py:129-129 (registration)
    The @mcp.tool() decorator registers the yahoo_finance_search function as an MCP tool.
    @mcp.tool()
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states the tool 'gets' information, implying a read-only operation, but doesn't clarify if it's safe, requires authentication, has rate limits, or what kind of data it returns. For a tool with zero annotation coverage, this is insufficient to guide the agent's expectations.

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 extremely concise and front-loaded, consisting of a single sentence that directly states the tool's purpose. There's no wasted language or unnecessary elaboration, making it efficient for quick understanding.

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

Completeness2/5

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

Given the complexity (2 parameters, no annotations, no output schema), the description is incomplete. It doesn't cover parameter meanings, return values, or behavioral traits. While it states the basic purpose, it lacks the depth needed for the agent to use the tool effectively without additional context.

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

Parameters1/5

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

The description adds no meaning beyond what the input schema provides. With 0% schema description coverage, both parameters ('symbol' and 'period') are undocumented in the schema, and the description doesn't explain what they represent, their formats, or valid values. This leaves the agent guessing about parameter usage.

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

Purpose4/5

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

The description clearly states the tool's purpose: 'Get stock information from Yahoo Finance.' It specifies the verb ('Get') and resource ('stock information from Yahoo Finance'), making it easy to understand what the tool does. However, it doesn't explicitly differentiate from sibling tools like 'internet_search' or 'wiki_search', which prevents a perfect score.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention sibling tools or any context for choosing this over general search tools. There's no information about prerequisites, limitations, or specific use cases, leaving the agent without usage direction.

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/dev484p/AgenticAI_MCP'

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