Skip to main content
Glama
marckwei

MCP Yahoo Finance

by marckwei

get_stock_price_by_date

Retrieve historical stock prices for specific dates using Yahoo Finance data. Enter a stock symbol and date to get the closing price for that trading day.

Instructions

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

Input Schema

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

Implementation Reference

  • The handler function in the YahooFinance class that implements the tool logic: creates a yfinance Ticker, fetches 1-day history starting from the given date, and returns the closing price formatted to 4 decimal places.
    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}"
  • Registers the get_stock_price_by_date tool in the MCP server's list_tools() by passing the handler method to generate_tool.
    generate_tool(yf.get_stock_price_by_date),
  • In the server's call_tool() dispatcher, matches the tool name and invokes the handler with arguments, returning the result as TextContent.
    case "get_stock_price_by_date":
        price = yf.get_stock_price_by_date(**args)
        return [TextContent(type="text", text=price)]
  • Helper function that generates the MCP Tool object (including schema inferred from function signature, docstring, and type annotations) used to register all tools including get_stock_price_by_date.
    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 tool 'Get[s] the stock price,' implying a read-only operation, but doesn't address critical aspects like data source (e.g., Yahoo Finance, implied by schema but not confirmed), potential rate limits, error handling (e.g., invalid symbols or dates), 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, well-structured sentence that efficiently conveys the core functionality without unnecessary details. It's front-loaded with the main action and includes key constraints, making it easy to parse. There's no wasted verbiage, earning a perfect score for conciseness.

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 tool's complexity (a read operation with specific parameters) and lack of annotations and output schema, the description is incomplete. It doesn't explain what the output looks like (e.g., price value, currency, or possible nulls), data freshness, or error scenarios. This leaves gaps that could hinder an agent's ability to use the tool effectively, especially without structured output information.

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?

The schema description coverage is 100%, with clear descriptions for both parameters ('symbol' and 'date'), including format details (e.g., 'Yahoo Finance format,' 'YYYY-MM-DD'). The description adds minimal value beyond the schema, only reiterating that parameters are for 'stock symbol' and 'specific date.' This meets the baseline score of 3, as the schema does the heavy lifting.

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 the stock price for a given stock symbol on a specific date.' It specifies the verb ('Get'), resource ('stock price'), and key constraints ('on a specific date'), making it easy to understand what the tool does. However, it doesn't explicitly differentiate from sibling tools like 'get_current_stock_price' or 'get_historical_stock_prices', which is why it doesn't achieve 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 like 'get_current_stock_price' (for current prices) or 'get_historical_stock_prices' (for date ranges), nor does it specify prerequisites or exclusions. This leaves the agent without context for tool selection, relying solely on the tool name and description.

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