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)
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden. It discloses that it fetches data and returns a markdown table, but lacks details on permissions, rate limits, data freshness, or whether it's a read-only operation. For a data-fetching tool with zero annotation coverage, this leaves significant behavioral gaps.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is well-structured and front-loaded with the core purpose. The Args and Returns sections are clear, though the parameter documentation is incomplete. It avoids unnecessary fluff, but could be more concise by integrating parameter details more seamlessly.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given no annotations, 0% schema coverage, and no output schema, the description is incomplete. It covers the basic purpose and one parameter but misses two parameters and lacks behavioral context like error handling or data scope limitations. For a tool with three parameters and no structured support, this is insufficient.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must compensate. It documents the 'date' parameter with format and default behavior, but omits 'limit' and 'format' parameters entirely. This leaves two of three parameters undocumented, failing to provide adequate semantic context beyond the bare schema.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool fetches a list of all stocks and their trading status for a date, specifying A-shares and indices. It distinguishes from siblings like get_sz50_stocks or get_hs300_stocks by indicating it returns all stocks, not subsets. However, it doesn't explicitly contrast with get_stock_basic_info or other data-fetching tools.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives like get_stock_basic_info, get_suspensions, or other stock-related tools. It mentions the date parameter but doesn't explain scenarios where this tool is preferred over others for similar data.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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