Skip to main content
Glama
narumiruna

Yahoo Finance MCP Server

yfinance_get_option_dates

Read-onlyIdempotent

Retrieve available option expiration dates for a stock symbol. Returns dates in YYYY-MM-DD format for use with option chain tools.

Instructions

Fetch available option expiration dates for a stock.

Returns JSON array of expiration dates in YYYY-MM-DD format.

Use these dates with the 'yfinance_get_option_chain' tool to fetch
the options chain for a specific date.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
symbolYesStock ticker symbol (e.g., 'AAPL', 'GOOGL', 'MSFT')

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The async function `get_option_dates` (registered as 'yfinance_get_option_dates') fetches available option expiration dates for a stock ticker symbol. It creates a yfinance Ticker, retrieves the options dates via `ticker.options`, handles errors via `_create_option_dates_fetch_error`, and returns JSON using `dump_json`.
    @mcp.tool(
        name="yfinance_get_option_dates",
        annotations=ToolAnnotations(
            readOnlyHint=True,
            destructiveHint=False,
            idempotentHint=True,
            openWorldHint=True,
        ),
    )
    async def get_option_dates(
        symbol: Annotated[str, Field(description="Stock ticker symbol (e.g., 'AAPL', 'GOOGL', 'MSFT')")],
    ) -> str:
        """Fetch available option expiration dates for a stock.
    
        Returns JSON array of expiration dates in YYYY-MM-DD format.
    
        Use these dates with the 'yfinance_get_option_chain' tool to fetch
        the options chain for a specific date.
        """
        try:
            ticker = await asyncio.to_thread(yf.Ticker, symbol)
            dates = await asyncio.to_thread(lambda: ticker.options)
        except Exception as exc:
            return _create_option_dates_fetch_error(
                symbol,
                exc,
                f"Failed to fetch option dates for '{symbol}'. Verify the symbol is correct.",
            )
    
        if not dates:
            return create_error_response(
                f"No options available for symbol '{symbol}'. "
                "This symbol may not have listed options (e.g., ETFs, stocks without options).",
                error_code="NO_DATA",
                details={"symbol": symbol},
            )
    
        return dump_json(dates)
  • The tool is registered via the `@mcp.tool()` decorator with the name 'yfinance_get_option_dates', annotated as readOnlyHint=True, idempotentHint=True, openWorldHint=True.
    @mcp.tool(
        name="yfinance_get_option_dates",
        annotations=ToolAnnotations(
            readOnlyHint=True,
            destructiveHint=False,
            idempotentHint=True,
            openWorldHint=True,
        ),
    )
  • Helper function `_create_option_dates_fetch_error` builds error responses for option dates fetching failures, distinguishing retryable errors (rate limits/network) from other API errors.
    def _create_option_dates_fetch_error(symbol: str, exc: Exception, api_message: str) -> str:
        if _is_retryable_yfinance_error(exc):
            return _create_retryable_error_response(f"fetching option dates for '{symbol}'", exc, {"symbol": symbol})
    
        return create_error_response(
            api_message,
            error_code="API_ERROR",
            details={"symbol": symbol, "exception": str(exc)},
        )
  • Utility function `dump_json` serializes payloads to JSON with `default=str` for non-serializable types.
    def dump_json(payload: object) -> str:
        return json.dumps(payload, ensure_ascii=False, default=str)
  • Utility function `create_error_response` builds a structured JSON error response with error message, error code, and optional details.
    def create_error_response(message: str, error_code: ErrorCode = "UNKNOWN_ERROR", details: dict | None = None) -> str:
        """Create a structured error response.
    
        Args:
            message: Human-readable error message
            error_code: Machine-readable error code for client handling
            details: Optional additional error details
    
        Returns:
            JSON string with error information
        """
        error_obj: dict[str, object] = {"error": message, "error_code": error_code}
        if details:
            error_obj["details"] = details
        return dump_json(error_obj)
Behavior4/5

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

The description discloses the return format (JSON array of YYYY-MM-DD dates) which adds value beyond annotations. Annotations already indicate read-only, non-destructive, idempotent behavior, so the description's format detail is sufficient for 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 only three sentences, front-loaded with purpose, and each sentence adds distinct value: purpose, return format, and cross-reference to sibling tool. No wasted words.

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

Completeness5/5

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

Given the tool's low complexity (single parameter, simple return), the description covers all necessary context: what it does, what it returns, and how to use it with a related tool. Output schema exists so return structure is further clarified.

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 coverage is 100% with the symbol parameter already well-described. The description adds no extra parameter meaning beyond what the schema provides, meeting the baseline expectation.

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 it fetches available option expiration dates for a stock, using specific verb 'fetch' and resource 'option expiration dates'. It distinguishes from sibling tools by mentioning usage with yfinance_get_option_chain.

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 explicitly tells when to use this tool (to get expiration dates) and how to use it with yfinance_get_option_chain. However, it does not explicitly state when not to use it or mention any prerequisites.

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/narumiruna/yfinance-mcp'

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