Skip to main content
Glama
24mlight

A-Share MCP Server

search_stocks

Search China A-share stocks by code substring on specific dates to identify trading status and retrieve matching stock information in multiple formats.

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 'search_stocks' tool handler function, registered via @app.tool(), which defines the tool schema via arguments and docstring, handles logging, and delegates to the core logic.
    @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 implementation of the search_stocks logic: input validation, fetch all stocks, filter by keyword in code column (case-insensitive), prepare metadata, and format output.
    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)
    Invocation of register_market_overview_tools which defines and registers the search_stocks tool handler to the FastMCP application.
    register_market_overview_tools(app, active_data_source)
Behavior2/5

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

With no annotations provided, the description carries full burden but only minimally describes behavior. It mentions the search returns 'matching stock codes with their trading status' but doesn't cover error handling, rate limits, authentication requirements, or what happens with invalid inputs.

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 with a clear purpose statement followed by Args and Returns sections. It's appropriately sized with no redundant information, though the formatting with extra quotes and indentation slightly reduces readability.

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?

For a search tool with 4 parameters, no annotations, and no output schema, the description covers the basic functionality and parameters adequately but lacks important context about error conditions, performance characteristics, and how it differs from similar tools in the extensive sibling set.

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 significant value beyond the 0% schema description coverage by clearly explaining all 4 parameters: 'keyword' as substring matching with examples, 'date' as optional with format and default behavior, 'limit' as max rows with default, and 'format' as output options with default. 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 by code substring') and resources ('stocks'), and distinguishes it from siblings by focusing on substring matching rather than retrieving specific data types like balance sheets or historical prices.

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 among the 40+ sibling tools. It doesn't mention prerequisites, use cases, or comparisons to tools like 'get_all_stock' or 'normalize_stock_code'.

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