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)

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