Skip to main content
Glama
16Coffee

Yahoo Finance MCP Server

by 16Coffee

get_option_expiration_dates

Retrieve available option expiration dates for a specific stock ticker using the Yahoo Finance MCP Server. Input the stock symbol to fetch relevant options data for informed trading decisions.

Instructions

获取指定股票可用的期权到期日。

参数说明: ticker: str 股票代码,例如 "AAPL"

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
tickerYes

Implementation Reference

  • The handler function that implements the core logic of the tool. It retrieves the available option expiration dates for the specified stock ticker from the Financial Modeling Prep API, handles errors, sorts the dates, and returns them as a JSON string.
    async def get_option_expiration_dates(ticker: str) -> str: """Fetch the available options expiration dates for a given ticker symbol.""" api_key = os.environ.get("FMP_API_KEY") if not api_key: return "Error: FMP_API_KEY environment variable not set." base = "https://financialmodelingprep.com/api/v3" try: resp = requests.get( f"{base}/options/available-expirations/{ticker}", params={"apikey": api_key}, timeout=10 ) resp.raise_for_status() data = resp.json() except Exception as e: return f"Error: getting option expiration dates for {ticker}: {e}" expirations = data if isinstance(data, list) else data.get("expirations", []) return json.dumps(sorted(expirations))
  • server.py:580-588 (registration)
    Registers the tool with the FastMCP server, specifying the name and a description that includes the input parameter schema (ticker: str).
    @fmp_server.tool( name="get_option_expiration_dates", description="""获取指定股票可用的期权到期日。 参数说明: ticker: str 股票代码,例如 "AAPL" """, )
  • Defines the input schema in the tool description: requires a 'ticker' parameter of type string (e.g., 'AAPL'). The function signature also provides type hints: ticker: str -> str.
    description="""获取指定股票可用的期权到期日。 参数说明: ticker: str 股票代码,例如 "AAPL" """,

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/16Coffee/finance-mcp'

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