Skip to main content
Glama
24mlight

A Share MCP

search_stocks

Search for A-share stocks by code substring on a specific date, returning matching codes with trading status in your preferred format.

Instructions

    Search stocks by code substring on a date.

    Args:
        keyword: Substring to match in the stock code (e.g., '600', '000001').
        date: Optional 'YYYY-MM-DD'. If None, uses current date.
        limit: Max rows to return. Defaults to 50.
        format: Output format: 'markdown' | 'json' | 'csv'. Defaults to 'markdown'.

    Returns:
        Matching stock codes with their trading status.
    

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
keywordYes
dateNo
limitNo
formatNomarkdown

Implementation Reference

  • The handler function for the 'search_stocks' tool. It is registered via the @app.tool() decorator, logs the call, and delegates execution to the fetch_search_stocks helper via run_tool_with_handling.
    @app.tool()
    def search_stocks(keyword: str, date: Optional[str] = None, limit: int = 50, format: str = "markdown") -> str:
        """
        Search stocks by code substring on a date.
    
        Args:
            keyword: Substring to match in the stock code (e.g., '600', '000001').
            date: Optional 'YYYY-MM-DD'. If None, uses current date.
            limit: Max rows to return. Defaults to 50.
            format: Output format: 'markdown' | 'json' | 'csv'. Defaults to 'markdown'.
    
        Returns:
            Matching stock codes with their trading status.
        """
        logger.info("Tool 'search_stocks' called keyword=%s, date=%s, limit=%s, format=%s", keyword, date or "default", limit, format)
        return run_tool_with_handling(
            lambda: fetch_search_stocks(active_data_source, keyword=keyword, date=date, limit=limit, format=format),
            context=f"search_stocks:{keyword}",
        )
  • Core helper function that implements the search logic: validates inputs, fetches all stocks, filters by keyword substring in stock code, and formats the output table.
    def fetch_search_stocks(data_source: FinancialDataSource, *, keyword: str, date: Optional[str], limit: int, format: str) -> str:
        validate_output_format(format)
        validate_non_empty_str(keyword, "keyword")
        df = data_source.get_all_stock(date=date)
        if df is None or df.empty:
            return "(No data available to display)"
        kw = keyword.strip().lower()
        filtered = df[df["code"].str.lower().str.contains(kw, na=False)]
        meta = {"keyword": keyword, "as_of": date or "current"}
        return format_table_output(filtered, format=format, max_rows=limit, meta=meta)
  • mcp_server.py:54-54 (registration)
    The call to register_market_overview_tools which includes the registration of the search_stocks tool via its @app.tool() decorator.
    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 mentions the tool returns 'matching stock codes with their trading status,' which adds some behavioral context, but fails to disclose critical traits like whether this is a read-only operation, potential rate limits, error conditions, or how results are structured (e.g., pagination). For a search tool with zero annotation coverage, this is a significant gap.

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 appropriately sized and front-loaded, starting with the core purpose in the first sentence. The structured 'Args' and 'Returns' sections are efficient and zero-waste, with each sentence earning its place by clarifying parameters and output without redundancy.

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

Completeness3/5

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

Given the tool's moderate complexity (4 parameters, no output schema, no annotations), the description is partially complete. It excels in parameter semantics but lacks behavioral details (e.g., safety, limits) and doesn't fully explain the return values beyond 'matching stock codes with their trading status.' Without annotations or output schema, more context on behavior and results would improve completeness.

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

Parameters5/5

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

The description adds substantial meaning beyond the input schema, which has 0% description coverage. It explains each parameter's purpose (e.g., 'keyword: Substring to match in the stock code'), provides examples ('e.g., '600', '000001''), clarifies defaults ('Defaults to 50'), and enumerates options for 'format' ('markdown' | 'json' | 'csv'). This fully compensates for the schema's lack of descriptions.

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

Purpose5/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 with specific verbs ('search stocks') and resources ('by code substring on a date'), distinguishing it from sibling tools that retrieve specific data types (e.g., get_balance_data, get_historical_k_data) rather than performing substring searches. It precisely defines what the tool does without being vague or tautological.

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

Usage Guidelines3/5

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

The description implies usage through its purpose statement ('search stocks by code substring on a date'), suggesting it's for finding stocks matching a keyword. However, it lacks explicit guidance on when to use this tool versus alternatives like get_all_stock or normalize_stock_code, and doesn't mention prerequisites or exclusions, leaving the agent to infer context.

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