Skip to main content
Glama
qubaomingg

@qubaomingg/stock-mcp

get-daily-stock-data

Retrieve daily stock price data for a specified symbol, with options for recent or historical data up to 20 years.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
symbolYesStock symbol (e.g., IBM, AAPL)
outputsizeNoAmount of data to return (compact: latest 100 data points, full: up to 20 years of data)

Implementation Reference

  • The handler function that executes the tool logic for 'get-daily-stock-data' by fetching daily stock data via the getStockData helper and returning formatted text content or error.
    async ({ symbol, outputsize = 'compact' }) => { try { const data = await getStockData(symbol, 'daily', outputsize); return { content: [{ type: 'text', text: data }], }; } catch (error) { return { content: [ { type: 'text', text: `Error fetching daily stock data: ${ error instanceof Error ? error.message : String(error) }`, }, ], isError: true, }; } }, );
  • Zod input schema for the 'get-daily-stock-data' tool defining parameters symbol (required string) and outputsize (optional enum: compact or full).
    symbol: z.string().describe('Stock symbol (e.g., IBM, AAPL)'), outputsize: z .enum(['compact', 'full']) .optional() .describe( 'Amount of data to return (compact: latest 100 data points, full: up to 20 years of data)', ), },
  • src/index.ts:119-150 (registration)
    Registration of the 'get-daily-stock-data' MCP tool using server.tool, including schema and inline handler.
    server.tool( 'get-daily-stock-data', { symbol: z.string().describe('Stock symbol (e.g., IBM, AAPL)'), outputsize: z .enum(['compact', 'full']) .optional() .describe( 'Amount of data to return (compact: latest 100 data points, full: up to 20 years of data)', ), }, async ({ symbol, outputsize = 'compact' }) => { try { const data = await getStockData(symbol, 'daily', outputsize); return { content: [{ type: 'text', text: data }], }; } catch (error) { return { content: [ { type: 'text', text: `Error fetching daily stock data: ${ error instanceof Error ? error.message : String(error) }`, }, ], isError: true, }; } }, );
  • Supporting getStockData function that implements the API call to Alpha Vantage, specifically handling 'daily' interval for TIME_SERIES_DAILY endpoint, formatting the response.
    export async function getStockData(symbol: string | string[], interval: string | string[] | 'daily', outputsize: string = 'compact'): Promise<string> { try { // Ensure parameters are strings, not arrays const symbolStr = Array.isArray(symbol) ? symbol[0] : symbol; const intervalStr = Array.isArray(interval) ? interval[0] : interval; const outputsizeStr = Array.isArray(outputsize) ? outputsize[0] : outputsize; let url: string; let timeSeriesKey: string; if (intervalStr === 'daily') { // Use TIME_SERIES_DAILY endpoint url = `${BASE_URL}?function=TIME_SERIES_DAILY&symbol=${symbolStr}&outputsize=${outputsizeStr}&apikey=${API_KEY}`; timeSeriesKey = 'Time Series (Daily)'; } else { // Use TIME_SERIES_INTRADAY endpoint url = `${BASE_URL}?function=TIME_SERIES_INTRADAY&symbol=${symbolStr}&interval=${intervalStr}&outputsize=${outputsizeStr}&apikey=${API_KEY}`; timeSeriesKey = `Time Series (${intervalStr})`; } const response = await axios.get(url); // Check for error messages from Alpha Vantage if (response.data['Error Message']) { throw new Error(response.data['Error Message']); } if (response.data['Note']) { console.warn('API Usage Note:', response.data['Note']); } // Extract the time series data const timeSeries = response.data[timeSeriesKey]; if (!timeSeries) { throw new Error('No time series data found in the response'); } // Format the data const formattedData = formatTimeSeriesData(timeSeries, symbolStr, intervalStr); return formattedData; } catch (error) { if (axios.isAxiosError(error)) { throw new Error(`API request failed: ${error.message}`); } throw error; } }

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/qubaomingg/stock-analysis-mcp'

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