@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
32 lines (31 loc) • 1.14 kB
JavaScript
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();
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) }],
};
}