finance_stock_price
Retrieve current stock prices for any ticker symbol using a public API. Enter a symbol like AAPL or MSFT to get real-time market data.
Instructions
Get current stock price from public API
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| symbol | Yes | Stock ticker symbol (e.g. AAPL, MSFT, GOOGL) |
Implementation Reference
- src/modules/finance.ts:8-19 (handler)The handler implementation for finance_stock_price tool, which fetches data from the Yahoo Finance API.
server.tool("finance_stock_price", "Get current stock price from public API", { symbol: z.string().describe("Stock ticker symbol (e.g. AAPL, MSFT, GOOGL)") }, async ({ symbol }) => { try { const data = await safeFetch(`https://query1.finance.yahoo.com/v8/finance/chart/${symbol.toUpperCase()}?range=1d&interval=1m`); const meta = data.chart.result[0].meta; const change = ((meta.regularMarketPrice - meta.previousClose) / meta.previousClose) * 100; return { content: [{ type: "text", text: `**${symbol.toUpperCase()}**\nPrice: ${formatCurrency(meta.regularMarketPrice)}\nPrev Close: ${formatCurrency(meta.previousClose)}\nChange: ${formatPercent(change)}\nVolume: ${meta.regularMarketVolume?.toLocaleString() || "N/A"}\nExchange: ${meta.exchangeName}` }] }; } catch { return { content: [{ type: "text", text: `Could not fetch ${symbol}. Try common tickers: AAPL, MSFT, GOOGL, AMZN, TSLA, NVDA` }] }; } });