Skip to main content
Glama

get_rate

Retrieve the official Bank of Russia exchange rate for a specified currency, optionally on a given date. Returns nominal, per-unit rate, and value.

Instructions

Get the official Bank of Russia exchange rate for a single currency on a given date (or the latest published date if 'on_date' is omitted). Returns nominal, value, per-unit rate and effective quote date.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
char_codeYes
on_dateNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
char_codeYesISO-letter code, e.g. 'USD'.
num_codeYesNumeric ISO 4217 code as string, e.g. '840'.
nameYesRussian-language currency name from CBR.
nominalYesNumber of foreign units the rate is given for.
valueYesRate of <nominal> units in RUB.
vunit_rateYesRate per single unit (value / nominal).
dateYesEffective quote date as published by CBR.
sourceNoЦентральный банк РФ

Implementation Reference

  • The core handler function for the get_rate tool. Fetches a single currency rate from CBR (with caching), parses the response, and returns a CurrencyRate model.
    async def get_rate(
        ctx: ToolContext,
        char_code: str,
        on_date: date | str | None = None,
    ) -> CurrencyRate:
        """Fetch the CBR quote for a single currency on the given (or latest) date."""
        canonical = normalize_char_code(char_code)
        target_date = _coerce_date(on_date)
        cache_key = f"daily:{canonical}:{target_date.isoformat() if target_date else 'latest'}"
    
        cached = await ctx.daily_cache.get(cache_key)
        if cached is not None:
            return cached  # type: ignore[no-any-return]
    
        raw = await ctx.client.fetch_currency_rate(canonical, on_date=target_date)
        nominal = int(raw.get("nominal") or 1)
        value = _decimal(raw["value"])
        vunit_text = raw.get("vunit_rate") or ""
        if vunit_text:
            vunit = _decimal(vunit_text)
        else:
            vunit = (value / nominal) if nominal else value
    
        quote_date = (
            date.fromisoformat(_iso_from_dotted(raw["date"]))
            if raw.get("date")
            else (target_date or date.today())
        )
        rate = CurrencyRate(
            char_code=canonical,
            num_code=raw.get("num_code", ""),
            name=raw.get("name", ""),
            nominal=nominal,
            value=value,
            vunit_rate=vunit,
            date=quote_date,
        )
        await ctx.daily_cache.set(cache_key, rate, ttl=DEFAULT_DAILY_TTL)
        return rate
  • Registration of the get_rate MCP tool via FastMCP @mcp.tool decorator. Maps the MCP tool name 'get_rate' to the handler function tool_get_rate, which delegates to _get_rate (the tools.get_rate implementation).
    @mcp.tool(
        name="get_rate",
        description=(
            "Get the official Bank of Russia exchange rate for a single currency"
            " on a given date (or the latest published date if 'on_date' is omitted)."
            " Returns nominal, value, per-unit rate and effective quote date."
        ),
    )
    async def tool_get_rate(
        ctx: Context,
        char_code: str,
        on_date: date | None = None,
    ) -> CurrencyRate:
        try:
            return await _get_rate(_ctx(ctx), char_code=char_code, on_date=on_date)
        except CbrError as exc:
            raise RuntimeError(_format_error(exc)) from exc
  • Helper function _coerce_date used by get_rate to accept date or ISO string input for the on_date parameter.
    def _coerce_date(value: date | str | None) -> date | None:
        """Accept either a ``date`` or an ISO ``YYYY-MM-DD`` string."""
        if value is None or isinstance(value, date):
            return value
        if isinstance(value, str):
            try:
                return date.fromisoformat(value)
            except ValueError as exc:
                raise CbrValidationError(f"invalid ISO date: {value!r}") from exc
        raise CbrValidationError(f"unsupported date value: {value!r}")
    
    
    def _decimal(text: str) -> Decimal:
        return Decimal(text.replace(",", ".").strip())
  • Helper function normalize_char_code from currency_codes.py — used to validate and canonicalize currency code input.
                raise CbrValidationError(f"invalid ISO date: {value!r}") from exc
        raise CbrValidationError(f"unsupported date value: {value!r}")
    
    
    def _decimal(text: str) -> Decimal:
        return Decimal(text.replace(",", ".").strip())
    
    
    async def get_rate(
        ctx: ToolContext,
        char_code: str,
        on_date: date | str | None = None,
    ) -> CurrencyRate:
  • The CurrencyRate Pydantic model returned by get_rate, defining fields like char_code, num_code, name, nominal, value, vunit_rate, and date.
    class CurrencyRate(CbrModel):
        """A single currency quote at a given date."""
    
        char_code: str = Field(..., description="ISO-letter code, e.g. 'USD'.")
        num_code: str = Field(..., description="Numeric ISO 4217 code as string, e.g. '840'.")
        name: str = Field(..., description="Russian-language currency name from CBR.")
        nominal: int = Field(..., ge=1, description="Number of foreign units the rate is given for.")
        value: Decimal = Field(..., description="Rate of <nominal> units in RUB.")
        vunit_rate: Decimal = Field(..., description="Rate per single unit (value / nominal).")
        date: _dt.date = Field(..., description="Effective quote date as published by CBR.")
        source: str = DEFAULT_SOURCE
Behavior3/5

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

No annotations provided, so the description carries the behavioral burden. It indicates a read operation and lists returned fields, but does not disclose authentication needs, rate limits, error handling, or side effects. Adequate but minimal.

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, well-structured sentence that conveys purpose, parameter usage, and return value in a compact form. No unnecessary words.

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

Completeness4/5

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

The tool has an output schema, so return details are covered externally. The description provides essential context for a simple read operation. Slight deduction for not mentioning any constraints or error conditions.

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

Parameters4/5

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

The input schema has 0% coverage (no descriptions for parameters). The description adds meaning: char_code is implied as the currency code, and on_date is explained as an optional date with fallback behavior. This compensates well for the schema gap.

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

Purpose5/5

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

The description clearly states the tool retrieves the official Bank of Russia exchange rate for a single currency on a given date, with fallback to latest date. It specifies returned fields (nominal, value, per-unit rate, effective quote date). Although sibling tools are present, the description is specific enough to distinguish usage.

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

Usage Guidelines3/5

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

The description explains when to use the tool (single currency, optional date) but does not provide explicit guidance on when not to use it or compare to sibling tools like history_rates or key_rate. Usage is implied but lacks alternatives or exclusion criteria.

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/atomno-labs/mcp-cbr-rates'

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