Skip to main content
Glama
24mlight

A Share MCP

get_stock_industry

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

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 main handler function for the 'get_stock_industry' MCP tool, decorated with @app.tool() for registration, logs the call, and delegates to the use case layer.
    @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'}",
        )
  • Use case helper that fetches industry data from data source, adds metadata, and formats output.
    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)
  • Core data source implementation querying Baostock API for stock industry classification.
    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}")
  • Abstract method in FinancialDataSource interface defining the schema for get_stock_industry.
    def get_stock_industry(self, code: Optional[str] = None, date: Optional[str] = None) -> pd.DataFrame:
        pass
  • mcp_server.py:53-53 (registration)
    Invocation of register_index_tools which defines and registers the get_stock_industry tool.
    register_index_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 of behavioral disclosure. It states the tool retrieves classification data but doesn't describe the return format, pagination behavior (though 'limit' parameter hints at it), error conditions, or data freshness. For a read operation with zero annotation coverage, this leaves significant gaps in understanding how the tool behaves.

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 front-loads the core purpose. There's no wasted wording, and it directly addresses what the tool does without unnecessary elaboration. It's appropriately sized for a straightforward data retrieval tool.

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 has 4 parameters with 0% schema coverage, no annotations, and no output schema, the description is incomplete. It doesn't explain parameter semantics, return values, or behavioral traits. For a tool that could return data for 'all stocks,' more context on output structure or limitations is needed, but the description lacks this.

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 schema provides no parameter descriptions. The description mentions 'a specific stock or all stocks on a date,' which loosely relates to the 'code' and 'date' parameters but doesn't explain their formats, defaults, or interactions. It ignores 'limit' and 'format' entirely. The description adds minimal value beyond the schema's structure.

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'). However, it doesn't explicitly differentiate from sibling tools like 'list_industries' or 'get_industry_members', which prevents a perfect score.

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 doesn't mention sibling tools like 'list_industries' (which might list industries without stock mappings) or 'get_industry_members' (which might list stocks within an industry), nor does it specify prerequisites or exclusions. The agent must infer usage from the purpose alone.

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