fidelity_get_quote
Get the current price for a stock or ETF symbol through Fidelity. Provide a ticker (e.g., AAPL) to receive the quote for investment decisions.
Instructions
Get the current price for a stock/ETF symbol via Fidelity's trade page.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| symbol | Yes | The stock/ETF ticker symbol (e.g., AAPL, SPY). |
Implementation Reference
- src/index.ts:201-230 (registration)Registration of the 'fidelity_get_quote' tool on the MCP server with Zod schema for the symbol parameter and inline handler that calls getQuote().
// ─── Get Quote ────────────────────────────────────────────────────────────────── server.tool( "fidelity_get_quote", "Get the current price for a stock/ETF symbol via Fidelity's trade page.", { symbol: z.string().describe("The stock/ETF ticker symbol (e.g., AAPL, SPY)."), }, async ({ symbol }) => { try { const quote = await getQuote(symbol); return { content: [ { type: "text", text: JSON.stringify(quote, null, 2), }, ], }; } catch (e) { return { content: [ { type: "text", text: `Failed to get quote: ${e instanceof Error ? e.message : String(e)}`, }, ], isError: true, }; } - src/trading.ts:129-151 (handler)Core handler function getQuote() that navigates to Fidelity's trade page, enters the symbol, reads the last price, and optionally fetches extended hours price.
export async function getQuote(symbol: string): Promise<QuoteResult> { await navigateToTrade(); await enterSymbol(symbol); const { price, isExtendedHours } = await getLastPrice(); const result: QuoteResult = { symbol: symbol.toUpperCase(), lastPrice: price, isExtendedHours, }; // Try to get extended hours price if (!isExtendedHours) { const enabled = await enableExtendedHours(); if (enabled) { const extPrice = await getLastPrice(); result.extendedHoursPrice = extPrice.price; } } return result; } - src/types.ts:53-58 (schema)Type definition for QuoteResult, the return type of the getQuote handler.
export interface QuoteResult { symbol: string; lastPrice: number; extendedHoursPrice?: number; isExtendedHours: boolean; } - src/trading.ts:41-55 (helper)Helper function enterSymbol() that fills the symbol input and waits for the quote panel to load.
async function enterSymbol(symbol: string): Promise<void> { const page = await getPage(); const symbolInput = page.getByLabel("Symbol", { exact: true }); await symbolInput.fill(symbol); await symbolInput.press("Enter"); // Wait for quote to load await page.waitForSelector("#quote-panel", { timeout: 15000 }); await waitForLoadingComplete(page); // Dismiss any autocomplete dropdown by clicking outside the symbol input await page.locator("#quote-panel").click(); await page.waitForTimeout(500); } - src/trading.ts:57-91 (helper)Helper function getLastPrice() that reads the stock price from the DOM and checks if extended hours trading is active.
async function getLastPrice(): Promise<{ price: number; isExtendedHours: boolean; }> { const page = await getPage(); const priceSpan = page.locator("#eq-ticket__last-price > span.last-price"); const priceText = await priceSpan.textContent({ timeout: 10000 }); if (!priceText) { throw new Error("Could not read stock price."); } const price = parseFloat(priceText.replace(/[$,]/g, "")); if (isNaN(price)) { throw new Error(`Invalid price: ${priceText}`); } // Check extended hours let isExtendedHours = false; try { const extToggle = page.locator("#eq-ticket_extendedhour"); if (await extToggle.isVisible({ timeout: 2000 })) { const toggleWrapper = page.locator(".eq-ticket__extendedhour-toggle"); const classes = (await toggleWrapper.getAttribute("class")) ?? ""; if (classes.includes("pvd-switch--on")) { isExtendedHours = true; } } } catch { // Not in extended hours } return { price, isExtendedHours }; }