mcp-banka
Version:
Model Context Protocol Server for Turkish Currency and Exchange Rate data from the Central Bank of The Republic of Turkey (TCMB) (TCMB)
43 lines (42 loc) • 1.29 kB
JavaScript
import { TcmbApiClient } from "./api.js";
// Create API instance
const tcmbApiClient = new TcmbApiClient();
/**
* Helper function to parse date parameter
*/
export function parseDateParam(date) {
let dateObj;
if (date) {
dateObj = new Date(date);
if (isNaN(dateObj.getTime())) {
throw new Error(`Invalid date format: ${date}. Please use YYYY-MM-DD format.`);
}
}
else {
// If date not provided, use today
dateObj = new Date();
}
return dateObj;
}
/**
* Helper function to get exchange rate URL
*/
export async function getExchangeRateUrl(date) {
try {
const dateObj = parseDateParam(date);
const url = tcmbApiClient.generateUrl(dateObj);
return {
url,
source: "Central Bank of The Republic of Turkey (TCMB)",
baseCurrency: "TRY",
date: dateObj.toISOString().split('T')[0]
};
}
catch (error) {
// Handle the specific "Maximum call stack size exceeded" error
const errorMessage = error instanceof Error ? error.message : String(error);
const isStackOverflow = errorMessage.includes("Maximum call stack size exceeded");
throw new Error(errorMessage);
}
}
export { tcmbApiClient };