UNPKG

@bujaayjaay/mcp-coincap-jj

Version:

A Model Context Protocol (MCP) server that provides real-time cryptocurrency data and analysis through CoinCap's API v3. Features include price tracking, market analysis, and historical trends. This is a fork of the original repo by truss44, with updates

36 lines (35 loc) 1.46 kB
import { z } from 'zod'; import { getAssets, getHistoricalData } from '../services/coincap.js'; import { formatHistoricalAnalysis } from '../services/formatters.js'; 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), }); export async function handleGetHistoricalAnalysis(args) { const { symbol, interval, days } = GetHistoricalAnalysisSchema.parse(args); const upperSymbol = symbol.toUpperCase(); const assetsData = await getAssets(); if (!assetsData) { return { content: [{ type: "text", text: "Failed to retrieve cryptocurrency data" }], }; } const asset = assetsData.data.find((a) => 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 || !historyData.data.length) { return { content: [{ type: "text", text: "Failed to retrieve historical data" }], }; } return { content: [{ type: "text", text: formatHistoricalAnalysis(asset, historyData.data) }], }; }