Skip to main content
Glama
guilhermelirio

Brasil API MCP

cambio-currencies-list

Retrieve available currencies for exchange rate queries from Brazilian public data services.

Instructions

List all available currencies for exchange rates

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • 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}` 
          }]
        };
      }
    );
  • Input schema: empty object `{}`, no parameters required.
    {},
  • 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);
  • 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
        };
      }
    }

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/guilhermelirio/brasil-api-mcp'

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