get_last_n_trading_days
Retrieve recent trading dates for A-share market analysis by specifying the number of days needed for financial calculations and reporting.
Instructions
Return the last N trading dates.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| days | No |
Implementation Reference
- src/tools/date_utils.py:61-67 (handler)MCP tool handler function for 'get_last_n_trading_days'. It wraps the core use case logic with standardized error handling via run_tool_with_handling.
@app.tool() def get_last_n_trading_days(days: int = 5) -> str: """Return the last N trading dates.""" return run_tool_with_handling( lambda: uc_date.get_last_n_trading_days(active_data_source, days=days), context=f"get_last_n_trading_days:{days}", ) - src/use_cases/date_utils.py:82-89 (helper)Core implementation that fetches recent trade dates from the financial data source and returns the last N trading days as a comma-separated string.
def get_last_n_trading_days(data_source: FinancialDataSource, *, days: int) -> str: today = datetime.now() start = (today - timedelta(days=days * 2)).strftime("%Y-%m-%d") end = today.strftime("%Y-%m-%d") df = _fetch_trading_days(data_source, start_date=start, end_date=end) trading_days = df[df["is_trading_day"] == "1"]["calendar_date"].tolist() return ", ".join(trading_days[-days:]) if trading_days else "" - mcp_server.py:56-56 (registration)Invocation of the registration function that adds the get_last_n_trading_days tool (among others) to the FastMCP app.
register_date_utils_tools(app, active_data_source)