/**
* MCP Tool: get_options_chain
*
* Fetch options chain data for a given symbol.
*/
import { z } from "zod";
import type { OptionsChain } from "@quant-companion/core";
import { getDefaultProvider } from "../marketData";
export const getOptionsChainSchema = z.object({
symbol: z.string().describe("Stock/ETF ticker symbol (e.g., AAPL, SPY)"),
expiration: z
.string()
.optional()
.describe("Optional expiration date (ISO format: YYYY-MM-DD). If omitted, returns nearest expiration."),
});
export type GetOptionsChainInput = z.infer<typeof getOptionsChainSchema>;
export type GetOptionsChainOutput = OptionsChain;
export async function getOptionsChain(
input: GetOptionsChainInput
): Promise<GetOptionsChainOutput> {
const provider = getDefaultProvider();
try {
const chain = await provider.getOptionsChain({
symbol: input.symbol,
expiration: input.expiration,
});
return chain;
} catch (error) {
const message = error instanceof Error ? error.message : "Unknown error";
throw new Error(`Options chain not found for ${input.symbol}: ${message}`);
}
}
export const getOptionsChainDefinition = {
name: "get_options_chain",
description:
"Fetch options chain data for a given stock/ETF symbol. Returns available expirations, strikes, and option contract details including bid/ask, volume, open interest, and implied volatility where available.",
inputSchema: {
type: "object",
properties: {
symbol: {
type: "string",
description: "Stock/ETF ticker symbol (e.g., AAPL, SPY, NVDA)",
},
expiration: {
type: "string",
description:
"Optional expiration date in ISO format (YYYY-MM-DD). If omitted, returns nearest expiration.",
},
},
required: ["symbol"],
},
};