UNPKG

mcp-crypto-price

Version:

A Model Context Protocol (MCP) server that provides real-time cryptocurrency data and analysis through CoinCap's API. Features include price tracking, market analysis, and historical trends.

42 lines (41 loc) 1.48 kB
import { z } from 'zod'; import { getAssets, getMarkets } from '../services/coincap.js'; import { formatMarketAnalysis } from '../services/formatters.js'; export const GetMarketAnalysisSchema = z.object({ symbol: z.string().min(1), }); export async function handleGetMarketAnalysis(args) { const { symbol } = GetMarketAnalysisSchema.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) => a.symbol.toUpperCase() === upperSymbol); if (!asset) { return { content: [{ type: "text", text: `Could not find cryptocurrency with symbol ${upperSymbol}` }], }; } const marketsData = await getMarkets(asset.id); if (!marketsData) { return { content: [{ type: "text", text: "Failed to retrieve market data" }], }; } return { content: [{ type: "text", text: formatMarketAnalysis(asset, marketsData.data) }], }; } catch (error) { return { content: [{ type: "text", text: error instanceof Error ? error.message : `Failed to retrieve data: ${String(error)}` }], }; } }