get-historical-analysis
Analyze historical cryptocurrency prices by specifying a symbol, time interval, and days. Use this tool to track market trends and make informed decisions with customizable timeframe data.
Instructions
Get historical price analysis with customizable timeframe
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| days | No | Number of days to analyze (1-30) | |
| interval | No | Time interval (m5, m15, m30, h1, h2, h6, h12, d1) | h1 |
| symbol | Yes | Cryptocurrency symbol (e.g., BTC, ETH) |
Implementation Reference
- src/tools/historical.ts:11-61 (handler)The handler function that implements the logic for get-historical-analysis tool: parses args, fetches asset and historical data from CoinCap, formats and returns analysis.
export async function handleGetHistoricalAnalysis(args: unknown) { const { symbol, interval, days } = GetHistoricalAnalysisSchema.parse(args); const upperSymbol = symbol.toUpperCase(); try { const assetsData = await getAssets(); if (!assetsData) { return { content: [{ type: "text", text: "Failed to retrieve cryptocurrency data" }], }; } const asset = assetsData.data.find( (a: { symbol: string; }) => a.symbol.toUpperCase() === upperSymbol ); if (!asset) { return { content: [{ type: "text", text: `Could not find cryptocurrency with symbol ${upperSymbol}` }], }; } const end = Date.now(); const start = end - (days * 24 * 60 * 60 * 1000); const historyData = await getHistoricalData(asset.id, interval, start, end); if (!historyData) { return { content: [{ type: "text", text: "Failed to retrieve historical data" }], }; } if (!historyData.data.length) { return { content: [{ type: "text", text: "No historical data available for the selected time period" }], }; } return { content: [{ type: "text", text: formatHistoricalAnalysis(asset, historyData.data) }], }; } catch (error) { return { content: [{ type: "text", text: error instanceof Error ? error.message : `Failed to retrieve historical data: ${String(error)}` }], }; } } - src/tools/historical.ts:5-9 (schema)Input schema using Zod for validating symbol, interval, and days parameters for the get-historical-analysis tool.
export const GetHistoricalAnalysisSchema = z.object({ symbol: z.string().min(1), interval: z.enum(['m5', 'm15', 'm30', 'h1', 'h2', 'h6', 'h12', 'd1']).default('h1'), days: z.number().min(1).max(30).default(7), }); - src/index.ts:65-77 (registration)Registers the 'get-historical-analysis' tool with the MCP server, specifying title, description, input schema, and handler function.
server.registerTool( "get-historical-analysis", { title: "Get Historical Analysis", description: "Get historical price analysis with customizable timeframe", inputSchema: GetHistoricalAnalysisSchema.shape, }, async (args, _extra) => { const result = await handleGetHistoricalAnalysis(args); return result as any; } );