Skip to main content
Glama
marckwei

MCP Yahoo Finance

by marckwei

get_current_stock_price

Retrieve current stock prices using Yahoo Finance data by providing a stock symbol. This tool enables users to access real-time financial information for investment decisions.

Instructions

Get the current stock price based on stock symbol.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
symbolYesStock symbol in Yahoo Finance format.

Implementation Reference

  • The handler function implementing the logic to fetch and format the current stock price for the given symbol using yfinance.Ticker.
    def get_current_stock_price(self, symbol: str) -> str:
        """Get the current stock price based on stock symbol.
    
        Args:
            symbol (str): Stock symbol in Yahoo Finance format.
        """
        stock = Ticker(ticker=symbol, session=self.session).info
        current_price = stock.get(
            "regularMarketPrice", stock.get("currentPrice", "N/A")
        )
        return (
            f"{current_price:.4f}"
            if current_price
            else f"Couldn't fetch {symbol} current price"
        )
  • Registers the get_current_stock_price tool in the MCP server's list_tools() method using generate_tool to create the Tool object.
    generate_tool(yf.get_current_stock_price),
  • Dispatches calls to the get_current_stock_price tool in the MCP server's call_tool() method.
    case "get_current_stock_price":
        price = yf.get_current_stock_price(**args)
        return [TextContent(type="text", text=price)]
  • Helper function that generates the MCP Tool schema (including input schema) from the handler function's signature and docstring, used for get_current_stock_price.
    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)

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observed

TDQS

C2.9/5.0
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It states the tool's function but doesn't describe traits such as rate limits, authentication needs, data freshness, error handling, or return format. This leaves significant gaps for a tool that likely interacts with external data sources.

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 with zero waste. It is appropriately sized for a simple tool and front-loads the key information without unnecessary elaboration.

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 lack of annotations and output schema, the description is incomplete. It doesn't address behavioral aspects like data source reliability, potential errors, or return structure. For a tool fetching real-time financial data, more context on limitations or usage constraints would be beneficial.

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 the parameter 'symbol' fully documented in the schema as 'Stock symbol in Yahoo Finance format.' The description adds no additional meaning beyond what the schema provides, 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 action ('Get') and resource ('current stock price') with the specific condition ('based on stock symbol'). It distinguishes from siblings like get_historical_stock_prices and get_stock_price_by_date by specifying 'current', but doesn't explicitly contrast them in the description text.

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 like get_stock_price_by_date or get_historical_stock_prices. It lacks any mention of prerequisites, exclusions, or comparative contexts with sibling tools.

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