Skip to main content
Glama
24mlight

A Share MCP

get_trade_dates

Retrieve trading date information for A-share markets within a specified date range. Returns a clear markdown table indicating trading days (1) or non-trading days (0).

Instructions

Fetches trading dates information within a specified range. Args: start_date: Optional. Start date in 'YYYY-MM-DD' format. Defaults to 2015-01-01 if None. end_date: Optional. End date in 'YYYY-MM-DD' format. Defaults to the current date if None. Returns: Markdown table indicating whether each date in the range was a trading day (1) or not (0).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
end_dateNo
start_dateNo

Implementation Reference

  • The core handler function for the 'get_trade_dates' MCP tool. It fetches trading dates from the active data source, handles errors, and formats the output as markdown or other formats.
    @app.tool() def get_trade_dates(start_date: Optional[str] = None, end_date: Optional[str] = None, limit: int = 250, format: str = "markdown") -> str: """ Fetch trading dates within a specified range. Args: start_date: Optional. Start date in 'YYYY-MM-DD' format. Defaults to 2015-01-01 if None. end_date: Optional. End date in 'YYYY-MM-DD' format. Defaults to the current date if None. Returns: Markdown table with 'is_trading_day' (1=trading, 0=non-trading). """ logger.info( f"Tool 'get_trade_dates' called for range {start_date or 'default'} to {end_date or 'default'}") try: # Add date validation if desired df = active_data_source.get_trade_dates( start_date=start_date, end_date=end_date) logger.info("Successfully retrieved trade dates.") meta = {"start_date": start_date or "default", "end_date": end_date or "default"} return format_table_output(df, format=format, max_rows=limit, meta=meta) except NoDataFoundError as e: logger.warning(f"NoDataFoundError: {e}") return f"Error: {e}" except LoginError as e: logger.error(f"LoginError: {e}") return f"Error: Could not connect to data source. {e}" except DataSourceError as e: logger.error(f"DataSourceError: {e}") return f"Error: An error occurred while fetching data. {e}" except ValueError as e: logger.warning(f"ValueError: {e}") return f"Error: Invalid input parameter. {e}" except Exception as e: logger.exception( f"Unexpected Exception processing get_trade_dates: {e}") return f"Error: An unexpected error occurred: {e}"
  • mcp_server.py:54-54 (registration)
    Top-level registration call that registers the market_overview tools, including 'get_trade_dates', to the FastMCP app instance.
    register_market_overview_tools(app, active_data_source)
  • Function that defines and registers the market overview tools (including get_trade_dates) by nesting the @app.tool() decorated functions inside it.
    def register_market_overview_tools(app: FastMCP, active_data_source: FinancialDataSource): """ Register market overview tools with the MCP app. Args: app: The FastMCP app instance active_data_source: The active financial data source """
  • Implementation of get_trade_dates in the BaostockDataSource class, which queries the Baostock API for trading dates and is called by the tool handler.
    def get_trade_dates(self, start_date: Optional[str] = None, end_date: Optional[str] = None) -> pd.DataFrame: """Fetches trading dates using Baostock.""" logger.info( f"Fetching trade dates from {start_date or 'default'} to {end_date or 'default'}") try: with baostock_login_context(): # Login might not be strictly needed for this, but keeping consistent rs = bs.query_trade_dates( start_date=start_date, end_date=end_date) if rs.error_code != '0': logger.error( f"Baostock API error (Trade Dates): {rs.error_msg} (code: {rs.error_code})") # Unlikely to have 'no record found' for dates, but handle API errors raise DataSourceError( f"Baostock API error fetching trade dates: {rs.error_msg} (code: {rs.error_code})") data_list = [] while rs.next(): data_list.append(rs.get_row_data()) if not data_list: # This case should ideally not happen if the API returns a valid range logger.warning( f"No trade dates returned for range {start_date}-{end_date} (empty result set).") raise NoDataFoundError( f"No trade dates found for range {start_date}-{end_date} (empty result set).") result_df = pd.DataFrame(data_list, columns=rs.fields) logger.info(f"Retrieved {len(result_df)} trade date records.") return result_df except (LoginError, NoDataFoundError, DataSourceError, ValueError) as e: logger.warning( f"Caught known error fetching trade dates: {type(e).__name__}") raise e except Exception as e: logger.exception(f"Unexpected error fetching trade dates: {e}") raise DataSourceError( f"Unexpected error fetching trade dates: {e}")
  • Function signature with type hints and docstring defining the input schema and output description for the MCP tool.
    def get_trade_dates(start_date: Optional[str] = None, end_date: Optional[str] = None, limit: int = 250, format: str = "markdown") -> str: """ Fetch trading dates within a specified range. Args: start_date: Optional. Start date in 'YYYY-MM-DD' format. Defaults to 2015-01-01 if None. end_date: Optional. End date in 'YYYY-MM-DD' format. Defaults to the current date if None. Returns: Markdown table with 'is_trading_day' (1=trading, 0=non-trading). """

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/24mlight/a_share_mcp_is_just_I_need'

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