Skip to main content
Glama
24mlight

A-Share MCP Server

get_stock_industry

Retrieve industry classification data for specific stocks or all A-share stocks on a given date to analyze market sectors and company categorization.

Instructions

Get industry classification for a specific stock or all stocks on a date.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
codeNo
dateNo
limitNo
formatNomarkdown

Implementation Reference

  • The MCP tool handler for get_stock_industry, decorated with @app.tool(). Logs the invocation and delegates execution to the use case layer via run_tool_with_handling.
    @app.tool()
    def get_stock_industry(code: Optional[str] = None, date: Optional[str] = None, limit: int = 250, format: str = "markdown") -> str:
        """Get industry classification for a specific stock or all stocks on a date."""
        logger.info(f"Tool 'get_stock_industry' called for code={code or 'all'}, date={date or 'latest'}")
        return run_tool_with_handling(
            lambda: fetch_stock_industry(active_data_source, code=code, date=date, limit=limit, format=format),
            context=f"get_stock_industry:{code or 'all'}",
        )
  • mcp_server.py:53-53 (registration)
    Top-level registration call to register_index_tools, which includes the @app.tool() decorator for get_stock_industry.
    register_index_tools(app, active_data_source)
  • Use case helper function that validates input, fetches raw data from the data source interface, and formats the output as a markdown table.
    def fetch_stock_industry(data_source: FinancialDataSource, *, code: Optional[str], date: Optional[str], limit: int, format: str) -> str:
        validate_output_format(format)
        df = data_source.get_stock_industry(code=code, date=date)
        meta = {"code": code or "all", "as_of": date or "latest"}
        return format_table_output(df, format=format, max_rows=limit, meta=meta)
  • Concrete data source implementation that performs the actual Baostock API query for stock industry classification data.
    def get_stock_industry(self, code: Optional[str] = None, date: Optional[str] = None) -> pd.DataFrame:
        """Fetches industry classification using Baostock."""
        log_msg = f"Fetching industry data for code={code or 'all'}, date={date or 'latest'}"
        logger.info(log_msg)
        try:
            with baostock_login_context():
                rs = bs.query_stock_industry(code=code, date=date)
    
                if rs.error_code != '0':
                    logger.error(
                        f"Baostock API error (Industry) for {code}, {date}: {rs.error_msg} (code: {rs.error_code})")
                    if "no record found" in rs.error_msg.lower() or rs.error_code == '10002':
                        raise NoDataFoundError(
                            f"No industry data found for {code}, {date}. Baostock msg: {rs.error_msg}")
                    else:
                        raise DataSourceError(
                            f"Baostock API error fetching industry data: {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 industry data found for {code}, {date} (empty result set).")
                    raise NoDataFoundError(
                        f"No industry data found for {code}, {date} (empty result set).")
    
                result_df = pd.DataFrame(data_list, columns=rs.fields)
                logger.info(
                    f"Retrieved {len(result_df)} industry records for {code or 'all'}, {date or 'latest'}.")
                return result_df
    
        except (LoginError, NoDataFoundError, DataSourceError, ValueError) as e:
            logger.warning(
                f"Caught known error fetching industry data for {code}, {date}: {type(e).__name__}")
            raise e
        except Exception as e:
            logger.exception(
                f"Unexpected error fetching industry data for {code}, {date}: {e}")
            raise DataSourceError(
                f"Unexpected error fetching industry data for {code}, {date}: {e}")
Behavior2/5

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

No annotations are provided, so the description must fully disclose behavioral traits. It states the tool retrieves industry classification, implying a read-only operation, but does not cover critical aspects such as data freshness, rate limits, authentication needs, error handling, or return format details. For a tool with 4 parameters and no output schema, this leaves significant behavioral gaps, making it inadequate for informed use.

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

Conciseness5/5

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

The description is a single, efficient sentence that directly states the tool's purpose without unnecessary words. It is front-loaded with the core function, making it easy to parse. Every part of the sentence contributes to understanding, achieving optimal conciseness for the information provided.

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 the tool's complexity (4 parameters, no annotations, no output schema), the description is incomplete. It lacks details on parameter usage, behavioral constraints, return values, and differentiation from siblings. Without annotations or output schema, the description does not provide enough context for reliable tool invocation, leaving the agent with insufficient information for effective use.

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?

The schema description coverage is 0%, so the description must compensate by explaining parameters. It mentions 'specific stock or all stocks on a date,' which hints at the 'code' and 'date' parameters but does not define their semantics, formats, or constraints. It omits 'limit' and 'format' entirely. With 4 undocumented parameters, the description adds minimal value beyond the schema, failing to address the coverage gap.

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's purpose: 'Get industry classification for a specific stock or all stocks on a date.' It specifies the verb ('Get'), resource ('industry classification'), and scope ('specific stock or all stocks on a date'), making the function unambiguous. However, it does not explicitly differentiate from sibling tools like 'list_industries' or 'get_industry_members', which prevents a score of 5.

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. It mentions 'specific stock or all stocks' but does not clarify when to choose one over the other, nor does it reference sibling tools like 'list_industries' for broader industry listings or 'get_industry_members' for industry-specific stocks. This lack of contextual guidance leaves the agent without clear usage directives.

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