cambio-currencies-list
Retrieve available currencies for exchange rate queries from Brazilian public data services.
Instructions
List all available currencies for exchange rates
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "cambio-currencies-list"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/tools/cambio/index.ts:15-37 (handler)Implements the core logic of the 'cambio-currencies-list' tool: fetches currency list from Brasil API endpoint `/cambio/v1/moedas`, handles errors, formats the currencies into a newline-separated list, and returns a structured text response.
async () => { console.error("Listing all available currencies"); const result = await getBrasilApiData(`/cambio/v1/moedas`); if (!result.success) { return formatErrorResponse(`Error listing currencies: ${result.message}`); } // Format the response data const currencies = result.data; const formattedCurrencies = currencies.map((currency: any) => `${currency.simbolo} - ${currency.nome} (Type: ${currency.tipo_moeda})` ).join("\n"); return { content: [{ type: "text" as const, text: `Available Currencies:\n${formattedCurrencies}` }] }; } ); - src/tools/cambio/index.ts:14-14 (schema)Input schema: empty object `{}`, no parameters required.
{}, - src/tools/cambio/index.ts:11-14 (registration)Direct registration of the 'cambio-currencies-list' tool using `server.tool()` with name, description, and input schema.
server.tool( "cambio-currencies-list", "List all available currencies for exchange rates", {}, - src/index.ts:30-30 (registration)Top-level invocation of `registerCambioTools(server)` in the main MCP server setup, which registers the cambio tools including 'cambio-currencies-list'.
registerCambioTools(server); - src/utils/api.ts:11-40 (helper)Shared `getBrasilApiData` helper function called within the handler to perform HTTP GET requests to the Brasil API and handle responses/errors.
export async function getBrasilApiData(endpoint: string, params: Record<string, any> = {}) { try { const url = `${BASE_URL}${endpoint}`; console.error(`Making request to: ${url}`); const response = await axios.get(url, { params }); return { data: response.data, success: true }; } catch (error: any) { console.error(`Error in API request: ${error.message}`); // Handle API errors in a structured format if (error.response) { return { success: false, statusCode: error.response.status, message: error.response.data?.message || error.message, error: error.response.data }; } return { success: false, message: error.message, error }; } }