UNPKG

mcp-server-ddd-sample

Version:

A sample of MCP implementation using DDD structure with some APIs call.

38 lines (37 loc) 1.29 kB
export class BitcoinService { apiService; constructor(apiService) { this.apiService = apiService; } async getPrices() { const pricesPossible = ["USD", "EUR", "GBP", "CAD", "CHF", "AUD", "JPY"]; const pricesData = await this.apiService.getPrices(); if (!pricesData) { return "Failed to retrieve prices data"; } let msg = ""; pricesPossible.forEach((element) => { if (!pricesData[element]) { msg += `Price in ${element} is not available.\n`; } else { msg += `price in ${element}: ${pricesData?.[element] || "N/A"}\n`; } }); msg += `Time: ${pricesData.time ? new Date(pricesData.time * 1000).toLocaleString() : "N/A"}`; return msg.trim(); } async getDifficultyAdjustment() { const difficultyData = await this.apiService.getDifficultyAdjustment(); if (!difficultyData) { return "Failed to retrieve difficulty data"; } let msg = "Bitcoin Difficulty Adjustment:\n"; for (const [key, value] of Object.entries(difficultyData)) { msg += `${key}: ${value ?? "N/A"}\n`; } return msg.trim(); } }