Skip to main content
Glama
marckwei

MCP Yahoo Finance

by marckwei

get_stock_price_date_range

Retrieve historical stock prices for a specific symbol within a defined date range using Yahoo Finance data.

Instructions

Get the stock prices for a given date range for a given stock symbol.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
symbolYesStock symbol in Yahoo Finance format.
start_dateYesThe start date in YYYY-MM-DD format.
end_dateYesThe end date in YYYY-MM-DD format.

Implementation Reference

  • Core implementation of the tool: fetches historical closing prices for the given stock symbol over the specified date range using yfinance, formats index as strings, and returns JSON.
    def get_stock_price_date_range(
        self, symbol: str, start_date: str, end_date: str
    ) -> str:
        """Get the stock prices for a given date range for a given stock symbol.
    
        Args:
            symbol (str): Stock symbol in Yahoo Finance format.
            start_date (str): The start date in YYYY-MM-DD format.
            end_date (str): The end date in YYYY-MM-DD format.
        """
        stock = Ticker(ticker=symbol, session=self.session)
        prices = stock.history(start=start_date, end=end_date)
        prices.index = prices.index.astype(str)
        return f"{prices['Close'].to_json(orient='index')}"
  • Tool registration in the MCP server's list_tools decorator method, specifically line 212 registers get_stock_price_date_range using generate_tool.
    @server.list_tools()
    async def list_tools() -> list[Tool]:
        return [            
            generate_tool(yf.cmd_run),
            generate_tool(yf.get_recommendations),
            generate_tool(yf.get_news),
            generate_tool(yf.get_current_stock_price),
            generate_tool(yf.get_stock_price_by_date),
            generate_tool(yf.get_stock_price_date_range),
            generate_tool(yf.get_historical_stock_prices),
            generate_tool(yf.get_dividends),
            generate_tool(yf.get_income_statement),
            generate_tool(yf.get_cashflow),
            generate_tool(yf.get_earning_dates),
        ]
  • Dispatch logic in the MCP server's call_tool method that calls the tool handler with arguments and returns the result as TextContent.
    case "get_stock_price_date_range":
        price = yf.get_stock_price_date_range(**args)
        return [TextContent(type="text", text=price)]
  • Helper function generate_tool that dynamically generates the tool's input schema from the Python function signature, type annotations, and Google-style docstring.
    def generate_tool(func: Any) -> Tool:
        """Generates a tool schema from a Python function."""
        signature = inspect.signature(func)
        docstring = inspect.getdoc(func) or ""
        param_descriptions = parse_docstring(docstring)
    
        schema = {
            "name": func.__name__,
            "description": docstring.split("Args:")[0].strip(),
            "inputSchema": {
                "type": "object",
                "properties": {},
            },
        }
    
        for param_name, param in signature.parameters.items():
            param_type = (
                "number"
                if param.annotation is float
                else "string"
                if param.annotation is str
                else "string"
            )
            schema["inputSchema"]["properties"][param_name] = {
                "type": param_type,
                "description": param_descriptions.get(param_name, ""),
            }
    
            if "required" not in schema["inputSchema"]:
                schema["inputSchema"]["required"] = [param_name]
            else:
                if "=" not in str(param):
                    schema["inputSchema"]["required"].append(param_name)
    
        return Tool(**schema)
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 action ('Get') but does not describe traits like whether this is a read-only operation, potential rate limits, data freshness, error handling, or output format. For a tool with no annotations, this is a significant gap in transparency.

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 a single, efficient sentence that front-loads the core purpose without unnecessary words. It is appropriately sized and avoids redundancy, making it easy to parse quickly.

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

Completeness3/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 (3 required parameters) and no output schema, the description is minimally adequate but incomplete. It specifies what the tool does but lacks details on behavior, usage context, and output, which are crucial for an agent to invoke it correctly without annotations.

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

Parameters3/5

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

Schema description coverage is 100%, with clear descriptions for all three parameters in the input schema. The description adds no additional semantic meaning beyond what the schema provides, such as format examples or constraints, so it meets the baseline for high schema coverage without compensating value.

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 with a specific verb ('Get') and resource ('stock prices'), and it specifies the scope ('for a given date range for a given stock symbol'). However, it does not explicitly distinguish it from sibling tools like 'get_historical_stock_prices' or 'get_stock_price_by_date', which likely have overlapping functionality, so it misses full differentiation.

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 such as 'get_historical_stock_prices' or 'get_stock_price_by_date'. It lacks context about prerequisites, exclusions, or specific scenarios, leaving the agent to infer usage based on the name alone.

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/marckwei/no-use-tools'

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