Skip to main content
Glama
sin4ch

Exchange Rate MCP Server

by sin4ch

convert_currency

Convert currency amounts between different currencies using current exchange rates. Input amount, base currency, and target currency to get the converted value.

Instructions

Convert an amount from one currency to another using current exchange rates.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
amountYes
base_currYes
target_currYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • main.py:15-47 (handler)
    The handler function for the 'convert_currency' tool. It uses the Exchange Rate API to convert an amount from base_curr to target_curr, handles various API errors, and formats the result with the exchange rate.
    @mcp.tool
    async def convert_currency(amount: float, base_curr: str, target_curr: str) -> str:
        """Convert an amount from one currency to another using current exchange rates."""
    
        try:
            async with httpx.AsyncClient() as client:
                response = await client.get(f"https://v6.exchangerate-api.com/v6/{EXCHANGE_RATE_API_KEY}/pair/{base_curr.upper()}/{target_curr.upper()}/{amount}")
                response.raise_for_status()
                data = response.json()
    
                if data.get("result") == "error":
                    error_type = data.get("error-type", "unknown")
                    if error_type == "unknown-code":
                        raise Exception(f"Unknown currency code: {base_curr} or {target_curr}")
                    elif error_type == "malformed-request":
                        raise Exception("Invalid request format")
                    elif error_type == "invalid-key":
                        raise Exception("Invalid API key")
                    elif error_type == "inactive-account":
                        raise Exception("API account inactive")
                    elif error_type == "quota-reached":
                        raise Exception("API quota exceeded")
                    else:
                        raise Exception(f"API error: {error_type}")
            
                return f"{amount} {base_curr.upper()} = {data.get('conversion_result'):.2f} {target_curr.upper()} (Rate: {data.get('conversion_rate')})"
            
        except httpx.HTTPStatusError as e:
            raise Exception(f"HTTP error occurred: {e.response.status_code} - {e.response.text}")
        except httpx.RequestError as e:
            raise Exception(f"Request error occurred: {str(e)}")
        except Exception as e:
            raise Exception(f"Unexpected error occurred: {str(e)}")
  • main.py:15-15 (registration)
    The @mcp.tool decorator registers the convert_currency function as an MCP tool.
    @mcp.tool
  • main.py:16-17 (schema)
    Input schema defined by type annotations: amount (float), base_curr (str), target_curr (str). Output: str. Docstring provides tool description.
    async def convert_currency(amount: float, base_curr: str, target_curr: str) -> str:
        """Convert an amount from one currency to another using current exchange rates."""
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions 'using current exchange rates,' which hints at real-time data, but fails to specify source reliability, rate limits, error handling, or whether the operation is read-only or has side effects.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, clear sentence with no wasted words. It is appropriately sized and front-loaded, efficiently conveying the core function without unnecessary elaboration.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's moderate complexity (3 parameters, no annotations, but with an output schema), the description is minimally adequate. The output schema likely covers return values, but the description lacks details on exchange rate sources, accuracy, or operational constraints.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must compensate. It implies parameters for amount and currencies but does not detail their semantics (e.g., currency codes, numeric formats). The description adds minimal value beyond the schema's structural definition.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: converting an amount between currencies using current exchange rates. It specifies the verb ('convert') and resource ('currency'), making the function unambiguous. However, with no sibling tools, it cannot demonstrate differentiation from alternatives.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives, prerequisites, or constraints. It simply states what the tool does without context about timing, limitations, or comparison to other methods.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

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/sin4ch/exchange-rate-mcp'

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