Skip to main content
Glama
16Coffee

Yahoo Finance MCP Server

by 16Coffee

get_option_chain

Retrieve detailed option chain data for a specific stock, including calls and puts, by providing the ticker symbol, expiration date, and option type. Use this to analyze and strategize financial options trading.

Instructions

根据股票代码、到期日和期权类型获取期权链数据。

参数说明: ticker: str 股票代码,例如 "AAPL" expiration_date: str 期权到期日,格式为 'YYYY-MM-DD' option_type: str 期权类型:'calls' 或 'puts'

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
expiration_dateYes
option_typeYes
tickerYes

Implementation Reference

  • The core handler function for the 'get_option_chain' tool. It retrieves option chain data from the Financial Modeling Prep API for a given ticker, filters by expiration date and option type (calls/puts), handles errors, and returns filtered JSON data.
    async def get_option_chain(ticker: str, expiration_date: str, option_type: str) -> str: """Fetch the option chain for a given ticker symbol, expiration date, and option type.""" 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/chain/{ticker}", params={"expiration": expiration_date, "apikey": api_key}, timeout=10, ) resp.raise_for_status() data = resp.json() except Exception as e: return f"Error: getting option chain for {ticker}: {e}" filtered = [ item for item in data if item.get("expirationDate") == expiration_date and item.get("optionType", "").lower() == option_type.lower() ] return json.dumps(filtered)
  • server.py:609-621 (registration)
    The @fmp_server.tool decorator registers the 'get_option_chain' tool, specifying its name and detailed description including input parameters (schema). This is how the tool is exposed in the MCP server.
    @fmp_server.tool( name="get_option_chain", description="""根据股票代码、到期日和期权类型获取期权链数据。 参数说明: ticker: str 股票代码,例如 "AAPL" expiration_date: str 期权到期日,格式为 'YYYY-MM-DD' option_type: str 期权类型:'calls' 或 'puts' """, )
  • Type hints in the function signature define the input schema: ticker (str), expiration_date (str), option_type (str), returning str (JSON).
    async def get_option_chain(ticker: str, expiration_date: str, option_type: str) -> str:

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