@sanlim/mempool-mcp-server
Version:
A sample of MCP implementation using DDD structure with some APIs call.
35 lines (34 loc) • 1.52 kB
JavaScript
import { z } from "zod";
import { BaseToolsController } from "./base/BaseToolsController.js";
export class GeneralToolsController extends BaseToolsController {
generalService;
constructor(server, generalService) {
super(server);
this.generalService = generalService;
}
registerTools() {
this.registerGetDifficultyAdjustmentHandler();
this.registerGetPriceHandler();
this.registerGetHistoricalPriceHandler();
}
registerGetDifficultyAdjustmentHandler() {
this.server.tool("get-difficulty-adjustment", "Returns current and next Bitcoin difficulty adjustment info", async () => {
const text = await this.generalService.getDifficultyAdjustment();
return { content: [{ type: "text", text }] };
});
}
registerGetPriceHandler() {
this.server.tool("get-price", "Returns the current BTC price in various fiat currencies", async () => {
const text = await this.generalService.getPrice();
return { content: [{ type: "text", text }] };
});
}
registerGetHistoricalPriceHandler() {
this.server.tool("get-historical-price", "Returns the BTC price for a specific date (YYYY-MM-DD)", {
date: z.string().regex(/^\d{4}-\d{2}-\d{2}$/).describe("The date in YYYY-MM-DD format")
}, async ({ date }) => {
const text = await this.generalService.getHistoricalPrice(date);
return { content: [{ type: "text", text }] };
});
}
}