Skip to main content
Glama
wesbos

Currency Converter MCP

by wesbos

convert_currency

Convert currency amounts between different codes using real-time exchange rates. Enter source and target currency codes with an amount to get the converted value.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
fromYesSource currency code (e.g., USD, EUR)
toYesTarget currency code (e.g., USD, EUR)
amountYesAmount to convert

Implementation Reference

  • The main handler function for convert_currency tool that fetches latest exchange rates from Frankfurter API, performs the conversion, and returns the result or error.
    export async function convertCurrency( input: ConvertCurrencyInput, ): Promise<ToolResponse> { const { from, to, amount } = input; try { const url = `${FRANKFURTER_API_BASE}/latest?base=${from.toUpperCase()}&symbols=${to.toUpperCase()}`; const response = await fetch(url); if (!response.ok) { return { content: [ { type: "text", text: `Error: Unable to fetch exchange rate. Status: ${response.status}`, }, ], }; } const data = (await response.json()) as ExchangeRateResponse; if (!data.rates || !data.rates[to.toUpperCase()]) { return { content: [ { type: "text", text: `Error: Exchange rate not available for ${from.toUpperCase()} to ${to.toUpperCase()}`, }, ], }; } const rate = data.rates[to.toUpperCase()]; const convertedAmount = Math.round(amount * rate * 100) / 100; const result: ConvertCurrencyOutput = { ...data, conversion: { from: from.toUpperCase(), to: to.toUpperCase(), amount: amount, result: convertedAmount, rate: rate, }, }; return { content: [ { type: "text", text: JSON.stringify(result), }, ], }; } catch (error) { return { content: [ { type: "text", text: `Error: Failed to convert currency - ${error instanceof Error ? error.message : "Unknown error"}`, }, ], }; } }
  • Zod schema defining the input validation for the convert_currency tool.
    export const convertCurrencySchema = { from: z .string() .length(3) .describe("Source currency code (e.g., USD, EUR)"), to: z.string().length(3).describe("Target currency code (e.g., USD, EUR)"), amount: z.number().positive().describe("Amount to convert"), };
  • src/index.ts:25-27 (registration)
    Registration of the convert_currency tool on the MCP server, linking schema and handler.
    this.server.tool("convert_currency", convertCurrencySchema, async (input) => convertCurrency(input), );

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/wesbos/currency-conversion-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server