Skip to main content
Glama
Drakoxw

MCP Server Demo

by Drakoxw

get_exchange_rate

Convert currency values by retrieving real-time exchange rates between two specified currencies, returning null if an error occurs during the process.

Instructions

Obtiene la cotización entre dos monedas. Devuelve None si hay error.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
from_currencyYes
to_currencyYes

Implementation Reference

  • server.py:25-35 (handler)
    The get_exchange_rate tool implementation - decorated with @mcp.tool() and contains the handler logic that makes an API call to exchangerate-api.com to fetch exchange rates between two currencies
    @mcp.tool()
    def get_exchange_rate(from_currency: str, to_currency: str) -> float | None:
        """Obtiene la cotización entre dos monedas. Devuelve None si hay error."""
        try:
            response = requests.get(f"https://api.exchangerate-api.com/v4/latest/{from_currency}", timeout=5)
            response.raise_for_status()
            data = response.json()
            return data.get("rates", {}).get(to_currency)
        except Exception as e:
            print(f"Error al obtener cotización: {e}")
            return None
  • server.py:1-9 (registration)
    Server setup and FastMCP initialization - creates the MCP server instance that registers the tool decorator used by get_exchange_rate
    from mcp.server.fastmcp import FastMCP
    import requests
    import os
    from dotenv import load_dotenv
    
    load_dotenv()
    
    # Create an MCP server
    mcp = FastMCP("Demo", host="0.0.0.0", port=int(os.getenv("PORT", 8000)))
Install Server

Other Tools

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/Drakoxw/mcp-server'

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