Skip to main content
Glama
24mlight

A-Share MCP Server

get_all_stock

Fetch A-share stocks and indices with trading status for a specific date. Returns a table showing which stocks are trading or suspended.

Instructions

Fetch a list of all stocks (A-shares and indices) and their trading status for a date. Args: date: Optional. The date in 'YYYY-MM-DD' format. If None, uses the current date. Returns: Markdown table listing stock codes and trading status (1=trading, 0=suspended).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
dateNo
limitNo
formatNomarkdown

Implementation Reference

  • Primary handler and registration for the MCP 'get_all_stock' tool. Decorated with @app.tool(), it processes inputs, logs the call, and delegates execution to the fetch_all_stock use case via run_tool_with_handling.
    @app.tool() def get_all_stock(date: Optional[str] = None, limit: int = 250, format: str = "markdown") -> str: """ Fetch a list of all stocks (A-shares and indices) and their trading status for a date. Args: date: Optional. The date in 'YYYY-MM-DD' format. If None, uses the current date. Returns: Markdown table listing stock codes and trading status (1=trading, 0=suspended). """ logger.info(f"Tool 'get_all_stock' called for date={date or 'default'}") return run_tool_with_handling( lambda: fetch_all_stock(active_data_source, date=date, limit=limit, format=format), context=f"get_all_stock:{date or 'default'}", )
  • Helper function that invokes the data source's get_all_stock method, validates format, and formats the resulting DataFrame as markdown/json/csv table.
    def fetch_all_stock(data_source: FinancialDataSource, *, date: Optional[str], limit: int, format: str) -> str: validate_output_format(format) df = data_source.get_all_stock(date=date) meta = {"as_of": date or "default"} return format_table_output(df, format=format, max_rows=limit, meta=meta)
  • Core data fetching implementation in BaostockDataSource class. Calls Baostock's query_all_stock API, handles errors, and constructs pandas DataFrame from results.
    def get_all_stock(self, date: Optional[str] = None) -> pd.DataFrame: """Fetches all stock list for a given date using Baostock.""" logger.info(f"Fetching all stock list for date={date or 'default'}") try: with baostock_login_context(): rs = bs.query_all_stock(day=date) if rs.error_code != '0': logger.error( f"Baostock API error (All Stock) for date {date}: {rs.error_msg} (code: {rs.error_code})") if "no record found" in rs.error_msg.lower() or rs.error_code == '10002': # Check if this applies raise NoDataFoundError( f"No stock data found for date {date}. Baostock msg: {rs.error_msg}") else: raise DataSourceError( f"Baostock API error fetching all stock list: {rs.error_msg} (code: {rs.error_code})") data_list = [] while rs.next(): data_list.append(rs.get_row_data()) if not data_list: logger.warning( f"No stock list returned for date {date} (empty result set).") raise NoDataFoundError( f"No stock list found for date {date} (empty result set).") result_df = pd.DataFrame(data_list, columns=rs.fields) logger.info( f"Retrieved {len(result_df)} stock records for date {date or 'default'}.") return result_df except (LoginError, NoDataFoundError, DataSourceError, ValueError) as e: logger.warning( f"Caught known error fetching all stock list for date {date}: {type(e).__name__}") raise e except Exception as e: logger.exception( f"Unexpected error fetching all stock list for date {date}: {e}") raise DataSourceError( f"Unexpected error fetching all stock list for date {date}: {e}")
  • Abstract method definition in FinancialDataSource interface, specifying the expected signature and purpose for concrete implementations.
    @abstractmethod def get_all_stock(self, date: Optional[str] = None) -> pd.DataFrame: """Fetches list of all stocks and their trading status on a given date.""" pass
  • mcp_server.py:54-54 (registration)
    Invocation of the registration function for market overview tools, including get_all_stock, in the main MCP server setup.
    register_market_overview_tools(app, active_data_source)

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