get_exchange_rate
Retrieve exchange rates for all currency pairs from Vietnam's stock market. Specify a date for historical data or get today's rates, with output in JSON or dataframe format.
Instructions
Get exchange rate of all currency pairs from stock market
Args:
date: str = None (if None, return today's price. Format: YYYY-MM-DD)
output_format: Literal['json', 'dataframe'] = 'json'
Returns:
pd.DataFrame
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| date | No | ||
| output_format | No | json |
Implementation Reference
- src/vnstock_mcp/server.py:650-669 (handler)The primary handler for the 'get_exchange_rate' MCP tool. It is registered via @server.tool() decorator and implements the core logic: fetches exchange rates using the external vcb_exchange_rate function for the specified date (defaults to today), and returns the result as JSON or pandas DataFrame based on the output_format parameter.@server.tool() def get_exchange_rate( date: str = None, output_format: Literal["json", "dataframe"] = "json" ): """ Get exchange rate of all currency pairs from stock market Args: date: str = None (if None, return today's price. Format: YYYY-MM-DD) output_format: Literal['json', 'dataframe'] = 'json' Returns: pd.DataFrame """ if not date: date = datetime.now().strftime("%Y-%m-%d") price = vcb_exchange_rate(date=date) if output_format == "json": return price.to_json(orient="records", force_ascii=False) else: return price
- src/vnstock_mcp/server.py:650-650 (registration)The @server.tool() decorator registers the get_exchange_rate function as an MCP tool with the FastMCP server instance.@server.tool()
- src/vnstock_mcp/server.py:651-652 (schema)The function signature defines the input schema with type hints: optional date (str), output_format as Literal['json', 'dataframe']. The docstring provides additional description for MCP tool schema.def get_exchange_rate( date: str = None, output_format: Literal["json", "dataframe"] = "json"
- src/vnstock_mcp/server.py:8-8 (helper)Import of the vcb_exchange_rate helper function from vnstock library, which is called within the tool handler to fetch the actual exchange rate data.from vnstock.explorer.misc.exchange_rate import vcb_exchange_rate