get_industry_members
Retrieve all stocks within a specific industry on a given date from China's A-share market to analyze sector composition and identify constituent companies.
Instructions
Get all stocks in a given industry on a date.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| industry | Yes | ||
| date | No | ||
| limit | No | ||
| format | No | markdown |
Implementation Reference
- src/tools/indices.py:74-81 (handler)MCP tool handler function for 'get_industry_members'. It logs the invocation and delegates execution to the 'fetch_industry_members' use case via 'run_tool_with_handling' for error handling and formatting.@app.tool() def get_industry_members(industry: str, date: Optional[str] = None, limit: int = 250, format: str = "markdown") -> str: """Get all stocks in a given industry on a date.""" logger.info("Tool 'get_industry_members' called industry=%s, date=%s", industry, date or "latest") return run_tool_with_handling( lambda: fetch_industry_members(active_data_source, industry=industry, date=date, limit=limit, format=format), context=f"get_industry_members:{industry}", )
- src/use_cases/indices.py:50-59 (helper)Core implementation logic that fetches all stock industry data, filters for the specified industry, handles empty cases, and formats the output as a table.def fetch_industry_members(data_source: FinancialDataSource, *, industry: str, date: Optional[str], limit: int, format: str) -> str: validate_output_format(format) validate_non_empty_str(industry, "industry") df = data_source.get_stock_industry(code=None, date=date) if df is None or df.empty: return "(No data available to display)" col = "industry" if "industry" in df.columns else df.columns[-1] filtered = df[df[col] == industry].copy() meta = {"industry": industry, "as_of": date or "latest"} return format_table_output(filtered, format=format, max_rows=limit, meta=meta)
- mcp_server.py:53-53 (registration)Top-level registration call that invokes the registration of index tools, including 'get_industry_members'.register_index_tools(app, active_data_source)
- src/tools/indices.py:21-21 (registration)Function that defines and registers all index-related tools, including the @app.tool() decorator for 'get_industry_members'.def register_index_tools(app: FastMCP, active_data_source: FinancialDataSource):