get_gold_price
Retrieve current or historical gold prices from Vietnam's stock market sources like SJC or BTMC in JSON or dataframe format.
Instructions
Get gold price from stock market
Args:
date: str = None (if None, return today's price. Format: YYYY-MM-DD)
source: Literal['SJC', 'BTMC'] = 'SJC' (source to get gold price)
output_format: Literal['json', 'dataframe'] = 'json'
Returns:
pd.DataFrameInput Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| date | No | ||
| source | No | SJC | |
| output_format | No | json |
Implementation Reference
- src/vnstock_mcp/server.py:621-648 (handler)The primary handler implementation for the 'get_gold_price' MCP tool. It is registered via the @server.tool() decorator, defines the input schema via type annotations and defaults, and executes the logic by calling underlying vnstock functions (sjc_gold_price or btmc_goldprice) based on parameters, formatting output as JSON or pandas DataFrame.
@server.tool() def get_gold_price( date: str = None, source: Literal["SJC", "BTMC"] = "SJC", output_format: Literal["json", "dataframe"] = "json", ): # pyright: ignore[reportUndefinedVariable] # noqa: F821 """ Get gold price from stock market Args: date: str = None (if None, return today's price. Format: YYYY-MM-DD) source: Literal['SJC', 'BTMC'] = 'SJC' (source to get gold price) output_format: Literal['json', 'dataframe'] = 'json' Returns: pd.DataFrame """ if date: price = sjc_gold_price(date=date) if output_format == "json": return price.to_json(orient="records", force_ascii=False) else: return price else: price = sjc_gold_price() if source == "SJC" else btmc_goldprice() if output_format == "json": return price.to_json(orient="records", force_ascii=False) else: return price